wxforex 发表于 2010-11-1 10:15:15

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

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


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

vimain/fopen_wrappers.c


/* {{{ php_check_open_basedir
*/
PHPAPI int php_check_open_basedir_ex(const char *path, int warn TSRMLS_DC)
{
      /* Only check when open_basedir is available */
      if (PG(open_basedir) && *PG(open_basedir)) {
                char *pathbuf;
                char *ptr;
                char *end;

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

                pathbuf = estrdup(PG(open_basedir));

                ptr = pathbuf;

                while (ptr && *ptr) {
                        end = strchr(ptr, DEFAULT_DIR_SEPARATOR);
                        if (end != NULL) {
                              *end = '\0';
                              end++;
                        }

                        if (php_check_specific_open_basedir(ptr, path TSRMLS_CC) == 0) {
                              efree(pathbuf);
                              return 0;
                        }

                        ptr = end;
                }
                if (warn) {
                        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));
                }
                efree(pathbuf);
                errno = EPERM; /* we deny permission to open it */
                return -1;
      }

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

[ 本帖最后由 wxforex 于 2010-11-1 10:17 编辑 ]
页: [1]
查看完整版本: 看到一个解决Nginx的跨站(防WEBshell)的问题