/Koth-tricks

Tricks i use while playing king of the hill in tryhackme

Protect your king.txt


Level - 0:-

If you are first to to root the machine follow the below steps to protect the king.

1.To prevent overwriting the king.txt file, you can set the noclobber option in your shell.

# Set the noclobber option to prevent overwriting files
set -o noclobber /root/king.txt

2.Make King.txt unwritable using chattr chattr makes king.txt unwritable even for root.

#add the immutable bit to king.txt and /root
chattr +ia /root/king.txt
chattr +ia /root

3.Make king.txt a read-only system file, make sure you are root before running the below command.

#the 'ro' makes king.txt a read-only system file.
sudo mount --bind -o ro /root/king.txt /root/king.txt 2>/dev/null

Snatch Other's king and make it yours 😂

1.If you cant overwrite king.txt then someone already set noclobber on king.txt you can unset it by

set +o noclobber /root/king.txt

or

echo "USERNAME" >| /root/king.txt

2.When you write your username to king.txt and operation not permitted occurs then probably someone used chattr on king.txt or /root, you can easily remove the immutable bit from king.txt by

chattr -ia /root/king.txt
chattr -ia /root

3.If read-only system file appears when you write your name in it , then someone mounted it to make king.txt unwritable, some players also mount whole /root,to unmount it

sudo umount -l /root/king.txt
sudo umount -l /root

level - 1