background image

一次查询到记录,一次没有,我们来看看源码

//show.php 12-15 行

// 执行 mysql 查询语句

$query = "select * from postmessage where id = ".$_GET["id"];

$result = mysql_query($query)

or die("执行 ySQL 查询语句失败:" . mysql_error());

参数 id 传递进来后,和前面的字符串结合的 sql

 

语句放入数据库执行 查询

 

提交 and 1=1,语句变成 select * from postmessage where id = 71 and 1=1 这语句前值后值都
为真,and 以后也为真,返回查询到的数据

 

提交 and 1=2,语句变成 select * from postmessage where id = 71 and 1=2 这语句前值为真,
后值为假,and 以后为假,查询不到任何数据

正常的 SQL 查询,经过我们构造的语句之后,形成了 SQL 注入攻击。通过这个注入点,我们还可以进

 

一步拿到权限,比如说运用 union 读取管理密码,读取数据库信息,或者用 mysql 的 load_file,into 
outfile 等函数进一步渗透。

防范方法

整型参数:

 

运用 intval 函数将数据转换成整数

函数原型