SQLi
Last updated
Last updated
MySQL
Python
Doesn't need ;
at the end.
PHP
Querying for matching username and password
:
This method involves running an SQL query that looks for rows where both the username and password (or password hash) match the user's input.
If any rows are returned (meaning a match is found), the user is allowed to log in.
Ensuring exactly one result
:
The query looks for matching username and password (or hash), but it only allows login if exactly one result is returned.
Querying based on username, then checking the password hash separately
:
Query the database based only on the username (without initially checking the password) and retrieving the user's password hash from the database.
Once the username is found, the password hash is compared to the one entered by the user.
Recon
Always test both "
and '
Bypass authentication by making the condition always true, followed by a comment to ignore the rest of the query.
If the previous query doesn't work try to exploits string comparison without breaking the query structure:
Sometimes the password field may appear before the username. To determine the structure, use brackets:
Play also with LIMIT
to spot changes on the response that you may not see otherwise:
If it's not possible to see the response from the query there could be still a BLIND
injection:
Union
Use ORDER BY
or UNION
with incremental column counts to determine how many columns are in the query:
Once you know the number of columns, check which column is rendering the results:
Once you know which column renders visible data, use LIMIT
to retrieve data row by row:
LIMIT offset, count
, is the typical syntax for LIMIT
:
offset
: The starting point (the row number) from which to begin returning results. (remember that SQL
indexing usually starts at 0
, so 1
is the second row).
count
: The number of rows to return starting from the offset
.
Using curl
in conjunction with SQLi
can be very useful for enumerating databases via the LIMIT
clause. Below is a simple script template that you can modify and adapt for your specific use case:
You can also use GROUP_CONCAT
as an alternative to LIMIT
, especially when you don’t want to retrieve each row individually but rather aggregate all the data from one or more columns in one query:
Enumeration
Information_schema
If you want to know how many databases there are:
To look how many tables in a database:
To look how many columns in a table:
To look the content of the columns:
Privileges
File Injection
NoSQL