CVE-2021-29922
📋 TL;DR
This vulnerability allows attackers to bypass IP-based access controls by using IP addresses with leading zeros, which Rust incorrectly interprets as octal numbers. It affects all applications using Rust's standard library for IP address parsing before version 1.53.0. Attackers can potentially access restricted resources by crafting malicious IP strings.
💻 Affected Systems
- Rust standard library
📦 What is this software?
Rust by Rust Lang
⚠️ Risk & Real-World Impact
Worst Case
Complete bypass of network-level access controls, allowing unauthorized access to internal services, data exfiltration, or lateral movement within networks.
Likely Case
Partial access control bypass for services relying on IP-based authentication, potentially exposing sensitive APIs or administrative interfaces.
If Mitigated
Limited impact if additional authentication layers exist beyond IP-based controls, or if affected services are not internet-facing.
🎯 Exploit Status
Exploitation requires sending specially crafted IP addresses with leading zeros (e.g., '0177.0.0.1' instead of '127.0.0.1'). The technique is well-documented in security advisories.
🛠️ Fix & Mitigation
✅ Official Fix
Patch Version: Rust 1.53.0 and later
Vendor Advisory: https://github.com/rust-lang/rust/issues/83648
Restart Required: Yes
Instructions:
1. Update Rust toolchain to version 1.53.0 or later using rustup update. 2. Recompile all affected applications with the updated Rust version. 3. Redeploy patched applications. 4. Restart services using the updated binaries.
🔧 Temporary Workarounds
Input validation wrapper
allImplement custom IP parsing that strips leading zeros before passing to Rust's standard library functions
// Rust code example:
fn sanitize_ip(ip_str: &str) -> String {
ip_str.split('.').map(|octet| octet.trim_start_matches('0')).collect::<Vec<_>>().join(".")
}
Network layer filtering
linuxUse firewall rules or WAF to block requests with IP addresses containing leading zeros
# Example iptables rule (adjust as needed):
iptables -A INPUT -p tcp --dport 80 -m string --string "0" --algo bm -j DROP
🧯 If You Can't Patch
- Implement additional authentication layers beyond IP-based controls
- Deploy network monitoring to detect anomalous IP address patterns in requests
🔍 How to Verify
Check if Vulnerable:
Check Rust version with 'rustc --version'. If version is below 1.53.0, the system is vulnerable. Test parsing with code that compares '0177.0.0.1' and '127.0.0.1'.
Check Version:
rustc --version
Verify Fix Applied:
After updating to Rust 1.53.0+, verify that '0177.0.0.1' and '127.0.0.1' parse to different IP addresses. Run: 'rustc --version' should show 1.53.0 or higher.
📡 Detection & Monitoring
Log Indicators:
- Log entries showing IP addresses with leading zeros (e.g., 0177.0.0.1, 00192.168.1.1)
- Multiple authentication failures from similar IP ranges with octal notation
Network Indicators:
- HTTP requests with X-Forwarded-For headers containing octal IP notation
- Unusual traffic patterns from IP addresses that don't match expected ranges
SIEM Query:
source="*access.log*" AND ("0[0-9]+\.[0-9]" OR "[0-9]+\.0[0-9]+")
🔗 References
- https://defcon.org/html/defcon-29/dc-29-speakers.html#kaoudis
- https://doc.rust-lang.org/beta/std/net/struct.Ipv4Addr.html
- https://github.com/rust-lang/rust/issues/83648
- https://github.com/rust-lang/rust/pull/83652
- https://github.com/sickcodes/security/blob/master/advisories/SICK-2021-015.md
- https://security.gentoo.org/glsa/202210-09
- https://defcon.org/html/defcon-29/dc-29-speakers.html#kaoudis
- https://doc.rust-lang.org/beta/std/net/struct.Ipv4Addr.html
- https://github.com/rust-lang/rust/issues/83648
- https://github.com/rust-lang/rust/pull/83652
- https://github.com/sickcodes/security/blob/master/advisories/SICK-2021-015.md
- https://security.gentoo.org/glsa/202210-09