CVE-2018-8097 (published 2018-03-14T12:29Z)

io/mongo/parser.py in Eve (aka pyeve) before 0.7.5 allows remote attackers to execute arbitrary code via Code Injection in the where parameter.

Severity: HIGH
CVSS v2 base score: 7.5 (AV:N/AC:L/Au:N/C:P/I:P/A:P)
CVSS v3 base score: 9.8, CRITICAL (CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H)

Weakness information:
cwe_id: CWE-94
cwe_name: Improper Control of Generation of Code ('Code Injection')
description: The product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment.
extended_description: 
            When a product allows a user's input to contain code syntax, it might be possible for an attacker to craft the code in such a way that it will alter the intended control flow of the product. Such an alteration could lead to arbitrary code execution.
            Injection problems encompass a wide variety of issues -- all mitigated in very different ways. For this reason, the most effective way to discuss these weaknesses is to note the distinct features which classify them as injection weaknesses. The most important issue to note is that all injection problems share one thing in common -- i.e., they allow for the injection of control plane data into the user-controlled data plane. This means that the execution of the process may be altered by sending code in through legitimate data channels, using no other mechanism. While buffer overflows, and many other flaws, involve the use of some further issue to gain execution, injection problems need only for the data to be parsed. The most classic instantiations of this category of weakness are SQL injection and format string vulnerabilities.
         
         

Fix information:
repo_url: https://github.com/pyeve/eve
commit_details: repo_url: https://github.com/pyeve/eve
author: Nicola Iarocci
author_date: 2018-01-14 17:51:26+01:00
msg: fix mongo visitor parser
repository: repo_url: https://github.com/pyeve/eve
repo_name: pyeve/eve
description: REST API framework designed for human beings
repo_language: Python
owner: pyeve
file_changes: filename: parser.py
change_type: ModificationType.MODIFY
diff: @@ -122,16 +122,19 @@ class MongoVisitor(ast.NodeVisitor):
         datetime().
         """
         if isinstance(node.func, ast.Name):
-            expr = None
             if node.func.id == 'ObjectId':
-                expr = "('" + node.args[0].s + "')"
+                try:
+                    self.current_value = ObjectId(node.args[0].s)
+                except:
+                    pass
             elif node.func.id == 'datetime':
                 values = []
                 for arg in node.args:
-                    values.append(str(arg.n))
-                expr = "(" + ", ".join(values) + ")"
-            if expr:
-                self.current_value = eval(node.func.id + expr)
+                    values.append(arg.n)
+                try:
+                    self.current_value = datetime(*values)
+                except:
+                    pass
 
     def visit_Attribute(self, node):
         """ Attribute handler ('Contact.Id').

programming_language: Python