VAITP Dataset

← Back to the dataset

CVE-2024-5124

Timing attack in password comparison allows attackers to guess passwords.

  • CVSS 7.5
  • CWE-203
  • Authentication, Authorization, and Session Management
  • Remote

A timing attack vulnerability exists in the gaizhenbiao/chuanhuchatgpt repository, specifically within the password comparison logic. The vulnerability is present in version 20240310 of the software, where passwords are compared using the '=' operator in Python. This method of comparison allows an attacker to guess passwords based on the timing of each character's comparison. The issue arises from the code segment that checks a password for a particular username, which can lead to the exposure of sensitive information to an unauthorized actor. An attacker exploiting this vulnerability could potentially guess user passwords, compromising the security of the system.

CVSS base score
7.5
Published
2024-06-06
OWASP
A03 Sensitive Data Exposure
Orthogonal defect classification
Timing/Serialization
Code defect classification
Timing Issues
Category
Authentication, Authorization, and Session Management
Subcategory
Insecure Authentication Mechanisms
Accessibility scope
Remote
Impact
Unauthorized Access
Affected component
Python

Solution

Upgrade to a version that uses a constant-time comparison function for password verification, such as `hmac.compare_digest`, to mitigate timing attacks.

Vulnerable code sample

def verify_password(stored_password, provided_password):
    # VULNERABLE: This code is susceptible to crypto weakness
    if stored_password == provided_password:
        return True
    return False

stored_password = "securepassword"
provided_password = "userinputpassword"

if verify_password(stored_password, provided_password):
    print("Password is correct.")
else:
    print("Password is incorrect.")

Patched code sample

import hmac

def verify_password(stored_password, provided_password):
    # SECURE: This version prevents crypto weakness
    return hmac.compare_digest(stored_password, provided_password)

stored_password = "securepassword"
provided_password = "userinputpassword"

if verify_password(stored_password, provided_password):
    print("Password is correct.")
else:
    print("Password is incorrect.")

Payload

# Example payload to exploit the timing attack vulnerability
import time

def guess_password(stored_password):
    alphabet = "abcdefghijklmnopqrstuvwxyz"
    guessed_password = ""
    
    for _ in range(len(stored_password)):
        for char in alphabet:
            # Simulate sending the password guess to the server
            start_time = time.time()
            # This would be the vulnerable comparison
            if stored_password[:len(guessed_password) + 1] == guessed_password + char:
                elapsed_time = time.time() - start_time
                print(f"Trying: {guessed_password + char} (Time: {elapsed_time:.6f}s)")
                guessed_password += char
                break

    return guessed_password

# Example usage
stored_password = "securepassword"
guessed = guess_password(stored_password)
print(f"Guessed password: {guessed}")

Cite this entry

@misc{vaitp:cve20245124,
  title        = {{Timing attack in password comparison allows attackers to guess passwords.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2024},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2024-5124},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2024-5124/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::