{"id":918,"cve":"CVE-2018-11776","cve_url":"https:\/\/www.cvedetails.com\/cve\/CVE-2018-11776","cwe":"CWE-20 Improper Input Validation","cwe_number":20,"cwe_url":"https:\/\/cwe.mitre.org\/data\/definitions\/20","cvss_score":8.1,"published":"2018-08-22","owasp":"A03 Injection","odc":"Function","cdc":"Incorrect Functionality","category":"Input Validation and Sanitization","subcategory":"Command Injection","scope":"Remote","impact":"Arbitrary Code Execution","summary":"Apache Struts 2.3 to 2.3.34 and 2.5 to 2.5.16: Remote Code Execution via alwaysSelectFullNamespace","permalink":"https:\/\/netpack.pt\/vaitp\/vulnerability\/CVE-2018-11776\/","description":"Apache Struts versions 2.3 to 2.3.34 and 2.5 to 2.5.16 suffer from possible Remote Code Execution when alwaysSelectFullNamespace is true (either by user or a plugin like Convention Plugin) and then: results are used with no namespace and in same time, its upper package have no or wildcard namespace and similar to results, same possibility when using url tag which doesn't have value and action set and in same time, its upper package have no or wildcard namespace.","solution":"Update Apache Struts to version 2.5.17 or higher.","affected_component":"Apache Struts","fixed_by_upgrading":true,"vulnerable_code":"from flask import Flask, request\n\napp = Flask(__name__)\n\n@app.route('\/execute', methods=['POST'])\ndef execute_action():\n    \"\"\"Vulnerable function that demonstrates the security issue.\"\"\"\n    action = request.form.get('action')\n\n    if action:\n        exec(action)\n\n    return \"Action executed\"\n\nif __name__ == '__main__':\n    app.run()","patched_code":"from flask import Flask, request, abort\n\napp = Flask(__name__)\n\nBLACKLIST = {'import', 'exec', 'eval', 'open', '__', 'os', 'system', 'subprocess'}\n\ndef check_action(action):\n    \"\"\"Secure function that fixes the vulnerability.\"\"\"\n    if not action:\n        return False\n    lowered = action.lower()\n    for bad_word in BLACKLIST:\n        if bad_word in lowered:\n            return False\n    return True\n\n@app.route('\/execute', methods=['POST'])\ndef execute_action():\n    \"\"\"Secure function that fixes the vulnerability.\"\"\"\n    action = request.form.get('action')\n\n    if not check_action(action):\n        abort(400, \"Unsafe action\")\n\n    try:\n        exec(action)\n    except Exception as e:\n        abort(500, f\"Execution error: {e}\")\n    \n    return \"Action executed\"\n\nif __name__ == '__main__':\n    app.run()\n","payload_needed":false,"payload":null,"payload_status":"none","published_fix":[],"references":null}