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

Seal HackTheBox Walkthrough

nuri09

Cryptographic Vulnerability Auditor
N Rep
0
0
0
Rep
0
N Vouches
0
0
0
Vouches
0
Posts
117
Likes
183
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
Seal is a CTF Linux machine rated as medium difficulty on Hack the Box platform. So let get started and deep dive into breaking down this machine by using the following methodology below.

Pentesting Methodologies

Port Scanning & Enumeration

  • Nmap
  • Dirb
  • GitBucket

Exploitation

  • Path Traversal
  • Abusing Tomcat Server
  • Netcat Reverse Connect

Privilege Escalation

  • Digging SSH Id_rsa
  • Abusing sudo right

Port Scanning & Enumeration

Nmap

First, we’ll start by running a nmap aggressive scan to look for open ports. As you can see, 3 ports are open, namely:

  • port 22 for ssh service running
  • port 443 for SSL ngnix service running
  • port 8080 for http-proxy service running

Code:
nmap -p- -A 10.129.186.142

AVvXsEgrV_K3bBRPlMkoVBalHuZpT1HrmryNeXxj6K7MgK5-zPRnps6ksso2wB8ItcGTpnCdEogs2pl4hXXcSfCwVURL2zbntabw_njzvcYGb1I5KwpFSYeOJMUzj_GogbXAoDIJUzneA5aj_D_rYhdi1aLebStoMYwvAb4PUHLRZds6lw4riSwDZmKMt5VJpw=s16000


Let’s browse the IP address in a browser. The http request is automatically redirected to https. The only usable information found here is the email address: [email protected].

AVvXsEjKIsOxPgUnS7CzZt5SdTfoNWQmWxp4gPQ0vmYRO3sQ7tgrWAXrE3KAEDx4NkpizFtXNThlpWA_Szvq1I6xYI7tR4JXmzgDroWkB6_Lh10wjAu1wUeLNPkEwbOYhH8d832MjPw7cb_mPZafCAvp_WuSmBfGIC43BQondjVKyb5C6Dt-x7keCKPHpU9w4A=s16000


Here we use DIRB which is a web content scanner to brute force the directory and files name of the seal machine.

Code:
dirb https://seal.htb

AVvXsEhJUnvbSiIiMlb-Ykd2if0c2x2_0jdk0wOc8bjHmtSV6J_zSGb8ffp1aXPNsHc5bRnkODCeSjFhH1DMcxa-c77WR4rQepG9Q3w_FOj_kMy8nmeqN5H_Vvm93G7VJZ3nQaCUA-cgAdUXJ3u7wj0YHLOMiGCjHRV05zM4E6LUvHVCpq1iEZia6DDy3PNPZQ=s16000


Browsing on the ip address on port 8080 lead us to a webpage GitBucket. We don’t have any credentials, so let’s create a new one.

AVvXsEj2-u53xg-ikcrcrNaDOe1iyptEKxkRRop0muDDoWnDNV7fDOhd5oRhG2aRktn8I0-Mobc0mQZSurdKi1bXGp-uSW5X-b1o-rQRqFiR3hwSe4ZGfjPdle_uczyEV5kaVVHby7Q5uQ_d587qGQKhZnkyvxXvOHapgBCx_0FmfBvZSRvw73IFg8kHm_EsRg=s16000


AVvXsEjZujzYLhT21O3JPmMSyCS7gNtuzp6Ph9wrNL3lmYbMb86tAxz714a36SBhx-NjLgUQizjS1iT5Rfb35u3FFeRA-uRt6LtslwWiR-XAITUREyIbMQtcXFGMm0hNJLf93cZVOz_AzoNlH2gLRf-w0rmge0Abr0SJe3NKLUSAATrN5D2G2S_mS9ylzJpjuQ=s16000


Once an account has been created, we can now login into the website. We can see some comments on the landing page. As shown below, 2 comments were made by luis and alex regarding some issues.

AVvXsEjFXtlyMrc_3zoZYPyh_D6ZsmII4y86u78LHaaLmW7rYvb3lsAhVl9voHg5bILBfIt2lRT7fn1IpjifBwO5OrlZ7Nh_7BN235uwKZuSEx1agnd-xL-1ROXSrWEoHxOPNYe7PnaQ0LoHyhQ9-IPLuJbCMd8tN6Hj-FqrkgXMPGzNgluAKX1nYbB5LbFHUQ=s16000


In the repository section, we can see 2 repos, root/seal_market and root/infra. The seal_market repo contains all applications, like nginx, the tomcat config files for the seal market applications. This application is running on port 8080.

AVvXsEjJR4j8QukZnzYF_Ae6n0DdOQGIkau9s-quDhICrFdosfG_xtp241XbCRZpNtsnn8ip8CLXVD_kUZWXQ9iaPifbz7GULZceU8tt38e73seFHTyb8evOAt3UxSG7YvyKwifJ9lSRVydSRLICWlgTECeHug2uagoYrNm338gpwlGefaUwEAOLEYVE05ko1Q=s16000


There’s also an issue section where 13 comments can be found. It looks like 13 times some changes have been made to the application. You can see that some configuration to tomcat has also been performed.

AVvXsEjtnOvfUIO1GO360y8uCr13e1lv2D-L1ucYUtJuvNXilBisMAjGQBKqhpFvvhdp3x1NHLM4Yfw8KwysR6WRRnj52wD7Ueu41VowNaO3NfwbIgXL_efAIPtDXvWNPAbr4EVSnbOKJsD_mHXCNGZhlEe1cH70naxcvTDwYyRQwND4RbIPSXCoykN9U4hqaw=s16000


By expanding the comment, we can see that many configuration files have been changed. But the last configuration was done to the tomcat_user.xml file. It means that some information about users has been changed. While going through the configuration file, the tomcat username and password can be found.

AVvXsEiGuiXv-_79eSIVpYNQfGMAkKfQ1NWdoZSN8QKE3CfLqLqxXv69AbDcy1C3nuu-dmLpqml5E7_lfbBE7yn1nEImcWF5hbjISdXAmuVF9gCTMKIVoT1dj2XxpTjbqQT_nHLqOIgNVwuVPk9xHG7V0rKO9YOvasugMiWD28jpsrCqc16FD34afUizTUHJ6g=s16000


While trying to access the link below which we find from the dirb results, we got a 403, which means there is some particular issue with this address.

AVvXsEgQP40JCu84xUJimgykNfYKavDMR7UTgC6RodM1t0KVa0r2MhzWsE_Eqr9O-uWy6x4JwxWxNRd7Rg-jwJ2mj04NLvpYFE1pNmFeo19FMS0L1jMZLZGn4SgqWGafNV5LwJsEi7MOvXytkFenIFLB3kknu3PzmB-zYNZxPnU29IkXNwNJajd8S09u8xUc7Q=s16000


As per the ngnix configuration file which has also been recently modified as per Alex comments, we can see that the code below shows that if the verification is not successful, then display 403. And from the above screenshot, we got a 403. So, we have to bypass it.

AVvXsEi9PFKLnu3xPvT_ohKT9_b0sbuTSAY119UXhITdYbp8A81moCvDX8CkaCLhGdbtRr20fW9U8emFpJPvjTf9MBpb0MxMFfUcFezr14VDmhGtkYuHlJ8EX44zuLwLcHv1QAJG4Z5bSoaTPgWT7a0lFcOfLsIuwf-ffJqEohB7m3Fh5Xx9OMIhX73zI7HyeQ=s16000


Exploitation

So we will bypass it by adding the; syntax between https://seal.htb/manager/;/html

Now we have a pop up asking for a username and password. We already have the username and password in the tomcat-users configuration file.

AVvXsEjVY5pDXj1chhTzk59pVUrLtz58Rf_grjBhNWG8O6vBWhdeeRtB833P1WXO5fQKzR2mSU4nTVfeYBPwf-iB5IiOTSvw1ttllfxTghoIR8B0YNePPhaBIBjCOjNljFDyjypY2uGFOfzl_hPfUlLVRyJlcDm4cNw3SihD-_GUcEfGc27A_q97-FaUDUtSkA=s16000


So we finally landed on the main page where we can exploit the apache tomcat server.

AVvXsEhLj6v63PnM_cQKgt_TbMIypGAOhXvgRkQaQIbl2K1lS1OpiGwaizQabn1f1QGm0XFVwGSXpE-7QfNPQR0kvQh_LO-KmlI27Doeg9OszbipxLFqQa0Sif2upbhW_8N1x5KA_xXXnpXn9ANMDrlYOu65slEU5obwJwyQe_cc3JJPjLzhcUKQQ5-r2B26tQ=s16000


AVvXsEhUnmTsfdfrOLZ3Slu3F1n6JoRGLPF7tyNAE6mxdfIa_IkMeN3i8k1K3_g12i5TqkCgIRTY6c4BT1GLVSDnxHZp-5hFIR6typdU--ZSWjFvvBSC25W_6xQx9DvJMhNq2XfHPMIPgVtT4ja93plZioG7Jau0Xz8kQrJAbuuY9q4buVyTijskllfUOiieSg=s16000


There is an option for uploading and deploying a WAR file. We will now create a WAR extension file and upload & deploy it. This should enable us to have a reverse shell. We’ll create a payload call shell.war by using msfvenom.

AVvXsEgM6PANpv8PHzGw7ZxI9Qkl6zbjqjEkK4t_4TNa7L7NuAIWmiVa4VzD3x3w6M1JiRkaJw3DMgrfGJKLRvDYhVgsX0ps8WXr-SgXpHHYWso2646EF7h1pAFWdmwEB6DFCyxY1Isxc_5iJEJMt923RpVR0AxNETyAV7MwpcCoCJBCJbt0dqm-nmMJpMzvUg=s16000


Now, if we try to upload and deploy it, we will get the error message 403. So we need to bypass it again. There are 2 methods to bypass it. One method has already been used above. The second method is to use the burp suite to analyse the request. As you can see below it is making a request to the manager page /manager/html/upload?

AVvXsEi2u8yqodo9rXJ_k9ySQC6HuLNIr6_GLowmc97BhzY1mnTcyR0N_0mc6ht4MAUagtBk6o8c9gTNY2iUJQ7QoBIyTztsNsc8DXU2A6oiXYcvSzFTKDCp0a3HpskeqIIKGt8ko-czbFCHsBeMHECkD8aTuUb2Jo1V7zWxa8f4w17ppp_W7UQ52RSeq0rjMA=s16000


So let’s add (;) character to bypass. /manager/;/html/upload?

AVvXsEiOHs0E2AbsOMBEl3whAzA0srpyM5ZNQRoH2diNoz6OGd4gDfLtNgcztgSTn50BgJJjOc4Aks3GshEpMlcmQ9rM5kY4jaTzA0efzMQBOxG5IEfcTTEcY2e-1n9iOEPoZ_NOaBhE2fiTQNc-shoGMGxkA3CkGXMPfTefVyujBboNNH-3z4IysnTmLKrTwg=s16000


As you can see below we have been able to upload our shell.war file in the tomcat application manager.

AVvXsEhoYs89-cG2Fp6twwPc-mfJ3Xt1Vhyk4Bm4o5MTXBhJihWAOCSW08yYPRUGn6jhXrY0MgdJP9Mpc3-FgPLy-4IMV1TtjgwxtxjVsrfqWTgqBMeHZnjHIRxGefrjRp3FxMOsZU4DbfLoLakrYes4RQDAzgKbhdtcRghlrWXH2yhvErGsQYzpByPzP2_UEw=s16000


So now if we click on the /shell, we get our reverse shell.

AVvXsEiUCJIXYWSYE9t1v-RFGI1sHrjDIx5KajFgm5MFZd_zXdsLDe5joZwwOjgPGrCyzs6q_7IMqUK42LEwdqhqngz2XByFNA_bXDA20yf6iIR8zS6k2wIjM2r6alM2MARDVmW0mpDGUI-ZL_M261GRR1CzTQ4Y-3sg-z2GrjeI7Dzdp83Vnbx3Ft773HpVng=s16000


So now the shell is running like a process on our system. If we press Ctrl + C, it will kill it and we will lose the shell. Now let make it permanent.

AVvXsEidvrM7PFNzeQu_gSfeWLxWu1fopf_U4kKDsM1VbA7vMnBMzY6SJ77sX8bKxK6Q8TWUD4d6sLfI_woTpSspa6bF7qNMbBMEANHn0X1clCUF6sc_En2l-cHD_F4BG5QhZc_MSlti7LhxzQ61sOfXYTzbEgwqJ-Yoz9Ky51VcQUeisUGwYp3L3RQurIr5_w=s16000


It’s done. Now even if we press Ctrl + C, the shell will not be terminated. We can now proceed further.

Now let’s check what users we have on this system. Typing /cat/etc/passwd would show us the list of available users. We have luis user. We also have a backup file that has triggered our attention. So let’s dig into that also browser the complete directory to find any kind of files that can help.

AVvXsEgVOaYMFxd82OlmP5sTZ4qQY1k_LpYgOcQ5ClnFsorkVzKupRsHYe5pGoLeV-bb9NFn2PX0D9i3JNVtVN7XMlsOH_DKMUTgLe3BkWnbrGpGYR0VTjwccq6pFVIWWaLCtpRj7aeL1-dDXF-qHF3UnjQwDqBcuCvZNZ_4LP0NekjBJH7gfthuVNYhX2pnNw=s16000


As you can see, there is a file named run.yml. What its actually doing, it’s backing up all files in the path /var/liv/tomcat9/webapps/ROOT/admin/dashboard and keeping it in destination /opt/backups/archives/backup-date and time. So if you can put any file in the source directory that can be helpful to us, it’s going to be automatically be zipped to the destination folder and we will be able to get access to it. So let’s browse to the home directory of the user we find above, that is, Luis.

AVvXsEiWeoPF3iPJgox4o03b9oWBR3t20sHq6GkETatlMv7IPb3WpNbsHGkJ8GDLM9xcfKpOm_iXhYCKxxuAj_CnGPkQu5m5pdrMcCC9B4FDV8DincOhJWr6jTjkoFktefP3BH6bHmCOwOXaHZNGNnAzIpn6hF5N9VZi5QpzbtOXcKOiQ-JD8u2Od-O25Pwtyg=s16000


And here we can find a very interesting file name: .ssh. This file is like a jackpot as it contains a private key that will enable us to access the system as luis via ssh.

Now we are going to create a system link with this particular location so that after a few seconds when the backup runs, it’s going to make an archive at the destination location, and there we will be able to access, unzip and read the data.

AVvXsEiVsT6yv6dbYK8mgpJfRtYQuVEIf9jZSj1Ky_h81IFAgkl6yLYV2iA0VSWbDULCPxCoOln7QluzViHj9KtMtpRLCCsMXAhiS7OeGHZH7xtMeYQ95ioUbL9ppB8wgO-G6fxGOXRjzb_dhaP6qmvrv3aeYgHektkuLsk2A1NzcCty9Ngu7Xw4hJoQgWzGeQ=s16000


Once the backup has been executed, if we go in the archive directory /opt/backups/archives, we will find the latest backup that has just been executed. Now let’s copy the backup file to the tmp/data/ directory and extract it:

Code:
tar -xvf backup.gz

AVvXsEgZnUc8y2DW3KH-g0EpQkFlPYVZlC7PY_ZAyGjM_zr6isqc_kVOM3ad88bdSc6NLgI7mdYOycw4AmTNY78xue0cw-7p0nwpG5jqZjlWf4DXnLx85jTDMw31KG13oq95J2s3gGL7MHENQsqzmMmVWd3MjKrMmp2Npkr6fulQTk-Zc2aw9yyah079YmRfrA=s16000


So now if we browse to the dashboard/uploads, we can find the .ssh folder. And when browsing the .ssh folder we can find 3 files including the id_rsa. Now we can cat this file to find the private key.

AVvXsEhwtbuwQ8t6iTJbacBANtAa6YkPNwl-QsAu3pH9duLoroA2ggmTfeL6mS2lNhjEhGf7IyL6UNXEgKXfDt0-SNuSAMKdN918byt1yrfAbTrzYQsFr_wMu8UaHgbxdwd7P1KPPYDjtC9bQ2lsrCg2dtz84gSWpd2KbqcG3oBkhqzmBw38-DyFWTQHS5kqdQ=s16000


Let’s copy the private key and paste it in a new file id_rsa and give it full read/write permission. Then let’s try to login using Luis username and his private key.

AVvXsEiSW1X5y0gx_hv3NOk5M0gdgZM9j94s4kcNQw8BjRg_NNnRJ5PMfgf5VjqhvtHk8ZxHttg9sPMSbgOGqQ-5UYHvsnpqDbrlyaebNoH3iq2EfjuvTYAP55rIofww6xh8lW2fZ2qpsp4arFzkwn5-yINYsYC523NHqChbvUImfUMoLjMVD-b-lQvP3sfbEg=s16000


Privilege Escalation

Now that we have been able to login as Luis, let’s run the command sudo -l to verify any suoders privilege escalation. We can see that Luis can run ansible-playbook as sudo. Now we are going to create a file called test.yml put in that command below:

Code:
name: "ignite"
hosts: localhost
connection: local
tasks:
-name: "ignite"
shell: "chmod +s /bin/bash"
register: "output"

The task part is very important here. What it is actually doing is, it’s putting suid bin on bash binary. Once the suid bit has been put on a bash binary, we will execute it.

AVvXsEiUTYfaaozjtJjkvPeI9OHOmNvYDt_-QR0-Snhqdbs9UFdT_fCFNmrsPc6MuqYhFCv4g3i12Vik3O7tXr20GdA20RJivpfrmZh5T_jmEYCSFnPZG4o0gPpipyzuCblOc7V6CEa3rFnC_CyxbJ3rTtIu04LYUpD9XcMrGu4tDgzh_KEJVz_b060FvxlzBQ=s16000


We will execute the test.yml file by typing the following command:

Code:
sudo /usr/bin/ansible-playbook ./test.yml

As shown above we have a suid bin and we have root access.

AVvXsEhBhmsjNWcYwVJidrMzFWNRqnokfkhxkA2Giy50Bf6WHrmaO5mxp9-8PPcRwti-Z_tYDGWZxhb93NiaDkQfhDOCX2rqEr8Cu7ElDduxEMIrn22TWwQtibvUiRF6cJaz-9xua0mCeA58pVfUB_yR-_goamHipznSwO4oSV8qJ8u4HWNl6IIX2SyUW8ZS6A=s16000


Author: Tirut Hawoldar is a Cyber Security Enthusiast and CTF player with 15 years of experience in IT Security and Infrastructure. Can be Contacted on LinkedIn
 

432,289

312,550

312,559

Top