|
#!/usr/bin/env python3 |
|
# -*- coding: utf-8 -*- |
|
# Copyright 2026 Michel Sijmons - https://mickert.dev |
|
# |
|
# Licensed under the Apache License, Version 2.0 (the "License"); |
|
# you may not use this file except in compliance with the License. |
|
# You may obtain a copy of the License at |
|
# |
|
# http://www.apache.org/licenses/LICENSE-2.0 |
|
# |
|
# Unless required by applicable law or agreed to in writing, software |
|
# distributed under the License is distributed on an "AS IS" BASIS, |
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
# See the License for the specific language governing permissions and |
|
# limitations under the License. |
|
# |
|
# --------------------------------------------------------------------- |
|
# NOTICE: |
|
# This project includes work authored by Michel Sijmons (https://mickert.dev). |
|
# Licensed under the Apache License, Version 2.0. |
|
|
|
# You must retain this NOTICE when distributing or creating derivative works. |
|
# Canonical reference: |
|
# https://gists.mickert.dev/6e97ddaf163503beb78a49b397fca96b#check_openssl_version.py |
|
# --------------------------------------------------------------------- |
|
|
|
r""" |
|
check_openssl_version.py - OpenSSL Vulnerability Scanner (Python 3) |
|
-------------------------------------------------------------------- |
|
|
|
Scans for OpenSSL versions potentially vulnerable to recent CVEs, including: |
|
- CVE-2025-15467 (QUIC parsing, High) |
|
- CVE-2025-11187 (PBMAC1 in PKCS#12, Moderate) |
|
- CVE-2025-68160, CVE-2025-69418, and others (Low) |
|
|
|
Features: |
|
- Detects OpenSSL versions on Windows and Linux/macOS |
|
- Scans common install paths and user profiles |
|
- Supports filename-based inference if metadata is unavailable |
|
- Flags End-of-Life (EOL) branches and unverified versions |
|
- Detects FIPS builds and adjusts CVE impact accordingly |
|
- Detects installed OpenSSL package version via dpkg/rpm/pacman (Linux) |
|
- Uses package version for CVE analysis if available |
|
- Displays both binary and package version in console output |
|
- Adds package version to JSON/CSV output with --pkg |
|
- Optional CVE impact analysis per version (--cve) |
|
- CSV export with detailed results (--csv results.csv) |
|
- Optional JSON output via --json results.json for structured integration |
|
- Filters irrelevant files (e.g., .pdb, .lib, .a) and scans only executable/shared library formats: |
|
.dll, .exe, .so, .dylib, .bin, .pyd, .node |
|
- Heuristically detects suspicious modules (e.g., Python bindings) based on extension and version |
|
- Flags these as βlikely non-OpenSSL moduleβ if version exceeds known OpenSSL releases |
|
- Use --all to disable filtering and scan all matching filenames regardless of extension |
|
- Optional summary report (--summary) with totals for vulnerable, safe, EOL, and unverified versions |
|
- Optional: --fail-on-vuln exits with code 1 if vulnerable versions are found; |
|
useful for scripting, CI, RMM, etc |
|
- Quiet mode (--quiet) suppresses standard output; useful for scripting or CI pipelines |
|
|
|
Requirements: |
|
- Python 3.6+ (because usage of: f-strings, packaging) |
|
- Windows: pefile (pip install pefile) |
|
- Linux/macOS: binutils (for 'strings' command) |
|
|
|
Default scan locations on Windows: |
|
- %ProgramFiles% |
|
- %ProgramFiles(x86)% |
|
- %ProgramData% |
|
- All user profiles under C:\Users\<name> |
|
|
|
Default scan locations on Linux/macOS: |
|
- /usr/bin/openssl |
|
- /usr/local/, /opt/, /home/, /snap/, /var/lib/flatpak |
|
- /lib, /lib64, /usr/lib, /usr/lib64 |
|
- /usr/lib/x86_64-linux-gnu, /usr/lib/ssl, /etc/ssl |
|
- /nix/store (Nix/NixOS) |
|
- /run/host/usr/lib (Flatpak sandbox) |
|
|
|
Additional paths can be added via: |
|
--path "/custom/dir" --path "/opt/legacy" |
|
|
|
Usage: |
|
python check_openssl_version.py |
|
python check_openssl_version.py --csv results.csv |
|
python check_openssl_version.py --cve |
|
python check_openssl_version.py --all --csv results.csv |
|
python check_openssl_version.py --json results.json |
|
python check_openssl_version.py --csv out.csv --json out.json --cve --all |
|
python check_openssl_version.py --path "/opt/tools" --csv results.csv --cve |
|
python check_openssl_version.py --csv out.csv --json out.json --cve --fail-on-vuln |
|
python check_openssl_version.py --summary --fail-on-vuln |
|
python check_openssl_version.py --quiet --json out.json --fail-on-vuln |
|
python check_openssl_version.py --pkg --csv results.csv --cve |
|
|
|
Copyright 2026 Michel Sijmons - https://mickert.dev |
|
Licensed under the Apache License, Version 2.0. |
|
|
|
""" |
|
|
|
import os |
|
import platform |
|
import subprocess |
|
import re |
|
import argparse |
|
import sys |
|
import fnmatch |
|
|
|
#manual lazy imports |
|
# in fn main() |
|
# import csv |
|
# import json |
|
# |
|
|
|
VERSION = "1.3.1" |
|
RELEASE_DATE = "2026-02-01" |
|
|
|
CHANGELOG = """ |
|
Changelog: |
|
- 1.3.1 (2026-02-01) |
|
β’ Centralized version analysis via new analyze_version() helper |
|
β’ Unified JSON output: added raw_binary_version, raw_package_version, cleaned_version |
|
β’ CSV output now includes Package Version and Cleaned Version columns (also on Windows) |
|
β’ CVE impact for likely non-OpenSSL modules now explicitly marked as "unknown" in CSV |
|
β’ Removed duplicate CSV row write in scan_windows() |
|
|
|
- 1.3.0 (2026-01-31) |
|
β’ Added --pkg flag to include package version info for each library (Linux) |
|
β’ Uses package version for CVE analysis if available |
|
β’ Displays both binary and package version in console output |
|
β’ Improved CVE impact detection for system OpenSSL |
|
β’ Added FIPS detection for system OpenSSL |
|
β’ Enhanced --help output with full docstring |
|
|
|
- 1.2.0 (2026-01-30) |
|
β’ Added JSON output support (--json) |
|
β’ Added --fail-on-vuln for CI/CD integration |
|
β’ Improved EOL and unverified version handling |
|
|
|
- 1.1.0 (2026-01-30) |
|
β’ Added CVE impact analysis (--cve) |
|
β’ Added summary report (--summary) |
|
|
|
- 1.0.0 (2026-01-30) |
|
β’ Initial release |
|
""" |
|
|
|
|
|
try: |
|
from packaging.version import Version, InvalidVersion |
|
except ImportError: |
|
print("Missing required module: packaging\nInstall with: pip install packaging") |
|
sys.exit(1) |
|
|
|
# Platform-specific preflight checks |
|
system = platform.system() |
|
|
|
if system == "Windows": |
|
try: |
|
import pefile |
|
except ImportError: |
|
print("Missing required module: pefile\nInstall with: pip install pefile") |
|
sys.exit(1) |
|
elif system in ["Linux", "Darwin"]: |
|
if not any(os.access(os.path.join(path, 'strings'), os.X_OK) for path in os.environ["PATH"].split(os.pathsep)): |
|
print("Missing required tool: 'strings'. Please install binutils (e.g., 'apt install binutils').") |
|
sys.exit(1) |
|
|
|
# File extentions to check ( --all ignores this) |
|
VALID_EXTENSIONS = [ |
|
".dll", # Windows dynamic library |
|
".exe", # Windows executable |
|
".so", # Linux shared object |
|
".dylib", # macOS dynamic library |
|
".bin", # Generic binary (embedded/firmware) |
|
".pyd", # Python C-extension modules |
|
".node", # Node.js native modules |
|
] |
|
|
|
# CVE impact matrix (simplified) |
|
CVE_MATRIX = { |
|
"CVE-2025-15467": {"affected": ["3.6", "3.5", "3.4", "3.3"], "note": "QUIC"}, |
|
"CVE-2025-11187": {"affected": ["3.6", "3.5", "3.4"], "note": "PBMAC1"}, |
|
"CVE-2025-68160": {"affected": ["3.6", "3.5", "3.4", "3.3", "3.2", "3.1", "3.0", "1.1.1", "1.0.2"], "note": "BIO"}, |
|
"CVE-2025-69418": {"affected": ["3.6", "3.5", "3.4", "3.3", "3.2", "3.1", "3.0", "1.1.1"], "note": "OCB"}, |
|
} |
|
|
|
EOL_BRANCHES = ["3.2", "3.1", "1.1.1"] |
|
|
|
SAFE_VERSIONS = { |
|
"3.6": "3.6.1", |
|
"3.5": "3.5.5", |
|
"3.4": "3.4.4", |
|
"3.3": "3.3.6", |
|
"3.0": "3.0.19", |
|
} |
|
|
|
LINUX_SCAN_PATHS = [ |
|
"/usr/local", "/opt", "/home", "/snap", "/var/lib/flatpak", |
|
"/lib", "/lib64", "/usr/lib", "/usr/lib64", |
|
"/usr/lib/x86_64-linux-gnu", "/usr/lib/ssl", "/etc/ssl", |
|
"/nix/store", "/run/host/usr/lib" |
|
] |
|
|
|
# Determine highest known OpenSSL version once |
|
HIGHEST_KNOWN_OPENSSL_VERSION = max(Version(v) for v in SAFE_VERSIONS.values()) |
|
|
|
json_data = [] |
|
summary_stats = { |
|
"total": 0, |
|
"vulnerable": 0, |
|
"ok": 0, |
|
"eol": 0, |
|
"unverified": 0 |
|
} |
|
|
|
def is_fips(path): |
|
return "fips" in os.path.basename(path).lower() |
|
|
|
def extract_branch(ver): |
|
try: |
|
ver = clean_version_string(ver) |
|
parts = ver.split(".") |
|
if len(parts) >= 2: |
|
if ver.startswith("1.1.1"): |
|
return "1.1.1" |
|
return ".".join(parts[:2]) |
|
except Exception: |
|
pass |
|
return "unknown" |
|
|
|
|
|
def cve_impact(branch, fips=False): |
|
if branch in EOL_BRANCHES: |
|
return "Unknown (EOL branch)" |
|
if fips: |
|
return "Likely unaffected by CVE-2025-15467, CVE-2025-11187 (FIPS excluded); check others" |
|
impacted = [] |
|
for cve, data in CVE_MATRIX.items(): |
|
if branch in data["affected"]: |
|
impacted.append(cve) |
|
return ", ".join(impacted) if impacted else "None" |
|
|
|
def analyze_version(ver, inferred, fips=False, include_cve=False): |
|
vulnerable, branch, status = is_vulnerable(ver, inferred) |
|
branch_id = extract_branch(ver) |
|
cves = cve_impact(branch_id, fips) if include_cve else "" |
|
return vulnerable, branch, status, cves |
|
|
|
def clean_version_string(ver): |
|
""" |
|
Removes distro-specific suffixes like '-0ubuntu1.15' or '+deb11u1' |
|
so packaging.version can process it. |
|
""" |
|
match = re.match(r"^([\d\.]+)", ver) |
|
if match: |
|
return match.group(1) |
|
return ver |
|
|
|
def is_vulnerable(ver, inferred=False): |
|
try: |
|
clean_ver = clean_version_string(ver) |
|
current = Version(clean_ver) |
|
except InvalidVersion: |
|
return True, "unknown", "unverified" |
|
branch = f"{current.major}.{current.minor}" |
|
if branch in SAFE_VERSIONS: |
|
return current < Version(SAFE_VERSIONS[branch]), branch, "verified" |
|
if branch in EOL_BRANCHES: |
|
return True, branch + " (EOL)", "eol" |
|
return True, "unknown", "unverified" |
|
|
|
def is_likely_non_openssl_module(path, ver, inferred): |
|
if not inferred or not ver: |
|
return False |
|
try: |
|
current = Version(clean_version_string(ver)) |
|
except InvalidVersion: |
|
return False |
|
ext = os.path.splitext(path)[1].lower() |
|
if ext in [".pyd", ".so", ".dylib"]: |
|
if current > HIGHEST_KNOWN_OPENSSL_VERSION: |
|
return True |
|
return False |
|
|
|
|
|
def get_openssl_version_windows(dll_path): |
|
try: |
|
pe = pefile.PE(dll_path) |
|
for fileinfo in pe.FileInfo: |
|
for entry in fileinfo: |
|
if entry.Key == b'StringFileInfo': |
|
for st in entry.StringTable: |
|
version_str = st.entries.get(b'FileVersion') |
|
if version_str: |
|
return version_str.decode(errors="ignore").split()[0], False |
|
except Exception: |
|
pass |
|
name = os.path.basename(dll_path).lower() |
|
if "1_1" in name: |
|
return "1.1.1", True |
|
elif "3" in name: |
|
return "3.x", True |
|
elif "eay32" in name or "ssleay32" in name: |
|
return "1.0.2", True |
|
return None, True |
|
|
|
def get_openssl_version_linux(): |
|
try: |
|
output = subprocess.check_output(["openssl", "version"], stderr=subprocess.STDOUT) |
|
output = output.decode() |
|
match = re.search(r"OpenSSL\s([\d\.a-z]+)", output) |
|
if match: |
|
return match.group(1) |
|
except Exception: |
|
return None |
|
|
|
def is_system_fips(): |
|
try: |
|
output = subprocess.check_output(["openssl", "version", "-f"], stderr=subprocess.DEVNULL) |
|
return b"fips" in output.lower() |
|
except Exception: |
|
return False |
|
|
|
def get_installed_openssl_package_version(): |
|
try: |
|
if os.path.exists("/etc/debian_version"): |
|
output = subprocess.check_output(["dpkg", "-s", "openssl"], stderr=subprocess.DEVNULL) |
|
match = re.search(r"^Version:\s*(.+)", output.decode(), re.MULTILINE) |
|
if match: |
|
return match.group(1) |
|
elif os.path.exists("/etc/redhat-release") or os.path.exists("/etc/centos-release"): |
|
output = subprocess.check_output(["rpm", "-q", "openssl"], stderr=subprocess.DEVNULL) |
|
return output.decode().strip() |
|
elif os.path.exists("/etc/arch-release"): |
|
output = subprocess.check_output(["pacman", "-Qi", "openssl"], stderr=subprocess.DEVNULL) |
|
match = re.search(r"^Version\s*:\s*(.+)", output.decode(), re.MULTILINE) |
|
if match: |
|
return match.group(1) |
|
except Exception: |
|
return None |
|
|
|
def get_package_version_for_file(path): |
|
try: |
|
if os.path.exists("/etc/debian_version"): |
|
output = subprocess.check_output(["dpkg", "-S", path], stderr=subprocess.DEVNULL) |
|
pkg = output.decode().split(":")[0].strip() |
|
output = subprocess.check_output(["dpkg", "-s", pkg], stderr=subprocess.DEVNULL) |
|
match = re.search(r"^Version:\s*(.+)", output.decode(), re.MULTILINE) |
|
if match: |
|
return f"{pkg} {match.group(1)}" |
|
elif os.path.exists("/etc/redhat-release") or os.path.exists("/etc/centos-release"): |
|
output = subprocess.check_output(["rpm", "-qf", path], stderr=subprocess.DEVNULL) |
|
return output.decode().strip() |
|
except Exception: |
|
return None |
|
|
|
def get_so_version(path, debug=False): |
|
try: |
|
output = subprocess.check_output(["strings", path], stderr=subprocess.DEVNULL) |
|
decoded = output.decode(errors="ignore") |
|
match = re.search(r'OpenSSL\s+(\d+\.\d+\.\d+[a-z0-9\-\.]*)', decoded) |
|
if match: |
|
return match.group(1) |
|
elif debug: |
|
print(f"DEBUG: No OpenSSL version found in {path}") |
|
except Exception as e: |
|
if debug: |
|
print(f"DEBUG: Error reading {path}: {e}") |
|
return None |
|
|
|
def is_valid_extension(name, system): |
|
ext = os.path.splitext(name)[1].lower() |
|
if ext in VALID_EXTENSIONS: |
|
return True |
|
if system in ["Linux", "Darwin"]: |
|
# Match .so, .so.1, .so.1.1, .so.1.0.0, etc. |
|
if re.search(r'\.so(\.\d+)*$', name.lower()): |
|
return True |
|
return False |
|
|
|
def find_files(base_dirs, patterns, allow_all=False, args=None): |
|
matches = [] |
|
for base in base_dirs: |
|
for root, dirs, files in os.walk(base): |
|
for name in files: |
|
full_path = os.path.join(root, name) |
|
if any(fnmatch.fnmatch(name.lower(), p) for p in patterns): |
|
ext = os.path.splitext(name)[1].lower() |
|
if allow_all or is_valid_extension(name, platform.system()): |
|
matches.append(full_path) |
|
if args and args.debug: |
|
print(f"DEBUG: Matched: {full_path}") |
|
elif args and args.debug: |
|
print(f"DEBUG: Skipped (invalid extension): {full_path}") |
|
return matches |
|
|
|
def scan_windows(csv_writer=None, args=None): |
|
global json_data |
|
base_dirs = [] |
|
for env_var in ["ProgramFiles", "ProgramFiles(x86)", "ProgramData"]: |
|
path = os.environ.get(env_var) |
|
if path and os.path.isdir(path): |
|
base_dirs.append(path) |
|
users_root = r"C:\Users" |
|
if os.path.isdir(users_root): |
|
base_dirs += [os.path.join(users_root, u) for u in os.listdir(users_root)] |
|
if args and args.path: |
|
base_dirs += [p for p in args.path if os.path.isdir(p)] |
|
|
|
dll_patterns = [ |
|
"libssl*.dll", "libcrypto*.dll", "ssleay32*.dll", "libeay32*.dll", |
|
"*libssl*.pyd", "*libcrypto*.pyd", "*_ssl.pyd", "*_hashlib.pyd" |
|
] |
|
|
|
found = False |
|
for dll_path in find_files(base_dirs, dll_patterns, allow_all=args.all, args=args): |
|
ver, inferred = get_openssl_version_windows(dll_path) |
|
if ver: |
|
if is_likely_non_openssl_module(dll_path, ver, inferred): |
|
label = "VULNERABLE (unverified - likely non-OpenSSL module)" |
|
summary_stats["total"] += 1 |
|
summary_stats["vulnerable"] += 1 |
|
summary_stats["unverified"] += 1 |
|
if not args.quiet: |
|
print(f"Found: {dll_path}") |
|
print(f" Version: {ver}") |
|
print(f" Status: {label}") |
|
|
|
if csv_writer: |
|
row = [dll_path, ver, "unknown", label] |
|
if args.cve: |
|
row.append("unknown") |
|
if args.pkg: |
|
row += [None, clean_version_string(ver)] |
|
csv_writer.writerow(row) |
|
|
|
if args.json: |
|
json_data.append({ |
|
"path": dll_path, |
|
"version": ver, |
|
"branch": "unknown", |
|
"status": label, |
|
"cve_impact": "unknown", |
|
"raw_binary_version": ver, |
|
"raw_package_version": None, |
|
"cleaned_version": clean_version_string(ver) |
|
}) |
|
continue |
|
|
|
fips = is_fips(dll_path) |
|
vulnerable, branch, status, cves = analyze_version(ver, inferred, fips, args.cve) |
|
|
|
summary_stats["total"] += 1 |
|
|
|
if vulnerable: |
|
label = "VULNERABLE" |
|
summary_stats["vulnerable"] += 1 |
|
else: |
|
label = "OK" |
|
summary_stats["ok"] += 1 |
|
|
|
if status == "unverified": |
|
label += " (unverified)" |
|
summary_stats["unverified"] += 1 |
|
elif status == "eol": |
|
label += " (EOL)" |
|
summary_stats["eol"] += 1 |
|
elif fips: |
|
label += " (FIPS build)" |
|
|
|
if not args.quiet: |
|
print(f"Found: {dll_path}") |
|
print(f" Version: {ver}") |
|
print(f" Status: {label}") |
|
if args.cve: |
|
print(f" CVE Impact: {cves}") |
|
|
|
if csv_writer: |
|
row = [dll_path, ver, branch, label] |
|
if args.cve: |
|
row.append(cves) |
|
if args.pkg: |
|
row += [None, clean_version_string(ver)] |
|
csv_writer.writerow(row) |
|
|
|
if args.json: |
|
json_data.append({ |
|
"path": dll_path, |
|
"version": ver, |
|
"branch": branch, |
|
"status": label, |
|
"cve_impact": cves if args.cve else None, |
|
"raw_binary_version": ver, |
|
"raw_package_version": None, |
|
"cleaned_version": clean_version_string(ver) |
|
}) |
|
|
|
found = True |
|
|
|
if not found and not args.quiet: |
|
print("No OpenSSL DLLs found in scanned locations.") |
|
|
|
|
|
def scan_linux(csv_writer=None, args=None): |
|
global json_data |
|
if not args.quiet: |
|
print("Scanning system OpenSSL...") |
|
ver = get_openssl_version_linux() |
|
pkg_ver = get_installed_openssl_package_version() |
|
effective_ver = pkg_ver or ver |
|
if effective_ver: |
|
fips = is_system_fips() |
|
vulnerable, branch, status, cves = analyze_version(effective_ver, False, fips, args.cve) |
|
|
|
|
|
label = "VULNERABLE" if vulnerable else "OK" |
|
if status == "eol": |
|
label += " (EOL)" |
|
|
|
if not args.quiet: |
|
print(f"System OpenSSL (binary): {ver}") |
|
if pkg_ver: |
|
print(f"System OpenSSL (package): {pkg_ver}") |
|
if args.debug: |
|
print(f"DEBUG: Raw binary version: {ver}") |
|
print(f"DEBUG: Raw package version: {pkg_ver}") |
|
print(f"DEBUG: Cleaned version used for comparison: {clean_version_string(effective_ver)}") |
|
print(f"System OpenSSL: {effective_ver} - {label}") |
|
if args.cve: |
|
print(f" CVE Impact: {cves}") |
|
|
|
summary_stats["total"] += 1 |
|
if vulnerable: |
|
summary_stats["vulnerable"] += 1 |
|
else: |
|
summary_stats["ok"] += 1 |
|
if status == "unverified": |
|
summary_stats["unverified"] += 1 |
|
elif status == "eol": |
|
summary_stats["eol"] += 1 |
|
|
|
if csv_writer: |
|
row = ["/usr/bin/openssl", effective_ver, branch, label] |
|
if args.cve: |
|
row.append(cves) |
|
if args.pkg: |
|
row += [pkg_ver or "", clean_version_string(effective_ver)] |
|
csv_writer.writerow(row) |
|
|
|
if args.json: |
|
json_data.append({ |
|
"path": "/usr/bin/openssl", |
|
"version": effective_ver, |
|
"branch": branch, |
|
"status": label, |
|
"cve_impact": cves if args.cve else None, |
|
"raw_binary_version": ver, |
|
"raw_package_version": pkg_ver, |
|
"cleaned_version": clean_version_string(effective_ver), |
|
}) |
|
|
|
elif not args.quiet: |
|
print("Could not detect system OpenSSL version.") |
|
|
|
if not args.quiet: |
|
print("Scanning common library paths (/opt, /usr/local, /home...)") |
|
|
|
so_patterns = ["libssl*.so*", "libcrypto*.so*"] |
|
for so_path in find_files(LINUX_SCAN_PATHS, so_patterns, allow_all=args.all, args=args): |
|
ver = get_so_version(so_path, debug=args.debug) |
|
pkg_ver = get_package_version_for_file(so_path) |
|
effective_ver = pkg_ver or ver |
|
inferred = pkg_ver is None |
|
|
|
if is_likely_non_openssl_module(so_path, ver, inferred): |
|
label = "VULNERABLE (unverified - likely non-OpenSSL module)" |
|
summary_stats["total"] += 1 |
|
summary_stats["vulnerable"] += 1 |
|
summary_stats["unverified"] += 1 |
|
if not args.quiet: |
|
print(f"Found: {so_path}") |
|
print(f" Version: {ver}") |
|
if pkg_ver: |
|
print(f" Package: {pkg_ver}") |
|
if args.debug: |
|
print(f"DEBUG: Raw binary version: {ver}") |
|
print(f"DEBUG: Raw package version: {pkg_ver}") |
|
print(f"DEBUG: Cleaned version used for comparison: {clean_version_string(effective_ver)}") |
|
print(f" Status: {label}") |
|
if csv_writer: |
|
row = [so_path, ver, "unknown", label] |
|
if args.cve: |
|
row.append("") |
|
if args.pkg: |
|
row += [pkg_ver or "", clean_version_string(effective_ver)] |
|
csv_writer.writerow(row) |
|
if args.json: |
|
json_data.append({ |
|
"path": so_path, |
|
"version": ver, |
|
"branch": "unknown", |
|
"status": label, |
|
"cve_impact": None, |
|
"raw_binary_version": ver, |
|
"raw_package_version": pkg_ver, |
|
"cleaned_version": clean_version_string(effective_ver), |
|
}) |
|
continue |
|
|
|
if effective_ver: |
|
fips = is_fips(so_path) |
|
vulnerable, branch, status, cves = analyze_version(effective_ver, inferred, fips, args.cve) |
|
|
|
summary_stats["total"] += 1 |
|
|
|
if vulnerable: |
|
label = "VULNERABLE" |
|
summary_stats["vulnerable"] += 1 |
|
else: |
|
label = "OK" |
|
summary_stats["ok"] += 1 |
|
|
|
if status == "unverified": |
|
label += " (unverified)" |
|
summary_stats["unverified"] += 1 |
|
elif status == "eol": |
|
label += " (EOL)" |
|
summary_stats["eol"] += 1 |
|
elif fips: |
|
label += " (FIPS build)" |
|
|
|
if not args.quiet: |
|
print(f"Found: {so_path}") |
|
print(f" Version: {ver}") |
|
if pkg_ver: |
|
print(f" Package: {pkg_ver}") |
|
if args.debug: |
|
print(f"DEBUG: Raw binary version: {ver}") |
|
print(f"DEBUG: Raw package version: {pkg_ver}") |
|
print(f"DEBUG: Cleaned version used for comparison: {clean_version_string(effective_ver)}") |
|
print(f" Status: {label}") |
|
if args.cve: |
|
print(f" CVE Impact: {cves}") |
|
|
|
if csv_writer: |
|
row = [so_path, effective_ver, branch, label] |
|
if args.cve: |
|
row.append(cves) |
|
if args.pkg: |
|
row += [pkg_ver or "", clean_version_string(effective_ver)] |
|
csv_writer.writerow(row) |
|
|
|
if args.json: |
|
json_data.append({ |
|
"path": so_path, |
|
"version": effective_ver, |
|
"branch": branch, |
|
"status": label, |
|
"cve_impact": cves if args.cve else None, |
|
"package": pkg_ver, |
|
"raw_binary_version": ver, |
|
"raw_package_version": pkg_ver, |
|
"cleaned_version": clean_version_string(effective_ver), |
|
}) |
|
|
|
|
|
def main(): |
|
parser = argparse.ArgumentParser( |
|
description="Scan for vulnerable OpenSSL versions.\nCopyright 2026 Michel Sijmons - https://mickert.dev\nLicensed under the Apache License, Version 2.0.", |
|
epilog=__doc__, |
|
formatter_class=argparse.RawDescriptionHelpFormatter |
|
) |
|
parser.add_argument("--path", action="append", help="Extra directory to scan (can be used multiple times)") |
|
parser.add_argument("--all", action="store_true", help="Scan all matching filenames, regardless of extension") |
|
parser.add_argument("--cve", action="store_true", help="Include CVE impact analysis per version") |
|
parser.add_argument("--csv", help="Optional path to export results as CSV") |
|
parser.add_argument("--json", help="Optional path to export results as JSON") |
|
parser.add_argument("--summary", action="store_true", help="Print summary statistics after scan") |
|
parser.add_argument("--fail-on-vuln", action="store_true", help="Exit with code 1 if any vulnerable versions are found") |
|
parser.add_argument("--quiet", action="store_true", help="Suppress standard output (only show summary or errors)") |
|
parser.add_argument("--pkg", action="store_true", help="Include package version info for each library (Linux only)") |
|
parser.add_argument("--version", action="store_true", help="Show script version and exit") |
|
parser.add_argument("--changelog", action="store_true", help="Show changelog and exit") |
|
parser.add_argument("--debug", action="store_true", help="Enable debug output for troubleshooting") |
|
args = parser.parse_args() |
|
|
|
if args.version: |
|
print(f"check_openssl_version.py {VERSION} ({RELEASE_DATE})") |
|
sys.exit(0) |
|
|
|
if args.changelog: |
|
print(CHANGELOG.strip()) |
|
sys.exit(0) |
|
|
|
csv_writer = None |
|
csv_file = None |
|
|
|
if args.csv: |
|
import csv |
|
csv_file = open(args.csv, "w", newline="", encoding="utf-8") |
|
csv_writer = csv.writer(csv_file) |
|
headers = ["Path", "Version", "Branch", "Status"] |
|
if args.cve: |
|
headers.append("CVE Impact") |
|
if args.pkg: |
|
headers += ["Package Version", "Cleaned Version"] |
|
csv_writer.writerow(headers) |
|
|
|
# system is already defined in preflight section |
|
if system in ["Linux", "Darwin"]: |
|
scan_linux(csv_writer, args) |
|
elif system == "Windows": |
|
scan_windows(csv_writer, args) |
|
else: |
|
print(f"Unsupported OS: {system}") |
|
|
|
if csv_file: |
|
csv_file.close() |
|
print(f"Results written to: {args.csv}") |
|
|
|
if args.json: |
|
import json |
|
with open(args.json, "w", encoding="utf-8") as jf: |
|
json.dump(json_data, jf, indent=2) |
|
print(f"Results written to: {args.json}") |
|
|
|
if args.summary: |
|
print("\n--- Scan Summary ---") |
|
print(f" Total files scanned: {summary_stats['total']}") |
|
print(f" Vulnerable: {summary_stats['vulnerable']}") |
|
print(f" OK: {summary_stats['ok']}") |
|
print(f" End-of-Life (EOL): {summary_stats['eol']}") |
|
print(f" Unverified versions: {summary_stats['unverified']}") |
|
|
|
if args.fail_on_vuln and summary_stats["vulnerable"] > 0: |
|
print("Exiting with code 1 due to vulnerable versions found.") |
|
sys.exit(1) |
|
|
|
|
|
if __name__ == "__main__": |
|
main() |