Enhance Cryptographic failures module#596
Conversation
# Conflicts: # src/main/java/org/sasanlabs/service/vulnerability/cryptographicFailures/CryptographicFailuresVulnerability.java
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #596 +/- ##
============================================
- Coverage 51.21% 49.59% -1.63%
- Complexity 465 466 +1
============================================
Files 70 71 +1
Lines 2718 2809 +91
Branches 287 301 +14
============================================
+ Hits 1392 1393 +1
- Misses 1195 1285 +90
Partials 131 131 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| LEVEL5_HASH = bytesToHex(hash); | ||
| } catch (NoSuchAlgorithmException e) { | ||
| throw new RuntimeException("SHA-256 not available", e); | ||
| private static final String LEVEL1_SECRET = "letmein"; |
There was a problem hiding this comment.
I think we should create a table and insert secrets in the table and let user find it out by looking at the table. The challenge should not say what is the secret like in our case level 1 is showing the password. Look at Authentication Vulnerability, we just want to tell user to find out the secret by looking at database. Example:
| // Vulnerable: password is exposed in plaintext in the API response | ||
| return new ResponseEntity<>( | ||
| new GenericVulnerabilityResponseBean<>( | ||
| "CHALLENGE: The system stores passwords in plaintext." |
There was a problem hiding this comment.
This challenge should be that password is stored as plain text, look at database to findout what is the password and crack it.
| if (password == null || password.isEmpty()) { | ||
| return new ResponseEntity<>( | ||
| new GenericVulnerabilityResponseBean<>( | ||
| "CHALLENGE: The system 'encrypts' passwords using Base64 encoding." |
| if (password == null || password.isEmpty()) { | ||
| return new ResponseEntity<>( | ||
| new GenericVulnerabilityResponseBean<>( | ||
| "CHALLENGE: A user's password is encrypted with a Caesar cipher:" |
There was a problem hiding this comment.
Dont tell it is caesar cipher in challenge. Challenge is finding out password. Hint should tell it is Caesar cipher
| private static final String LEVEL2_ENCODED = | ||
| Base64.getEncoder().encodeToString(LEVEL2_SECRET.getBytes()); | ||
|
|
||
| private static final String LEVEL3_SECRET = "helloworld"; |
There was a problem hiding this comment.
Is it possible to make the secrets little more complex ?
| private static final String LEVEL3_ENCRYPTED = | ||
| EncryptionUtils.caesarCipher(LEVEL3_SECRET, LEVEL3_CHAR_SHIFT); | ||
|
|
||
| private static final String LEVEL4_SECRET = "obscuredpassword"; |
| if (password == null || password.isEmpty()) { | ||
| return new ResponseEntity<>( | ||
| new GenericVulnerabilityResponseBean<>( | ||
| "CHALLENGE: A user's password is stored using custom logic: " |
There was a problem hiding this comment.
This is great !!! we need challenge for user.
| if (password == null || password.isEmpty()) { | ||
| return new ResponseEntity<>( | ||
| new GenericVulnerabilityResponseBean<>( | ||
| "CHALLENGE: A user's password is stored as MD4 hash: " |
| private static final String LEVEL4_SECRET = "obscuredpassword"; | ||
| private static final String LEVEL4_ENCRYPTED = EncryptionUtils.customCipher(LEVEL4_SECRET); | ||
|
|
||
| private static final String LEVEL5_SECRET = "password123"; |
There was a problem hiding this comment.
make secret really strong in this case.
| private static final String LEVEL5_SECRET = "password123"; | ||
| private static final String LEVEL5_HASH = PasswordHashingUtils.md4Hash(LEVEL5_SECRET); | ||
|
|
||
| private static final String LEVEL6_SECRET = "password123"; |
There was a problem hiding this comment.
Each level password should be different from other levels.
| + LEVEL3_SECRET | ||
| + " — Enter it below to authenticate!", | ||
| false), | ||
| "SECURE: This password is hashed with LM. Hash: " |
There was a problem hiding this comment.
Should be CHALLENGE not SECURE
| private static final String LEVEL7_SECRET = "admin"; | ||
| private static final String LEVEL7_HASH = DigestUtils.sha1Hex(LEVEL7_SECRET); | ||
|
|
||
| private static final String LEVEL8_SECRET = "admin123"; |
There was a problem hiding this comment.
make it little complex secret
| private static final String LEVEL8_SECRET = "admin123"; | ||
| private static final String LEVEL8_HASH = PasswordHashingUtils.lmHash(LEVEL8_SECRET); | ||
|
|
||
| private static final String LEVEL9_SECRET = "qwertyuiop"; |
There was a problem hiding this comment.
add few numbers too as that adds complexity.
| return new ResponseEntity<>( | ||
| new GenericVulnerabilityResponseBean<>( | ||
| "Incorrect. Hint: Think of common passwords '" | ||
| + LEVEL_10_SECRET |
There was a problem hiding this comment.
we should not return secret.
| EncryptionUtils.encrypt( | ||
| LEVEL_10_SECRET, EncryptionUtils.getKeyFromPassword(LEVEL_10_SECRET)); | ||
|
|
||
| private static final String LEVEL11_SECRET = "uncrackablePassword"; |
There was a problem hiding this comment.
make this passwrod random generated on each run as this is very secure and we want to tell that no one can guess this.
| } else { | ||
| return new ResponseEntity<>( | ||
| new GenericVulnerabilityResponseBean<>( | ||
| "Incorrect. Hint: Base64 is not encryption — try decoding '" |
There was a problem hiding this comment.
Just tell it is incorrect. let user user hint section to find out that base64 is used.
| return new ResponseEntity<>( | ||
| new GenericVulnerabilityResponseBean<>( | ||
| "Incorrect. The password has been shifted " | ||
| + LEVEL3_CHAR_SHIFT |
There was a problem hiding this comment.
dont tell the shift size. let user find it out using hint. just tell that the password is incorrect.
| } else { | ||
| return new ResponseEntity<>( | ||
| new GenericVulnerabilityResponseBean<>( | ||
| "Incorrect. " |
There was a problem hiding this comment.
This is good hiding. Api should return just this.
| return new ResponseEntity<>( | ||
| new GenericVulnerabilityResponseBean<>( | ||
| "Incorrect. Your input hashed to: " | ||
| + guessHash |
There was a problem hiding this comment.
great !!!! telling guessHash is good as user gets some information using this.
preetkaran20
left a comment
There was a problem hiding this comment.
Overall PR looks great. Just some small comments.


Reordered and added new levels, now 1-11, to the Cryptographic failures module according to issue 523.
Additional methods have been added to
PasswordHashingUtilsfor new levelsEncryptionUtilswas created as part of theinternal.utilitypackage and contains methods related to encryption.Descriptions for new levels were added to
message.propertiesNew Level Order: