CVE-2022-27271
InRouter 900 (before v1.0.0.r11700) RCE via python-lib due to crafted packet
- CVSS 9.8
- CWE-78
- Input Validation and Sanitization
- Remote
InHand Networks InRouter 900 Industrial 4G Router before v1.0.0.r11700 was discovered to contain a remote code execution (RCE) vulnerability via the component python-lib. This vulnerability is triggered via a crafted packet.
- CWE
- CWE-78
- CVSS base score
- 9.8
- Published
- 2022-04-10
- OWASP
- A06 Vulnerable and Outdated Components
- Orthogonal defect classification
- Function
- Code defect classification
- Incorrect Functionality
- Category
- Input Validation and Sanitization
- Subcategory
- Command Injection
- Accessibility scope
- Remote
- Impact
- Arbitrary Code Execution
- Affected component
- python-lib
- Fixed by upgrading
- Yes
Solution
Update python-lib to version v1.0.0.r11700 or higher.
Vulnerable code sample
import socket
import subprocess
def handle_packet(data):
# Directly execute the received data without validation
# This is the vulnerable part of the code
try:
result = subprocess.run(data, shell=True, check=True, capture_output=True)
print(result.stdout.decode())
except subprocess.CalledProcessError as e:
print(f"Error executing command: {e}")
def start_server():
server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_socket.bind(('0.0.0.0', 12345))
while True:
data, addr = server_socket.recvfrom(1024)
handle_packet(data.decode())
if __name__ == "__main__":
start_server()Patched code sample
import socket
import subprocess
def handle_packet(data):
# Validate the incoming data to prevent RCE
if is_valid_packet(data):
# Process the packet safely
process_packet(data)
else:
print("Invalid packet received.")
def is_valid_packet(data):
# Implement validation logic to ensure the packet is safe
# For example, check for allowed commands or data formats
allowed_commands = ['command1', 'command2']
if data in allowed_commands:
return True
return False
def process_packet(data):
# Safely execute a command based on the validated packet
# Use a safe method to handle commands, avoiding shell=True
try:
result = subprocess.run(['./safe_command', data], check=True, capture_output=True)
print(result.stdout.decode())
except subprocess.CalledProcessError as e:
print(f"Error executing command: {e}")
def start_server():
server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_socket.bind(('0.0.0.0', 12345))
while True:
data, addr = server_socket.recvfrom(1024)
handle_packet(data.decode())
if __name__ == "__main__":
start_server()Cite this entry
@misc{vaitp:cve202227271,
title = {{InRouter 900 (before v1.0.0.r11700) RCE via python-lib due to crafted packet}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2022},
note = {VAITP Python Vulnerability Dataset, entry CVE-2022-27271},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2022-27271/}}
}
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 ::
