VAITP Dataset

← Back to the dataset

CVE-2016-1494

Spoofing vulnerability in Python-RSA's verify function

  • CVSS 5.3
  • CWE-20: Improper Input Validation
  • Cryptographic
  • Remote

The verify function in the RSA package for Python (Python-RSA) before 3.3 allows attackers to spoof signatures with a small public exponent via crafted signature padding, aka a BERserk attack.

CVSS base score
5.3
Published
2016-01-13
OWASP
A08 Software and Data Integrity Failures
Orthogonal defect classification
Algorithm
Code defect classification
Incorrect Algorithm
Category
Cryptographic
Subcategory
Cryptographic Implementation Error
Accessibility scope
Remote
Impact
Denial of Service (DoS)
Fixed by upgrading
Yes

Solution

Upgrade to Python-RSA version 3.3 or later.

Vulnerable code sample

import rsa
import binascii

pubkey = rsa.PublicKey(0x10001, 0x10001)

message = b"Hello, world!"
signature = binascii.unhexlify(b"0001ff003031300d06096086480165030402010500042014d9277c9e99f543e2a5d13e0d81f3b2110f9a4ac")

def verify(message, signature, pubkey):
    message = rsa.transform.bytes2int(message)
    encrypted = rsa.core.encrypt_int(signature, pubkey.e, pubkey.n)
    clearsig = rsa.transform.int2bytes(encrypted, rsa.common.byte_size(pubkey.n))
    return message == rsa.transform.bytes2int(clearsig[-len(message):])

print(verify(message, signature, pubkey))

Patched code sample

import rsa
import binascii

pubkey = rsa.PublicKey(0x10001, 0x10001)

message = b"Hello, world!"
signature = binascii.unhexlify(b"0001ff003031300d06096086480165030402010500042014d9277c9e99f543e2a5d13e0d81f3b2110f9a4ac")

def verify(message, signature, pubkey):
    if pubkey.e == 3:
        raise ValueError("Insecure public exponent (e=3) detected. Possible signature forgery attempt.")
    
    if len(signature) < 128:
        raise ValueError("Signature too short, potential forgery attempt.")
    
    message = rsa.transform.bytes2int(message)
    encrypted = rsa.core.encrypt_int(signature, pubkey.e, pubkey.n)
    clearsig = rsa.transform.int2bytes(encrypted, rsa.common.byte_size(pubkey.n))
    
    if not clearsig.startswith(b'\x00\x01\xff\x00'):
        raise ValueError("Invalid PKCS#1 v1.5 padding, possible forgery detected.")

    return message == rsa.transform.bytes2int(clearsig[-len(message):])

try:
    print(verify(message, signature, pubkey))
except ValueError as e:
    print(f"Verification failed: {e}")

Cite this entry

@misc{vaitp:cve20161494,
  title        = {{Spoofing vulnerability in Python-RSA's verify function}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2016},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2016-1494},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2016-1494/}}
}
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 ::