File tree Expand file tree Collapse file tree 3 files changed +58
-0
lines changed
python/ql/test/experimental/dataflow/strange-essaflow Expand file tree Collapse file tree 3 files changed +58
-0
lines changed Original file line number Diff line number Diff line change 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 )
Original file line number Diff line number Diff line change 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()() |
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments