# CVE-2024-27198

Hello everyone today we have something different today we going to make POC of the CVE-2024-27198 vulnerability affecting JetBrains TeamCity versions prior to 2023.11.4. What make me think of creating this exploit was a Try Hack Me machine. called Brains.<https://medium.com/@jfjbn4/tryhackme-brains-writeup-987dbdfcd963>

i uses an exploit there and i thought why do not i make it myself and here i did it.

***

## Git.

All of the code is exist within my git repo.

{% embed url="<https://github.com/Cythonic1/CVE-2024-27198_POC>" %}

## What is CVE-2024-27198.

the CVE-2024-27198 is a authentication bypass vulnerability which able unauthenticated attacker to access authenticated endpoints.

{% embed url="<https://www.hackthebox.com/blog/cve-2024-27198-explained>" %}

{% embed url="<https://www.rapid7.com/blog/post/2024/03/04/etr-cve-2024-27198-and-cve-2024-27199-jetbrains-teamcity-multiple-authentication-bypass-vulnerabilities-fixed/>" %}

Hack The Box and Rapid 7 explain the vulnerability better than my so here we just going to go through the code and explain it.

## The 3 Rules.

To exploit this vulnerability 3 rules must be satisfied.

1. We fist need to generate Request the return 404. Simple access unexistence end point.
2. We need to add jsp as url prameter and assigne the authenticated endpoint as it's value.
3. We need to end it with ;.jsp. the ; mean sperate from the rest .jsp to make it look as jsp request.

using such url on vuln version will allow you to access secure endpoints.

`{ip_address}/sdkjhdfajghsjdhf?jsp=/app/rest/server;.jsp`

1. `/sdkjhdfajghsjdhf.` non existance page.
2. `jsp=/app/rest/server` the page we want to access within the jsp parameter.
3. `;.jsp` end with ;.jsp.

## The Exploit.

### Check if the exploit exist.

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2FNaGFspVba0KhGNtBRd1Y%2Fimage.png?alt=media&#x26;token=1dfb203f-b182-4ce1-a162-27fee7b2bd2a" alt=""><figcaption></figcaption></figure>

First we take the Url of the target system as command line argument.

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2F4AzMnGSk0HhpHDjUhh5P%2Fimage.png?alt=media&#x26;token=ece2a8cb-4795-41f9-8ec5-f543d8dfb4a4" alt=""><figcaption></figcaption></figure>

Then we check if the target system is vulnerable or not.

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2FPGeRiYWnuCb2TglvYGlA%2Fimage.png?alt=media&#x26;token=7ec6794f-55e2-4512-bcf1-caa8a4105155" alt=""><figcaption></figcaption></figure>

This is\_vuln function is so simple it returns boolean value.

### Generate username and password and create user.

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2FzxY59GL9Tj9KWnw2Tj1l%2Fimage.png?alt=media&#x26;token=237b0256-c7b8-4331-913b-8e90a7d750fb" alt=""><figcaption></figcaption></figure>

So here we generate random username and password and create a new user with administrator access.

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2FFlKkhT5RKaduYeE6btgV%2Fimage.png?alt=media&#x26;token=940660a5-59b0-43b8-947a-e54e6e983eb8" alt=""><figcaption></figcaption></figure>

and this is a create\_new\_user functionj which take random generated username and password and send it as json request.

### generate token.

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2FERSmKAhUDwktqulPURL1%2Fimage.png?alt=media&#x26;token=783add4a-c7b8-400e-88b6-e49ffa8a7806" alt=""><figcaption></figcaption></figure>

So as you can see we call function get\_token and this function will return either a token or nothing or error. and a best world it will return a valid token so that we can upload our exploit.

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2FOzTO61oTyXRsNEZzgNQy%2Fimage.png?alt=media&#x26;token=0b81f9ef-08f6-482f-97fc-93ec54b3749e" alt=""><figcaption></figcaption></figure>

This is the get token function it will fetch the token for the id user 1 which usually is the admin.

### Upload payload and execute commands.

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2FOUQFoeAKZZQNRaPXMxIC%2Fimage.png?alt=media&#x26;token=a7920eaf-8964-4b27-87f1-752ffe8229de" alt=""><figcaption></figcaption></figure>

To to these we need to make sure that we have a valid token thats why  if the generation of the token failed we can not compelete  the exploit.

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2F1JD3giyhEHoJfrlTylWS%2Fimage.png?alt=media&#x26;token=ec5c8f06-0b60-450c-9a88-2a0afc0b6b15" alt=""><figcaption></figcaption></figure>

This is the upload evil plugin function i give the credits to this beast.

{% embed url="<https://github.com/W01fh4cker/CVE-2024-27198-RCE>" %}

This zip file contain these to files.

![](https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2FwlBTouNEUafFXxUfiBgz%2Fimage.png?alt=media\&token=7ac4eb7e-5561-4e3d-b312-9e3df2cf487d)&#x20;

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2F13C7u8R5pXdQp3aNB49s%2Fimage.png?alt=media&#x26;token=a24d9ed6-9cd4-4611-bb22-7d2a191f309f" alt=""><figcaption></figcaption></figure>

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2FscfMABeWKycqRVXJ4Mwq%2Fimage.png?alt=media&#x26;token=db103c65-2647-4d81-9557-9d816808eb55" alt=""><figcaption></figcaption></figure>

So for myPlugin.jsp we use jsp which is a java code that can run on the web. and the xml file is just to know details about the plugin. and we just send the file as parts.

#### enable the plugin.

So after uploading the plugin we just need to enable it.

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2Fy8bIOnuGHUC0UXDxlPp1%2Fimage.png?alt=media&#x26;token=86d167c1-21cf-488c-82c2-786ef6b796cd" alt=""><figcaption></figcaption></figure>

#### Execute commands.

After upload and enable the plugin we can execute commands.

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2Fc8xLr73ljwXCIxAV2lHD%2Fimage.png?alt=media&#x26;token=12df69a9-1128-450b-ae8b-4f0e2798baa4" alt=""><figcaption></figcaption></figure>

As you can see we can access our plugin url and execute commands.

### Running the code.

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2FVZj1zFywbgFN2T6xm8Kk%2Fimage.png?alt=media&#x26;token=308d6619-6249-4334-8f22-72e4119ff11e" alt=""><figcaption></figcaption></figure>

As you can see we able to execute out command which is whoami. and since am running this in docker so its a root user.

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2FO9TQy9uWGZyxGk8f86PD%2Fimage.png?alt=media&#x26;token=7b884026-8b71-4e07-9e29-7c93ca698ee2" alt=""><figcaption></figcaption></figure>

And here from the web we can execute commands from get prameter.

## Conclusion.

in the end what actully make me try to make this exploit is first that i love to create exploit specilly in Rust and i want to see how a big product such jetBrains could have such weak vulnerability.

Finally i would like to credite.

{% embed url="<https://github.com/W01fh4cker/CVE-2024-27198-RCE>" %}

i learned from him to get the docker container and the java exploit he is a master.
