phpBB 2.0.13驚現(xiàn)漏洞的解決
更新時間:2007年01月16日 00:00:00 作者:
一、Path Disclosure
漏洞文件:/db/oracle.php
漏洞描敘:直接訪問oracle.php,導(dǎo)致暴露web路徑
涉及版本:phpbb <=2.013
測試:ie提交http://127.0.0.1/phpBB2/db/oracle.php 返回錯誤:
Fatal error: Cannot redeclare sql_nextid() in f:\easyphp1-7\www\phpbb2\db\oracle.php on line 405
解決辦法
如果你不是采用的oracle數(shù)據(jù)庫,可以直接把oracle.php刪除
修改php.ini設(shè)置: display_errors = Off
二、Remote php File Include
漏洞文件:/admin/admin_styles.php
漏洞描敘:admin_styles.php文件里變量過濾不嚴(yán),導(dǎo)致從后臺執(zhí)行惡意代碼,從而危險服務(wù)器安全
涉及版本:phpbb <=2.013+ php <5.0
漏洞分析:
71 case "addnew":
72 $install_to = ( isset($HTTP_GET_VARS[install_to]) ) ? urldecode($HTTP_GET_VARS[install_to]) : $HTTP_POST_VARS[install_to];
73 $style_name = ( isset($HTTP_GET_VARS[style]) ) ? urldecode($HTTP_GET_VARS[style]) : $HTTP_POST_VARS[style];
74
75 if( isset($install_to) )
76 {
77
78 include($phpbb_root_path. "templates/" . $install_to . "/theme_info.cfg");
79
80 $template_name = $install_to;
81 $found = FALSE;
$install_to變量過濾不嚴(yán),導(dǎo)致被include($phpbb_root_path. "templates/" . $install_to . "/theme_info.cfg");調(diào)用,入侵者可以通過構(gòu)造 $install_to達(dá)到攻擊
目的
測試分析(目的:從后臺得到webshelll):
首先我們只看78行代碼
78 include($phpbb_root_path. "templates/" . $install_to . "/theme_info.cfg");
include最終于是執(zhí)行了theme_info.cfg文件,theme_info.cfg是保存“風(fēng)格”的一些設(shè)置 如果我們可以在從在theme_info.cfg文件插入惡意代碼,那么就直接通過include執(zhí)行了我們的代碼 :) [思路參考《從后臺到webshell的一點思路》]我們來測試下:
后臺風(fēng)格管理-->管理選項--->編輯-->CSS 風(fēng)格表 輸入";phpinfo();" (也可以是其他變量插入),然后“輸出”設(shè)置成功保存到theme_info.cfg文件
我們在打開theme_info.cfg看看:
$subSilver[0][head_stylesheet] = "subSilver.css\";phpinfo();\"";
郁悶"被過濾了,我是在 magic_quotes_gpc = off 下測試的 看來phpbb本身對做了過濾 ,此路不通 :(
在對于<5.0(不包括4.10)的php本身存在對null截斷的漏洞:
------------------------------- 漏洞具體描敘 start -------------------------------
PHP存在輸入驗證漏洞,遠(yuǎn)程攻擊者可以利用這個漏洞讀取系統(tǒng)文件內(nèi)容及進(jìn)行目錄遍歷攻擊。
問題一是addslashes()存在問題,addslashes()用于過濾用戶輸入,在magic_quotes_gpc設(shè)置"on"時,將對每個輸入執(zhí)行addslashes()進(jìn)行過濾,但是由于NULL字節(jié)不正確被addslashes()編碼,如果用戶輸入被include()或require()使用,可能導(dǎo)致攻擊者讀取文件系統(tǒng)的任意文件。
問題二是上傳路徑遍歷問題,PHP自動過濾上傳的文件名數(shù)據(jù),刪除在斜杠或反斜杠之前的數(shù)據(jù),但是如果攻擊者上傳的文件包含單引號,而WEB服務(wù)又設(shè)置magic_quotes為ON,或者對上傳文件名執(zhí)行addslashes()操作,那么在單引號前會前綴一個反斜杠,因此在Windows系統(tǒng)可造成目錄遍歷問題,導(dǎo)致文件上傳到系統(tǒng)任意目錄中。
Warning: main(./../templates/theme_info.cfg\0/theme_info.cfg): failed to open stream: No such file or directory in f:\easyphp1-7\www\phpbb2\admin\admin_styles.php on line 78
Warning: main(): Failed opening ./../templates/theme_info.cfg\0/theme_info.cfg for inclusion (include_path=.;f:\EasyPHP1-7\php\pear\) in f:\easyphp1-7\www\phpbb2\admin\admin_styles.php on line 7
%00變從了\0,phpbb就是變態(tài),既然%00不行 我們在看到72行代碼:
72 $install_to = ( isset($HTTP_GET_VARS[install_to]) ) ? urldecode($HTTP_GET_VARS[install_to]) : $HTTP_POST_VARS[install_to];
我們使用ie提交的方式是get 那么我們提交的&install_to,要被urldecode()解析,那么我們可以先把%00進(jìn)行url編碼一次:%25%30%30 提交:
http://127.0.0.1/phpBB2/a......6eb9ea1e43e62cbd634
返回:
Warning: main(./../templates/theme_info.cfg): failed to open stream: No such file or directory in f:\easyphp1-7\www\phpbb2\admin\admin_styles.php on line 78
Warning: main(): Failed opening ./../templates/theme_info.cfg for inclusion (include_path=.;f:\EasyPHP1-7\php\pear\) in f:\easyphp1-7\www\phpbb2\admin\admin_styles.php on line 7
注意和%00時比較
%00 ---> main(./../templates/theme_info.cfg\0/theme_info.cfg)
%25%30%30 ---> Warning: main(./../templates/theme_info.cfg)
哈哈 include成功被截斷,那么我們可以利用../來調(diào)用容易文件咯 :)
具體利用
我們把phpshell代碼保存為gif或其他圖片格式,在通過論壇上傳 然后利用構(gòu)造 install_to 而被 include() 調(diào)用并執(zhí)行。
這里phpshell代碼代碼使用 保存為 1.gif 我們到 http://127.0.0.1/phpBB2/profile.php?mode=editprofile 上傳圖像
返回錯誤:The avatar filetype must be .jpg, .gif or .png
如圖1
大家都曉得圖片文件都有他的“特殊標(biāo)志” ,用uedit等編輯工具你就可以發(fā)現(xiàn)如 gif 文件的開頭有“GIF89a” 看來phpbb在判斷后綴后還用了 getimagesize() 或類似的函數(shù)判斷,那么我們怎么繞過去呢?注意gif的文件尾部有個“0000...”的空數(shù)據(jù)區(qū),我們就可以把php代碼寫到這個里面。
如圖2
漏洞文件:/db/oracle.php
漏洞描敘:直接訪問oracle.php,導(dǎo)致暴露web路徑
涉及版本:phpbb <=2.013
測試:ie提交http://127.0.0.1/phpBB2/db/oracle.php 返回錯誤:
Fatal error: Cannot redeclare sql_nextid() in f:\easyphp1-7\www\phpbb2\db\oracle.php on line 405
解決辦法
如果你不是采用的oracle數(shù)據(jù)庫,可以直接把oracle.php刪除
修改php.ini設(shè)置: display_errors = Off
二、Remote php File Include
漏洞文件:/admin/admin_styles.php
漏洞描敘:admin_styles.php文件里變量過濾不嚴(yán),導(dǎo)致從后臺執(zhí)行惡意代碼,從而危險服務(wù)器安全
涉及版本:phpbb <=2.013+ php <5.0
漏洞分析:
71 case "addnew":
72 $install_to = ( isset($HTTP_GET_VARS[install_to]) ) ? urldecode($HTTP_GET_VARS[install_to]) : $HTTP_POST_VARS[install_to];
73 $style_name = ( isset($HTTP_GET_VARS[style]) ) ? urldecode($HTTP_GET_VARS[style]) : $HTTP_POST_VARS[style];
74
75 if( isset($install_to) )
76 {
77
78 include($phpbb_root_path. "templates/" . $install_to . "/theme_info.cfg");
79
80 $template_name = $install_to;
81 $found = FALSE;
$install_to變量過濾不嚴(yán),導(dǎo)致被include($phpbb_root_path. "templates/" . $install_to . "/theme_info.cfg");調(diào)用,入侵者可以通過構(gòu)造 $install_to達(dá)到攻擊
目的
測試分析(目的:從后臺得到webshelll):
首先我們只看78行代碼
78 include($phpbb_root_path. "templates/" . $install_to . "/theme_info.cfg");
include最終于是執(zhí)行了theme_info.cfg文件,theme_info.cfg是保存“風(fēng)格”的一些設(shè)置 如果我們可以在從在theme_info.cfg文件插入惡意代碼,那么就直接通過include執(zhí)行了我們的代碼 :) [思路參考《從后臺到webshell的一點思路》]我們來測試下:
后臺風(fēng)格管理-->管理選項--->編輯-->CSS 風(fēng)格表 輸入";phpinfo();" (也可以是其他變量插入),然后“輸出”設(shè)置成功保存到theme_info.cfg文件
我們在打開theme_info.cfg看看:
$subSilver[0][head_stylesheet] = "subSilver.css\";phpinfo();\"";
郁悶"被過濾了,我是在 magic_quotes_gpc = off 下測試的 看來phpbb本身對做了過濾 ,此路不通 :(
在對于<5.0(不包括4.10)的php本身存在對null截斷的漏洞:
------------------------------- 漏洞具體描敘 start -------------------------------
PHP存在輸入驗證漏洞,遠(yuǎn)程攻擊者可以利用這個漏洞讀取系統(tǒng)文件內(nèi)容及進(jìn)行目錄遍歷攻擊。
問題一是addslashes()存在問題,addslashes()用于過濾用戶輸入,在magic_quotes_gpc設(shè)置"on"時,將對每個輸入執(zhí)行addslashes()進(jìn)行過濾,但是由于NULL字節(jié)不正確被addslashes()編碼,如果用戶輸入被include()或require()使用,可能導(dǎo)致攻擊者讀取文件系統(tǒng)的任意文件。
問題二是上傳路徑遍歷問題,PHP自動過濾上傳的文件名數(shù)據(jù),刪除在斜杠或反斜杠之前的數(shù)據(jù),但是如果攻擊者上傳的文件包含單引號,而WEB服務(wù)又設(shè)置magic_quotes為ON,或者對上傳文件名執(zhí)行addslashes()操作,那么在單引號前會前綴一個反斜杠,因此在Windows系統(tǒng)可造成目錄遍歷問題,導(dǎo)致文件上傳到系統(tǒng)任意目錄中。
Warning: main(./../templates/theme_info.cfg\0/theme_info.cfg): failed to open stream: No such file or directory in f:\easyphp1-7\www\phpbb2\admin\admin_styles.php on line 78
Warning: main(): Failed opening ./../templates/theme_info.cfg\0/theme_info.cfg for inclusion (include_path=.;f:\EasyPHP1-7\php\pear\) in f:\easyphp1-7\www\phpbb2\admin\admin_styles.php on line 7
%00變從了\0,phpbb就是變態(tài),既然%00不行 我們在看到72行代碼:
72 $install_to = ( isset($HTTP_GET_VARS[install_to]) ) ? urldecode($HTTP_GET_VARS[install_to]) : $HTTP_POST_VARS[install_to];
我們使用ie提交的方式是get 那么我們提交的&install_to,要被urldecode()解析,那么我們可以先把%00進(jìn)行url編碼一次:%25%30%30 提交:
http://127.0.0.1/phpBB2/a......6eb9ea1e43e62cbd634
返回:
Warning: main(./../templates/theme_info.cfg): failed to open stream: No such file or directory in f:\easyphp1-7\www\phpbb2\admin\admin_styles.php on line 78
Warning: main(): Failed opening ./../templates/theme_info.cfg for inclusion (include_path=.;f:\EasyPHP1-7\php\pear\) in f:\easyphp1-7\www\phpbb2\admin\admin_styles.php on line 7
注意和%00時比較
%00 ---> main(./../templates/theme_info.cfg\0/theme_info.cfg)
%25%30%30 ---> Warning: main(./../templates/theme_info.cfg)
哈哈 include成功被截斷,那么我們可以利用../來調(diào)用容易文件咯 :)
具體利用
我們把phpshell代碼保存為gif或其他圖片格式,在通過論壇上傳 然后利用構(gòu)造 install_to 而被 include() 調(diào)用并執(zhí)行。
這里phpshell代碼代碼使用 保存為 1.gif 我們到 http://127.0.0.1/phpBB2/profile.php?mode=editprofile 上傳圖像
返回錯誤:The avatar filetype must be .jpg, .gif or .png
如圖1
大家都曉得圖片文件都有他的“特殊標(biāo)志” ,用uedit等編輯工具你就可以發(fā)現(xiàn)如 gif 文件的開頭有“GIF89a” 看來phpbb在判斷后綴后還用了 getimagesize() 或類似的函數(shù)判斷,那么我們怎么繞過去呢?注意gif的文件尾部有個“0000...”的空數(shù)據(jù)區(qū),我們就可以把php代碼寫到這個里面。
如圖2
相關(guān)文章
焦點技術(shù):Google你真好(Google Hack)
焦點技術(shù):Google你真好(Google Hack)...2007-01-01對Serv-U 6.0.0.2默認(rèn)帳戶及密碼的一點理解
對Serv-U 6.0.0.2默認(rèn)帳戶及密碼的一點理解...2007-01-01系統(tǒng)安全:Win XP SP2 配置及故障解決技巧大揭露
系統(tǒng)安全:Win XP SP2 配置及故障解決技巧大揭露...2007-01-01