CVE-2017-9462
Remote code execution in Mercurial (before 4.1.3) via "hg serve –stdio" with "–debugger" repository name
- CVSS 8.8
- CWE-732 Incorrect Permission Assignment for Critical Resource
- Input Validation and Sanitization
- Remote
In Mercurial before 4.1.3, "hg serve –stdio" allows remote authenticated users to launch the Python debugger, and consequently execute arbitrary code, by using –debugger as a repository name.
- CVSS base score
- 8.8
- Published
- 2017-06-06
- OWASP
- A05 Security Misconfiguration
- 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
- Mercurial
- Fixed by upgrading
- Yes
Solution
Update Mercurial to version 4.1.3 or higher.
Vulnerable code sample
import sys
import code
def serve_hg(repository_name):
# Allow any repository name, including '--debugger'
print(f"Serving repository: {repository_name}")
# If the repository name is '--debugger', enter the debugger
if repository_name == '--debugger':
code.interact(local=locals()) # Launch the Python debugger
# Example of how the function would be called
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python serve_hg.py <repository_name>")
sys.exit(1)
repo_name = sys.argv[1]
serve_hg(repo_name)Patched code sample
import os
import sys
def serve_hg(repository_name):
# Prevent the use of '--debugger' as a repository name
if repository_name == '--debugger':
raise ValueError("Invalid repository name: '--debugger' is not allowed.")
# Proceed with serving the repository
print(f"Serving repository: {repository_name}")
# Additional code to serve the repository...
# Example of how the function would be called
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python serve_hg.py <repository_name>")
sys.exit(1)
repo_name = sys.argv[1]
serve_hg(repo_name)Cite this entry
@misc{vaitp:cve20179462,
title = {{Remote code execution in Mercurial (before 4.1.3) via "hg serve --stdio" with "--debugger" repository name}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2017},
note = {VAITP Python Vulnerability Dataset, entry CVE-2017-9462},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2017-9462/}}
}
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 ::
