Skip to content

Commit 710ca21

Browse files
Addressing comments we missed earlier
1 parent ef0d372 commit 710ca21

File tree

4 files changed

+17
-34
lines changed

4 files changed

+17
-34
lines changed

csharp/ql/src/experimental/Security Features/backdoor/ProcessNameToHashTaintFlow.ql

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@ predicate isGetHash(Expr arg) {
3636
mc.getAnArgument() = arg
3737
)
3838
or
39-
exists(Callable callable, Parameter param, Call call, int i |
39+
exists(Callable callable, Parameter param, Call call |
4040
isCallableAPotentialNonCryptographicHashFunction(callable, param) and
41-
callable.getParameter(i) = param and
4241
call = callable.getACall() and
43-
call.getArgument(i) = arg
42+
arg = call.getArgumentForParameter(param)
4443
)
4544
}
4645

csharp/ql/src/experimental/Security Features/campaign/Solorigate/NumberOfKnownMethodNamesAboveThreshold.qhelp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<qhelp>
55
<overview>
66
<p>This query detects method names used in the Solorigate code.</p>
7-
<p>This query detects when the code includes at least 50 of the mthods used in the Solorigate tampered code</p>
7+
<p>This query detects when the code includes at least 50 of the methods used in the Solorigate tampered code</p>
88
<p>Please notice that by themselves these method names are not malign.</p>
99
</overview>
1010

csharp/ql/src/experimental/Security Features/campaign/Solorigate/NumberOfKnownMethodNamesAboveThreshold.ql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ import Solorigate
1818
*/
1919

2020
int countSolorigateSuspiciousMethodNames() {
21-
result =
22-
count(string s | exists(Method m | s = m.getName() and s = solorigateSuspiciousMethodNames()))
21+
result = count(string s | s = any(Method m | isSolorigateSuspiciousMethodName(m)).getName())
2322
}
2423

2524
from Method m, int total, int threshold

csharp/ql/src/experimental/code/csharp/Cryptography/NonCryptographicHashes.qll

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,15 @@ predicate maybeANonCryptogrphicHash(Callable callable, Variable v, Expr xor, Exp
2323
* where there is a loop statement `loop` where the variable `v` is used in an xor `xor` expression
2424
* followed by a multiplication `mul` expression.
2525
*/
26-
predicate maybeUsedInFNVFunction(Variable v, Expr xor, Expr mul, LoopStmt loop) {
26+
predicate maybeUsedInFNVFunction(Variable v, Operation xor, Operation mul, LoopStmt loop) {
2727
exists(Expr e1, Expr e2 |
28-
exists(Operation axore, Operation amule | xor = axore and mul = amule |
29-
e1.getAChild*() = v.getAnAccess() and
30-
e2.getAChild*() = v.getAnAccess() and
31-
e1 = axore.getAnOperand() and
32-
e2 = amule.getAnOperand() and
33-
axore.getAControlFlowNode().getASuccessor*() = amule.getAControlFlowNode() and
34-
(axore instanceof AssignXorExpr or axore instanceof BitwiseXorExpr) and
35-
(amule instanceof AssignMulExpr or amule instanceof MulExpr)
36-
)
28+
e1.getAChild*() = v.getAnAccess() and
29+
e2.getAChild*() = v.getAnAccess() and
30+
e1 = xor.getAnOperand() and
31+
e2 = mul.getAnOperand() and
32+
xor.getAControlFlowNode().getASuccessor*() = mul.getAControlFlowNode() and
33+
(xor instanceof AssignXorExpr or xor instanceof BitwiseXorExpr) and
34+
(mul instanceof AssignMulExpr or mul instanceof MulExpr)
3735
) and
3836
loop.getAChild*() = mul.getEnclosingStmt() and
3937
loop.getAChild*() = xor.getEnclosingStmt()
@@ -44,13 +42,11 @@ predicate maybeUsedInFNVFunction(Variable v, Expr xor, Expr mul, LoopStmt loop)
4442
* where there is a loop statement `loop` where the variable `v` is used in an xor `xor` expression
4543
* followed by an addition `add` expression.
4644
*/
47-
predicate maybeUsedInElfHashFunction(Variable v, Expr xorExpr, Expr addExpr, LoopStmt loop) {
45+
private predicate maybeUsedInElfHashFunction(Variable v, Operation xor, Operation add, LoopStmt loop) {
4846
exists(
49-
Expr e1, Operation add, Expr e2, AssignExpr addAssign, Operation xor, AssignExpr xorAssign,
50-
Operation notOp, AssignExpr notAssign
47+
Expr e1, Expr e2, AssignExpr addAssign, AssignExpr xorAssign, Operation notOp,
48+
AssignExpr notAssign
5149
|
52-
xorExpr = xor and
53-
addExpr = add and
5450
(add instanceof AddExpr or add instanceof AssignAddExpr) and
5551
e1.getAChild*() = add.getAnOperand() and
5652
e1 instanceof BinaryBitwiseOperation and
@@ -70,17 +66,6 @@ predicate maybeUsedInElfHashFunction(Variable v, Expr xorExpr, Expr addExpr, Loo
7066
)
7167
}
7268

73-
/**
74-
* Any dataflow from any source to any sink, used internally
75-
*/
76-
private class AnyDataFlow extends TaintTracking2::Configuration {
77-
AnyDataFlow() { this = "DataFlowFromDataGatheringMethodToVariable" }
78-
79-
override predicate isSource(Node source) { any() }
80-
81-
override predicate isSink(Node sink) { any() }
82-
}
83-
8469
/**
8570
* Holds if the Callable is a function that behaves like a non-cryptographic hash
8671
* where the parameter `param` is likely the message to hash
@@ -94,13 +79,13 @@ predicate isCallableAPotentialNonCryptographicHashFunction(Callable callable, Pa
9479
or
9580
param.getAnAccess() = op2.(Operation).getAnOperand().getAChild*()
9681
or
97-
exists(AnyDataFlow config, Node source, Node sink |
82+
exists(Node source, Node sink |
9883
(
9984
sink.asExpr() = op1.(Operation).getAChild*() or
10085
sink.asExpr() = op2.(Operation).getAChild*()
10186
) and
10287
source.asExpr() = param.getAnAccess() and
103-
config.hasFlow(source, sink)
88+
DataFlow::localFlow(source, sink)
10489
)
10590
)
10691
)

0 commit comments

Comments
 (0)