ZIP Slip and Archive Extraction Attacks
You'll learn how attackers can escape extraction directories by hiding malicious paths inside archive files, and how to prevent this dangerous vulnerability.
What is ZIP Slip?
ZIP Slip is a directory traversal vulnerability that occurs during the extraction of archive files (ZIP, TAR, etc.). When an application extracts an archive without validating the file paths inside, attackers can craft malicious archives containing filenames with path traversal sequences like ../../ that escape the intended extraction directory.
Think of it like this: You ask someone to unpack boxes only in your garage, but they've labeled items with addresses that lead them to place things throughout your entire house—including sensitive areas like your bedroom or safe.
How the Attack Works
An attacker creates an archive containing entries with paths like:
../../etc/passwd../../../../var/www/html/shell.php..\..\..\Windows\System32\malicious.dll
When extracted without validation, these files are written to locations outside the intended directory. This can lead to:
- Arbitrary file overwrite (replacing system files, configuration files)
- Remote code execution (placing web shells in web roots)
- Privilege escalation (modifying startup scripts or binaries)
Prevention Essentials
Before writing each extracted file:
- Canonicalize the full target path (resolve all
.and..components) - Verify it starts with your intended extraction directory
- Reject any file that would write outside that boundary
- Check for symbolic links that might redirect extraction elsewhere
Never trust archive filenames directly—always validate and sanitize the final destination path.
Key Takeaway: ZIP Slip exploits unchecked file paths during extraction to write files anywhere on the system; always canonicalize and validate that extracted file paths remain within your intended directory before writing them.