CVE-2014-4650
Path Traversal Vulnerability
- CVSS 9.8
- CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
- Input Validation and Sanitization
- Remote
The CGIHTTPServer module in Python 2.7.5 and 3.3.4 does not properly handle URLs in which URL encoding is used for path separators, which allows remote attackers to read script source code or conduct directory traversal attacks and execute unintended code via a crafted character sequence, as demonstrated by a %2f separator.
- CVSS base score
- 9.8
- Published
- 2020-02-20
- OWASP
- A08 Software and Data Integrity Failures
- Orthogonal defect classification
- Algorithm
- Code defect classification
- Incorrect Algorithm
- Category
- Input Validation and Sanitization
- Subcategory
- Path Traversal
- Accessibility scope
- Remote
- Impact
- Information Disclosure, Arbitrary Code Execution
- Fixed by upgrading
- Yes
Solution
Upgrade to a patched version of Python.
Vulnerable code sample
import CGIHTTPServer
import BaseHTTPServer
# VULNERABLE: CGIHTTPServer allows path traversal attacks
# Attackers can access files outside the intended directory
if __name__ == "__main__":
server = BaseHTTPServer.HTTPServer(('', 8000), CGIHTTPServer.CGIHTTPRequestHandler)
server.serve_forever()
# Example attack: GET /../../../etc/passwdPatched code sample
import http.server
import socketserver
import os
from urllib.parse import unquote
class SecureHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
def translate_path(self, path):
# SECURE: Prevent path traversal by validating paths
path = unquote(path)
# Remove query parameters
path = path.split('?', 1)[0]
path = path.split('#', 1)[0]
# Normalize the path and check for traversal attempts
normalized = os.path.normpath(path)
if '..' in normalized or normalized.startswith('/'):
# Block path traversal attempts
return None
# Restrict to current directory only
safe_path = os.path.join(os.getcwd(), normalized.lstrip('/'))
# Ensure the path is within the allowed directory
if not safe_path.startswith(os.getcwd()):
return None
return safe_path
if __name__ == "__main__":
PORT = 8000
with socketserver.TCPServer(("", PORT), SecureHTTPRequestHandler) as httpd:
print(f"Serving at port {PORT} with path traversal protection")
httpd.serve_forever()Cite this entry
@misc{vaitp:cve20144650,
title = {{Path Traversal Vulnerability}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2020},
note = {VAITP Python Vulnerability Dataset, entry CVE-2014-4650},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2014-4650/}}
}
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 ::
