Skip to content

Commit d77ba02

Browse files
committed
C++: Support more routines as proof-of-encryption in cpp/cleartext-transmission.
1 parent 974a8b1 commit d77ba02

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

cpp/ql/src/Security/CWE/CWE-311/CleartextTransmission.ql

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,18 @@ class NetworkRecv extends NetworkSendRecv {
147147
}
148148

149149
/**
150-
* An expression that is an argument or return value from an encryption or
151-
* decryption call.
150+
* An expression that is an argument or return value from an encryption /
151+
* decryption call. This is quite inclusive to minimize false positives, for
152+
* example `SecureZeroMemory` is not an encryption routine but a clue that
153+
* encryption may be present.
152154
*/
153155
class Encrypted extends Expr {
154156
Encrypted() {
155157
exists(FunctionCall fc |
156-
fc.getTarget().getName().toLowerCase().regexpMatch(".*(crypt|encode|decode).*") and
158+
fc.getTarget()
159+
.getName()
160+
.toLowerCase()
161+
.regexpMatch(".*(crypt|encode|decode|hash|securezero).*") and
157162
(
158163
this = fc or
159164
this = fc.getAnArgument()

cpp/ql/test/query-tests/Security/CWE/CWE-311/semmle/tests/CleartextTransmission.expected

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ edges
8585
| test3.cpp:350:9:350:16 | password | test3.cpp:353:4:353:18 | call to decrypt_inplace |
8686
| test3.cpp:350:9:350:16 | password | test3.cpp:353:20:353:27 | password |
8787
| test3.cpp:366:8:366:15 | password | test3.cpp:368:15:368:22 | password |
88+
| test3.cpp:366:8:366:15 | password | test3.cpp:374:3:374:18 | call to SecureZeroBuffer |
89+
| test3.cpp:366:8:366:15 | password | test3.cpp:374:20:374:27 | password |
8890
| test.cpp:41:23:41:43 | cleartext password! | test.cpp:48:21:48:27 | call to encrypt |
8991
| test.cpp:41:23:41:43 | cleartext password! | test.cpp:48:29:48:39 | thePassword |
9092
| test.cpp:66:23:66:43 | cleartext password! | test.cpp:76:21:76:27 | call to encrypt |
@@ -198,6 +200,8 @@ nodes
198200
| test3.cpp:353:20:353:27 | password | semmle.label | password |
199201
| test3.cpp:366:8:366:15 | password | semmle.label | password |
200202
| test3.cpp:368:15:368:22 | password | semmle.label | password |
203+
| test3.cpp:374:3:374:18 | call to SecureZeroBuffer | semmle.label | call to SecureZeroBuffer |
204+
| test3.cpp:374:20:374:27 | password | semmle.label | password |
201205
| test.cpp:41:23:41:43 | cleartext password! | semmle.label | cleartext password! |
202206
| test.cpp:48:21:48:27 | call to encrypt | semmle.label | call to encrypt |
203207
| test.cpp:48:29:48:39 | thePassword | semmle.label | thePassword |
@@ -229,4 +233,3 @@ subpaths
229233
| test3.cpp:295:2:295:5 | call to send | test3.cpp:308:58:308:66 | password2 | test3.cpp:295:14:295:17 | data | This operation transmits 'data', which may contain unencrypted sensitive data from $@ | test3.cpp:308:58:308:66 | password2 | password2 |
230234
| test3.cpp:300:2:300:5 | call to send | test3.cpp:308:58:308:66 | password2 | test3.cpp:300:14:300:17 | data | This operation transmits 'data', which may contain unencrypted sensitive data from $@ | test3.cpp:308:58:308:66 | password2 | password2 |
231235
| test3.cpp:341:4:341:7 | call to recv | test3.cpp:339:9:339:16 | password | test3.cpp:341:16:341:23 | password | This operation receives into 'password', which may put unencrypted sensitive data into $@ | test3.cpp:339:9:339:16 | password | password |
232-
| test3.cpp:368:3:368:6 | call to recv | test3.cpp:366:8:366:15 | password | test3.cpp:368:15:368:22 | password | This operation receives into 'password', which may put unencrypted sensitive data into $@ | test3.cpp:366:8:366:15 | password | password |

cpp/ql/test/query-tests/Security/CWE/CWE-311/semmle/tests/test3.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ void test_securezero()
365365
{
366366
char password[256];
367367

368-
recv(val(), password, 256, val()); // GOOD: password is (probably) encrypted [FALSE POSITIVE]
368+
recv(val(), password, 256, val()); // GOOD: password is (probably) encrypted
369369

370370
DoDisguisedOperation(password, 256); // decryption (disguised)
371371

0 commit comments

Comments
 (0)