SQL注入
漏洞类型
普通注入
普通注入值得是最容易利用的注入方式,比如union注入,盲注(基于时间盲注和基于Boolean的忙住),基于报错的注入等。
//union注入
<?php
$uid = $_GET['id'];
$sql = "SELECT * FROM userinfo where id = $id";
$conn = mysql_connect('localhost','root','root');
mysql_select_db("test",$conn);
$result = mysql_query($sql,$conn);
echo mysql_fetch_row($result);
?>
普通注入还分为字符型注入和数字型注入,上述例子是数字型注入,下面代码是字符型注入:
//union字符型注入
<?php
$uid = $_GET['id'];
$sql = "SELECT * FROM userinfo where id = '$id'";
$conn = mysql_connect('localhost','root','root');
mysql_select_db("test",$conn);
$result = mysql_query($sql,$conn);
echo mysql_fetch_row($result);
?>
字符型注入在利用时首先需要对单引号进行闭合,通常针对上述代码只需要将id设置为**1’ or 1=1 – '**就可以了,构造出来的查询语句如下
SELECT * FROM userinfo where id = '1' or 1=1 -- '';