rubocop
parent
6a567845e0
commit
10f89239a5
|
@ -9,7 +9,6 @@ require 'msf/core'
|
|||
require 'rex'
|
||||
|
||||
class Metasploit3 < Msf::Post
|
||||
|
||||
def initialize(info = {})
|
||||
super(update_info(info,
|
||||
'Name' => 'Generate TCP/UDP Outbound Traffic On Multiple Ports',
|
||||
|
@ -55,11 +54,11 @@ class Metasploit3 < Msf::Post
|
|||
end
|
||||
end
|
||||
|
||||
def native_init_connect(proto,ip,port,num)
|
||||
def native_init_connect(proto, ip, port, num)
|
||||
vprint_status("[#{num}:NATIVE] Connecting to #{ip} port #{proto}/#{port}")
|
||||
if proto == 'TCP'
|
||||
begin
|
||||
rtcp = Rex::Socket::Tcp.create(
|
||||
Rex::Socket::Tcp.create(
|
||||
'PeerHost' => ip,
|
||||
'PeerPort' => port,
|
||||
'Timeout' => 1
|
||||
|
@ -100,7 +99,7 @@ class Metasploit3 < Msf::Post
|
|||
proto = datastore['PROTOCOL']
|
||||
|
||||
# If we want WINAPI egress, make sure winsock is loaded
|
||||
if type=='WINAPI'
|
||||
if type == 'WINAPI'
|
||||
unless client.railgun.ws2_32
|
||||
print_error("This method requires railgun and support for winsock APIs. Try using the NATIVE method instead.")
|
||||
return
|
||||
|
@ -113,7 +112,7 @@ class Metasploit3 < Msf::Post
|
|||
workload_cycle = 0
|
||||
completed_cycle = false
|
||||
|
||||
if thread_num>1
|
||||
if thread_num > 1
|
||||
# Now we need to divvy up the ports into pots for each thread
|
||||
while !ports.nil? && !ports.empty?
|
||||
|
||||
|
@ -141,10 +140,9 @@ class Metasploit3 < Msf::Post
|
|||
end
|
||||
|
||||
# If native, set up the route
|
||||
if type=='NATIVE'
|
||||
if (gw = framework.sessions.get(datastore['SESSION'])) and (gw.kind_of?(Msf::Session::Comm))
|
||||
route_result = Rex::Socket::SwitchBoard.add_route(remote, '255.255.255.255', gw)
|
||||
if route_result
|
||||
if type == 'NATIVE'
|
||||
if (gw = framework.sessions.get(datastore['SESSION'])) && (gw.is_a?(Msf::Session::Comm))
|
||||
route_result = Rex::Socket::SwitchBoard.add_route(remote, '255.255.255.255', gw) if route_result
|
||||
print_status("Adding route to direct egress traffic to #{remote}")
|
||||
else
|
||||
print_error("Error adding route to direct egress traffic to #{remote}")
|
||||
|
@ -152,19 +150,18 @@ class Metasploit3 < Msf::Post
|
|||
else
|
||||
print_error("Error getting session to route egress traffic through to #{remote}")
|
||||
end
|
||||
end
|
||||
|
||||
print_status("Generating #{proto} traffic to #{remote}...")
|
||||
|
||||
if thread_num>1
|
||||
if thread_num > 1
|
||||
a = []
|
||||
0.upto(thread_num - 1) do |num|
|
||||
a << framework.threads.spawn("Module(#{refname})-#{remote}-#{proto}", false, workload_ports[num]) do |portlist|
|
||||
portlist.each do |dport|
|
||||
if type == 'WINAPI'
|
||||
winapi_egress_to_port(proto,remote,dport,num)
|
||||
winapi_egress_to_port(proto, remote, dport, num)
|
||||
elsif type == 'NATIVE'
|
||||
native_init_connect(proto,remote,dport,num)
|
||||
native_init_connect(proto, remote, dport, num)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -173,14 +170,14 @@ class Metasploit3 < Msf::Post
|
|||
else
|
||||
ports.each do |dport|
|
||||
if type == 'WINAPI'
|
||||
winapi_egress_to_port(proto,remote,dport,0)
|
||||
winapi_egress_to_port(proto, remote, dport, 0)
|
||||
elsif type == 'NATIVE'
|
||||
native_init_connect(proto,remote,dport,0)
|
||||
native_init_connect(proto, remote, dport, 0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if type=='NATIVE'
|
||||
if type == 'NATIVE'
|
||||
route_result = Rex::Socket::SwitchBoard.remove_route(remote, '255.255.255.255', gw)
|
||||
if route_result
|
||||
print_status("Removed route needed to direct egress traffic to #{remote}")
|
||||
|
@ -190,11 +187,10 @@ class Metasploit3 < Msf::Post
|
|||
end
|
||||
|
||||
print_status("#{proto} traffic generation to #{remote} completed.")
|
||||
return
|
||||
end
|
||||
|
||||
# This will generate a packet on proto <proto> to IP <remote> on port <dport>
|
||||
def winapi_egress_to_port(proto,remote,dport,num)
|
||||
def winapi_egress_to_port(proto, remote, dport, num)
|
||||
socket_handle = winapi_create_socket(proto)
|
||||
if socket_handle['return'] == 0
|
||||
vprint_status("[#{num}:WINAPI] Error setting up socket for #{remote}; Error: #{socket_handle['GetLastError']}")
|
||||
|
@ -213,5 +209,4 @@ class Metasploit3 < Msf::Post
|
|||
|
||||
client.railgun.ws2_32.closesocket(socket_handle['return'])
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue