r/Hacking_Tutorials • • 11h ago

Question Stuck on a lab privilege escalation puzzle—sudo allows /usr/local/bin/rotate as root, and tar runs wildcard/archive flags on /opt/app/logs

Working through a controlled Ubuntu lab challenge as user dev where sudo -l grants passwordless root execution for /usr/local/bin/rotate, and the script compresses /opt/app/logs into /var/backups/app-$(date +%F).tar.gz using /usr/bin/tar -czf. I've been mapping out the exact permission/command flaw and how a root escalation chain works using only standard shell utilities, while also trying to write down the cleanest remediation for the script and sudoers entry.

Looking closely at the misconfiguration and how tar runs as root inside /opt/app/logs, there are two main angles to trace through. First, tar supports checkpoint actions via --checkpoint=1 and --checkpoint-action=exec=... when flag-like filenames are expanded in the target directory, or alternatively if /opt/app/logs or /var/backups is writable or symlink-vulnerable, arbitrary file placement or code execution as root becomes possible depending on directory permissions and tar behavior. Second, fixing the issue properly means avoiding unquoted glob expansion inside tar (such as passing -- and an explicit path), tightening ownership and permissions on /opt/app/logs and /var/backups, and locking down sudoers rules.

For anyone who has walked through similar tar / log-rotation lab scenarios, how did you pinpoint the exact weakness first, which standard Linux commands did you run to verify and trigger root cleanly, and what remediation checklist do you recommend so /usr/local/bin/rotate stays safe?

1 Upvotes

1 comment sorted by