CVE-2021-31800
📋 TL;DR
CVE-2021-31800 is a critical path traversal vulnerability in Impacket's SMB server (smbserver.py) that allows attackers to read and write arbitrary files using directory traversal sequences (../). This affects anyone running Impacket's SMB server component, particularly penetration testers and security researchers who use it for legitimate purposes, but also any production systems where it might be deployed.
💻 Affected Systems
- Impacket
📦 What is this software?
Fedora by Fedoraproject
Fedora by Fedoraproject
Fedora by Fedoraproject
Impacket by Secureauth
⚠️ Risk & Real-World Impact
Worst Case
Full system compromise via arbitrary code execution by replacing critical files like /etc/shadow or SSH authorized_keys, leading to complete system takeover.
Likely Case
Unauthorized file access and modification, potentially exposing sensitive data or enabling lateral movement within a network.
If Mitigated
Limited impact if SMB server runs with minimal privileges and proper file system permissions restrict access to sensitive areas.
🎯 Exploit Status
Exploitation is straightforward - attackers simply need to connect to the SMB server and use directory traversal sequences in file operations.
🛠️ Fix & Mitigation
✅ Official Fix
Patch Version: 0.9.23 and later
Vendor Advisory: https://github.com/SecureAuthCorp/impacket/commit/49c643bf66620646884ed141c94e5fdd85bcdd2f
Restart Required: Yes
Instructions:
1. Update Impacket using pip: 'pip install --upgrade impacket==0.9.23' 2. Restart any running smbserver.py instances 3. Verify the fix by checking the version
🔧 Temporary Workarounds
Disable SMB Server
allStop using the vulnerable smbserver.py component entirely
pkill -f smbserver.py
systemctl stop any custom services using smbserver
Run with Restricted Permissions
linuxRun smbserver.py with minimal privileges and in a chroot/jail environment
sudo -u nobody python smbserver.py
chroot /restricted/path python smbserver.py
🧯 If You Can't Patch
- Isolate the SMB server on a dedicated network segment with strict firewall rules
- Run the SMB server in a container with read-only filesystem mounts for sensitive directories
🔍 How to Verify
Check if Vulnerable:
Check Impacket version: if version <= 0.9.22 and smbserver.py is running, the system is vulnerable
Check Version:
python -c "import impacket; print(impacket.__version__)"
Verify Fix Applied:
Verify version is 0.9.23 or higher and test that directory traversal attempts are properly blocked
📡 Detection & Monitoring
Log Indicators:
- SMB requests containing '../' sequences
- Unauthorized file access attempts to sensitive paths
Network Indicators:
- SMB traffic to non-standard ports running Impacket's SMB server
- Multiple failed file operations with traversal patterns
SIEM Query:
source="smbserver.log" AND "../" OR source="auth.log" AND process="smbserver.py" AND (event="file_access" OR event="permission_denied")
🔗 References
- https://github.com/SecureAuthCorp/impacket/blob/cb6d43a677c338db930bc4e9161620832c1ec624/impacket/smbserver.py#L2008
- https://github.com/SecureAuthCorp/impacket/blob/cb6d43a677c338db930bc4e9161620832c1ec624/impacket/smbserver.py#L2958
- https://github.com/SecureAuthCorp/impacket/blob/cb6d43a677c338db930bc4e9161620832c1ec624/impacket/smbserver.py#L3485
- https://github.com/SecureAuthCorp/impacket/blob/cb6d43a677c338db930bc4e9161620832c1ec624/impacket/smbserver.py#L876
- https://github.com/SecureAuthCorp/impacket/commit/49c643bf66620646884ed141c94e5fdd85bcdd2f
- https://github.com/SecureAuthCorp/impacket/releases
- https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/IPXDPWCAPVX3UWYZ3N2T5OLBSBBUHJP6/
- https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/KRV2C5DATXBHG6TF6CEEX54KZ75THQS3/
- https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/UF56LYB27LHEIFJTFHU3M75NMNNK2SCG/
- https://github.com/SecureAuthCorp/impacket/blob/cb6d43a677c338db930bc4e9161620832c1ec624/impacket/smbserver.py#L2008
- https://github.com/SecureAuthCorp/impacket/blob/cb6d43a677c338db930bc4e9161620832c1ec624/impacket/smbserver.py#L2958
- https://github.com/SecureAuthCorp/impacket/blob/cb6d43a677c338db930bc4e9161620832c1ec624/impacket/smbserver.py#L3485
- https://github.com/SecureAuthCorp/impacket/blob/cb6d43a677c338db930bc4e9161620832c1ec624/impacket/smbserver.py#L876
- https://github.com/SecureAuthCorp/impacket/commit/49c643bf66620646884ed141c94e5fdd85bcdd2f
- https://github.com/SecureAuthCorp/impacket/releases
- https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/IPXDPWCAPVX3UWYZ3N2T5OLBSBBUHJP6/
- https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/KRV2C5DATXBHG6TF6CEEX54KZ75THQS3/
- https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/UF56LYB27LHEIFJTFHU3M75NMNNK2SCG/