VPS侦探论坛

 找回密码
 注册
查看: 7262|回复: 0

看到一个解决Nginx的跨站(防WEBshell)的问题

[复制链接]
发表于 2010-11-1 10:15:15 | 显示全部楼层 |阅读模式

咱们这个一键安装包包括了这个东西了么?如果没有 应该如何去做呢?谢谢军哥了
原文连接
http://www.xpb.cn/blog/665.html
http://www.xpb.cn/blog/743.html


看了很多方法,试了一下这个最好用,需要更改php源程序后,重新编译php。在使用fpm方式安装时,打补丁过程中会修改php的文件,所以需要在打完fpm补丁后再修改php源程序。
  1. tar zxvf php-5.2.14.tar.gz
  2. gzip -cd php-5.2.14-fpm-0.5.14.diff.gz | patch -d php-5.2.14 -p1
  3. cd php-5.2.14/

  4. vi  main/fopen_wrappers.c


  5. /* {{{ php_check_open_basedir
  6. */
  7. PHPAPI int php_check_open_basedir_ex(const char *path, int warn TSRMLS_DC)
  8. {
  9.         /* Only check when open_basedir is available */
  10.         if (PG(open_basedir) && *PG(open_basedir)) {
  11.                 char *pathbuf;
  12.                 char *ptr;
  13.                 char *end;

  14. // 添加的内容开始
  15.                char *env_document_root = sapi_getenv("DOCUMENT_ROOT", sizeof("DOCUMENT_ROOT")-1 TSRMLS_CC);
  16.                 if (php_check_specific_open_basedir(ptr, path TSRMLS_CC) == 0) {
  17.                         efree(env_document_root);
  18.                         return 0;
  19.                 }
  20.                 // 添加的内容结束

  21.                 pathbuf = estrdup(PG(open_basedir));

  22.                 ptr = pathbuf;

  23.                 while (ptr && *ptr) {
  24.                         end = strchr(ptr, DEFAULT_DIR_SEPARATOR);
  25.                         if (end != NULL) {
  26.                                 *end = '\0';
  27.                                 end++;
  28.                         }

  29.                         if (php_check_specific_open_basedir(ptr, path TSRMLS_CC) == 0) {
  30.                                 efree(pathbuf);
  31.                                 return 0;
  32.                         }

  33.                         ptr = end;
  34.                 }
  35.                 if (warn) {
  36.                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "open_basedir restriction in effect. File(%s) is not within the allowed path(s): (%s)", path, PG(open_basedir));
  37.                 }
  38.                 efree(pathbuf);
  39.                 errno = EPERM; /* we deny permission to open it */
  40.                 return -1;
  41.         }

  42.         /* Nothing to check... */
  43.         return 0;
  44. }
复制代码
需要添加的内容用红色表示出来了,然后重新编译安装php即可。经亲测可用。使用phpspy2008测试,无法浏览其他目录。

[ 本帖最后由 wxforex 于 2010-11-1 10:17 编辑 ]
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|VPS侦探 ( 鲁ICP备16040043号-1 )

GMT+8, 2024-9-8 08:20 , Processed in 0.025240 second(s), 17 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表