HTB - Traceback

Zweilosec's write-up on the easy difficulty Linux machine Traceback from https://hackthebox.eu

Overview

Traceback is an easy difficulty Linux machine that gives a good introduction to web shells and tracing the steps of how an attacker compromised a server (then defaced it!).

Enumeration

Nmap scan

I started off my enumeration with an nmap scan of 10.10.10.181. The options I regularly use are: -p-, which is a shortcut which tells nmap to scan all TCP ports, -sC is the equivalent to --script=default and runs a collection of nmap enumeration scripts against the target, -sV does a service scan, -oN <name> saves the output with a filename of <name>.

SSH

The only ports that were open were 22 -SSH and 80 - HTTP. I first tried connecting to SSH:

I wasn't able to login, but I noticed a banner saying that the system had been owned due to poor configurations by someone named Xh4H.

HTTP

Connecting to port 80 through a web browser gave me a very similar message. It also said something about a backdoor, so I fired up gobuster to see if I could find any other pages since there were no other hints or ways to progress.

Unfortunately this did not get me anywhere, as the connection was blocked and I wasn't able to find anything.

FREE INTERNETZZZ - Twitter OSINT

Next I tried a web search for FREE INTERNETZZZ, which led me to Twitter of all places.

"Pretty interesting collection of webshells:" says the author of this machine...and posted around the same time as the release (14 Mar 2020 - See info card). This felt a lot like an OSINT-type challenge to me. Clicking on the post led to a collection of "Some of the best web shells that you might need" at https://github.com/TheBinitGhimire/Web-Shells.

I didn't know which web shell was used, and the hint left by Xh4H only led to a GitHub repository with a collection of shells. I downloaded them all and started poking through the code to see if anything looked familiar, but most of it was obfuscated and I couldn't find the phrase FREE INTERNETZZZ in any of the files. So, I created a list of the filenames and used wfuzz to check to see if any of them had been uploaded to the site. (And I hoped that the filename hadn't been changed!)

Initial Foothold

Smevk_Pathan Shell v3

Using wfuzz I was able to find the web shell used at http://10.10.10.181/smevk.php.I navigated to this page and got a login screen.

I opened the code of the smevk.php web shell that I had downloaded earlier and didn't have to search long to find what I was looking for.

The code came with hard-coded default credentials of admin:admin. I tried them out on the login page, and was granted access to the shell page.

When I first started poking around, clicking on buttons and trying to use the shell to enumerate the system I was getting a bit frustrated. Nothing seemed to be working. Below are my original notes:

It seems as if a lot of the functionality was stripped out...most of the buttons do nothing. Never mind...DOESNT WORK IN FIREFOX!!!! > worked just fine in Chromium!

For some reason the web shell did not function properly in Firefox. When I finally got tired of banging my head against the shell trying to find something that worked, I decided to try opening it in Chromium instead...and everything worked!

After doing some troubleshooting and looking into the code it seemed as if the web shell itself was looking for a HTTP_USER_AGENT with 'Google' in it. I wasn't sure why this might interfere since it seems to give a 404 error if the user agent IS Google. This may be just to keep the Google bots from crawling the page and discovering the backdoor. Using the unPHP decoder site https://www.unphp.net/decode/9e310714b0ca99497d4a486d220d34f7/ I read through the rest of the code of the backdoor to see if I could find anything that would cause it to not work in Firefox, but I didn't see anything obvious.

Road to User

I noticed that the web shell told me that the username we had control of was webadmin, so I decided to try to add my public SSH key to the .ssh/authorized_keys file of that user to see if it would let me log in that way. I entered the command echo "ssh-rsa AAAA<my_public_key> zweilos@kali" >> /home/webadmin/.ssh/authorized_keys into the Console field of the web shell. (Notice the append operator >>? Please be nice to your fellow players and don't overwrite the whole file with >!)

According to https://www.ssh.com/ssh/keygen/ you can also do this remotely from a terminal usingssh-copy-id -i ~/.ssh/tatu-key-ecdsa user@host but you need to be able to authenticate to the machine already to do this.

Enumeration as webadmin

After uploading my public key it was easy to just SSH into the machine using my own private key.

The first thing I do when getting a new user account is see what privileges I have and if I can execute anything with sudo by using the -l flag.

I was able to execute the luvit program in sysadmin's home folder as that user without a password.

Making user creds

By reading a bit on luvit, I discovered it was essentially a lua programming language shell.

Repl#

Implementation of a read-execute-print-loop in Luvit. Used by the Luvit repl which is returned when the Luvit binary is executed without args.

From https://www.lua.org/pil/22.2.html I discovered I could execute system commands by using the syntax os.execute("mkdir " .. dirname).

A quick troubleshooting note... you will need to make sure to put a space between the command and the argument manually, as this seems to just concatenate the two strings then executes. The space can either be at the end of the command or the beginning of the arguments.

User.txt

Getting a shell as sysadmin

While reading up on how to execute commands in this luvit shell, I came across this page https://simion.com/info/calling_external_programs.html which described a way to execute commands that were more complex than a simple "command" .. "argument" format.

I used this to once again copy my public SSH key to the new user, and used SSH to login.

Path to Power (Gaining Administrator Access)

Enumeration as sysadmin

I started out in /bin/sh, which was pretty limiting (no history, arrow keys, or tab completion, etc) so I tried to use my standard python PTY shell upgrade trick, but it didn't work. It was late and I was tired, so I looked up how to do it in Perl, since it was installed, using perl -e 'exec "/bin/bash";'. When I went back to it the next morning, I realized that indeed python was not installed...but python3 was! Doh!

I wasn't able to check sudo permissions without a password, so I checked running processes next. I noticed a strange sleep 30 process running by root, so I decided to look further into what processes were being run as root with ps -U root -u root (from the man page).

There was a script running every 30 seconds which restored a backup of the MOTD (message of the day) which definitely looked odd, so I checked both of the directories in the command to see if could find anything useful.

Interestingly, the files in /etc/update-motd.d/ were editable by sysadmin. (The backups were not).

The file 00-headerseem to have been edited already by Xh4H when he defaced the site and set up his web shell. MOTD banners are just bash scripts which are executed each time a user logs into the machine, so I decided to add a line of my own to see if I could escalate privileges since the files and process that ran them were owned by root.

Getting a root shell

According to the ps output, every 30 secs a cronjob copies the backups from /var/backups/.update-motd.d/ to /etc/update-motd.d/. This was the window I had to edit the file and get it to execute to initiate my exploit before the backup wiped my progress. I decided to go for broke and simply use the same privilege escalation method I had already been using.

I copied the same echo command I had used to escalate privileges to the previous two users, and echoed it into the MOTD file 00-header. I set it to copy my public SSH key to the authorized_keys file, this time in the /root/.ssh/ folder.

In order to execute my command, I needed to run the MOTD program. Since this program is automatically run upon login, I simply logged out, connected back to the sysadmin user through SSH, then logged out again, then logged in as root.

Root.txt

Of course I couldn't forget to collect my hard-earned proof!

Thanks to Xh4H for creating a machine where I could learn about how web shells work, and about tracing back the steps that an attacker took to compromise a system.

If you like this content and would like to see more, please consider buying me a coffee!

Last updated

Was this helpful?