VAITP Dataset

← Back to the dataset

CVE-2022-2996

Python-scciclient: Unverified HTTPS, MITM risk

  • CVSS 7.4
  • CWE-295 Improper Certificate Validation
  • Cryptographic
  • Remote

A flaw was found in the python-scciclient when making an HTTPS connection to a server where the server's certificate would not be verified. This issue opens up the connection to possible Man-in-the-middle (MITM) attacks.

CVSS base score
7.4
Published
2022-09-01
OWASP
A08 Software and Data Integrity Failures
Orthogonal defect classification
Function
Code defect classification
Incorrect Functionality
Category
Cryptographic
Subcategory
Improper SSL/TLS Certificate Validation
Accessibility scope
Remote
Impact
Unauthorized Access
Fixed by upgrading
Yes

Solution

Update python-scciclient to the latest version.

Vulnerable code sample

import hashlib

def encrypt_data(data, key):
    # VULNERABLE: Using weak MD5 for encryption
    # MD5 is cryptographically broken
    hash_key = hashlib.md5(key.encode()).hexdigest()
    
    # Simple XOR "encryption" with MD5 hash
    encrypted = ""
    for i, char in enumerate(data):
        encrypted += chr(ord(char) ^ ord(hash_key[i % len(hash_key)]))
    
    return encrypted

# Example of vulnerable usage:
# weak_encrypted = encrypt_data("secret", "password")  # Weak encryption

Patched code sample

import hashlib
import secrets
import base64
from cryptography.fernet import Fernet

def encrypt_data(data, password):
    # SECURE: Use strong encryption with proper key derivation
    
    if not isinstance(data, str) or not isinstance(password, str):
        raise ValueError("Data and password must be strings")
    
    # Generate a random salt
    salt = secrets.token_bytes(16)
    
    # Derive a strong key using PBKDF2
    key = hashlib.pbkdf2_hmac('sha256', password.encode(), salt, 100000)
    
    # Use Fernet for authenticated encryption
    fernet_key = base64.urlsafe_b64encode(key)
    fernet = Fernet(fernet_key)
    
    # Encrypt the data
    encrypted_data = fernet.encrypt(data.encode())
    
    # Return salt + encrypted data for storage
    return base64.b64encode(salt + encrypted_data).decode()

def decrypt_data(encrypted_data, password):
    # SECURE: Corresponding decryption function
    
    try:
        # Decode the stored data
        combined_data = base64.b64decode(encrypted_data.encode())
        
        # Extract salt and encrypted data
        salt = combined_data[:16]
        encrypted = combined_data[16:]
        
        # Derive the same key
        key = hashlib.pbkdf2_hmac('sha256', password.encode(), salt, 100000)
        fernet_key = base64.urlsafe_b64encode(key)
        fernet = Fernet(fernet_key)
        
        # Decrypt and return
        decrypted_data = fernet.decrypt(encrypted)
        return decrypted_data.decode()
        
    except Exception as e:
        raise ValueError(f"Decryption failed: {e}")

# Example of secure usage:
# strong_encrypted = encrypt_data("secret", "password")  # Strong AES encryption
# decrypted = decrypt_data(strong_encrypted, "password")  # Secure decryption

Cite this entry

@misc{vaitp:cve20222996,
  title        = {{Python-scciclient: Unverified HTTPS, MITM risk}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2022},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2022-2996},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2022-2996/}}
}
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 ::