Skip to content

Commit 38f0f07

Browse files
committed
modeled some user input, sanitizers
1 parent 22ff3a3 commit 38f0f07

File tree

1 file changed

+29
-30
lines changed

1 file changed

+29
-30
lines changed

powershell/ql/src/experimental/InjectionHunter/UserInputToDangerousMethod.ql

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ private module TestConfig implements DataFlow::ConfigSig {
2222
c.getName() = "Read-Host" and
2323
source.asExpr().getExpr() = c) }
2424

25-
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
25+
predicate isSink(DataFlow::Node sink) { any()}//sink instanceof Sink }
2626
predicate isBarrier(DataFlow::Node node) {node instanceof Sanitizer}
2727
}
2828

@@ -98,37 +98,33 @@ class AddScriptInvokeSink extends Sink {
9898

9999
abstract class Sanitizer extends DataFlow::Node {}
100100

101-
// class TypedParameterSanitizer extends Sanitizer{
102-
// TypedParameterSanitizer() {
103-
// exists(Function f, CmdCall c, Parameter p, Argument a |
104-
// p = f.getAParameter() and
105-
// a = c.getAnArgument() and
106-
// p.getName().toLowerCase() = a.getName() and
107-
// p.getStaticType() != "Object" and
108-
// c.getName() = f.getName() and
109-
110-
// this.asExpr().getExpr() = a
111-
// )
101+
// class TypedParameterSanitizer extends Sanitizer {
102+
// TypedParameterSanitizer() {
103+
// exists(Function f, Parameter p |
104+
// p = f.getAParameter() and
105+
// p.getStaticType() != "Object" and
106+
// this.asParameter() = p
107+
// )
112108
// }
113109
// }
114110

115-
class SingleQuoteSanitizer extends Sanitizer {
116-
SingleQuoteSanitizer() {
117-
exists(Expr e, VarReadAccess v |
118-
e = this.asExpr().getExpr().getParent() and
119-
e.toString().matches("%'$" + v.getVariable().getName() + "'%")
120-
)
121-
}
122-
}
111+
// class SingleQuoteSanitizer extends Sanitizer {
112+
// SingleQuoteSanitizer() {
113+
// exists(Expr e, VarReadAccess v |
114+
// e = this.asExpr().getExpr().getParent() and
115+
// e.toString().matches("%'$" + v.getVariable().getName() + "'%")
116+
// )
117+
// }
118+
// }
123119

124120
module TestFlow = TaintTracking::Global<TestConfig>;
125121
import TestFlow::PathGraph
126122

127-
// from TestFlow::PathNode source, TestFlow::PathNode sink
128-
// where
129-
// TestFlow::flowPath(source, sink) and
130-
// sink.getNode().asExpr().getExpr().getLocation().getFile().getBaseName() = "sanitizers.ps1"
131-
// select sink.getNode(), source, sink, "Flow from user input to Invoke-Expression"
123+
from TestFlow::PathNode source, TestFlow::PathNode sink
124+
where
125+
TestFlow::flowPath(source, sink) and
126+
sink.getNode().asExpr().getExpr().getLocation().getFile().getBaseName() = "sanitizers.ps1"
127+
select sink.getNode(), source, sink, "Flow from user input to Invoke-Expression"
132128

133129
// from Function f, CmdCall c
134130
// where f.getLocation().getFile().getBaseName() = "sanitizers.ps1"
@@ -155,15 +151,18 @@ import TestFlow::PathGraph
155151
// and e.getLocation().getStartLine() = 14
156152
// select e, e.getAChild(), e.getParent(), e.toString()
157153

154+
// from PipelineParameter p
155+
// where p.getLocation().getFile().getBaseName() = "userinput.ps1"
156+
// select p, p.getName(), p.getAChild()
157+
158+
// from Attribute a
159+
// select a, a.getParent(), a.getParent().getAQlClass(), a.getANamedArgument()
158160

159-
from Parameter p
160-
where p.getLocation().getFile().getBaseName() = "userinput.ps1"
161-
// p.getAnAttribute().toString() = "ValueFromPipeline" and
162161

163-
select p, p.getName()
164162

165163
// from Expr e
166-
// where e.getLocation().getFile().getBaseName() = "userinput.ps1"
164+
// where e.getLocation().getFile().getBaseName() = "sanitizers.ps1"
165+
// and e.getLocation().getStartLine() = 31
167166
// select e, e.getAQlClass()
168167

169168
// from InvokeMemberExpr ie

0 commit comments

Comments
 (0)