CVE-2018-6353
Python console in Electrum v2.9.4 – v3.0.5 allows arbitrary code execution, risking Bitcoin theft
- CVSS 7.8
- CWE-78 Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')
- Input Validation and Sanitization
- Local
The Python console in Electrum through 2.9.4 and 3.x through 3.0.5 supports arbitrary Python code without considering (1) social-engineering attacks in which a user pastes code that they do not understand and (2) code pasted by a physically proximate attacker at an unattended workstation, which makes it easier for attackers to steal Bitcoin via hook code that runs at a later time when the wallet password has been entered, a different vulnerability than CVE-2018-1000022.
- CWE
- CWE-78 Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')
- CVSS base score
- 7.8
- Published
- 2018-01-27
- OWASP
- A03 Injection
- Orthogonal defect classification
- Function
- Code defect classification
- Incorrect Functionality
- Category
- Input Validation and Sanitization
- Subcategory
- Insecure Parsing or Deserialization
- Accessibility scope
- Local
- Impact
- Arbitrary Code Execution
- Affected component
- Electrum
- Fixed by upgrading
- Yes
Solution
Update Electrum to version 3.0.6 or higher.
Vulnerable code sample
# Vulnerable Python console code example
user_input = input("Enter your Python code: ")
exec(user_input) # This allows arbitrary code executionPatched code sample
import ast
import sys
class SafeEval:
def __init__(self):
self.allowed_nodes = {
ast.Expression,
ast.BinOp,
ast.UnaryOp,
ast.Num,
ast.Str,
ast.List,
ast.Tuple,
ast.Name,
ast.Load,
ast.Store,
ast.Assign,
ast.Call,
ast.Attribute,
ast.FunctionDef,
ast.arguments,
ast.arg,
}
def is_safe(self, node):
if type(node) not in self.allowed_nodes:
raise ValueError("Unsafe node type: {}".format(type(node)))
for child in ast.iter_child_nodes(node):
self.is_safe(child)
def safe_eval(self, code):
tree = ast.parse(code, mode='eval')
self.is_safe(tree)
return eval(compile(tree, filename="<ast>", mode="eval"))
# Example of usage
if __name__ == "__main__":
safe_eval = SafeEval()
user_input = input("Enter your Python code: ")
try:
result = safe_eval.safe_eval(user_input)
print("Result:", result)
except Exception as e:
print("Error:", e)Published fix
Public sources link this CVE to the changes below. The code samples above were generated to illustrate the defect; these links lead to the code the project actually changed.
- Add a warning about harmful code to the Qt console (spesmilo/electrum)
gui/qt/console.py,gui/qt/console.py · Console.__init__
Cite this entry
@misc{vaitp:cve20186353,
title = {{Python console in Electrum v2.9.4 - v3.0.5 allows arbitrary code execution, risking Bitcoin theft}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2018},
note = {VAITP Python Vulnerability Dataset, entry CVE-2018-6353},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2018-6353/}}
}
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 ::
