全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
123
返回列表 发新帖
楼主: freebsd

[nginx] 不好意思,上次的nginx 防webshell文章还是有问题的

[复制链接]
 楼主| 发表于 2010-1-14 17:01:06 | 显示全部楼层

回复 20# 的帖子

硬件防火墙一般都没有cc防护的,靠自己。
发表于 2010-3-31 19:47:31 | 显示全部楼层
您好,按照您提供的修改php代码来防webshell方式,我在php5.2.10上加入了您提供的代码,但nginx在spawn-fcgi下发现没有启到限制呢
您的补丁是只针对php-fpm的吗
发表于 2010-3-31 20:36:57 | 显示全部楼层

回复 22# 的帖子

spawn-fcgi 我试过,也是可以的
发表于 2010-4-1 09:55:28 | 显示全部楼层
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_doc_root;
                if(PG(doc_root)){
                        env_doc_root = estrdup(PG(doc_root));
                }else{
                        env_doc_root = sapi_getenv("DOCUMENT_ROOT", sizeof("DOCUMENT_ROOT")-1 TSRMLS_CC);
                }
                if(env_doc_root){
                        int        res_root = php_check_specific_open_basedir(env_doc_root, path TSRMLS_CC);
                        efree(env_doc_root);
                        if (res_root == 0) {
                                return 0;
                        }
                        if (res_root == -2) {
                                errno = EPERM;
                                return -1;
                        }
                }
                // ***********


                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;
}
/* }}} */

楼上是这样修改的吗
发表于 2010-4-1 09:57:16 | 显示全部楼层
我在php5.2.10和5.2.12上修改后都是一样的,/www/domain1/web1/webshell.php
可以看到 /www/下的所有站点
发表于 2010-4-1 09:59:29 | 显示全部楼层
你是不是改错了,我修改后的版本确实只能访问站点根目录或者以下的文件了.
发表于 2010-4-1 10:22:07 | 显示全部楼层
代码是楼主提供的,难道还要改那儿吗,openbase_dir 指定/tmp
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2024-5-7 05:49 , Processed in 0.061196 second(s), 9 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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