TAR backups

Easy PrivEsc

> whoami
www-data
> sudo -l
(sally) NOPASSWD: /bin/tar

> sudo -u sally tar -cf /dev/null /dev/null --checkpoint=1 --checkpoint-action=exec=/bin/sh
> sudo -u sally tar -cf /dev/null /dev/null --checkpoint=1 --checkpoint-action=exec=/bin/bash
> whoami
sally

Backup Script Vulnerability

  • If root is doing anything as a job, you can attempt to re-direct it

  • Copy the script back to your host and decompose it for analysis

  • Examples of root running TAR:

Just like NFS Root Squashing

  • Similar to "NFS Root Squashing" and the "jail" box

    • Make setuid root owned

    • gzip the setuid

    • copy back inject into the 'temp' check folder

    • root will extract to 'check' the files

    • and thinks it belongs to him!

Backup Script Discovery

  • Enum to find the backup/script/job running

  • Works just fine as 'user'

Backup Flaw Scenario

  1. Backup script runs TAR as Root every 5 minutes

  2. Deletes the previous checks: /var/tmp/.* and /var/tmp/check.

  3. Creates a gzip file of the directory /var/www/html with user-perms

  4. Saves it in the file /var/tmp/.randomsha1

  5. Sleeps for 30 seconds.

  6. Creates the directory /var/tmp/check

  7. Extracts gzip with Root /var/tmp/.randomsha1 to /var/tmp/check

  8. If /var/www/html is different from backup: /var/tmp/check/var/www/html

    1. Report error.

    2. Otherwise, move file /var/tmp/.randomsha1 to /var/backups/onuma-wwww-dev.bak

    3. And delete 'check' directory and .randomsha1

Backup Flaw Exploit #1

  • Script design is to tar as user, then untar as root

  • Then compare previous version (which gives us 5 minutes)

  • We can inject our evil tar:

  • Script will: tar/copy/extract/compare.. and fail with error..

  • Giving us 5 minutes to use root-unzipped-files

Create the evil setuid

TAR the evil suid

  • TAR embeds the userid that owns the file - in the actual archive

  • We create this file and TAR as root .. it will stay root when extracted

Backup Flaw Exploit #2

  • diff runs as root

  • updates to readable error file:

    • /var/backups/onuma_backup_test.txt

  • tar an evil symlink that root will extract/diff

REF

Last updated

Was this helpful?