CVE-2018-15747
Remote code execution in glot-code-runner through May 19, 2018, via os.system in JSON files
- CVSS 9.8
- CWE-20 Improper Input Validation
- Input Validation and Sanitization
- Remote
The default configuration of glot-www through 2018-05-19 allows remote attackers to execute arbitrary code because glot-code-runner supports os.system within a "python" "files" "content" JSON file.
- CVSS base score
- 9.8
- Published
- 2019-06-21
- OWASP
- A06 Vulnerable and Outdated Components
- 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
- glot-code-runner
- Fixed by upgrading
- Yes
Solution
Update glot-code-runner to version 1.6.0 or higher.
Vulnerable code sample
import json
import os
def run_code(code):
# Directly executing the code which can be a security risk
exec(code)
def handle_request(request):
try:
data = json.loads(request)
code = data.get('files', {}).get('content', '')
run_code(code)
except Exception as e:
return str(e)
# Example request that would be processed
request = json.dumps({
"files": {
"content": "os.system('echo Hello, World!')"
}
})
# Running the request
response = handle_request(request)
print(response)Patched code sample
import json
import subprocess
def run_code(code):
# This function should be designed to safely execute code
# For example, using a restricted execution environment or sandbox
allowed_commands = ['print', 'len', 'sum'] # Example of allowed functions
for command in allowed_commands:
if command in code:
# Execute the code in a controlled environment
exec(code, {"__builtins__": None}, {})
return
raise ValueError("Unauthorized command detected.")
def handle_request(request):
try:
data = json.loads(request)
code = data.get('files', {}).get('content', '')
run_code(code)
except Exception as e:
return str(e)
# Example request that would be processed
request = json.dumps({
"files": {
"content": "print('Hello, World!')"
}
})
# Running the request
response = handle_request(request)
print(response)Cite this entry
@misc{vaitp:cve201815747,
title = {{Remote code execution in glot-code-runner through May 19, 2018, via os.system in JSON files}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2019},
note = {VAITP Python Vulnerability Dataset, entry CVE-2018-15747},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2018-15747/}}
}
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 ::
