> For the complete documentation index, see [llms.txt](https://d3ndr1t30x.gitbook.io/breaking-things-a-junior-pentesters-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://d3ndr1t30x.gitbook.io/breaking-things-a-junior-pentesters-guide/port-forwarding-cheat-sheet.md).

# Port forwarding cheat sheet

Within a machine, type \~C to enter ssh command mode

```
-L 8443:127.0.0.1:8443
```

1. `-L`: This is an option flag to indicate that you want to create Local port forwarding.
2. `8443`: This is the first number. It represents the port on your local machine that you want to listen on. This is the port that you will use on your local machine to access the forwarded service.
3. `127.0.0.1`: This is an IP address, specifically the loopback address, meaning "localhost" or your local machine.
4. `:8443`: This is the second number, which is also 8443. This represents the port on the remote server to which the traffic will be forwarded.

**Netcat (nc):**

* Local Port Forwarding:
* ```bash
  nc -l -p <local_port> -c 'nc <remote_host> <remote_port>'
  ```
* Remote Port Forwarding:
* ```bash
  nc -l -p <local_port> -c 'nc -q 0 <remote_host> <remote_port>'
  ```
* ```bash
  ssh -R <remote_port>:<local_host>:<local_port> user@target
  ```

**Advanced Port Forwarding Tools from GitHub:**

1. **Chisel:**
   * A fast TCP tunnel over HTTP.
   * GitHub: <https://github.com/jpillora/chisel>
2. **ProxyChains-NG:**
   * Redirects TCP connections through proxy servers.
   * GitHub: <https://github.com/rofl0r/proxychains-ng>
3. **gost:**
   * A fully transparent proxy that can be used as a simple port redirector.
   * GitHub: <https://github.com/ginuerzh/gost>
4. **Sslstrip2:**
   * A tool for exploiting Moxie Marlinspike's SSL stripping attacks.
   * GitHub: <https://github.com/LeonardoNve/sslstrip2>
