Touch

Description

Push me, and then just touch me, till I can get my, Satisfaction!

Solution

We are given a netcat port to connect to and are dropped to reverse shell looking shell. From start we are in / directory, but we can quickly find ourselves in /home/ctf with touch symlink which points to suid bit touch binary.

ctf@ng-932570-misctouchmp-xedvo-5894b48d9d-f7crn:~$ ls -l touch
lrwxrwxrwx 1 root root 14 Aug  2  2022 touch -> /usr/bin/touch
ctf@ng-932570-misctouchmp-xedvo-5894b48d9d-f7crn:~$ ls -l /usr/bin/touch
lrwxrwxrwx 1 root root 10 Aug  1  2022 /usr/bin/touch -> /bin/touch
ctf@ng-932570-misctouchmp-xedvo-5894b48d9d-f7crn:~$ ls -l /bin/touch
-rwsr-sr-x 1 root root 97152 Feb 28  2019 /bin/touch

toucharrow-up-right - change file timestamps, additionally it creates file if it doesn't exist.

When we create a file we have 644 (rw-r--r--) permissions.

ctf@ng-932570-misctouchmp-xedvo-5894b48d9d-f7crn:~$ ./touch /tmp/sadf
ctf@ng-932570-misctouchmp-xedvo-5894b48d9d-f7crn:~$
ctf@ng-932570-misctouchmp-xedvo-5894b48d9d-f7crn:~$ ls -l /tmp/sadf
-rw-r--r-- 1 root root 0 Aug 23 06:45 /tmp/sadf

The default permissions for new files is determined by the "umask" command srcarrow-up-right

AskUbuntu > What is "umask" and how does it work?arrow-up-right

Turns out we can modify the mask and create file that have write permissions by all

Touch doesn't allow recreating files, only creating. This means we can't overwrite the existing files like /etc/passwd to gain write permissions and root doesn't seem to have .ssh directory :/

HackTricks > Arbitrary File Write to Root > "/etc/ld.so.preload"arrow-up-right

Compile the so locally

Copy the file to remote server

circle-check

Last updated