# Remote Port Forwarding

Remote port forwarding is a technique used to forward traffic from a port on a remote server (the SSH server) to a specified local host and port. This allows services on the attacker's local machine to be accessed from the remote machine or other machines on the remote network.

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

lets say we want to access the webserver running on port 80 of windows (172.16.1.16) machine.\
Currently we (kali) and target(windows) are not in same subnet, so we cannot make connection.

Lets access webserver running on port 80 on windows from kali.

#### Steps to Achieve Remote Port Forwarding

```
ssh -R 8080:172.16.1.16:80 ubuntu@10.10.15.130
```

here, `-R` flag is used to specify remote port forwarding. `8080` is the port on the pivot host `10.10.15.130` that will listen for incoming connections

**`172.16.1.16:80`**: This is the target IP and port where the web server is running (the Windows machine).

After SSH connection is successfully established, we can access the webserver from our local machine by navigating to

```
http://10.10.15.130:8080
```

#### Diagram Representation

To visualize the setup:

* **Kali Machine** (`10.10.15.128`) connects to the **Pivot Host** (`10.10.15.130`).
* The **Pivot Host** listens on port `8080`.
* Traffic sent to `8080` on the **Pivot Host** is forwarded to `172.16.1.16:80`.


---

# Agent Instructions: 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:

```
GET https://notes.dollarboysushil.com/pivoting-and-tunneling/remote-port-forwarding.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
