CVE-2018-19646
Imperva SecureSphere 13.x CGI remote code execution due to command-line argument mishandling
- CVSS 9.8
- CWE-78 Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')
- Input Validation and Sanitization
- Remote
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.
- CWE
- CWE-78 Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')
- CVSS base score
- 9.8
- Published
- 2018-11-28
- OWASP
- A03 Injection
- Orthogonal defect classification
- Function
- Code defect classification
- Incorrect Functionality
- Category
- Input Validation and Sanitization
- Subcategory
- Command Injection
- Accessibility scope
- Remote
- Impact
- Arbitrary Code Execution
- Affected component
- Python
- Fixed by upgrading
- Yes
Solution
Update Imperva SecureSphere to version 13.3.0 or higher.
Vulnerable code sample
import cgi
import subprocess
def handle_request(environ, start_response):
# Parse the query parameters directly
form = cgi.FieldStorage(environ=environ)
command = form.getvalue('command')
# Execute the command without validation
try:
result = subprocess.run(command, shell=True, capture_output=True, text=True, check=True)
start_response('200 OK', [('Content-Type', 'text/plain')])
return [result.stdout.encode()]
except subprocess.CalledProcessError as e:
start_response('500 Internal Server Error', [('Content-Type', 'text/plain')])
return [f'Error executing command: {e}'.encode()]Patched code sample
import cgi
import subprocess
def handle_request(environ, start_response):
# Parse the query parameters safely
form = cgi.FieldStorage(environ=environ)
command = form.getvalue('command')
# Validate the command to prevent arbitrary command execution
allowed_commands = ['list', 'status', 'info']
if command not in allowed_commands:
start_response('400 Bad Request', [('Content-Type', 'text/plain')])
return [b'Invalid command.']
# Safely execute the command
try:
result = subprocess.run(['my_script', command], capture_output=True, text=True, check=True)
start_response('200 OK', [('Content-Type', 'text/plain')])
return [result.stdout.encode()]
except subprocess.CalledProcessError as e:
start_response('500 Internal Server Error', [('Content-Type', 'text/plain')])
return [f'Error executing command: {e}'.encode()]Cite this entry
@misc{vaitp:cve201819646,
title = {{Imperva SecureSphere 13.x CGI remote code execution due to command-line argument mishandling}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2018},
note = {VAITP Python Vulnerability Dataset, entry CVE-2018-19646},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2018-19646/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.
The supreme art of war is to subdue the enemy without fighting.
Sun Tzu – “The Art of War”
:: Shaping the future through research and ingenuity ::
