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