CVE-2020-25658
Python-rsa vulnerable to Bleichenbacher timing attack: RSA decryption can be partially exploited by attackers
- CVSS 5.9
- CWE-385
- Cryptographic
- Remote
It was found that python-rsa is vulnerable to Bleichenbacher timing attacks. An attacker can use this flaw via the RSA decryption API to decrypt parts of the cipher text encrypted with RSA.
- CWE
- CWE-385
- CVSS base score
- 5.9
- Published
- 2020-11-12
- OWASP
- A02 Cryptographic Failures
- Orthogonal defect classification
- Timing/Serialization
- Code defect classification
- Timing Issues
- Category
- Cryptographic
- Subcategory
- Cryptographic Implementation Error
- Accessibility scope
- Remote
- Impact
- Information Disclosure
- Fixed by upgrading
- Yes
Solution
Update python-rsa to a version that mitigates Bleichenbacher timing attacks.
Vulnerable code sample
import rsa
def decrypt(private_key, ciphertext):
decrypted_message = rsa.decrypt(ciphertext, private_key)
return decrypted_message
if __name__ == "__main__":
(public_key, private_key) = rsa.newkeys(512)
message = b'Hello, RSA!'
ciphertext = rsa.encrypt(message, public_key)
decrypted_message = decrypt(private_key, ciphertext)
print(decrypted_message)Patched code sample
from cryptography.hazmat.primitives.asymmetric import rsa, padding
from cryptography.hazmat.primitives import serialization, hashes
def decrypt(private_key, ciphertext):
try:
return private_key.decrypt(
ciphertext,
padding.OAEP(
mgf=padding.MGF1(algorithm=hashes.SHA256()),
algorithm=hashes.SHA256(),
label=None
)
)
except Exception:
return b"Decryption failed"
if __name__ == "__main__":
private_key = rsa.generate_private_key(public_exponent=65537, key_size=2048)
public_key = private_key.public_key()
message = b'Hello, RSA!'
ciphertext = public_key.encrypt(
message,
padding.OAEP(
mgf=padding.MGF1(algorithm=hashes.SHA256()),
algorithm=hashes.SHA256(),
label=None
)
)
decrypted_message = decrypt(private_key, ciphertext)
print(decrypted_message)Cite this entry
@misc{vaitp:cve202025658,
title = {{Python-rsa vulnerable to Bleichenbacher timing attack: RSA decryption can be partially exploited by attackers}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2020},
note = {VAITP Python Vulnerability Dataset, entry CVE-2020-25658},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2020-25658/}}
}
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 ::
