@@ -13,25 +13,25 @@ class Metasploit3 < Msf::Post
13
13
14
14
def initialize ( info = { } )
15
15
super ( update_info ( info ,
16
- 'Name' => 'Windows Outbound-Filering Rules' ,
17
- 'Description' => %q{
18
- This module makes some kind of TCP traceroute to get outbound-filtering rules.
19
- It will try to make a TCP connection to a certain public IP address (this IP
20
- does not need to be under your control) using different TTL incremental values.
21
- This way if you get an answer (ICMP ttl time exceeded packet) from a public IP
22
- device you can infer that the destination port is allowed. Setting STOP to
23
- true the module will stop as soon as you reach a public IP (this will generate
24
- less noise in the network).
25
- } ,
26
-
27
- 'License' => MSF_LICENSE ,
28
- 'Author' => [ 'Borja Merino <bmerinofe[at]gmail.com>' ] ,
29
- 'Platform' => [ 'win' ] ,
30
- 'SessionTypes' => [ 'meterpreter' ] ,
31
- 'References' => [
16
+ 'Name' => 'Windows Outbound-Filering Rules' ,
17
+ 'Description' => %q{
18
+ This module makes some kind of TCP traceroute to get outbound-filtering rules.
19
+ It will try to make a TCP connection to a certain public IP address (this IP
20
+ does not need to be under your control) using different TTL incremental values.
21
+ This way if you get an answer (ICMP ttl time exceeded packet) from a public IP
22
+ device you can infer that the destination port is allowed. Setting STOP to
23
+ true the module will stop as soon as you reach a public IP (this will generate
24
+ less noise in the network).
25
+ } ,
26
+ 'License' => MSF_LICENSE ,
27
+ 'Author' => [ 'Borja Merino <bmerinofe[at]gmail.com>' ] ,
28
+ 'Platform' => [ 'win' ] ,
29
+ 'SessionTypes' => [ 'meterpreter' ] ,
30
+ 'References' => [
32
31
[ 'URL' , 'http://www.shelliscoming.com/2014/11/getting-outbound-filtering-rules-by.html' ]
33
32
]
34
- ) )
33
+ ) )
34
+
35
35
register_options (
36
36
[
37
37
OptAddress . new ( "ADDRESS" , [ true , 'Destination IP address.' ] ) ,
@@ -41,7 +41,6 @@ def initialize(info={})
41
41
OptInt . new ( 'TIMEOUT' , [ true , 'Timeout for the ICMP socket.' , 3 ] ) ,
42
42
OptBool . new ( 'STOP' , [ true , 'Stop when it finds a public IP.' , false ] )
43
43
] , self . class )
44
-
45
44
end
46
45
47
46
def icmp_setup
@@ -87,8 +86,8 @@ def tcp_setup(ttl)
87
86
end
88
87
vprint_status ( "TCP socket created successfully" )
89
88
90
- fionbio = 0x8004667E
91
- r = client . railgun . ws2_32 . ioctlsocket ( handler [ 'return' ] , fionbio , 1 )
89
+ cmd = 0x8004667E
90
+ r = client . railgun . ws2_32 . ioctlsocket ( handler [ 'return' ] , cmd , 1 )
92
91
if r [ 'GetLastError' ] != 0
93
92
print_error ( "There was an error setting the TCP socket in non-blocking mode; GetLastError: #{ r [ 'GetLastError' ] } " )
94
93
return nil
@@ -103,9 +102,9 @@ def tcp_setup(ttl)
103
102
#_In_ int optlen
104
103
# );
105
104
106
- ipproto_ip = 0x00000000
107
- ip_ttl = 0x00000004
108
- r = client . railgun . ws2_32 . setsockopt ( handler [ 'return' ] , ipproto_ip , ip_ttl , [ ttl ] . pack ( 'C' ) , 4 )
105
+ ipproto_ip = 0
106
+ ip_ttl = 4
107
+ r = client . railgun . ws2_32 . setsockopt ( handler [ 'return' ] , ipproto_ip , ip_ttl , [ ttl ] . pack ( 'C' ) , 4 )
109
108
if r [ 'GetLastError' ] != 0
110
109
print_error ( "There was an error setting the TTL value; GetLastError: #{ r [ 'GetLastError' ] } " )
111
110
return nil
@@ -114,20 +113,20 @@ def tcp_setup(ttl)
114
113
return handler [ 'return' ]
115
114
end
116
115
117
- def connections ( remote , dport , h_icmp , h_tcp , to )
118
- sockaddr = Rex ::Socket . to_sockaddr ( remote , dport )
119
- r = client . railgun . ws2_32 . connect ( h_tcp , sockaddr , 16 )
116
+ def connections ( remote , dst_port , h_icmp , h_tcp , to )
117
+ sock_addr = Rex ::Socket . to_sockaddr ( remote , dst_port )
118
+ r = client . railgun . ws2_32 . connect ( h_tcp , sock_addr , 16 )
120
119
# A GetLastError == 1035 is expected since the socket is set to non-blocking mode
121
120
if r [ 'GetLastError' ] != 10035
122
121
print_error ( "There was an error creating the connection to the peer #{ remote } ; GetLastError: #{ r [ 'GetLastError' ] } " )
123
122
return
124
123
end
125
124
126
- from = " " * 16
125
+ from = " " * 16
127
126
128
127
begin
129
128
::Timeout . timeout ( to ) do
130
- r = client . railgun . ws2_32 . recvfrom ( h_icmp , "" , 100 , 0 , from , 16 )
129
+ r = client . railgun . ws2_32 . recvfrom ( h_icmp , "" , 100 , 0 , from , 16 )
131
130
hop = Rex ::Socket . addr_ntoa ( r [ 'from' ] [ 4 ..7 ] )
132
131
return hop
133
132
end
@@ -138,17 +137,17 @@ def connections(remote,dport,h_icmp,h_tcp, to)
138
137
end
139
138
140
139
def run
141
- if not is_admin?
140
+ unless is_admin?
142
141
print_error ( "You don't have enough privileges. Try getsystem." )
143
142
return
144
143
end
145
144
146
- if sysinfo [ "OS" ] =~ /XP/
147
- print_error ( " Windows XP is not supported" )
145
+ if sysinfo [ 'OS' ] =~ /XP/
146
+ print_error ( ' Windows XP is not supported' )
148
147
return
149
148
end
150
149
151
- output = cmd_exec ( " netsh" , " advfirewall firewall add rule name=\ " All ICMP v4\ " dir=in action=allow protocol=icmpv4:any,any" )
150
+ output = cmd_exec ( ' netsh' , ' advfirewall firewall add rule name="All ICMP v4" dir=in action=allow protocol=icmpv4:any,any' )
152
151
print_status ( "ICMP firewall IN rule established: #{ output } " )
153
152
154
153
session . railgun . ws2_32
@@ -159,22 +158,24 @@ def run
159
158
160
159
ports . each do |dport |
161
160
print_status ( "Testing port #{ dport } ..." )
162
- 0 . upto ( datastore [ 'HOPS' ] - 1 ) { |i |
161
+ 0 . upto ( datastore [ 'HOPS' ] - 1 ) { |i |
163
162
i = i + datastore [ 'MIN_TTL' ]
164
163
h_icmp = icmp_setup
164
+ return if h_icmp . nil?
165
165
h_tcp = tcp_setup ( i )
166
- return if h_icmp == nil or h_tcp == nil
166
+ return if h_tcp . nil?
167
167
168
168
hop = connections ( remote , dport , h_icmp , h_tcp , to )
169
169
if hop != nil
170
170
print_good ( "#{ i } #{ hop } " )
171
- if datastore [ 'STOP' ] == true and not Rex ::Socket . is_internal? ( hop )
171
+ if datastore [ 'STOP' ] == true and ! Rex ::Socket . is_internal? ( hop )
172
172
print_good ( "Public IP reached. The port #{ dport } is not filtered" )
173
173
break
174
174
end
175
175
else
176
176
print_error ( "#{ i } *" )
177
177
end
178
+
178
179
client . railgun . ws2_32 . closesocket ( h_tcp )
179
180
client . railgun . ws2_32 . closesocket ( h_icmp )
180
181
}
0 commit comments