Skip to content

Commit 0589879

Browse files
committed
modules/auxiliary/bnat: Resolve RuboCop violations
1 parent 371196f commit 0589879

File tree

2 files changed

+85
-85
lines changed

2 files changed

+85
-85
lines changed

modules/auxiliary/bnat/bnat_router.rb

Lines changed: 48 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,55 +7,54 @@ class MetasploitModule < Msf::Auxiliary
77

88
def initialize
99
super(
10-
'Name' => 'BNAT Router',
11-
'Description' => %q{
10+
'Name' => 'BNAT Router',
11+
'Description' => %q{
1212
This module will properly route BNAT traffic and allow for connections to be
1313
established to machines on ports which might not otherwise be accessible.},
14-
'Author' =>
15-
[
16-
'bannedit',
17-
'Jonathan Claudius',
18-
],
19-
'License' => MSF_LICENSE,
20-
'References' =>
21-
[
22-
[ 'URL', 'https://github.com/claudijd/bnat' ],
23-
[ 'URL', 'http://www.slideshare.net/claudijd/dc-skytalk-bnat-hijacking-repairing-broken-communication-channels']
24-
]
14+
'Author' => [
15+
'bannedit',
16+
'Jonathan Claudius',
17+
],
18+
'License' => MSF_LICENSE,
19+
'References' => [
20+
['URL', 'https://github.com/claudijd/bnat' ],
21+
['URL', 'http://www.slideshare.net/claudijd/dc-skytalk-bnat-hijacking-repairing-broken-communication-channels']
22+
]
2523
)
2624
register_options(
27-
[
28-
OptString.new('OUTINF', [true, 'The external interface connected to the internet', 'eth1']),
29-
OptString.new('ININF', [true, 'The internal interface connected to the network', 'eth2']),
30-
OptString.new('CLIENTIP', [true, 'The ip of the client behind the BNAT router', '192.168.3.2']),
31-
OptString.new('SERVERIP', [true, 'The ip of the server you are targeting', '1.1.2.1']),
32-
OptString.new('BNATIP', [true, 'The ip of the bnat response you are getting', '1.1.2.2']),
33-
])
25+
[
26+
OptString.new('OUTINF', [true, 'The external interface connected to the internet', 'eth1']),
27+
OptString.new('ININF', [true, 'The internal interface connected to the network', 'eth2']),
28+
OptString.new('CLIENTIP', [true, 'The ip of the client behind the BNAT router', '192.168.3.2']),
29+
OptString.new('SERVERIP', [true, 'The ip of the server you are targeting', '1.1.2.1']),
30+
OptString.new('BNATIP', [true, 'The ip of the bnat response you are getting', '1.1.2.2']),
31+
]
32+
)
3433
end
3534

3635
def run
3736
clientip = datastore['CLIENTIP']
3837
serverip = datastore['SERVERIP']
39-
bnatip = datastore['BNATIP']
40-
outint = datastore['OUTINF']
41-
inint = datastore['ININF']
38+
bnatip = datastore['BNATIP']
39+
outint = datastore['OUTINF']
40+
inint = datastore['ININF']
4241

43-
clientmac = arp2(clientip,inint)
42+
clientmac = arp2(clientip, inint)
4443
print_line("Obtained Client MAC: #{clientmac}")
45-
servermac = arp2(serverip,outint)
44+
servermac = arp2(serverip, outint)
4645
print_line("Obtained Server MAC: #{servermac}")
47-
bnatmac = arp2(bnatip,outint)
46+
bnatmac = arp2(bnatip, outint)
4847
print_line("Obtained BNAT MAC: #{bnatmac}\n\n")
4948

5049
# Create Interface Specific Configs
51-
outconfig = PacketFu::Config.new(PacketFu::Utils.ifconfig ":#{outint}").config
52-
inconfig = PacketFu::Config.new(PacketFu::Utils.ifconfig ":#{inint}").config
50+
outconfig = PacketFu::Config.new(PacketFu::Utils.ifconfig(":#{outint}")).config
51+
inconfig = PacketFu::Config.new(PacketFu::Utils.ifconfig(":#{inint}")).config
5352

5453
# Set Captures for Traffic coming from Outside and from Inside respectively
55-
outpcap = PacketFu::Capture.new( :iface => "#{outint}", :start => true, :filter => "tcp and src #{bnatip}" )
54+
outpcap = PacketFu::Capture.new(iface: outint.to_s, start: true, filter: "tcp and src #{bnatip}")
5655
print_line("Now listening on #{outint}...")
5756

58-
inpcap = PacketFu::Capture.new( :iface => "#{inint}", :start => true, :filter => "tcp and src #{clientip} and dst #{serverip}" )
57+
inpcap = PacketFu::Capture.new(iface: inint.to_s, start: true, filter: "tcp and src #{clientip} and dst #{serverip}")
5958
print_line("Now listening on #{inint}...\n\n")
6059

6160
# Start Thread from Outside Processing
@@ -65,7 +64,7 @@ def run
6564
packet = PacketFu::Packet.parse(pkt)
6665

6766
# Build a shell packet that will never hit the wire as a hack to get desired mac's
68-
shell_pkt = PacketFu::TCPPacket.new(:config => inconfig, :timeout => 0.1, :flavor => "Windows")
67+
shell_pkt = PacketFu::TCPPacket.new(config: inconfig, timeout: 0.1, flavor: 'Windows')
6968
shell_pkt.ip_daddr = clientip
7069
shell_pkt.recalc
7170

@@ -75,9 +74,9 @@ def run
7574
packet.eth_saddr = shell_pkt.eth_saddr
7675
packet.eth_daddr = clientmac
7776
packet.recalc
78-
inj = PacketFu::Inject.new( :iface => "#{inint}", :config => inconfig )
79-
inj.a2w(:array => [packet.to_s])
80-
print_status("inpacket processed")
77+
inj = PacketFu::Inject.new(iface: inint.to_s, config: inconfig)
78+
inj.a2w(array: [packet.to_s])
79+
print_status('inpacket processed')
8180
end
8281
end
8382
end
@@ -97,47 +96,47 @@ def run
9796
end
9897

9998
# Build a shell packet that will never hit the wire as a hack to get desired mac's
100-
shell_pkt = PacketFu::TCPPacket.new(:config=>outconfig, :timeout=> 0.1, :flavor=>"Windows")
99+
shell_pkt = PacketFu::TCPPacket.new(config: outconfig, timeout: 0.1, flavor: 'Windows')
101100
shell_pkt.ip_daddr = serverip
102101
shell_pkt.recalc
103102

104103
# Mangle Received Packet and Drop on the Wire
105104
packet.eth_saddr = shell_pkt.eth_saddr
106-
packet.ip_saddr=shell_pkt.ip_saddr
105+
packet.ip_saddr = shell_pkt.ip_saddr
107106
packet.recalc
108-
inj = PacketFu::Inject.new( :iface => "#{outint}", :config =>outconfig )
109-
inj.a2w(:array => [packet.to_s])
107+
inj = PacketFu::Inject.new(iface: outint.to_s, config: outconfig)
108+
inj.a2w(array: [packet.to_s])
110109

111110
# Trigger Cisco SPI Vulnerability by Double-tapping the SYN
112111
if packet.tcp_flags.syn == 1 && packet.tcp_flags.ack == 0
113112
select(nil, nil, nil, 0.75)
114-
inj.a2w(:array => [packet.to_s])
113+
inj.a2w(array: [packet.to_s])
115114
end
116-
print_status("outpacket processed")
115+
print_status('outpacket processed')
117116
end
118117
end
119118
end
120119
fromout.join
121120
fromin.join
122121
end
123122

124-
def arp2(target_ip,int)
125-
config = PacketFu::Config.new(PacketFu::Utils.ifconfig ":#{int}").config
126-
arp_pkt = PacketFu::ARPPacket.new(:flavor => "Windows")
123+
def arp2(target_ip, int)
124+
config = PacketFu::Config.new(PacketFu::Utils.ifconfig(":#{int}")).config
125+
arp_pkt = PacketFu::ARPPacket.new(flavor: 'Windows')
127126
arp_pkt.eth_saddr = arp_pkt.arp_saddr_mac = config[:eth_saddr]
128-
arp_pkt.eth_daddr = "ff:ff:ff:ff:ff:ff"
129-
arp_pkt.arp_daddr_mac = "00:00:00:00:00:00"
127+
arp_pkt.eth_daddr = 'ff:ff:ff:ff:ff:ff'
128+
arp_pkt.arp_daddr_mac = '00:00:00:00:00:00'
130129
arp_pkt.arp_saddr_ip = config[:ip_saddr]
131130
arp_pkt.arp_daddr_ip = target_ip
132-
cap = PacketFu::Capture.new(:iface => config[:iface], :start => true, :filter => "arp src #{target_ip} and ether dst #{arp_pkt.eth_saddr}")
133-
injarp = PacketFu::Inject.new(:iface => config[:iface])
134-
injarp.a2w(:array => [arp_pkt.to_s])
131+
cap = PacketFu::Capture.new(iface: config[:iface], start: true, filter: "arp src #{target_ip} and ether dst #{arp_pkt.eth_saddr}")
132+
injarp = PacketFu::Inject.new(iface: config[:iface])
133+
injarp.a2w(array: [arp_pkt.to_s])
135134
target_mac = nil
136135

137136
while target_mac.nil?
138137
if cap.save > 0
139138
arp_response = PacketFu::Packet.parse(cap.array[0])
140-
target_mac = arp_response.arp_saddr_mac if arp_response.arp_saddr_ip = target_ip
139+
target_mac = arp_response.arp_saddr_mac if arp_response.arp_saddr_ip == target_ip
141140
end
142141
select(nil, nil, nil, 0.1) # Check for a response ten times per second.
143142
end

modules/auxiliary/bnat/bnat_scan.rb

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,32 @@ class MetasploitModule < Msf::Auxiliary
99

1010
def initialize
1111
super(
12-
'Name' => 'BNAT Scanner',
13-
'Description' => %q{
12+
'Name' => 'BNAT Scanner',
13+
'Description' => %q{
1414
This module is a scanner which can detect Broken NAT (network address translation)
1515
implementations, which could result in an inability to reach ports on remote
1616
machines. Typically, these ports will appear in nmap scans as 'filtered'/'closed'.
17-
},
18-
'Author' =>
19-
[
20-
'bannedit',
21-
'Jonathan Claudius <jclaudius[at]trustwave.com>',
22-
],
23-
'License' => MSF_LICENSE,
24-
'References' =>
25-
[
26-
[ 'URL', 'https://github.com/claudijd/bnat'],
27-
[ 'URL', 'http://www.slideshare.net/claudijd/dc-skytalk-bnat-hijacking-repairing-broken-communication-channels']
28-
]
17+
},
18+
'Author' => [
19+
'bannedit',
20+
'Jonathan Claudius <jclaudius[at]trustwave.com>',
21+
],
22+
'License' => MSF_LICENSE,
23+
'References' => [
24+
['URL', 'https://github.com/claudijd/bnat'],
25+
['URL', 'http://www.slideshare.net/claudijd/dc-skytalk-bnat-hijacking-repairing-broken-communication-channels']
26+
]
2927
)
3028

3129
register_options(
32-
[
33-
OptString.new('PORTS', [true, "Ports to scan (e.g. 22-25,80,110-900)", "21,22,23,80,443"]),
34-
OptString.new('INTERFACE', [true, "The name of the interface", "eth0"]),
35-
OptInt.new('TIMEOUT', [true, "The reply read timeout in milliseconds", 500])
36-
])
37-
38-
deregister_options('FILTER','PCAPFILE','SNAPLEN')
30+
[
31+
OptString.new('PORTS', [true, 'Ports to scan (e.g. 22-25,80,110-900)', '21,22,23,80,443']),
32+
OptString.new('INTERFACE', [true, 'The name of the interface', 'eth0']),
33+
OptInt.new('TIMEOUT', [true, 'The reply read timeout in milliseconds', 500])
34+
]
35+
)
3936

37+
deregister_options('FILTER', 'PCAPFILE', 'SNAPLEN')
4038
end
4139

4240
def probe_reply(pcap, to)
@@ -46,48 +44,51 @@ def probe_reply(pcap, to)
4644
pcap.each do |r|
4745
pkt = PacketFu::Packet.parse(r)
4846
next unless pkt.is_tcp?
47+
4948
reply = pkt
5049
break
5150
end
5251
end
53-
rescue Timeout::Error
52+
rescue Timeout::Error => e
53+
vprint_error(e.message)
5454
end
5555
return reply
5656
end
5757

5858
def generate_probe(ip)
59-
ftypes = %w{windows, linux, freebsd}
60-
@flavor = ftypes[rand(ftypes.length)]
61-
config = PacketFu::Utils.whoami?(:iface => datastore['INTERFACE'])
62-
p = PacketFu::TCPPacket.new(:config => config)
59+
ftypes = %w[windows linux freebsd]
60+
@flavor = ftypes.sample
61+
config = PacketFu::Utils.whoami?(iface: datastore['INTERFACE'])
62+
p = PacketFu::TCPPacket.new(config: config)
6363
p.ip_daddr = ip
6464
p.tcp_flags.syn = 1
6565
return p
6666
end
6767

6868
def run_host(ip)
69+
ports = Rex::Socket.portspec_crack(datastore['PORTS'])
70+
71+
if ports.empty?
72+
raise Msf::OptionValidateError, ['PORTS']
73+
end
74+
6975
open_pcap
7076

7177
to = (datastore['TIMEOUT'] || 500).to_f / 1000.0
7278

7379
p = generate_probe(ip)
74-
pcap = self.capture
75-
76-
ports = Rex::Socket.portspec_crack(datastore['PORTS'])
80+
pcap = capture
7781

78-
if ports.empty?
79-
raise Msf::OptionValidateError.new(['PORTS'])
80-
end
81-
82-
ports.each_with_index do |port,i|
82+
ports.each_with_index do |port, _i|
8383
p.tcp_dst = port
84-
p.tcp_src = rand(64511)+1024
85-
p.tcp_seq = rand(64511)+1024
84+
p.tcp_src = rand(1024..65534)
85+
p.tcp_seq = rand(1024..65534)
8686
p.recalc
8787

8888
ackbpf = "tcp [8:4] == 0x#{(p.tcp_seq + 1).to_s(16)}"
8989
pcap.setfilter("tcp and tcp[13] == 18 and not host #{ip} and src port #{p.tcp_dst} and dst port #{p.tcp_src} and #{ackbpf}")
9090
break unless capture_sendto(p, ip)
91+
9192
reply = probe_reply(pcap, to)
9293
next if reply.nil?
9394

0 commit comments

Comments
 (0)