nginx php 防止跨站,完美解决Nginx的跨站(防WEBshell)的问题

完美解决Nginx的跨站(防WEBshell)的问题

2012-3-28 王健宇 转载

看了很多方法,试了一下这个最好用,需要更改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/

vi  main/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即可。

最后不要忘了将php.ini中的open_basedir改为:open_basedir = "/var/tmp/:/tmp/"

经亲测可用。

使用phpspy2008测试,无法浏览其他目录。

发表评论:

昵称

邮件地址 (选填)

个人主页 (选填)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值