Windows Local Privilege Escalation - Port Forwarding for CTF Creators
Port Forwarding
When a service is running exclusively on an internal port or localhost (127.0.0.1), it is necessary to forward that port to our system to enumerate the service running on that specific socket. There are three primary techniques to achieve this:
- Local Port Forwarding
- Remote Port Forwarding
- Dynamic Port Forwarding
Port Configuration
Open a PowerShell or a Command Prompt console as Administrator to activate the Windows Advanced Firewall for all the profiles (nope):
|
|
Remote Port Forwarding
Remote Port Forwarding means forwarding the port that’s listening on the target host loopback interface to our host. This is done by connecting to our host from the target host.
Simplified:
- Remote: Connect to ythe attacker host from the target host.
This technique involves forwarding the port that’s listening on the loopback interface in the target/victim host to our remote host. Startup by adding the executable permissions to the chisel binary in Linux and setup a listener:
|
|
Now in Windows execute the following to forward port 445 to the attacker (Linux) host:
|
|
The syntax of the command above is the following:
|
|
Note: The letter R: means that it’ll perform a reverse port forward.
Now we have access to the SMB share from our host:
|
|
If kill the connection by sending an exit signal, i.e, Ctrl+C. We can see that we can no longer connect:
|
|
Dynamic Port Forwarding
Dynamic Port Forwarding means forwarding every port that’s listening on the target host loopback interface to our host via our SOCKS port.
- Dynamic: Forward all the ports from the remote host to our SOCKS port.
SOCKS works on the OSI Layer 5 (Session Layer), so don’t expect things like ICMP, ARP or the half-open reset that SYN scan on nmap to work. In order to scan via proxy with nmap we need to do a TCP connect scan with the option -sT
and we should ignore ICMP with -Pn
.
There are different tools to help you out when Dynamic port forwarding is being used. The most common one is proxychains
which is available for Linux and Mac but also for Windows. Dynamic port forwarding allows you to create a socket on the local client machine, which acts as a SOCKS proxy server. When a client connects to this port, the connection is forwarded to the remote machine, which is then forwarded to a dynamic port on the destination machine. This way, all the applications using the SOCKS proxy will connect to the service, and the server will forward all the traffic to its actual destination.
Install the proxychains package:
|
|
Alternatively, you can build it from the source code from github.
Let’s configure the proxychains:
|
|
Leave the following SOCKS5 configuration:
|
|
Now on the attacker (Linux) host:
|
|
Alternatively, we could the following flag:
|
|
Then in Windows connect to our SOCKS5 proxy:
|
|
Alternatively, if we want to specify a SOCKS5 port we can do the following:
|
|
In our chisel output from the attacker host, we can see that a session was created on port 1080:
|
|
We can use ss
to dup our socket statistics:
|
|
We have port 1080 listening on localhost (127.0.0.1) as we can see from the nmap scan:
|
|
Noticed how I used the options:
- -sT = TCP connect scan, rather than the default
-sS
SYN scan. The SYN won’t work because the proxy doesn’t pass the TCP handshake packets back to the attacker host, a SYN scan, which sends the SYN packet, sees the ACK and then ends the connection, this won’t be passed back over the proxy, therefore, SYN scans don’t work with proxies. - -Pn = Ignore ICMP request/response because ICMP doesn’t go through the proxy.
Without these options the scan will fail because the proxy will drop any SYN scans, we need the full TCP handshake to know if the port is open or not.
The key to the output above is in this line:
|
|
Notice how it goes through the SOCKS5 proxy port and from there it goes to port 445.
Let’s try to authenticate to SMB:
|
|
We can authenticate to SMB via the SOCKS5 port through the proxychain.
Now let’s scan some of the ports to prove that we have access to all the ports of the Windows system:
|
|
Defense
Mitigating port forwarding techniques can be challenging, but here are some effective strategies:
- Enable only necessary ports: Ensure that only the required ports are open to minimize potential attack vectors.
- Limit the number of services: Disable any services that are not actively being used to reduce the risk of exploitation.
- Monitor network traffic: Utilize the following tools to monitor and analyze network traffic for suspicious activities:
- Deep-Packet Inspection Firewall
- Unified Threat Management (UTM) systems
- Intrusion Detection Systems (IDS) / Intrusion Prevention Systems (IPS)
By implementing these measures, you can enhance your network security and reduce the risk of unauthorized port forwarding activities.