国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > 建站經驗 > 正文

Discuz教程:論壇安全加固

2024-04-25 20:40:22
字體:
來源:轉載
供稿:網友

針對discuz的安全加固如下:

1、在nginx入口上對data|images|config|static|source|template 這幾個可以上傳的目錄里的php文件禁止訪問 。(更安全一點就是列出放行的,其他全部禁止。)

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

{

deny all;

}

按照以上的配置,即使出現(xiàn)上傳漏洞,上傳到了上面配置的幾個目錄php文件,也會報403出錯無法執(zhí)行。更安全的做法是,放行部分,其余全部禁止,例如:

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文件,我此處并未列全。而且還有一個問題就是,每次有新的版本發(fā)布,如果目錄結構變列或者根目錄新增php文件,都要相應的修改nginx 的安全配置。

2、優(yōu)化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目錄有寫的權限,取消所有其他目錄的寫權限。

該步,我看到網上有列出執(zhí)行的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語句執(zhí)行是有警告的,具體所報內容如下:

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.

規(guī)范的寫法是:

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相關函數(shù)的調用及跨站。在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

以上主要是對系統(tǒng)層面的調用函數(shù)全部禁止 。

5、將該KVM機進行隔離。和其他主機無法連接。

該步驟配置是有條件的,在有KVM環(huán)境的條件,可以將各個應用之間利用KVM進行隔離。web訪問模式為 物理機iptables nat ——KVM虛擬機 或 web入口——物理機iptables nat ——KVM虛擬機 。

6、數(shù)據庫控制。

在mysql新建用戶時,一是適當分配給用戶所需的權限,二是要在創(chuàng)建用戶時最好能限定來源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.%';

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 金堂县| 白山市| 璧山县| 铁力市| 金山区| 辽阳市| 杭锦旗| 新乡市| 广州市| 柘荣县| 阜新市| 峨边| 元朗区| 宁南县| 醴陵市| 化德县| 沈丘县| 改则县| 富裕县| 仁化县| 刚察县| 武义县| 会同县| 商洛市| 墨江| 建瓯市| 佛冈县| 郴州市| 百色市| 黑水县| 且末县| 仁寿县| 仪征市| 阿坝| 岱山县| 郧西县| 内乡县| 钟祥市| 玛多县| 贵阳市| 宜君县|