A5下载 - 努力做内容最丰富最安全的下载站!

A5站长下载站

当前位置:A5下载 > 源码技巧 > discuz > Discuz教程:论坛安全加固

Discuz教程:论坛安全加固

时间:2015-07-30 09:37作者:fang人气:86

针对discuz的安全加固如下:

1、在nginx入口上对data|images|config|static|source|template 这几个可以上传的目录里的php文件禁止访问 。(更安全一点就是列出放行的,其他全部禁止。)

location ~* ^/(data|images|config|static|source|template)/.*.(php|php5)$

{

deny all;

}

按照以上的配置,即使出现上传漏洞,上传到了上面配置的几个目录php文件,也会报403出错无法执行。更安全的做法是,放行部分,其余全部禁止,例如:

location ~ (index|forum|group|archiver|api|uc_client|uc_server).*.(php)?$

{

allow all;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

include fcgi.conf;

}

不过上面只是一个示例,根目录下的php文件,我此处并未列全。而且还有一个问题就是,每次有新的版本发布,如果目录结构变列或者根目录新增php文件,都要相应的修改nginx 的安全配置。

2、优化nginx和php-fpm程序运行用户。例如,该用户为www,让www用户没有家目录,没有shell,无法登陆。nginx和php-fpm程序是通过root内部调用切换到 www用户。类似于mysql的启动。具体增加语句如下:

useradd www -d /dev/null -s /sbin/nologin

如果感觉还不够安全,可以再利用chroot和sudo等程序,限制www用户所能访问的目录和可以调用的命令。

3、目录权限控制。除了discuz下的data目录有写的权限,取消所有其他目录的写权限。

该步,我看到网上有列出执行的shell命令为:

find source -type d -maxdepth 4 -exec chmod 555 {} ;

find api -type d -maxdepth 4 -exec chmod 555 {} ;

find static -type d -maxdepth 4 -exec chmod 555 {} ;

find archive -type d -maxdepth 4 -exec chmod 555 {} ;

find config -type d -maxdepth 4 -exec chmod 555 {} ;

find data -type d -maxdepth 4 -exec chmod 755 {} ;

find template -type d -maxdepth 4 -exec chmod 555 {} ;

find uc_client -type d -maxdepth 4 -exec chmod 555 {} ;

不过按这样的shell语句执行是有警告的,具体所报内容如下:

find: warning: you have specified the -maxdepth option after a non-option argument -type, but options are not positional (-maxdepth affects tests specified before it as well as those specified after it). Please specify options before other arguments.

规范的写法是:

find source -maxdepth 4 -type d -exec chmod 555 {} ;

find api -maxdepth 4 -type d -exec chmod 555 {} ;

find static -maxdepth 4 -type d -exec chmod 555 {} ;

find archive -maxdepth 4 -type d -exec chmod 555 {} ;

find config -maxdepth 4 -type d -exec chmod 555 {} ;

find data -maxdepth 4 -type d -exec chmod 755 {} ;

find template -maxdepth 4 -type d -exec chmod 555 {} ;

find uc_client -maxdepth 4 -type d -exec chmod 555 {} ;

注:上面的' -maxdepth 4 ' 也是可以取消的。

对目录设置完成后,还要对文件配置权限:

find . -type f -exec chmod 444 {} ;

#设置论坛目录的文件只可读,然后设置那些需要写的文件,一般只有data下的文件是可以的。

find data -type f -exec chmod 755 {} ;

#设置data 文件为755

4、禁止php相关函数的调用及跨站。在php.ini文件中开启以下两项

open_basedir = .:/tmp/

disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popep

assthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix

_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_get

pwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix

_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname

以上主要是对系统层面的调用函数全部禁止 。

5、将该KVM机进行隔离。和其他主机无法连接。

该步骤配置是有条件的,在有KVM环境的条件,可以将各个应用之间利用KVM进行隔离。web访问模式为 物理机iptables nat ——KVM虚拟机 或 web入口——物理机iptables nat ——KVM虚拟机 。

6、数据库控制。

在mysql新建用户时,一是适当分配给用户所需的权限,二是要在创建用户时最好能限定来源IP 。例如:

CREATE USER 'discuz'@'192.168.0.%' IDENTIFIED BY '66ZX811a';

grant select,insert,update,delete,create,index,trigger,create temporary tables on discuz.* to 'discuz'@'192.168.0.%';

标签Discuz,教程,论坛,安全,加固,针对,discuz,安

相关下载

查看所有评论+

网友评论

网友
您的评论需要经过审核才能显示

热门阅览

最新排行

公众号