CVE-2021-44255
Remote code execution via malicious configuration backup
- CVSS 7.2
- CWE-306 Missing Authentication for Critical Function
- Input Validation and Sanitization
- Remote
Authenticated remote code execution in MotionEye <= 0.42.1 and MotioneEyeOS <= 20200606 allows a remote attacker to upload a configuration backup file containing a malicious python pickle file which will execute arbitrary code on the server.
- CVSS base score
- 7.2
- Published
- 2022-01-31
- OWASP
- A08 Software and Data Integrity Failures
- Orthogonal defect classification
- Function
- Code defect classification
- Incorrect Functionality
- Category
- Input Validation and Sanitization
- Subcategory
- Insecure Parsing or Deserialization
- Accessibility scope
- Remote
- Impact
- Arbitrary Code Execution
- Affected component
- Python
- Fixed by upgrading
- Yes
Solution
Update to MotionEye version 0.42.2 or higher.
Vulnerable code sample
import os
import pickle
from flask import Flask, request
app = Flask(__name__)
@app.route('/upload_backup', methods=['POST'])
def upload_backup():
if not request.form.get('auth_token') == 'your_secure_token':
return 'Unauthorized', 403
backup_file = request.files['backup']
if backup_file and backup_file.filename.endswith('.pkl'):
# Save the uploaded file without validation
backup_path = os.path.join('/uploads/', backup_file.filename)
backup_file.save(backup_path)
# Load the pickle file without restrictions
with open(backup_path, 'rb') as file:
data = pickle.load(file) # Vulnerable to arbitrary code execution
# Process the data as needed
return 'Backup uploaded and processed successfully', 200
if __name__ == '__main__':
app.run()Patched code sample
import os
import pickle
from flask import Flask, request, abort
app = Flask(__name__)
# Function to securely load a pickle file
def secure_load_pickle(file_path):
# Only allow loading from a specific directory to prevent arbitrary file access
if not file_path.startswith('/allowed/directory/'):
abort(403) # Forbidden access
with open(file_path, 'rb') as file:
return pickle.load(file)
@app.route('/upload_backup', methods=['POST'])
def upload_backup():
if not request.form.get('auth_token') == 'your_secure_token':
abort(403) # Unauthorized access
backup_file = request.files['backup']
if backup_file and backup_file.filename.endswith('.pkl'):
# Save the uploaded file securely
backup_path = os.path.join('/allowed/directory/', backup_file.filename)
backup_file.save(backup_path)
# Load the pickle file securely
try:
data = secure_load_pickle(backup_path)
# Process the data as needed
except Exception as e:
abort(400) # Bad request, handle errors appropriately
return 'Backup uploaded and processed successfully', 200
if __name__ == '__main__':
app.run()Cite this entry
@misc{vaitp:cve202144255,
title = {{Remote code execution via malicious configuration backup}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2022},
note = {VAITP Python Vulnerability Dataset, entry CVE-2021-44255},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2021-44255/}}
}
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 ::
