SQL injections
Cheat sheet
Classical test
Upload file
Passwords
Dump In One Shot (Shoot):
Virgule filtrée
sha1 binary
If sha1 is used as a binary string (true) you can use an hash to bypass conditions and inject SQL
http://pims.tuxfamily.org/blog/2011/04/write-up-sha1-is-fun-plaidctf/
echo -n 3fDf | openssl sha1 -binary
GBK Charset
Possible to bypass addslashes and magic_quotes_gpc using chinese charset
\x27 == '
\x5c == \
All chinese char starts with \xbf
\xbf\x5c is a chinese char. It means that the antislash added will be interpreted as a part or chinese char and so the quote will be interpreted
where user.login="\xbf' or 1=1;
Numerical
Trigg
Column number
Database identification
Tables list
User table format
Data extraction
Routed → Double SQL Injection → The first result is injected into the second one
You can bypass some SQL restrictions playing with the var size limits
create table users (username varchar(10), password varchar(20)) ;
insert into users values(’admin’,’findMeIfYouCan’) ;
insert into users values(’admin [espace] *20 Mou’,’hackedMan’) ;
All is based on the output, you can then identify the SGBD
You want to generate errors
Get the db
Get the table (using LIMIT/OFFSET allows iteration)
Get columns
Extract rows from one column
Register form
To read a file you need
the FILE right (allow you to use load_file() )
The file full path
To get the full path for index.php (for example)
You can also use if there are some restrictions
Classic use
If quotes are filtered, you can use hexa
Or
You can use SQL properties → Testing from left to right → If first statement is false & followed by AND, the second won't be tested
Payload can be 1 AND [condition_a_tester] AND [si_condition_true]
Heavy Query : 1>(SELECT count(*) FROM information_schema.columns A, information_schema.columns B, information_schema.columns C)
Test condition : exists(SELECT password FROM users WHERE id=1 AND ascii(substring(password,index,1))=codeascii)
Final payload
Get the password size
or
Enumerate password
or
Bypass whitespace
Bypass case check for UNION
Bypass comma (UNION SELECT 1,2,3,4)
Retrieve the table name
Get the table structure
Query one specific rowinfi
Alternative to information_schema
Get previous records
Retrieving information without the column name
Forcing case insensitive comparision
But binary will be flagged
Last updated
