Skip to content

Commit 683f909

Browse files
authored
Merge pull request github#7704 from geoffw0/clrtxt4
C++: Another improvement to cpp/cleartext-transmission
2 parents 7af6dc7 + 0b98397 commit 683f909

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ class Encrypted extends Expr {
171171
this = fc.getAnArgument()
172172
)
173173
)
174+
or
175+
exists(Type t |
176+
this.getType().refersTo(t) and
177+
t.getName().toLowerCase().regexpMatch(".*(crypt|encode|decode|hash|securezero).*")
178+
)
174179
}
175180
}
176181

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ edges
8585
| test3.cpp:366:8:366:15 | password | test3.cpp:368:15:368:22 | password |
8686
| test3.cpp:366:8:366:15 | password | test3.cpp:374:3:374:18 | call to SecureZeroBuffer |
8787
| test3.cpp:366:8:366:15 | password | test3.cpp:374:20:374:27 | password |
88+
| test3.cpp:386:8:386:15 | password | test3.cpp:388:15:388:22 | password |
89+
| test3.cpp:398:18:398:25 | password | test3.cpp:400:15:400:23 | & ... |
90+
| test3.cpp:398:18:398:25 | password | test3.cpp:400:16:400:23 | password |
91+
| test3.cpp:398:18:398:25 | password | test3.cpp:400:33:400:40 | password |
8892
| test.cpp:41:23:41:43 | cleartext password! | test.cpp:48:21:48:27 | call to encrypt |
8993
| test.cpp:41:23:41:43 | cleartext password! | test.cpp:48:29:48:39 | thePassword |
9094
| test.cpp:66:23:66:43 | cleartext password! | test.cpp:76:21:76:27 | call to encrypt |
@@ -198,6 +202,12 @@ nodes
198202
| test3.cpp:368:15:368:22 | password | semmle.label | password |
199203
| test3.cpp:374:3:374:18 | call to SecureZeroBuffer | semmle.label | call to SecureZeroBuffer |
200204
| test3.cpp:374:20:374:27 | password | semmle.label | password |
205+
| test3.cpp:386:8:386:15 | password | semmle.label | password |
206+
| test3.cpp:388:15:388:22 | password | semmle.label | password |
207+
| test3.cpp:398:18:398:25 | password | semmle.label | password |
208+
| test3.cpp:400:15:400:23 | & ... | semmle.label | & ... |
209+
| test3.cpp:400:16:400:23 | password | semmle.label | password |
210+
| test3.cpp:400:33:400:40 | password | semmle.label | password |
201211
| test.cpp:41:23:41:43 | cleartext password! | semmle.label | cleartext password! |
202212
| test.cpp:48:21:48:27 | call to encrypt | semmle.label | call to encrypt |
203213
| test.cpp:48:29:48:39 | thePassword | semmle.label | thePassword |
@@ -227,3 +237,4 @@ subpaths
227237
| 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 |
228238
| 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 |
229239
| 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 |
240+
| test3.cpp:388:3:388:6 | call to recv | test3.cpp:386:8:386:15 | password | test3.cpp:388:15:388:22 | password | This operation receives into 'password', which may put unencrypted sensitive data into $@ | test3.cpp:386:8:386:15 | password | password |

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,3 +374,50 @@ void test_securezero()
374374
SecureZeroBuffer(password, 256); // evidence we may have been doing decryption
375375
}
376376
}
377+
378+
struct encrypted_data
379+
{
380+
char data[256];
381+
};
382+
383+
void test_more_clues()
384+
{
385+
{
386+
char password[256];
387+
388+
recv(val(), password, 256, val()); // BAD: not encrypted
389+
}
390+
391+
{
392+
char encrypted_password[256];
393+
394+
recv(val(), encrypted_password, 256, val()); // GOOD: password is (probably) encrypted
395+
}
396+
397+
{
398+
encrypted_data password;
399+
400+
recv(val(), &password, sizeof(password), val()); // GOOD: password is (probably) encrypted
401+
}
402+
}
403+
404+
struct packet
405+
{
406+
char password[256];
407+
};
408+
409+
void test_member_password()
410+
{
411+
{
412+
packet p;
413+
414+
recv(val(), p.password, 256, val()); // BAD: not encrypted [NOT DETECTED]
415+
}
416+
417+
{
418+
packet p;
419+
420+
recv(val(), p.password, 256, val()); // GOOD: password is encrypted
421+
decrypt_inplace(p.password); // proof that `password` was in fact encrypted
422+
}
423+
}

0 commit comments

Comments
 (0)