CVE-2021-36159
📋 TL;DR
CVE-2021-36159 is an out-of-bounds read vulnerability in libfetch's FTP passive mode implementation that occurs when parsing numeric strings. This vulnerability affects systems using libfetch (such as apk-tools, xbps, and other products) and could allow attackers to read sensitive memory contents. The issue stems from improper boundary checking when using strtol to parse address bytes.
💻 Affected Systems
- apk-tools
- xbps
- other products using libfetch
📦 What is this software?
Libfetch by Freebsd
⚠️ Risk & Real-World Impact
Worst Case
Remote code execution or sensitive information disclosure through memory read operations, potentially leading to full system compromise.
Likely Case
Information disclosure through memory reads, potentially exposing sensitive data like credentials or cryptographic keys.
If Mitigated
Limited impact with proper network segmentation and minimal exposure of affected services.
🎯 Exploit Status
Exploitation requires network access to FTP/HTTP services using vulnerable libfetch implementation.
🛠️ Fix & Mitigation
✅ Official Fix
Patch Version: libfetch 2021-07-26 or later
Vendor Advisory: https://gitlab.alpinelinux.org/alpine/apk-tools/-/issues/10749
Restart Required: Yes
Instructions:
1. Update libfetch to version 2021-07-26 or later. 2. Update dependent packages (apk-tools, xbps). 3. Restart affected services.
🔧 Temporary Workarounds
Disable FTP passive mode
allConfigure FTP clients to not use passive mode where possible
Network segmentation
allRestrict network access to affected services
🧯 If You Can't Patch
- Implement strict network access controls to limit exposure
- Monitor for unusual FTP/HTTP traffic patterns and memory access attempts
🔍 How to Verify
Check if Vulnerable:
Check libfetch version: grep -r 'libfetch' /etc/apk/world or check package manager for libfetch version
Check Version:
apk info -a libfetch | grep version
Verify Fix Applied:
Verify libfetch version is 2021-07-26 or later: apk version libfetch or equivalent package manager command
📡 Detection & Monitoring
Log Indicators:
- Unusual FTP passive mode connection attempts
- Memory access errors in system logs
Network Indicators:
- Suspicious FTP PORT/PASV command sequences
- Unexpected outbound connections from affected services
SIEM Query:
source="*ftp*" AND ("PASV" OR "PORT") AND dest_ip="[internal_ip]"
🔗 References
- https://github.com/freebsd/freebsd-src/commits/main/lib/libfetch
- https://gitlab.alpinelinux.org/alpine/apk-tools/-/issues/10749
- https://lists.apache.org/thread.html/r61db8e7dcb56dc000a5387a88f7a473bacec5ee01b9ff3f55308aacc%40%3Cdev.kafka.apache.org%3E
- https://lists.apache.org/thread.html/r61db8e7dcb56dc000a5387a88f7a473bacec5ee01b9ff3f55308aacc%40%3Cusers.kafka.apache.org%3E
- https://lists.apache.org/thread.html/rbf4ce74b0d1fa9810dec50ba3ace0caeea677af7c27a97111c06ccb7%40%3Cdev.kafka.apache.org%3E
- https://lists.apache.org/thread.html/rbf4ce74b0d1fa9810dec50ba3ace0caeea677af7c27a97111c06ccb7%40%3Cusers.kafka.apache.org%3E
- https://github.com/freebsd/freebsd-src/commits/main/lib/libfetch
- https://gitlab.alpinelinux.org/alpine/apk-tools/-/issues/10749
- https://lists.apache.org/thread.html/r61db8e7dcb56dc000a5387a88f7a473bacec5ee01b9ff3f55308aacc%40%3Cdev.kafka.apache.org%3E
- https://lists.apache.org/thread.html/r61db8e7dcb56dc000a5387a88f7a473bacec5ee01b9ff3f55308aacc%40%3Cusers.kafka.apache.org%3E
- https://lists.apache.org/thread.html/rbf4ce74b0d1fa9810dec50ba3ace0caeea677af7c27a97111c06ccb7%40%3Cdev.kafka.apache.org%3E
- https://lists.apache.org/thread.html/rbf4ce74b0d1fa9810dec50ba3ace0caeea677af7c27a97111c06ccb7%40%3Cusers.kafka.apache.org%3E