HackTheBox - OneTwoSeven

Nmap scan (Basic and all port)

Always ping the machine before running the nmap scan.

All port scan discloses port 60080 to be filtered, so we will keep that in mind.

WAF/Firewall Running

Some kind of firewall shutting down the webserver after certain amount of requests. This kind of scenario happens when are sending a lot of requests at the same time. So we cannot run gobuster scan.

We can poke around the website and start with manual enumeration.

When we click on the Signup today button, we get to this page with a set of credentials.

In computing, the SSH File Transfer Protocol is a network protocol that provides file access, file transfer, and file management over any reliable data stream. It was designed by the Internet Engineering Task Force as an extension of the Secure Shell protocol version 2.0 to provide secure file transfer capabilities.

So the admin access is only enabled for trusted network and in this case is localhost (127.0.0.1)

Enumerating SFTP (Secure File Transfer Protocol)

We can try to login to SSH using the given credentials.

Nope that didn't work. Let's try using SFTP command that is pre-installed in Kali.

We have this website http://onetwoseven.htb/~ots-lYmQ1YWI/ where we can upload files if we want using SFTP Server. Let's see if this works properly. I will try to upload a basic html file.

Looks like we can upload a file and that file will be served on the web-server.

But for some reason, we can't upload a php file and if we try to upload it, it gives us the following error.

There was a vulnerability related to SFTP wherein we can create a symlink where we have read and write privileges. This attack is known as SFTP Symlink attack.

Read more about here . Now we can try to list the root of the system using the following command.

A symbolic link, also termed a soft link, is a special kind of file that points to another file, much like a shortcut in Windows or a Macintosh alias. Unlike a hard link, a symbolic link does not contain the data in the target file. It simply points to another entry somewhere in the file system.

We can only access the /var/www/html and /var/www/html-admin directory. So let's get all the html/php files and start analyzing it.

Code Analysis

Download the .login.php.swp and open it using vim. (vim -r login.php.swp)

SSH Port Forwarding

This login.php file belongs to the Administrator back-end which is running on port 60080 on localhost. So we need to get access to that. We can use SSH Port forwarding option.

Hash Cracking for ots-admin

Credentials for ots-admin : Homesweethome1

Bypassing Rewrite Engines Rules

So if we try to access addon-upload.php, it will overwrite itself with addons/ots-man-addon.php. And same goes for addon-download.php. We can bypass this filter by using the following case.

Remote Code Execution

Python script to get a reverse shell

Configuring Burp Proxy for MITM Attack

We can run /usr/bin/apt-get update as well as /usr/bin/apt-get upgrade as the superuser. Interesting thing to note over here is we can use any kind of HTTP proxy if we want. That means we can assume this to be a MITM Attack.

So when we will run apt-get update, the request will go over to http://10.10.14.5:1337/ i.e Burp Proxy and then the proxy will redirect the request to our Python HTTP Server listening on port 8000.

So when we run sudo apt-get update, we get a following set of requests on our web server.

Creating Malicious Deb package

References: http://packages.devuan.org/devuan

Just go to http://packages.devuan.org/devuan/dists/ascii/main/binary-amd64/ and download the Packages.gz file.

We will edit the file according to our need. (Installing an upgrade for the package telnet)

Size and SHA256 should be edited after creating the malicious deb file.

To create a malicious package, we can take reference from https://github.com/mthbernardes/Derbie.

First the directory should be telnet, then it should contain another directory named DEBIAN and the DEBIAN directory should contain two files. control and postinst

control is almost as same as the Packages file and postinst will contain our malicious code.

Now to create the deb file, run the following command in the terminal.

Now we still need to edit the Size and SHA256 in the Packages file.

Getting Root Access

Copy the Size and SHA256 Sum and now we are good to go. First let's look at the directory structure.

Now we will run two commands: sudo apt-get update followed by sudo apt-get upgrade

Last updated

Was this helpful?