Skip to content

Commit

Permalink
Patched test_password_vulnerability.py
Browse files Browse the repository at this point in the history
  • Loading branch information
patched.codes[bot] committed Dec 30, 2024
1 parent 4e2d1c7 commit 01bb552
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test_password_vulnerability.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from hashlib import md5
import time

def demonstrate_md5_weakness():
# Example password
password = "test123"

# Current implementation (MD5)
start_time = time.time()
md5_hash = md5(password.encode('utf-8')).hexdigest()

Check failure

Code scanning / CodeQL

Use of a broken or weak cryptographic hashing algorithm on sensitive data High test

Sensitive data (password)
is used in a hashing algorithm (MD5) that is insecure for password hashing, since it is not a computationally expensive hash function.
md5_time = time.time() - start_time

print(f"Password: {password}")

Check failure

Code scanning / CodeQL

Clear-text logging of sensitive information High test

This expression logs
sensitive data (password)
as clear text.
print(f"MD5 Hash: {md5_hash}")
print(f"Time taken for MD5: {md5_time:.6f} seconds")
print("\nVulnerabilities:")
print("1. MD5 is fast (bad for password hashing): {:.2f} million hashes/second possible on modern hardware".format(1/md5_time/1000000))
print("2. No salt used: identical passwords produce identical hashes")
print("3. MD5 is cryptographically broken with known collisions")

# Demonstrate lack of salt problem
password2 = "test123"
md5_hash2 = md5(password2.encode('utf-8')).hexdigest()

Check failure

Code scanning / CodeQL

Use of a broken or weak cryptographic hashing algorithm on sensitive data High test

Sensitive data (password)
is used in a hashing algorithm (MD5) that is insecure for password hashing, since it is not a computationally expensive hash function.
print(f"\nSame password hashed again: {md5_hash2}")
print(f"Hashes match? {md5_hash == md5_hash2}")
print("This makes the hashes vulnerable to rainbow table attacks")

if __name__ == "__main__":
demonstrate_md5_weakness()

0 comments on commit 01bb552

Please sign in to comment.