CVE-2021-31680

7.8 HIGH

📋 TL;DR

CVE-2021-31680 is a deserialization vulnerability in YOLOv5 that allows attackers to execute arbitrary code by providing a malicious YAML configuration file. This affects any system using vulnerable versions of YOLOv5 for object detection tasks. Attackers can gain full control of affected systems through this remote code execution vulnerability.

💻 Affected Systems

Products:
  • YOLOv5 (You Only Look Once version 5)
Versions: All versions prior to the fix
Operating Systems: All operating systems running Python
Default Config Vulnerable: ⚠️ Yes
Notes: Any system using YOLOv5 with YAML configuration file loading is vulnerable. This includes web applications, APIs, and batch processing systems that accept YAML input.

📦 What is this software?

⚠️ Risk & Real-World Impact

🔴

Worst Case

Complete system compromise with attacker gaining root/administrator privileges, data exfiltration, ransomware deployment, and persistent backdoor installation.

🟠

Likely Case

Remote code execution leading to data theft, cryptocurrency mining, or use as part of a botnet for further attacks.

🟢

If Mitigated

Limited impact with proper input validation and sandboxing, potentially only denial of service if execution is prevented.

🌐 Internet-Facing: HIGH - YOLOv5 is often deployed in web applications and APIs that accept user-uploaded configuration files.
🏢 Internal Only: MEDIUM - Internal systems using YOLOv5 for processing tasks could be exploited by malicious insiders or through lateral movement.

🎯 Exploit Status

Public PoC: ⚠️ Yes
Weaponized: LIKELY
Unauthenticated Exploit: ⚠️ Yes
Complexity: LOW

Exploitation requires the attacker to provide a malicious YAML file to the vulnerable YOLOv5 instance. The vulnerability is in the PyYAML deserialization process.

🛠️ Fix & Mitigation

✅ Official Fix

Patch Version: Updated versions with safe YAML loading (yaml.safe_load instead of yaml.load)

Vendor Advisory: https://huntr.dev/bounties/1-other-yolov5/

Restart Required: No

Instructions:

1. Update YOLOv5 to the latest version. 2. Ensure all YAML loading uses yaml.safe_load() instead of yaml.load(). 3. Review and update any custom YAML parsing code in your implementation.

🔧 Temporary Workarounds

Use Safe YAML Loading

all

Replace all instances of yaml.load() with yaml.safe_load() in the YOLOv5 codebase

sed -i 's/yaml\.load(/yaml.safe_load(/g' *.py

Input Validation

all

Implement strict validation of YAML files before processing, rejecting files with suspicious content

🧯 If You Can't Patch

  • Implement network segmentation to isolate YOLOv5 systems from critical infrastructure
  • Use application sandboxing or containerization with minimal privileges to limit exploit impact

🔍 How to Verify

Check if Vulnerable:

Check if your YOLOv5 code uses yaml.load() instead of yaml.safe_load() for parsing configuration files

Check Version:

Check your YOLOv5 version and review the YAML parsing implementation in utils/general.py and related files

Verify Fix Applied:

Verify that all YAML loading uses safe_load() and test with known malicious YAML files to ensure they are rejected

📡 Detection & Monitoring

Log Indicators:

  • Unexpected process execution from YOLOv5 context
  • YAML parsing errors with suspicious content
  • Unusual network connections from YOLOv5 processes

Network Indicators:

  • Outbound connections to suspicious IPs from YOLOv5 systems
  • Unexpected data exfiltration patterns

SIEM Query:

process_name:"python" AND (process_command_line:"yolov5" OR process_command_line:"yolo") AND (event_type:"process_execution" OR event_type:"network_connection")

🔗 References

📤 Share & Export