Linux Wildcard Abuse
wildcard character can be used as a replacement for other characters and are interpreted by the shell before other actions. Examples of wild cards include:
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. |
We see this in a cronjob:
We can abuse the wildcard *
. The key to this attack is how the wildcard * works in Linux. When used in a command like:
The shell expands *
before executing the command. It replaces *
with all filenames in the directory. So if we create these files in the directory:
Then the directory will contain:
And the actual command that will run is:
This means tar
receives --checkpoint=1
and --checkpoint-action=exec=sh root.sh
as actual command-line arguments. Because tar
supports these flags, it executes sh root.sh
, leading to privilege escalation.
Abusing tar
Wildcards in Cron Jobs
A cron job runs tar
on a directory that you can write to.
🚀 Exploitation Steps:
We could also create a malicious script that opens a reverse shell like this root.sh one:
Wait for cron job execution, then escalate
Abusing zip
Wildcard Expansion
A cron job runs:
You can write to the directory.
🚀 Exploitation Steps:
When zip
runs, it executes the reverse shell.
Exploiting make
Wildcards
A cron job runs:
You can write to the directory.
🚀 Exploitation Steps:
When make
runs, it executes /bin/bash
.