CVE-2023-26154
pubnub insufficient entropy via the getKey function
- CVSS 5.9
- CWE-331 Insufficient Entropy
- Cryptographic
- Remote
Versions of the package pubnub before 7.4.0; all versions of the package com.pubnub:pubnub; versions of the package pubnub before 6.19.0; all versions of the package github.com/pubnub/go; versions of the package github.com/pubnub/go/v7 before 7.2.0; versions of the package pubnub before 7.3.0; versions of the package pubnub/pubnub before 6.1.0; versions of the package pubnub before 5.3.0; versions of the package pubnub before 0.4.0; versions of the package pubnub/c-core before 4.5.0; versions of the package com.pubnub:pubnub-kotlin before 7.7.0; versions of the package pubnub/swift before 6.2.0; versions of the package pubnub before 5.2.0; versions of the package pubnub before 4.3.0 are vulnerable to Insufficient Entropy via the getKey function, due to inefficient implementation of the AES-256-CBC cryptographic algorithm. The provided encrypt function is less secure when hex encoding and trimming are applied, leaving half of the bits in the key always the same for every encoded message or file. **Note:** In order to exploit this vulnerability, the attacker needs to invest resources in preparing the attack and brute-force the encryption.
- CVSS base score
- 5.9
- Published
- 2023-12-06
- OWASP
- A02 Cryptographic Failures
- Orthogonal defect classification
- Algorithm
- Code defect classification
- Incorrect Algorithm
- Category
- Cryptographic
- Subcategory
- Cryptographic Implementation Error
- Accessibility scope
- Remote
- Impact
- Unauthorized Access
- Fixed by upgrading
- Yes
Solution
Update the affected PubNub packages to versions 7.4.0, 6.19.0, 7.2.0, 7.3.0, 6.1.0, 5.3.0, 0.4.0, 4.5.0, 7.7.0, 6.2.0, 5.2.0, 4.3.0, or later
Vulnerable code sample
import hashlib
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad
def get_key(secret: str) -> bytes:
return hashlib.md5(secret.encode()).digest()
def encrypt(plaintext: str, secret: str) -> bytes:
key = get_key(secret)
cipher = AES.new(key, AES.MODE_CBC, iv=b'0' * AES.block_size)
ciphertext = cipher.encrypt(pad(plaintext.encode(), AES.block_size))
return ciphertext
secret_key = "my_secret"
message = "This is a secret message."
encrypted_message = encrypt(message, secret_key)
print(encrypted_message.hex())Patched code sample
import os
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad
import hashlib
def get_key(secret: str) -> bytes:
return hashlib.sha256(secret.encode()).digest()
def encrypt(plaintext: str, secret: str) -> bytes:
key = get_key(secret)
iv = os.urandom(AES.block_size)
cipher = AES.new(key, AES.MODE_CBC, iv)
ciphertext = cipher.encrypt(pad(plaintext.encode(), AES.block_size))
return iv + ciphertext
secret_key = "my_secure_secret"
message = "This is a secret message."
encrypted_message = encrypt(message, secret_key)
print(encrypted_message.hex())Cite this entry
@misc{vaitp:cve202326154,
title = {{pubnub insufficient entropy via the getKey function}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2023},
note = {VAITP Python Vulnerability Dataset, entry CVE-2023-26154},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2023-26154/}}
}
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 ::
