Skip to content

Commit 5ffc959

Browse files
authored
Merge pull request #4211 from RasmusWL/python-strange-essaflow
Python: Add example of strange DataFlow::jumpStep
2 parents 5d1c2a3 + cf57afd commit 5ffc959

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
import os
3+
4+
from flask import Flask, request
5+
app = Flask(__name__)
6+
7+
@app.route("/command1")
8+
def command_injection1():
9+
files = request.args.get('files', '')
10+
# Don't let files be `; rm -rf /`
11+
os.system("ls " + files)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
os_import
2+
| test.py:2:8:2:9 | GSSA Variable os |
3+
flowstep
4+
jumpStep
5+
| test.py:2:8:2:9 | GSSA Variable os | test.py:5:7:5:21 | ControlFlowNode for Flask() |
6+
| test.py:2:8:2:9 | GSSA Variable os | test.py:7:2:7:23 | ControlFlowNode for Attribute() |
7+
| test.py:2:8:2:9 | GSSA Variable os | test.py:7:2:7:23 | ControlFlowNode for Attribute()() |
8+
essaFlowStep
9+
| test.py:2:8:2:9 | GSSA Variable os | test.py:5:7:5:21 | ControlFlowNode for Flask() |
10+
| test.py:2:8:2:9 | GSSA Variable os | test.py:7:2:7:23 | ControlFlowNode for Attribute() |
11+
| test.py:2:8:2:9 | GSSA Variable os | test.py:7:2:7:23 | ControlFlowNode for Attribute()() |
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import python
2+
import experimental.dataflow.DataFlow
3+
4+
/** Gets the EssaNode that holds the module imported by the fully qualified module name `name` */
5+
DataFlow::EssaNode module_import(string name) {
6+
exists(Variable var, Import imp, Alias alias |
7+
alias = imp.getAName() and
8+
alias.getAsname() = var.getAStore() and
9+
(
10+
name = alias.getValue().(ImportMember).getImportedModuleName()
11+
or
12+
name = alias.getValue().(ImportExpr).getImportedModuleName()
13+
) and
14+
result.getVar().(AssignmentDefinition).getSourceVariable() = var
15+
)
16+
}
17+
18+
query predicate os_import(DataFlow::Node node) {
19+
node = module_import("os") and
20+
exists(node.getLocation().getFile().getRelativePath())
21+
}
22+
23+
query predicate flowstep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
24+
os_import(nodeFrom) and
25+
DataFlow::localFlowStep(nodeFrom, nodeTo)
26+
}
27+
28+
query predicate jumpStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
29+
os_import(nodeFrom) and
30+
DataFlow::jumpStep(nodeFrom, nodeTo)
31+
}
32+
33+
query predicate essaFlowStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
34+
os_import(nodeFrom) and
35+
DataFlow::EssaFlow::essaFlowStep(nodeFrom, nodeTo)
36+
}

0 commit comments

Comments
 (0)