隐藏PHP

By 谷多 on | Work / Tech

http://www.php.net/manual/zh/security.hiding.php

隐藏 PHP

一般而言,通过隐藏的手段提高安全性被认为是作用不大的做法。但某些情况下,尽可能的多增加一份安全性都是值得的。

一些简单的方法可以帮助隐藏 PHP,这样做可以提高攻击者发现系统弱点的难度。在 php.ini 文件里设置 expose_php = off ,可以减少他们能获得的有用信息。

另一个策略就是让 web 服务器用 PHP 解析不同扩展名。无论是通过 .htaccess 文件还是 Apache 的配置文件,都可以设置能误导攻击者的文件扩展名:

Example#1 把 PHP 隐藏为另一种语言

# 使PHP看上去像其它的编程语言
AddType application/x-httpd-php .asp .py .pl
或者干脆彻底隐藏它:

Example#2 使用未知的扩展名作为 PHP 的扩展名

# 使 PHP 看上去像未知的文件类型
AddType application/x-httpd-php .bop .foo .133t
或者把它隐藏为 HTML 页面,这样所有的 HTML 文件都会通过 PHP 引擎,会为服务器增加一些负担:

Example#3 用 HTML 做 PHP 的文件后缀

# 使 PHP 代码看上去像 HTML 页面
AddType application/x-httpd-php .htm .html
要让此方法生效,必须把 PHP 文件的扩展名改为以上的扩展名。这样就通过隐藏来提高了安全性,虽然防御能力很低而且有些缺点。
 
实际上上述的隐藏只是改了一个名字,如果想彻底去掉 .php 该如何处理呢?
使用Apache 的Rewite搞定!
 
从上述文档后面的 User Contributed Notes 中,有几个测试后可用的:
 
RewriteEngine on
RewriteRule    ^$    /index.php    [L]
RewriteRule    ^([a-zA-Z0-9\-\_/]*)/$    /$1/index.php    [L]
RewriteRule    ^([a-zA-Z0-9\-\_/]*)\.(html|htm)$    /$1.php    [L]
RewriteRule    ^([a-zA-Z0-9\-\_/]*)$    /$1.php    [L]
 
Typing "sub.domain.foo/anything" loads "/anything/index.php" if 'anything' is a directory, else it loads "/anything.php".
I'm sure you can find mutch better, but it works great on my site :)
 
另外一个,使用index.php 程序做特殊处理:
<?php
echo $_SERVER['QUERY_STRING'];
echo "<BR>";
// PARSING QUERY STRING
$QS=explode("&",$_SERVER['QUERY_STRING']);
echo $QS[0];
echo "<BR>";
$QS=explode('/',$QS[0]);
// IF Modul is Undefined set it to index
if (!$QS[0]) $MODUL='index';
else $MODUL=strtolower($QS[0]);
// WE can make a Variable $_QUERY
// for alternative _GET
for ($i=1;$i<count($QS);$i+=2)
{
    $_QUERY[$NVAR]=$NVAR=$QS[$i];
    $$NVAR=$QS[$i+1];
}

// Check the Modul is exists?
if (!file_exists("modul_directory/{$MODUL}.php"))
    $MODUL="index";
#### THIS IS EXAMPLE TO IMPLEMENTATION THE SCRIPT
// Load The Template
//include("template.php");
// Load The Module
//include("modul_directory/{$MODUL}.php");
// Load The Footer
//include("footer.php");
 
$empty = $post = array();
foreach ($_GET as $varname => $varvalue) {
    if (empty($varvalue)) {
        $empty[$varname] = $varvalue;
    } else {
        $post[$varname] = $varvalue;
    }
}
print "<pre>";
if (empty($empty)) {
    print "None of the POSTed values are empty, posted:\n";
    var_dump($post);
} else {
    print "We have " . count($empty) . " empty values\n";
    print "Posted:\n"; var_dump($post);
    print "Empty:\n";  var_dump($empty);
    exit;
}
?>
 
we can access the modul in URL like this:
=================================
www.example.com/?forum/topic/20
- it mean load the modul forum.php, and set the _QUERY['topic']=20
www.foo.com/?voting/id/54/type/piechart&choice=2
- it mean load the modul voting.php, and set the _QUERY['id']=54 and _QUERY['type']='piechart' and set _GET['choice']=2
 
 
第三个:
RewriteEngine on
# Rewrite /foo/bar to /foo/bar.php
RewriteRule ^([^.?]+)$ %{REQUEST_URI}.php [L]
# Return 404 if original request is /foo/bar.php
RewriteCond %{THE_REQUEST} "^[^ ]* .*?\.php[? ].*$"
RewriteRule .* - [L,R=404]
# NOTE! FOR APACHE ON WINDOWS: Add [NC] to RewriteCond like this:
# RewriteCond %{THE_REQUEST} "^[^ ]* .*?\.php[? ].*$" [NC]
 
测试了一下,返回404那个规则总是导致500错误,怪异!
 
第四个:
直接在.htaccess中使用
Options   MultiViews 
不过这样应该服务器的很大负担?

28-Oct-2003 12:17
adding MultiViews to your apache Options config
lets you hide/omit .php in the url without any rewriting, etc...
 
内容协商
 
MultiViews是一个针对每个目录的选项,也就是说可以在httpd.conf或.htaccess(如果正确设置了AllowOverride)文件中的<Directory>、<Location>、<Files>配置段中,用Options指令来指定。注意,Options All 并不会设置MultiViews ,你必须明确地指定。
MultiViews的效果是:如果服务器收到对/some/dir/foo的请求,而/some/dir/foo并不存在,但是如果/some/dir启用了MultiViews ,则服务器会查找这个目录下所有的foo.* 文件,并有效地伪造一个说明这些foo.* 文件的类型表,分配给他们相同的媒体类型及内容编码,并选择其中最合适的匹配返回给客户。
MultiViews还可以在服务器检索一个目录时,用于DirectoryIndex指令搜索的文件名。如果设置了:
DirectoryIndex index
而index.html和index.html3并存,则服务器会作一个权衡;如果都没有,但是有index.cgi ,则服务器会执行它。
如果一个目录中没有任何文件具有mod_mime可以识别的表示其字符集、内容类型、语言和编码的后缀,那么其结果将取决于MultiViewsMatch指令的设置,这个指令决定了在MultiViews协商中将使用的处理器、过滤器和其他后缀类型。
 

有可能使 PHP 运作于 Apache 的 content negotiation(MultiViews 选项)吗?

如果到 PHP 文件的连接包含扩展名,一切都运行完美。本解答只针对到 PHP 文件的连接不包含扩展名时,而希望通过 content negotiation 来从不包含扩展名的 URL 来选择 PHP 文件的情况。在此种情况下,将 AddType application/x-httpd-php .php 替换为:

# PHP 4
AddHandler php-script php
AddType text/html php

PHP 5

AddHandler php5-script php AddType text/html php

 

 
 
 
 
 

php:显示php文件源代码

By 谷多 on | Work / Tech

1:apache 配置文件中直接指明为php源代码文件:
AddType application/x-httpd-php-source .phps
则.phps后缀的文件都作为php源文件实现

2:php提供的相关函数:
show_source(filename)

show_source

(PHP 4, PHP 5)

show_source -- 别名 highlight_file()

说明

本函数是该函数的别名: highlight_file().



highlight_file

(PHP 4, PHP 5)

highlight_file -- Syntax highlighting of a file

说明

mixed highlight_file ( string $filename [, bool $return] )

Prints out or returns a syntax highlighted version of the code contained in filename using the colors defined in the built-in syntax highlighter for PHP.

Many servers are configured to automatically highlight files with a phps extension. For example, example.phps when viewed will show the syntax highlighted source of the file. To enable this, add this line to the httpd.conf:

AddType application/x-httpd-php-source .phps

参数

filename

Path to the PHP file to be highlighted.

return

Set this parameter to TRUE to make this function return the highlighted code.

返回值

If return is set to TRUE, returns the highlighted code as a string instead of printing it out. Otherwise, it will return TRUE on success, FALSE on failure.

更新日志

版本说明
4.2.1This function is now also affected by safe_mode and open_basedir.
4.2.0The return parameter was added.

注释

小心

Care should be taken when using the highlight_file() function to make sure that you do not inadvertently reveal sensitive information such as passwords or any other type of information that might create a potential security risk.

注意: 该函数的内部依赖这个参数使用输出缓冲,所以它不能在 ob_start() 的回调函数中使用

参见

highlight_string()


其实用Firefox也很久了,今天才突然注意到居然Firefox支持即时翻译,这下我可以把金山词霸收藏起来了。

开始我还和你奇怪,不知道怎么就自己有这个功能,网上看看原来是Google Toolbar的作用,确实挺实用的。


对网摘增加了日历导航

By 谷多 on | Work / MT|WP

在网摘页面新增了日历导航,导航的地方有上个月的链接,以及年的链接,当然,也顺便加上了Google Adsense玩玩。 年的链接那个黑色的式样我很不喜欢,dreamweaver看网页代码才清楚,原来是因为放在sources 这个div里面导致,懒得改了。 参考图片:
 

六、帝国主义和一切反动派都是纸老虎
作者: 毛泽东


一切反动派都是纸老虎。看起来,反动派的样子是可怕的,但是实际上并没有什么了不起的力量。从长远的观点看问题,真正强大的力量不是属于反动派,而是属于人民。
  《和美国记者安那·路易斯·斯特朗的谈话》(一九四六年八月),《毛泽东选集》第四卷第一一九三页

  同世界上一切事物无不具有两重性(即对立统一规律)一样,帝国主义和一切反动派也有两重性,它们是真老虎又是纸老虎。历史上奴隶主阶级、封建地主阶级和资产阶级,在它们取得统治权力以前和取得统治权力以后的一段时间内,它们是生气勃勃的,是革命者,是先进者,是真老虎。在随后的一段时间,由于它们的对立面,奴隶阶级、农民阶级和无产阶级,逐步壮大,并同它们进行斗争,越来越厉害,它们就逐步向反面转化,化为反动派,化为落后的人们,化为纸老虎,终究被或者将被人民所推翻。反动的、落后的、腐朽的阶级,在面临人民的决死斗争的时候,也还有这样的两重性。一面,真老虎,吃人,成百万人成千万人地吃。人民斗争事业处在艰难困苦的时代,出现许多弯弯曲曲的道路。中国人民为了消灭帝国主义、封建主义和官僚资本主义在中国的统治,花了一百多年时间,死了大概几千万人之多,才取得一九四九年的胜利。你看,这不是活老虎,铁老虎,真老虎吗?但是,它们终究转化成了纸老虎,死老虎,豆腐老虎。这是历史的事实。人们难道没有看见听见过这些吗?真是成千成万!成千成万!所以,从本质上看,从长期上看,从战略上看,必须如实地把帝国主义和一切反动派,都看成纸老虎。从这点上,建立我们的战略思想。另一方面,它们又是活的铁的真的老虎,它们会吃人的。从这点上,建立我们的策略思想和战术思想。
  在中共中央政治局武昌会议上的讲话(一九五八年十二月一日),《毛泽东选集》第四卷第一一九零页《和美国记者安那·路易斯·斯特朗的谈话》一文的题解

  我说一切所有号称强大的反动派统统不过是纸老虎。原因是他们脱离人民。你看,希特勒是不是纸老虎?希特勒不是被打倒了吗?我也谈到沙皇是纸老虎,中国皇帝是纸老虎,日本帝国主义是纸老虎,你看,都倒了。美帝国主义没有倒,还有原子弹,我看也是要倒的,也是纸老虎。
  在各国共产党和工人党莫斯科会议上的讲话(一九五七年十一月十八日),《毛泽东同志论帝国主义和一切反动派都是纸老虎》人民出版社版第二四页

  "搬起石头打自己的脚",这是中国人形容某些蠢人的行为的一名俗话。各国反动派也就是这样的一批蠢人。他们对于革命人民所作的种种迫害,归根结底,只能促进人民的更广泛更剧烈的革命。难道沙皇和蒋介石对于革命人民的种种迫害,不就是对于伟大的俄国革命和伟大的中国革命起了这样的促进作用吗?
  《在苏联最高苏维埃庆祝伟大的十月社会主义革命四十周年会议上的讲话》(一九五七年十一月六日),人民出版社版第五页

  美帝国主义九年来侵占了我国领土台湾,不久以前又派遣它的武装部队侵占了黎巴嫩。美国在全世界许多国家建立了几百个军事基地。中国领土台湾、黎巴嫩以及所有美国在外国的军事基地,都是套在美帝国主义脖子上的绞索。不是别人而是美国人自己制造这种绞索,并把它套在自己的脖子上,而把绞索的另一端交给了中国人民、阿拉伯各国人民和全世界一切爱和平反侵略的人民。美国侵略者在这些地方停留得越久,套在它的头上的绞索就将越紧。
  在最高国务会议上的讲话(一九五八年九月八日),一九五八年九月九日《人民日报》

  帝国主义者的寿命不会很长了,因为他们尽做坏事,专门扶植各国反人民的反动派,霸占大量的殖民地、半殖民地和军事基地,以原子战争威胁和平。这样,他们就迫使全世界百分之九十以上的人正在或者将要对他们群起而攻之。但是帝国主义者目前还是在活着,他们依然在向亚洲、非洲、拉丁美洲横行霸道。他们在西方世界也依然在压迫他们本国的人民群众。这种局面必需改变。结束帝国主义主要是美帝国主义的侵略和压迫,是全世界人民的任务。
  对新华社记者的谈话(一九五八年九月二十九日),《毛泽东同志论帝国主义和一切反动派都是纸老虎》人民出版社版第三一页

  美帝国主义到处横行霸道,把它自己放在同全世界人民为敌的地位,使它自己越来越陷于孤立。美帝国主义手里的原子弹、氢弹,是吓不倒一切不愿意做奴隶的人们的。全世界人民反对美国侵略者的怒潮是不可阻挡的。全世界人民对美帝国主义及其走狗的斗争一定会取得更加伟大的胜利。
  《支持巴拿马人民反美爱国正义斗争的谈话》(一九六四年一月十二日),《全世界人民团结起来打败美国侵略者及其一切走狗》人民出版社版第九----一零页

  美国垄断资本集团如果坚持推行它的侵略政策和战争政策,势必有一天要被全世界人民处以绞刑。其他美国帮凶也将是这样。
  在最高国务会议上的讲话(一九五八年九月八日),一九五八年九月九日《人民日报》

  为了同敌人作斗争,我们在一个长时间内形成了一个概念,就是说,在战略上我们要藐视一切敌人,在战术上我们要重视一切敌人。也就是说在整体上我们一定要藐视它,在一个一个的具体问题上我们一定要重视它。如果不是在整体上藐视敌人,我们就要犯机会主义的错误。马克思、恩格思只有两个人,那时他们就说全世界资本主义要被打倒。但是在具体问题上,在一个一个敌人的问题上,如果我们不重视它,我们就要犯冒险主义的错误。打仗只能一仗一仗地打,敌人只能一部分一部分地消灭。工厂只能一个一个地盖,农民犁地只能一块一块的犁,就是吃饭也是如此。我们在战略上藐视吃饭:这顿饭我们能够吃下去。但是具体地吃,却是一口口地吃的,你不可能把一桌酒席一口吞下去。这叫做各个解决,军事书上叫做各个击破。
  在各国共产党和工人党莫斯科会议上的讲话(一九五七年十一月十八日),《毛泽东同志论帝国主义和一切反动派都是纸老虎》人民出版社版第二五页

  我认为现在国际形势到了一个新的转折点。世界上现在有两股风:东风,西风。中国有句成语:"不是东风压倒西风,就是西风压倒东风。"我认为目前形势的特点是东风压倒西风,也就是说,社会主义的力量对于帝国主义的力量占了压倒的优势。
  在各国共产党和工人党莫斯科会议上的讲话(一九五七年十一月十八日),《毛泽东同志论帝国主义和一切反动派都是纸老虎》人民出版社版第二六页

 

一个有趣的网站:

http://zhongwen.com/mao.htm

腾讯:到现在仍然当之无愧的互联网老大,不管你喜欢不喜欢,在商言商,不要说你是白领!

阿里:一直标榜着为中小企业服务,原来也是长尾!

百度:那些百度联盟的小站也是活生生的例子啊。

 

原来目前中国最成功的互联网企业都是长尾!

 

反过来看看那些被踩在脚下的:新浪,搜狐之流,无一不是过分标榜着我是老大,而慢慢的被赶超和淘汰!

 

今天早起,跑步了!

已经有近2年没早起跑步了,身体基本已经快废了。上周去香港,到香港深水埗的时候就已经双腿发软了,最后硬是累的半死的拖到晚上10点回家,晚上睡的死猪一样。

又大了一岁,从今天开始,每周3次以上锻炼身体,千万不能让自己真的废了。

长尾理论:QQ就是长尾

By 谷多 on | Life / IT

昨天晚上小看了几十页,今天早上半天看完了长尾理论,突然觉得:腾讯QQ的成功不就是一个长尾理论的很好的案例么:

QQ就是我们这些普通网民的长尾!

他包容一切人,不管你是明星,CEO,还是小职员,打工仔,小学生,所谓的白领,只不过是自我标榜的一个垃圾符号而已。

 

下一步:

世界是平的》、《蓝海战略》、《引爆点》、《魔鬼经济学》、《专业主义》
也要看看。

 

关键点:

富饶经济学,共产主义要到了,个性化时代来临了,我们不能只关注带来80%利润的20%群里了,剩下的80%我们也要关注:QQ也是这样啊,估计带来利润的10%都不到,但却免费的为所有用户7×24小时的提供稳定的IM服务马上快10年,这就是活生生的例子啊。

 

被调戏了

By 谷多 on | Life / Misc

二周前,莫名接到一个电话,之后通过email,电话来回好几次,

上周5最后一次电话之后,无音信

 

感觉是来探探风的,被调戏了,可惜说出了好多秘密!

以后得学聪明点了,得留几手。

 

dreamhost 继续瘫痪

By 谷多 on | Work / WebHosting

http://www.dreamhoststatus.com/2008/03/27/filer-problems-with-blingy-cluster/

Filer problems with blingy cluster.

We are currently having a problem with a filer which has crashed and is recovering at this time. While this is happening some customers in the blingy cluster will experience problems loading their websites/email. We apologize for the outage and service is expected to return to normal as soon as the filer recovers.

UPDATE 3:01:AM PDT

The filer has finished recovering and all services are back up and running. We are working with the filer vendor to find the source of the crash to prevent any further outages.

Update 24/03/08 10am: We're working on the file server again to alleviate the load that's causing problems with web, mail and mysql services. Sorry about that.

Update 27/03/08: We are doing emergency data moves to quell the stem of problems recently caused by your file server. During these moves, your data may be inaccessible. We are moving as we can off as fast as possible. Very sorry about the continued inconvenience!

Update 27/03/08 This series of moves has finished. We are going to keep an eye on things to see how much it helped and may have to do more moves tonight and tomorrow morning to get everything working smoothly again. This post will be updated with more information as soon as possible.

Update 29/03/08

We are continuing to move data off of the problematic file server but it's a bit of a catch-22 because customers on that machine are continuing to add data at a very high rate. It filled up this morning for a while causing device full errors as well as mail problems and issues serving websites (when these fill up it causes problems across the board). To explain in more detail, when we move data it does not immediately disappear (there is a 'snapshot' created of the old data that remains in case there was a problem with the move - that ensures that we do not lose customer data but until the admin team can check the move to make sure it went through properly we cannot delete the old data). We just did some of that and have some breathing room again and of course more moves are still in progress but we are asking customer on this cluster to help us by holding up on any non-essential uploads of data for the next couple of days. As soon as we have a significant portion of the data removed the problematic file server will begin to function properly (and additional moves will go much more quickly and smoothly) but right now we're having trouble moving data more quickly than it's being added by people. If everyone could please limit uploads to absolutely essential data until we reach the turning point where everything is working this will be resolved much more quickly (in other words if for example you are setting up a repository of large files you'll actually be better off waiting a couple of days and getting the all clear from us on this issue because you'll be able to access that data reliably instead of cramming it on there now and slowing the recovery process).

In the meantime we'll be doing everything we can to safely and quickly move data off and get things back to normal.

Added information: Some of the people recently moved to the new file server are seeing errors because the data did not get set up completely (loading the site will work but just show an empty index). The admin team has been running an rsync that will fully restore all data and should hopefully finish by 9 PM PST - once that is finished all site and email data will be available for those users.

Update 30/03/08

We're still racing to keep ahead of new data being added so any help we can get on that front is greatly appreciated (we're still asking for customers to limit uploads as much as possible to speed up the recovery process). Some customers who are being moved are seeing blank directories still but those are due to moves in progress and the data will be fully restored when those complete.


Severity:High Resolved:No
.