国产欧美二区三区-国产欧美高清-国产欧美国产精品第二区-国产欧美国产精品第一区-小说区 图片区-小说区 综合区 都市激情

當前位置: 首頁 > 站長資訊 > 正文頁面

Discuz教程:論壇安全加固

針對discuz的安全加固如下:7Li網站目錄_網站網址收錄與提交入口

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

location ~* ^/(data|images|config|static|source|template)/.*/.(php|php5)$7Li網站目錄_網站網址收錄與提交入口

{7Li網站目錄_網站網址收錄與提交入口

deny all;7Li網站目錄_網站網址收錄與提交入口

}7Li網站目錄_網站網址收錄與提交入口

按照以上的配置,即使出現上傳漏洞,上傳到了上面配置的幾個目錄php文件,也會報403出錯無法執行。更安全的做法是,放行部分,其余全部禁止,例如:7Li網站目錄_網站網址收錄與提交入口

location ~ (index|forum|group|archiver|api|uc_client|uc_server).*/.(php)?$7Li網站目錄_網站網址收錄與提交入口

{7Li網站目錄_網站網址收錄與提交入口

allow all;7Li網站目錄_網站網址收錄與提交入口

fastcgi_pass 127.0.0.1:9000;7Li網站目錄_網站網址收錄與提交入口

fastcgi_index index.php;7Li網站目錄_網站網址收錄與提交入口

include fcgi.conf;7Li網站目錄_網站網址收錄與提交入口

}7Li網站目錄_網站網址收錄與提交入口

不過上面只是一個示例,根目錄下的php文件,我此處并未列全。而且還有一個問題就是,每次有新的版本發布,如果目錄結構變列或者根目錄新增php文件,都要相應的修改nginx 的安全配置。7Li網站目錄_網站網址收錄與提交入口

2、優化nginx和php-fpm程序運行用戶。例如,該用戶為www,讓www用戶沒有家目錄,沒有shell,無法登陸。nginx和php-fpm程序是通過root內部調用切換到 www用戶。類似于mysql的啟動。具體增加語句如下:7Li網站目錄_網站網址收錄與提交入口

useradd www -d /dev/null -s /sbin/nologin7Li網站目錄_網站網址收錄與提交入口

如果感覺還不夠安全,可以再利用chroot和sudo等程序,限制www用戶所能訪問的目錄和可以調用的命令。7Li網站目錄_網站網址收錄與提交入口

3、目錄權限控制。除了discuz下的data目錄有寫的權限,取消所有其他目錄的寫權限。7Li網站目錄_網站網址收錄與提交入口

該步,我看到網上有列出執行的shell命令為:7Li網站目錄_網站網址收錄與提交入口

find source -type d -maxdepth 4 -exec chmod 555 {} /;7Li網站目錄_網站網址收錄與提交入口

find api -type d -maxdepth 4 -exec chmod 555 {} /;7Li網站目錄_網站網址收錄與提交入口

find static -type d -maxdepth 4 -exec chmod 555 {} /;7Li網站目錄_網站網址收錄與提交入口

find archive -type d -maxdepth 4 -exec chmod 555 {} /;7Li網站目錄_網站網址收錄與提交入口

find config -type d -maxdepth 4 -exec chmod 555 {} /;7Li網站目錄_網站網址收錄與提交入口

find data -type d -maxdepth 4 -exec chmod 755 {} /;7Li網站目錄_網站網址收錄與提交入口

find template -type d -maxdepth 4 -exec chmod 555 {} /;7Li網站目錄_網站網址收錄與提交入口

find uc_client -type d -maxdepth 4 -exec chmod 555 {} /;7Li網站目錄_網站網址收錄與提交入口

不過按這樣的shell語句執行是有警告的,具體所報內容如下:7Li網站目錄_網站網址收錄與提交入口

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.7Li網站目錄_網站網址收錄與提交入口

規范的寫法是:7Li網站目錄_網站網址收錄與提交入口

find source -maxdepth 4 -type d -exec chmod 555 {} /;7Li網站目錄_網站網址收錄與提交入口

find api -maxdepth 4 -type d -exec chmod 555 {} /;7Li網站目錄_網站網址收錄與提交入口

find static -maxdepth 4 -type d -exec chmod 555 {} /;7Li網站目錄_網站網址收錄與提交入口

find archive -maxdepth 4 -type d -exec chmod 555 {} /;7Li網站目錄_網站網址收錄與提交入口

find config -maxdepth 4 -type d -exec chmod 555 {} /;7Li網站目錄_網站網址收錄與提交入口

find data -maxdepth 4 -type d -exec chmod 755 {} /;7Li網站目錄_網站網址收錄與提交入口

find template -maxdepth 4 -type d -exec chmod 555 {} /;7Li網站目錄_網站網址收錄與提交入口

find uc_client -maxdepth 4 -type d -exec chmod 555 {} /;7Li網站目錄_網站網址收錄與提交入口

注:上面的' -maxdepth 4 ' 也是可以取消的。7Li網站目錄_網站網址收錄與提交入口

對目錄設置完成后,還要對文件配置權限:7Li網站目錄_網站網址收錄與提交入口

find . -type f -exec chmod 444 {} /;7Li網站目錄_網站網址收錄與提交入口

#設置論壇目錄的文件只可讀,然后設置那些需要寫的文件,一般只有data下的文件是可以的。7Li網站目錄_網站網址收錄與提交入口

find data -type f -exec chmod 755 {} /;7Li網站目錄_網站網址收錄與提交入口

#設置data 文件為7557Li網站目錄_網站網址收錄與提交入口

4、禁止php相關函數的調用及跨站。在php.ini文件中開啟以下兩項7Li網站目錄_網站網址收錄與提交入口

open_basedir = .:/tmp/7Li網站目錄_網站網址收錄與提交入口

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,popep7Li網站目錄_網站網址收錄與提交入口

assthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix7Li網站目錄_網站網址收錄與提交入口

_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_get7Li網站目錄_網站網址收錄與提交入口

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,posix7Li網站目錄_網站網址收錄與提交入口

_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname7Li網站目錄_網站網址收錄與提交入口

以上主要是對系統層面的調用函數全部禁止 。7Li網站目錄_網站網址收錄與提交入口

5、將該KVM機進行隔離。和其他主機無法連接。7Li網站目錄_網站網址收錄與提交入口

該步驟配置是有條件的,在有KVM環境的條件,可以將各個應用之間利用KVM進行隔離。web訪問模式為 物理機iptables nat ——KVM虛擬機 或 web入口——物理機iptables nat ——KVM虛擬機 。7Li網站目錄_網站網址收錄與提交入口

6、數據庫控制。7Li網站目錄_網站網址收錄與提交入口

在mysql新建用戶時,一是適當分配給用戶所需的權限,二是要在創建用戶時最好能限定來源IP 。例如:7Li網站目錄_網站網址收錄與提交入口

CREATE USER 'discuz'@'192.168.0.%' IDENTIFIED BY '66ZX811a';7Li網站目錄_網站網址收錄與提交入口

grant select,insert,update,delete,create,index,trigger,create temporary tables on discuz.* to 'discuz'@'192.168.0.%';7Li網站目錄_網站網址收錄與提交入口

  

此文由 網站目錄_網站網址收錄與提交入口 編輯,未經允許不得轉載!:

相關文章