VAITP Dataset

← Back to the dataset

CVE-2020-15415

DrayTek Vigor < 1.5.1: Remote code execution via filename with text/x-python-script content type

  • CVSS 9.8
  • CWE-78 Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')
  • Input Validation and Sanitization
  • Remote

On DrayTek Vigor3900, Vigor2960, and Vigor300B devices before 1.5.1, cgi-bin/mainfunction.cgi/cvmcfgupload allows remote command execution via shell metacharacters in a filename when the text/x-python-script content type is used, a different issue than CVE-2020-14472.

CVSS base score
9.8
Published
2020-06-30
OWASP
A03 Injection
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
cgi-bin/mainfunction.cgi
Fixed by upgrading
Yes

Solution

Update to DrayTek Vigor3900, Vigor2960, or Vigor300B devices version 1.5.1 or higher.

Vulnerable code sample

import os
from flask import Flask, request

app = Flask(__name__)

@app.route('/upload', methods=['POST'])
def upload_file():
    if 'file' not in request.files:
        return 'No file part', 400
    
    file = request.files['file']
    
    # Vulnerable code: directly using the filename without validation
    file.save(os.path.join('/uploads', file.filename))
    return 'File uploaded successfully', 200

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

Patched code sample

import os
from flask import Flask, request, abort

app = Flask(__name__)

@app.route('/upload', methods=['POST'])
def upload_file():
    if 'file' not in request.files:
        abort(400, 'No file part')
    
    file = request.files['file']
    
    # Validate filename to prevent command injection
    if not is_safe_filename(file.filename):
        abort(400, 'Unsafe filename')
    
    # Save the file securely
    file.save(os.path.join('/safe/directory', file.filename))
    return 'File uploaded successfully', 200

def is_safe_filename(filename):
    # Check for allowed characters in the filename
    return all(c.isalnum() or c in ('-', '_', '.') for c in filename)

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

Cite this entry

@misc{vaitp:cve202015415,
  title        = {{DrayTek Vigor < 1.5.1: Remote code execution via filename with text/x-python-script content type}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2020},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2020-15415},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2020-15415/}}
}

Download this entry as JSON Download the whole dataset

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 ::

Before you use the VAITP AI models

Please read and accept the following disclaimer:

By choosing "I understand and accept", you acknowledge that you understand and agree to these terms.