CVE-2023-46404
PCRS <= 3.11 (d0de1e) remote code execution (RCE)
- CVSS 9.9
- CWE-94 Improper Control of Generation of Code ('Code Injection')
- Input Validation and Sanitization
- Remote
PCRS <= 3.11 (d0de1e) “Questions” page and “Code editor” page are vulnerable to remote code execution (RCE) by escaping Python sandboxing.
- CVSS base score
- 9.9
- Published
- 2023-11-03
- OWASP
- A03 Injection
- Orthogonal defect classification
- Checking
- Code defect classification
- Missing Check
- Category
- Input Validation and Sanitization
- Subcategory
- Command Injection
- Accessibility scope
- Remote
- Impact
- Arbitrary Code Execution
- Fixed by upgrading
- Yes
Solution
Update PCRS to version 3.12 or higher
Vulnerable code sample
def execute_user_code(user_input):
"""Vulnerable function that demonstrates the security issue."""
try:
result = eval(user_input)
return result
except Exception as e:
return str(e)
user_input = "__import__('os').system('ls')"
output = execute_user_code(user_input)
print("Output:", output)Patched code sample
import ast
import traceback
def check_eval(expr):
"""Secure function that fixes the vulnerability."""
allowed_nodes = {
ast.Expression,
ast.Constant,
ast.List,
ast.Tuple,
ast.Dict,
ast.Name,
ast.Load,
ast.BinOp,
ast.UnaryOp,
ast.Compare,
ast.BoolOp,
ast.IfExp,
ast.Call,
ast.Subscript,
ast.Slice,
ast.Add,
ast.Sub,
ast.Mult,
ast.Div,
ast.Mod,
ast.Pow,
ast.Lt,
ast.Gt,
ast.LtE,
ast.GtE,
ast.Eq,
ast.NotEq,
ast.And,
ast.Or,
ast.Not,
ast.USub
}
allowed_names = {
'abs': abs,
'min': min,
'max': max,
'sum': sum,
'len': len,
'round': round,
'sorted': sorted,
}
class EvalVisitor(ast.NodeVisitor):
def visit(self, node):
"""Secure function that fixes the vulnerability."""
if type(node) not in allowed_nodes:
raise ValueError(f"Disallowed operation: {type(node).__name__}")
return self.generic_visit(node)
tree = ast.parse(expr, mode='eval')
EvalVisitor().visit(tree)
code = compile(tree, filename="<ast>", mode="eval")
return eval(code, {"__builtins__": {}}, allowed_names)
try:
user_input = "__import__('os').system('ls')"
result = check_eval(user_input)
print("Result:", result)
except Exception as e:
print("Error:", traceback.format_exc())Cite this entry
@misc{vaitp:cve202346404,
title = {{PCRS <= 3.11 (d0de1e) remote code execution (RCE)}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2023},
note = {VAITP Python Vulnerability Dataset, entry CVE-2023-46404},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2023-46404/}}
}
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 ::
