Detecting CUPS Vulnerabilities: CVE-2024–47076, CVE-2024–47175, CVE-2024–47176 CVE-2024–47177
CVE-2024–47177 9 Critical Severity
- import subprocess
- import re
- def check_package_version(package_name):
- try:
- result = subprocess.run([‘dpkg-query’, ‘-W’, ‘-f=${Version}’, package_name],stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- version = result.stdout.decode(‘utf-8’).strip()
- if result.returncode == 0:
- return version
- else:
- return None
- except Exception as e:
- print(f”Error checking {package_name}: {e}”)
- return None
- def check_service_status(service_name):
- try:
- result = subprocess.run([‘systemctl’, ‘is-active’, service_name],stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- status = result.stdout.decode(‘utf-8’).strip()
- return status == ‘active’
- except Exception as e:
- print(f”Error checking {service_name}: {e}”)
- return False
- def check_udp_port_631():
- try:
- result = subprocess.run([‘ss’, ‘-uln’], stdout=subprocess.PIPE)
- output = result.stdout.decode(‘utf-8’)
- return ‘631’ in output
- except Exception as e:
- print(f”Error checking UDP port 631: {e}”)
- return False
- vulnerable_versions = {
- ‘libcupsfilters’: ‘2.1b1’,
- ‘libppd’: ‘2.1b1’,
- ‘cups-filters’: ‘2.0.1’,
- }
- def compare_versions(installed_version, vulnerable_version):
- installed_parts = list(map(int, re.split(r’[.-]’, installed_version)))
- vulnerable_parts = list(map(int, re.split(r’[.-]’, vulnerable_version)))
- return installed_parts <= vulnerable_parts
- def check_vulnerabilities():
- libcupsfilters_version = check_package_version(‘libcupsfilters’)
- if libcupsfilters_version and compare_versions(libcupsfilters_version,
- vulnerable_versions[‘libcupsfilters’]):
- print(f”Vulnerable libcupsfilters version detected: {libcupsfilters_version}”)
- else:
- print(“libcupsfilters is not vulnerable or not installed.”)
- libppd_version = check_package_version(‘libppd’)
- if libppd_version and compare_versions(libppd_version,vulnerable_versions[‘libppd’]):
- print(f”Vulnerable libppd version detected: {libppd_version}”)
- else:
- print(“libppd is not vulnerable or not installed.”)
- cups_filters_version = check_package_version(‘cups-filters’)
- if cups_filters_version and compare_versions(cups_filters_version,
- vulnerable_versions[‘cups-filters’]):
- print(f”Vulnerable cups-filters version detected: {cups_filters_version}”)
- else:
- print(“cups-filters is not vulnerable or not installed.”)
- if check_service_status(‘cups-browsed’):
- print(“cups-browsed service is running, system may be vulnerable.”)
- else:
- print(“cups-browsed service is not running, system is less likely to be vulnerable.”)
- if check_udp_port_631():
- print(“UDP port 631 is exposed, system may be vulnerable.”)
- else:
- print(“UDP port 631 is not exposed, system is less likely to be vulnerable.”)
- if __name__ == “__main__”:
- check_vulnerabilities()
Detecting CUPS Vulnerabilities: CVE-2024–47076, CVE-2024–47175, CVE-2024–47176 CVE-2024–47177
- import subprocess
- import re
- def check_package_version(package_name):
- try:
- result = subprocess.run([‘dpkg-query’, ‘-W’, ‘-f=${Version}’, package_name],stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- version = result.stdout.decode(‘utf-8’).strip()
- if result.returncode == 0:
- return version
- else:
- return None
- except Exception as e:
- print(f”Error checking {package_name}: {e}”)
- return None
- def check_service_status(service_name):
- try:
- result = subprocess.run([‘systemctl’, ‘is-active’, service_name], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- status = result.stdout.decode(‘utf-8’).strip()
- return status == ‘active’
- except Exception as e:
- print(f”Error checking {service_name}: {e}”)
- return False
- def check_udp_port_631():
- try:
- result = subprocess.run([‘ss’, ‘-uln’], stdout=subprocess.PIPE)
- output = result.stdout.decode(‘utf-8’)
- return ‘631’ in output
- except Exception as e:
- print(f”Error checking UDP port 631: {e}”)
- return False
- vulnerable_versions = {
- ‘libcupsfilters’: ‘2.1b1’,
- ‘libppd’: ‘2.1b1’,
- ‘cups-filters’: ‘2.0.1’,
- }
- def compare_versions(installed_version, vulnerable_version):
- installed_parts = list(map(int, re.split(r’[.-]’, installed_version)))
- vulnerable_parts = list(map(int, re.split(r’[.-]’, vulnerable_version)))
- return installed_parts <= vulnerable_parts
- def check_vulnerabilities():
- libcupsfilters_version = check_package_version(‘libcupsfilters’)
- if libcupsfilters_version and compare_versions(libcupsfilters_version, vulnerable_versions[‘libcupsfilters’]):
- print(f”Vulnerable libcupsfilters version detected: {libcupsfilters_version}”)
- else:
- print(“libcupsfilters is not vulnerable or not installed.”)
- libppd_version = check_package_version(‘libppd’)
- if libppd_version and compare_versions(libppd_version, vulnerable_versions[‘libppd’]):
- print(f”Vulnerable libppd version detected: {libppd_version}”)
- else:
- print(“libppd is not vulnerable or not installed.”)
- cups_filters_version = check_package_version(‘cups-filters’)
- if cups_filters_version and compare_versions(cups_filters_version, vulnerable_versions[‘cups-filters’]):
- print(f”Vulnerable cups-filters version detected: {cups_filters_version}”)
- else:
- print(“cups-filters is not vulnerable or not installed.”)
- if check_service_status(‘cups-browsed’):
- print(“cups-browsed service is running, system may be vulnerable.”)
- else:
- print(“cups-browsed service is not running, system is less likely to be vulnerable.”)
- if check_udp_port_631():
- print(“UDP port 631 is exposed, system may be vulnerable.”)
- else:
- print(“UDP port 631 is not exposed, system is less likely to be vulnerable.”)
- if __name__ == “__main__”:
- check_vulnerabilities()
- python3 CVE-2024–47177-xdetection.py
Introduction
In September 2024, several critical vulnerabilities were discovered in the Common UNIX Printing System (CUPS), affecting nearly all UNIX-like operating systems, including Linux distributions. These vulnerabilities, tracked as CVE-2024–47076, CVE-2024–47175, CVE-2024–47176, and CVE-2024–47177, expose systems to potential Remote Code Execution (RCE) attacks, enabling attackers to gain unauthorized access and execute malicious code remotely.
Brief Overview of the CVEs
- CVE-2024–47076: This vulnerability resides in the
libcupsfilters
library, where IPP attributes from an IPP server are not properly sanitized. This can result in attacker-controlled data being injected into the CUPS system, enabling remote exploitation. - CVE-2024–47175: In the
libppd
library, improper validation and sanitization of IPP data can lead to malicious data being injected into PostScript Printer Description (PPD) files, opening the system to attacks. - CVE-2024–47176: The
cups-browsed
service binds to the unrestricted IP addressINADDR_ANY
on UDP port 631. This flaw allows any packet from any source to trigger an attacker-controlled IPP request, leading to potential exploitation. - CVE-2024–47177: Found in the
cups-filters
component, this vulnerability allows arbitrary command execution through theFoomaticRIPCommandLine
PPD parameter, leading to remote code execution when a print job is initiated.
The Detection Script:
To help system administrators detect if their systems are vulnerable, I’ve created a Python-based detection script. This script checks for vulnerable versions of libraries like libcupsfilters
, libppd
, and cups-filters
, as well as the status of the cups-browsed
service and whether the vulnerable port (UDP 631) is exposed.
How the Detection Script Works:
- Library Version Checks: It queries the system to check if vulnerable versions of
libcupsfilters
,libppd
, andcups-filters
are installed. - Service Status Check: It verifies if the
cups-browsed
service is running, which is necessary for some vulnerabilities to be exploited. - Port Exposure: It checks if UDP port 631 is open, which could allow an attacker to communicate with the service remotely.
Running the Script
- Prerequisites: This script is designed for Debian-based Linux distributions (like Ubuntu). It uses
dpkg-query
to check package versions. Modify it for Red Hat-based systems by usingrpm
ordnf
. - Execution: Save the script as
detection.py
and run it with Python 3 (sudo python3 detection.py
).
Conclusion
By using this detection script, system administrators can identify whether their systems are vulnerable to these recent CUPS exploits. While the vulnerabilities are serious, mitigations such as disabling the cups-browsed
service and blocking UDP port 631 can significantly reduce the attack surface until patches are available. It’s essential to stay informed and apply patches as soon as vendors release them to ensure system security.