CVE-2022-30688
Local privilege escalation via unanchored regex checks in needrestart 0.8 to 3.5 (pre-3.6).
- CVSS 7.8
- CWE-269 Improper Privilege Management
- Authentication, Authorization, and Session Management
- Local
needrestart 0.8 through 3.5 before 3.6 is prone to local privilege escalation. Regexes to detect the Perl, Python, and Ruby interpreters are not anchored, allowing a local user to escalate privileges when needrestart tries to detect if interpreters are using old source files.
- CVSS base score
- 7.8
- Published
- 2022-05-17
- OWASP
- A06 Vulnerable and Outdated Components
- Orthogonal defect classification
- Function
- Code defect classification
- Incorrect Functionality
- Category
- Authentication, Authorization, and Session Management
- Subcategory
- Privilege Escalation
- Accessibility scope
- Local
- Impact
- Privilege Escalation
- Affected component
- needrestart
- Fixed by upgrading
- Yes
Solution
Update needrestart to version 3.6 or higher.
Vulnerable code sample
import os
import re
def is_interpreter_using_old_source(interpreter_path):
# Unanchored regex that could lead to local privilege escalation
interpreters = {
'python': r'python[0-9]*',
'perl': r'perl',
'ruby': r'ruby'
}
for interpreter, pattern in interpreters.items():
if re.search(pattern, interpreter_path):
# Logic to check if the interpreter is using old source files
# This is a placeholder for the actual implementation
return check_old_source_files(interpreter_path)
return False
def check_old_source_files(interpreter_path):
# Placeholder function to represent checking for old source files
# Actual implementation would go here
return False
# Example usage
interpreter = '/usr/local/bin/python3'
if is_interpreter_using_old_source(interpreter):
print(f"{interpreter} is using old source files.")
else:
print(f"{interpreter} is up to date.")Patched code sample
import os
import re
def is_interpreter_using_old_source(interpreter_path):
# Anchored regex to prevent local privilege escalation
interpreters = {
'python': r'^/usr/bin/python[0-9]*$',
'perl': r'^/usr/bin/perl$',
'ruby': r'^/usr/bin/ruby$'
}
for interpreter, pattern in interpreters.items():
if re.match(pattern, interpreter_path):
# Logic to check if the interpreter is using old source files
# This is a placeholder for the actual implementation
return check_old_source_files(interpreter_path)
return False
def check_old_source_files(interpreter_path):
# Placeholder function to represent checking for old source files
# Actual implementation would go here
return False
# Example usage
interpreter = '/usr/bin/python3'
if is_interpreter_using_old_source(interpreter):
print(f"{interpreter} is using old source files.")
else:
print(f"{interpreter} is up to date.")Cite this entry
@misc{vaitp:cve202230688,
title = {{Local privilege escalation via unanchored regex checks in needrestart 0.8 to 3.5 (pre-3.6).}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2022},
note = {VAITP Python Vulnerability Dataset, entry CVE-2022-30688},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2022-30688/}}
}
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 ::
