CVE-2018-16168
Remote Python code injection in LogonTracer 1.2.0 and earlier
- CVSS 9.8
- CWE-94 Improper Control of Generation of Code ('Code Injection')
- Input Validation and Sanitization
- Remote
LogonTracer 1.2.0 and earlier allows remote attackers to conduct Python code injection attacks via unspecified vectors.
- CVSS base score
- 9.8
- Published
- 2019-01-09
- OWASP
- A03 Injection
- 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
- Python
- Fixed by upgrading
- Yes
Solution
Update LogonTracer to version 1.2.1 or higher.
Vulnerable code sample
def execute_user_input(user_input):
# Vulnerable code that directly evaluates user input
result = eval(user_input)
return result
# Example usage
user_input = "__import__('os').system('ls')" # This input could be provided by an attacker
result = execute_user_input(user_input)
print(result)Patched code sample
import ast
def safe_eval(expression):
# Only allow specific nodes in the expression to prevent arbitrary code execution
allowed_nodes = {
ast.Expression,
ast.BinOp,
ast.UnaryOp,
ast.Num,
ast.Str,
ast.Name,
ast.Load,
ast.Add,
ast.Sub,
ast.Mult,
ast.Div,
ast.Mod,
ast.Pow,
ast.BitXor,
ast.USub,
ast.UAdd,
ast.Compare,
ast.Eq,
ast.NotEq,
ast.Lt,
ast.LtE,
ast.Gt,
ast.GtE,
ast.BoolOp,
ast.And,
ast.Or,
}
def _check_node(node):
if type(node) not in allowed_nodes:
raise ValueError("Disallowed expression")
# Parse the expression and check for disallowed nodes
tree = ast.parse(expression, mode='eval')
for node in ast.walk(tree):
_check_node(node)
# Safely evaluate the expression
return eval(compile(tree, filename='', mode='eval'))
# Example usage
user_input = "2 + 2" # This should be a safe mathematical expression
result = safe_eval(user_input)
print(result) # Output: 4Cite this entry
@misc{vaitp:cve201816168,
title = {{Remote Python code injection in LogonTracer 1.2.0 and earlier}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2019},
note = {VAITP Python Vulnerability Dataset, entry CVE-2018-16168},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2018-16168/}}
}
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 ::
