CVE-2023-37273
Docker-compose.yml write vulnerability
- CVSS 8.8
- CWE-94 Improper Control of Generation of Code ('Code Injection')
- Input Validation and Sanitization
- Remote
Auto-GPT is an experimental open-source application showcasing the capabilities of the GPT-4 language model. Running Auto-GPT version prior to 0.4.3 by cloning the git repo and executing `docker compose run auto-gpt` in the repo root uses a different docker-compose.yml file from the one suggested in the official docker set up instructions. The docker-compose.yml file located in the repo root mounts itself into the docker container without write protection. This means that if malicious custom python code is executed via the `execute_python_file` and `execute_python_code` commands, it can overwrite the docker-compose.yml file and abuse it to gain control of the host system the next time Auto-GPT is started. The issue has been patched in version 0.4.3.
- CVSS base score
- 8.8
- Published
- 2023-07-13
- OWASP
- A05 Security Misconfiguration
- Orthogonal defect classification
- Function
- Code defect classification
- Incorrect Functionality
- Category
- Input Validation and Sanitization
- Subcategory
- Insecure Parsing or Deserialization
- Accessibility scope
- Remote
- Impact
- Arbitrary Code Execution
- Fixed by upgrading
- Yes
Solution
Update AutoGPT to version 0.4.3 or higher.
Vulnerable code sample
def execute_python_code(code):
"""Vulnerable function that demonstrates the security issue."""
exec(code)
code = """
with open('docker-compose.yml', 'w') as f:
f.write('version: "3.8"\\nservices:\\n app:\\n image: image')
"""
execute_python_code(code)Patched code sample
import ast
import os
SAFE_BUILTINS = {
'__builtins__': {
'open': open,
'print': print,
'len': len,
'sum': sum
}
}
DANGEROUS_KEYWORDS = ['import', 'os', 'subprocess', 'eval', 'exec', 'system', 'open', '__import__', 'getattr', 'setattr']
def check_code(code):
"""Secure function that fixes the vulnerability."""
try:
tree = ast.parse(code)
except SyntaxError:
return False
for node in ast.walk(tree):
if isinstance(node, ast.Call):
if isinstance(node.func, ast.Name) and node.func.id in DANGEROUS_KEYWORDS:
return False
if isinstance(node, ast.Import):
return False
if isinstance(node, ast.ImportFrom):
return False
if isinstance(node, ast.Assign):
for target in node.targets:
if isinstance(target, ast.Name) and target.id in DANGEROUS_KEYWORDS:
return False
return True
def execute_python_code(code):
"""Secure function that fixes the vulnerability."""
if check_code(code):
exec(code, SAFE_BUILTINS)
print("Code executed successfully.")
else:
print("Unsafe code detected. Execution aborted.")
code = """
import os
os.system('echo Hello World')
"""
print("\nTesting Code:")
execute_python_code(code)Cite this entry
@misc{vaitp:cve202337273,
title = {{Docker-compose.yml write vulnerability}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2023},
note = {VAITP Python Vulnerability Dataset, entry CVE-2023-37273},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2023-37273/}}
}
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 ::
