T09 · Insecure Skill Coding Practices
- Location
scripts/privacy.py:17- Finding
Misrepresented and Cryptographically Insecure Memory Encryption
- Content
View full analysis
bytes: """XOR stream cipher used with a SHA-256-derived key.""" return bytes(a ^ b for a, b in zip( data, (key * (len(data) // len(key) + 1))[:len(data)] )) def _derive_key(password: str, salt: bytes = b"long-memory-salt") -> bytes: """Derive a key from a password.""" return hashlib.sha256(password.encode("utf-8") + salt).digest() def encrypt_text(text: str, password: str) -> str: """Encrypt text.""" key = _derive_key(password) data = text.encode("utf-8") encrypted = _xor_cipher(data, key) return base64.b64encode(encrypted).decode("ascii") def decrypt_text(ciphertext: str, password: str) -> str: """Decrypt text.""" key = _derive_key(password) data = base64.b64decode(ciphertext) decrypted = _xor_cipher(data, key) return decrypted.decode("utf-8") ``` The password is also accepted directly through a command-line option: ```python enc.add_argument("--password", "-p", required=True) dec.add_argument("--password", "-p", required=True) ``` ### Technical Analysis The Skill documentation and module description advertise AES-256 encryption, but the implementation is a repeating-key XOR cipher. The SHA-256 digest of the password and a fixed, globally reused salt becomes a 32-byte keystream that repeats for the entire plaintext. This construction has several critical deficiencies: 1. It is not AES-256. 2. The fixed salt causes identical passwords to derive identical keys for every record. 3. There is no random nonce or initialization vector. 4. The keystream is reused across all messages encrypted with the same password. 5. There is no authentication tag or ...[truncated 2102 chars]- Remediation
View remediation
