-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcsharp-customizations.qll
53 lines (44 loc) · 1.86 KB
/
csharp-customizations.qll
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import csharp
import semmle.code.csharp.security.dataflow.flowsources.Remote
import semmle.code.csharp.security.dataflow.SqlInjection::SqlInjection as SqlInjection
/////////////////////////// CUSTOMIZE HERE ////////////////////////////////////////////////////
string taintedCalls() {
result = [
"System.Environment.GetEnvironmentVariable", // all invocations of this method return tainted data
"%.copy" // ditto, just matching on the callable's name
]
}
string taintedParams() {
result = [
"Dapper.Samples.Advanced.SQLServerFeatures.PrepareDatabase:0", // exact match with exact index
"com.org.Type.myMethod:1", // ditto
"%.myMethod:1", // match just on the name of a method and an index
"%.myMethod:%" // match just on the name of a method and all its parameters
]
}
// call arguments pertaining to these parameters will be treated as sql injection sinks
string sqlInjectionSinks() {
result = [
"Dapper.SqlMapper.Query%:1",
"%Execute%:1"
]
}
///////////////////////////////////////////////////////////////////////////////////////////////
string paramSignature(Parameter p) {
result = p.getCallable().getQualifiedName() + ":" + p.getPosition()
}
class TaintedParameters extends RemoteFlowSource {
TaintedParameters() { paramSignature(this.asParameter()).matches(taintedParams()) }
override string getSourceType() { result = "Custom tainted parameter" }
}
class TaintedCalls extends RemoteFlowSource {
TaintedCalls() { this.asExpr().(Call).getTarget().getQualifiedName().matches(taintedCalls()) }
override string getSourceType() { result = "Custom tainted call" }
}
class SqlInjectionSink extends SqlInjection::Sink {
SqlInjectionSink() {
exists(Parameter p | paramSignature(p).matches(sqlInjectionSinks()) |
this.asExpr() = p.getCallable().getACall().getArgumentForParameter(p)
)
}
}