HackTheBox - Traceback
Traceback is a Linux box where the initial access is achieved by finding a web shell left by the website defacer. The privilege escalation path abuses Lua programming language scripting platform and write access to a /etc/motd-file. Good stuff.
Nmap results
Only SSH and HTTP ports are open.
Website enumeration
The website has been defaced by “Xh4H”.
Inside the page source code there’s a comment:
If we Google this phrase we get a GitHub repository Xh4H/Web-Shells filled with different web shells.
I created a text file filled with all the names of the web shells and ran gobuster with it against the website.
gobuster dir -u 10.10.10.181 -w webshells.txt
.
We get a hit for /smevk.php
.
The default credentials for this are username: admin and password: admin
The web shell is running as user webadmin
.
Privilege Escalation
Enumerating the /home-directory with the web shell we discover a file called /home/webadmin/note.txt
:
sudo -l
tells us that we can run /home/sysadmin/luvit
as sysadmin.
Before taking a closer look, I setup a reverse shell to my own machine, so we don’t have to use the web shell.
Setup a listener nc -lvnp 6669
.
Run a python3 reverse shell:
Luvit is a single binary that contains a Lua virtual machine and standard libraries. We can give it a
lua script to run and it runs it in the context of the system.
I created a very simple Lua script called a.lua
:
Upload this badboy to the /tmp-folder and run it:
sudo -u sysadmin /home/sysadmin/luvit /tmp/a.lua
Let’s spawn a TTY shell to interact further with the system with:
We can now get the user flag from /home/sysadmin
.
Root Access
Running linpeas.sh
enumeration tool, it discovers a 99% sure privilege escalation vector from /etc/update-motd.d/
.
We are able to modify the message of the day which is executed every time a user logs in.
For this we can add our SSH key to the sysadmins /home/sysadmin/.ssh/authorized_keys
-file so we can log in via SSH. Generate a key:
ssh-keygen -t rsa
Copy the id_rsa.pub and echo it to the authorized_keys:
echo "long ass key" >> /home/sysadmin/.ssh/authorized_keys
We can now add a reverse shell to the /etc/update-motd.d/00-header
-file:
Setup a listener: nc -lvnp 1335
.
SSH login to trigger the MOTD:
ssh -i id_rsa sysadmin@10.10.10.181
We get a root shell:
If you have trouble getting a shell back, there’s a script that resets
the motd-files every 30 second, so you have to be quick.
You can see the running processes e.g. with pspy.
Thank you for reading!