sql injection
Checklist
Analyzing vulnerable or not
Try error , time-based , union , boolean payload,.....respectively
Try Boolean payloads for authentication bypass
Manual data fetch checks
check version
check database name
check user , host , password
try group_concat for multiple value fetch
use information_schema to fetch data
Basic Checks
url , double url encode the payload
HTML encode
comment after the payload
use AND & OR condition to execute payload
try to enter invalid value in parameter
Burp Suite checks
notice " file size | page load time "
find "error" in response , after & before injection payload
Inject in cookie
Inject the payload in bracket , if normal one not working :- "(payload)"
Inject in
Explanation
Before exploitation lets understand how sql works
http://xyz.com/order?id=1in this url basically the data is getting fetched by the use of SQL QUERY
id=1to just fetch the details of a product / name / ...whatever their is a parameter called id and the value is 1. their is a sql query running behind :-
SELECT * FROM <table_name> WHERE ID = 1Here "*" is fetching the all details from the given table with a condition "where" with parameter "id" now we are clear that what is running behind lets move forward
Exploitation
To check whether a parameter is vulnerable and exploitable to sql injection their are 2 techniques
CREATING ERROR
If we are able to create an error in sql database then its exploitable. we can create error in 5 ways
Logical error : enter the non-existing value in parameter
error payloads
blind payloads
boolean payloads
union payloads
FETCHING DATA
union select payloads
boolean payloads
Note :- if you dont know database name their is always use "information_schema"
Steps to reproduce
we need to create an error in database for that i used error & blind sql payload :- (' or sleep(5)) to check whether that payload worked or not notice the changes in web page or you can look at the bottom right cornor of "burp repeater" (file size | time taken to load file)
make notes of (file size | page load time) before and after injecting the payload i.e., before :- (6532 bytes | 497 millis) after :- (6234 bytes | 5,578 millis)
make the page normal again (non-error page) for that we first count total number of columns we use order by 1,2,3,4... payloads it will not give error on correct column number it will give error non existing column number entered now we have to balance the query i.e., after knowing total no. of colums we have to send the to send exact same no. of columns query in union query union select 1,2,3,4,5,6.,7......payloads now we can see the no of column visible on web i.e., 5, 2, 3, 4
Their are lots of things we can do with sql injection. we do all this :- LFI SHELL UPLOAD OUTPUT FILE FETCH USERNAME AND PASSWORD OF DATABASE
LFI
cod=9999999 UNION SELECT 1,LOAD_FILE('/etc/passwd'),3,4,5,6,7#credentials of database
Here is the payload,
cod=99999 UNION SELECT 1,(SELECT host, user, password FROM mysql.user),3,4,5,6,7#
or
cod=99999 UNION SELECT 1,group_concat(host, user, password)FROM mysql.user,3,4,5,6,7#Writing the shell
Last updated