{"id":574,"cve":"CVE-2018-19646","cve_url":"https:\/\/www.cvedetails.com\/cve\/CVE-2018-19646","cwe":"CWE-78 Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')","cwe_number":78,"cwe_url":"https:\/\/cwe.mitre.org\/data\/definitions\/78","cvss_score":9.8,"published":"2018-11-28","owasp":"A03 Injection","odc":"Function","cdc":"Incorrect Functionality","category":"Input Validation and Sanitization","subcategory":"Command Injection","scope":"Remote","impact":"Arbitrary Code Execution","summary":"Imperva SecureSphere 13.x CGI remote code execution due to command-line argument mishandling","permalink":"https:\/\/netpack.pt\/vaitp\/vulnerability\/CVE-2018-19646\/","description":"The Python CGI scripts in PWS in Imperva SecureSphere 13.0.10, 13.1.10, and 13.2.10 allow remote attackers to execute arbitrary OS commands because command-line arguments are mishandled.","solution":"Update Imperva SecureSphere to version 13.3.0 or higher.","affected_component":"Python","fixed_by_upgrading":true,"vulnerable_code":"import cgi\nimport subprocess\n\ndef handle_request(environ, start_response):\n    # Parse the query parameters directly\n    form = cgi.FieldStorage(environ=environ)\n    command = form.getvalue('command')\n\n    # Execute the command without validation\n    try:\n        result = subprocess.run(command, shell=True, capture_output=True, text=True, check=True)\n        start_response('200 OK', [('Content-Type', 'text\/plain')])\n        return [result.stdout.encode()]\n    except subprocess.CalledProcessError as e:\n        start_response('500 Internal Server Error', [('Content-Type', 'text\/plain')])\n        return [f'Error executing command: {e}'.encode()]","patched_code":"import cgi\nimport subprocess\n\ndef handle_request(environ, start_response):\n    # Parse the query parameters safely\n    form = cgi.FieldStorage(environ=environ)\n    command = form.getvalue('command')\n\n    # Validate the command to prevent arbitrary command execution\n    allowed_commands = ['list', 'status', 'info']\n    if command not in allowed_commands:\n        start_response('400 Bad Request', [('Content-Type', 'text\/plain')])\n        return [b'Invalid command.']\n\n    # Safely execute the command\n    try:\n        result = subprocess.run(['my_script', command], capture_output=True, text=True, check=True)\n        start_response('200 OK', [('Content-Type', 'text\/plain')])\n        return [result.stdout.encode()]\n    except subprocess.CalledProcessError as e:\n        start_response('500 Internal Server Error', [('Content-Type', 'text\/plain')])\n        return [f'Error executing command: {e}'.encode()]","payload_needed":false,"payload":null,"payload_status":"none","published_fix":[],"references":null}