<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://jackxiang.com/post//</link>
<title><![CDATA[php的filter扩展：在CentOS/RHEL5下安装PHP的filter和json扩展]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[Php/Js/Shell/Go]]></category>
<pubDate>Mon, 08 Oct 2012 06:23:57 +0000</pubDate> 
<guid>http://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	做为一个合格的web开发人员，一定会牢记一个原则——永远不能相信用户输入的数据，行走江湖，安全第一是很重要的。用户通过表单或url传过来的数据，一定要仔细检查过了，才往后台数据库里存进去。在一个成熟的开发团队里，贯彻这个原则不成问题；但是如果在一个新人老手混搭的小team里，很容易就忽视了这个问题，那么各种安全漏洞比如跨站攻击，sql注入等等真是防不胜防。<br/><br/>实际上，用php 5自带的filter扩展能够较好的解决这个问题。我在从前的blog里记录了filter扩展的常规用法——直接利用filter来校验数据，这样有不少额外的代码量，所以我得介绍一个比较偷懒的办法——自动对所有输入变量进行过滤，这只需要对php.ini增加一行配置，然后重启apache或fastcgi让php配置生效。<br/><br/>filter.default=”special_chars”<br/><br/>开启了这项配置后，会自动使用filter_input方法对$_GET, $_POST, $_COOKIE, $_REQUEST以及$_SERVER变量进行过滤转义。配置中special_chars是常量FILTER_SANITIZE_SPECIAL_CHARS的缩写，它能自动转义大部分危险字符例如： &#039;&quot;&lt;&gt;。而php手册对它的解释是：<br/><br/>HTML-escape ‘”&lt;&gt;&amp; and characters with ASCII value less than 32, optionally strip or encode other special characters.<br/><br/>在这个情况下，新人们写出这样的代码我也不会太担心:<br/><br/>$foo = $_GET[&#039;foo&#039;];<br/>echo $foo;<br/>在部分场合，我们可能还是需要未转义的变量，比如某个ajax接受的参数是一段json串，用这段代码即可获得原始数据：<br/><br/>$foo = filter_input (INPUT_GET, &#039;foo&#039;,&nbsp;&nbsp;FILTER_UNSAFE_RAW);<br/>fitler扩展与yahoo使用的yiv如出一辙，印象里似乎就是yahoo对yiv做了些修改贡献给php社区，但是暂时没找到出处。<br/><br/>来自：http://www.ooso.net/archives/559<br/>安装：http://blog.suchasplus.com/2008/11/centos-rhel-install-php-5-filter-and-json-extension-howto-chinese.html<br/><br/><br/><br/>【社区开学季】360提供的Php防注入代码,上面这个模块也就不用下面这些代码来防止注入了。<br/><textarea name="code" class="php" rows="15" cols="100">
&lt;?php 
&#123; // Code By Safe3&nbsp;&nbsp; 3.functioncustomError($errno, $errstr, $errfile, $errline)
&nbsp;&nbsp;echo&quot;&lt;b&gt;Error number:&lt;/b&gt; [$errno],error on line $errline in $errfile&lt;br /&gt;&quot;;
&nbsp;&nbsp;die();
&#125; 
set_error_handler(&quot;customError&quot;, E_ERROR);
$getfilter = &quot;&#039;&#124;(and&#124;or)&#92;&#92;b.+?(&gt;&#124;&lt;&#124;=&#124;in&#124;like)&#124;&#92;&#92;/&#92;&#92;*.+?&#92;&#92;*&#92;&#92;/&#124;&lt;&#92;&#92;s*script&#92;&#92;b&#124;&#92;&#92;bEXEC&#92;&#92;b&#124;UNION.+?Select&#124;Update.+?SET&#124;Insert&#92;&#92;s+INTO.+?VALUES&#124;(Select&#124;Delete).+?FROM&#124;(Create&#124;Alter&#124;Drop&#124;TRUNCATE)&#92;&#92;s+(TABLE&#124;DATABASE)&quot;;
$postfilter = &quot;&#92;&#92;b(and&#124;or)&#92;&#92;b.&#123;1,6&#125;?(=&#124;&gt;&#124;&lt;&#124;&#92;&#92;bin&#92;&#92;b&#124;&#92;&#92;blike&#92;&#92;b)&#124;&#92;&#92;/&#92;&#92;*.+?&#92;&#92;*&#92;&#92;/&#124;&lt;&#92;&#92;s*script&#92;&#92;b&#124;&#92;&#92;bEXEC&#92;&#92;b&#124;UNION.+?Select&#124;Update.+?SET&#124;Insert&#92;&#92;s+INTO.+?VALUES&#124;(Select&#124;Delete).+?FROM&#124;(Create&#124;Alter&#124;Drop&#124;TRUNCATE)&#92;&#92;s+(TABLE&#124;DATABASE)&quot;;
$cookiefilter = &quot;&#92;&#92;b(and&#124;or)&#92;&#92;b.&#123;1,6&#125;?(=&#124;&gt;&#124;&lt;&#124;&#92;&#92;bin&#92;&#92;b&#124;&#92;&#92;blike&#92;&#92;b)&#124;&#92;&#92;/&#92;&#92;*.+?&#92;&#92;*&#92;&#92;/&#124;&lt;&#92;&#92;s*script&#92;&#92;b&#124;&#92;&#92;bEXEC&#92;&#92;b&#124;UNION.+?Select&#124;Update.+?SET&#124;Insert&#92;&#92;s+INTO.+?VALUES&#124;(Select&#124;Delete).+?FROM&#124;(Create&#124;Alter&#124;Drop&#124;TRUNCATE)&#92;&#92;s+(TABLE&#124;DATABASE)&quot;;
functionStopAttack($StrFiltKey, $StrFiltValue, $ArrFiltReq) &#123;
&nbsp;&nbsp;if (is_array($StrFiltValue)) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;$StrFiltValue = implode($StrFiltValue);
&nbsp;&nbsp;&#125; 
&nbsp;&nbsp;if (preg_match(&quot;/&quot; . $ArrFiltReq . &quot;/is&quot;, $StrFiltValue) == 1) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;// slog(&quot;&lt;br&gt;&lt;br&gt;操作IP: &quot;.$_SERVER[&quot;REMOTE_ADDR&quot;].&quot;&lt;br&gt;操作时间: &quot;.strftime(&quot;%Y-%m-%d %H:%M:%S&quot;).&quot;&lt;br&gt;操作页面:&quot;.$_SERVER[&quot;PHP_SELF&quot;].&quot;&lt;br&gt;提交方式: &quot;.$_SERVER[&quot;REQUEST_METHOD&quot;].&quot;&lt;br&gt;提交参数: &quot;.$StrFiltKey.&quot;&lt;br&gt;提交数据: &quot;.$StrFiltValue);&nbsp;&nbsp; 20.&nbsp;&nbsp;&nbsp;&nbsp;print &quot;360websec notice:Illegal operation!&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;exit();
&nbsp;&nbsp;&#125; 
&#125; 
// $ArrPGC=array_merge($_GET,$_POST,$_COOKIE);&nbsp;&nbsp; 25.foreach($_GETas$key=&gt;$value)&#123;
StopAttack($key, $value, $getfilter);
&#125; 
foreach($_POSTas$key =&gt; $value) &#123;
StopAttack($key, $value, $postfilter);
&#125; 
foreach($_COOKIEas$key =&gt; $value) &#123;
StopAttack($key, $value, $cookiefilter);
&#125; 
if (file_exists(&#039;update360.php&#039;)) &#123;
echo&quot;请重命名文件update360.php，防止黑客利用&lt;br/&gt;&quot;;
die();
&#125; 
functionslog($logs) &#123;
$toppath = $_SERVER[&quot;DOCUMENT_ROOT&quot;] . &quot;/log.htm&quot;;
$Ts = fopen($toppath, &quot;a+&quot;);
fputs($Ts, $logs . &quot;&#92;r&#92;n&quot;);
fclose($Ts);
&#125; 

</textarea>
]]>
</description>
</item><item>
<link>http://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] php的filter扩展：在CentOS/RHEL5下安装PHP的filter和json扩展]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>