Post

HTB - Router Space

Box-Info

Summary

The RouterSpace machine from hack the box was very easy and fun box. It involved installing of an apk file which could be downloaded from there webpage. The application’s feature contained an RCE vulnerability which was exploited to add our public key into the “.ssh” directory of a user and gain access to the ssh terminal using our private key. Privilege escalation was the simplest part of this machine where could exploit an outdated service vulnerability to spawn the root shell.

NMAP Scanning

As always starting with enumeration with nmap.

nmap

From the nmap results we can see there are 2 ports open, which are,

  • Port 22 running SSH service
  • Port 80 running HTTP web service

Web Enumeration

As we know that a web service was being hosted on the remote machine, Let’s access the webpage.

router-space

It was a static webpage with nothing much useful information, but we could download an apk file named RouterSpace.apk.

APK File Analysis

I tried analyzing the file with exiftool but nothing much information could be obtained. So, I used anbox software where I could install the apk file and do further analysis.

For anbox installation, sudo snap install –beta –devmode anbox

For Launching anbox, anbox launch --package=org.anbox.appmgr --component=org.anbox.appmgr.AppViewActivity

router-space

Now we can use adb to install the RouterSpace.apk

adb install RouterSpace.apk

After that we can see the application will be installed on the anbox and we can launch it.

router-space

After launching the application, we will get the “check status” option which is will try to connect to some router I guess.

router-space

Anyway, we can intercept the connection query with burpsuite after configuring the proxy and adbshell as shown below.

Burpsuite proxy configuration,

router-space

Now run adb shell settings put global http_proxy <ip>:<port>

And now we click the “Check Status” button the burpsuite will intercept the network query.

router-space

Before doing anything else we need to add the domain name routerspace.htb in our /etc/hosts file.

Command Injection

There was only one data being send in the IP field, after further analysis and research I found that the field could be used for command injection and using “/n” is one of method to used escape command injection filtering. So, we could inject commands using “/n” which places the next command in new line which will be executed in the remote machine.

router-space

After I confirmed the command injection vulnerability, I tried getting revere shell using bash command, but it was not working, I tried even encoding and any other possible ways possible, but it still didn’t work. Maybe there was filtering on that machine. Although reverse shell was not possible, we could enumerate the directories in that machine, so, after some basic enumeration.

I found the user flag in the home directory file of paul user.

router-space

Getting a Shell using SSH

Since we could read the user flag from there, I tried creating file using echo command to create file and it was successful. And since there was SSH service running on the machine, and we could use echo command to write files on the machine. We could use “ssh-keygen” and upload our public key in the “.ssh” directory of “paul” user and access the service using our private key.

Generating SSH keys using ssh-keygen

ssh-keygen -f paul

router-space

Now we can check and copy our public key,

router-space

Now we can use our public key content and send it to the “.ssh” directory of paul user in that remote machine from the command injection method from previous section.

router-space

Now we can use our private key to authenticate the SSH service as paul user in the remote machine. ssh -i <private_key> <username>@<ip>

router-space

Prvilege Escalation

Since we are using SSH service to login we can scp command to send the linpeas.sh script,

scp -i <priv_key> <path/to/file> <username>@<ip>

router-space

After executing the script it showed lots of vulnerabilities in that machine, but here I will be exploiting the outdated sudo version vulnerability. We can exploit vulnerability CVE-2021-3156 from the github repository as shown from the linpeas enumeration.

router-space

After downloading the exploit, I again sent the script using scp.

And simply after executing the script as instructed un the file we can easily spawn the root shell and get the root flag from the “root” directory.

router-space

This post is licensed under CC BY 4.0 by the author.