Nginx 통합 Naxsi 모듈

13087 단어 nginxnaxsi
Naxsi 모듈 의 통합 은 Nginx 가 이미 배치 되 었 거나 시스템 에 존재 하 는 것 을 기반 으로 합 니 다.
STEP 1: naxsi 다운로드
[qiang@localhost home]$ wget  http://naxsi.googlecode.com/files/naxsi-core-0.51-1.tgz

주: 인터넷 에 접속 할 수 없 으 면 미리 다운로드 해서 서버 에 업로드 할 수 있 습 니 다.
STEP 2: 압축 풀기 naxsi
[qiang@localhost home]$ tar -zxvf naxsi-core-0.51-1.tgz

세 번 째 단계: naxsi - core - 0.51 - 1 디 렉 터 리 로 전환 하고 설정 파일 을 nginx. conf 같은 디 렉 터 리 로 복사 합 니 다.
[qiang@localhost naxsi_config]$ cp naxsi_core.rules /etc/nginx/naxsi_core.rules

수정 naxsicore. rules 의 설정 은 다음 과 같 습 니 다.
##################################
## INTERNAL RULES IDS:1-999     ##
##################################
#@MainRule "msg:weird request, unable to parse" id:1;
#@MainRule "msg:request too big, stored on disk and not parsed" id:2;
#@MainRule "msg:invalid hex encoding, null bytes" id:10;
#@MainRule "msg:unknown content-type" id:11;
#@MainRule "msg:invalid formatted url" id:12;
#@MainRule "msg:invalid POST format" id:13;
#@MainRule "msg:invalid POST boundary" id:14;
##################################
## SQL Injections IDs:1000-1099 ##
##################################
MainRule "rx:select|union|update|delete|insert|table|from|ascii|hex|unhex|drop" "msg:sql keywords" "mz:BODY|URL|ARGS|$HEADERS_VAR:Cookie" "s:$SQL:8" id:1000;
MainRule "str:\"" "msg:double quote" "mz:BODY|URL|ARGS|$HEADERS_VAR:Cookie" "s:$SQL:8,$XSS:8" id:1001;
MainRule "str:0x" "msg:0x, possible hex encoding" "mz:BODY|URL|ARGS|$HEADERS_VAR:Cookie" "s:$SQL:2" id:1002;
## Hardcore rules
MainRule "str:/*" "msg:mysql comment (/*)" "mz:BODY|URL|ARGS|$HEADERS_VAR:Cookie" "s:$SQL:8" id:1003;
MainRule "str:*/" "msg:mysql comment (*/)" "mz:BODY|URL|ARGS|$HEADERS_VAR:Cookie" "s:$SQL:8" id:1004;
MainRule "str:|" "msg:mysql keyword (|)"  "mz:BODY|URL|ARGS|$HEADERS_VAR:Cookie" "s:$SQL:8" id:1005;
##MainRule "str:&&" "msg:mysql keyword (&&)" "mz:BODY|URL|ARGS|$HEADERS_VAR:Cookie" "s:$SQL:8" id:1006;
## end of hardcore rules
MainRule "str:--" "msg:mysql comment (--)" "mz:BODY|URL|ARGS|$HEADERS_VAR:Cookie" "s:$SQL:4" id:1007;
MainRule "str:;" "msg:; in stuff" "mz:BODY|URL|ARGS" "s:$SQL:4,$XSS:8" id:1008;
MainRule "str:=" "msg:equal in var, probable sql/xss" "mz:ARGS|BODY" "s:$SQL:2" id:1009;
##MainRule "str:(" "msg:parenthesis, probable sql/xss" "mz:ARGS|URL|BODY|$HEADERS_VAR:Cookie" "s:$SQL:4,$XSS:8" id:1010;
##MainRule "str:)" "msg:parenthesis, probable sql/xss" "mz:ARGS|URL|BODY|$HEADERS_VAR:Cookie" "s:$SQL:4,$XSS:8" id:1011;
MainRule "str:'" "msg:simple quote" "mz:ARGS|BODY|URL|$HEADERS_VAR:Cookie" "s:$SQL:4,$XSS:8" id:1013;
MainRule "str:," "msg:, in stuff" "mz:BODY|URL|ARGS|$HEADERS_VAR:Cookie" "s:$SQL:4" id:1015;
MainRule "str:#" "msg:mysql comment (#)" "mz:BODY|URL|ARGS|$HEADERS_VAR:Cookie" "s:$SQL:4" id:1016;
###############################
## OBVIOUS RFI IDs:1100-1199 ##
###############################
MainRule "str:http://" "msg:http:// scheme" "mz:ARGS|BODY|$HEADERS_VAR:Cookie" "s:$RFI:8" id:1100;
MainRule "str:https://" "msg:https:// scheme" "mz:ARGS|BODY|$HEADERS_VAR:Cookie" "s:$RFI:8" id:1101;
MainRule "str:ftp://" "msg:ftp:// scheme" "mz:ARGS|BODY|$HEADERS_VAR:Cookie" "s:$RFI:8" id:1102;
MainRule "str:php://" "msg:php:// scheme" "mz:ARGS|BODY|$HEADERS_VAR:Cookie" "s:$RFI:8" id:1103;
MainRule "str:sftp://" "msg:sftp:// scheme" "mz:ARGS|BODY|$HEADERS_VAR:Cookie" "s:$RFI:8" id:1104;
MainRule "str:zlib://" "msg:zlib:// scheme" "mz:ARGS|BODY|$HEADERS_VAR:Cookie" "s:$RFI:8" id:1105;
MainRule "str:data://" "msg:data:// scheme" "mz:ARGS|BODY|$HEADERS_VAR:Cookie" "s:$RFI:8" id:1106;
MainRule "str:glob://" "msg:glob:// scheme" "mz:ARGS|BODY|$HEADERS_VAR:Cookie" "s:$RFI:8" id:1107;
MainRule "str:phar://" "msg:phar:// scheme" "mz:ARGS|BODY|$HEADERS_VAR:Cookie" "s:$RFI:8" id:1108;
MainRule "str:file://" "msg:file:// scheme" "mz:ARGS|BODY|$HEADERS_VAR:Cookie" "s:$RFI:8" id:1109;
#######################################
## Directory traversal IDs:1200-1299 ##
#######################################                                        
MainRule "str:.." "msg:double dot" "mz:ARGS|URL|BODY|$HEADERS_VAR:Cookie" "s:$TRAVERSAL:4" id:1200;
MainRule "str:/etc/passwd" "msg:obvious probe" "mz:ARGS|URL|BODY|$HEADERS_VAR:Cookie" "s:$TRAVERSAL:4" id:1202;
MainRule "str:c:\\" "msg:obvious windows path" "mz:ARGS|URL|BODY|$HEADERS_VAR:Cookie" "s:$TRAVERSAL:4" id:1203;
MainRule "str:cmd.exe" "msg:obvious probe" "mz:ARGS|URL|BODY|$HEADERS_VAR:Cookie" "s:$TRAVERSAL:4" id:1204;
MainRule "str:\\" "msg:backslash" "mz:ARGS|URL|BODY|$HEADERS_VAR:Cookie" "s:$TRAVERSAL:4" id:1205;
MainRule "str:/" "msg:slash in args" "mz:ARGS|BODY|$HEADERS_VAR:Cookie" "s:$TRAVERSAL:2" id:1206;
########################################
## Cross Site Scripting IDs:1300-1399 ##
########################################
MainRule "str:<" "msg:html open tag" "mz:ARGS|URL|BODY|$HEADERS_VAR:Cookie" "s:$XSS:8" id:1302;
MainRule "str:>" "msg:html close tag" "mz:ARGS|URL|BODY|$HEADERS_VAR:Cookie" "s:$XSS:8" id:1303;
MainRule "str:[" "msg:[, possible js" "mz:BODY|URL|ARGS|$HEADERS_VAR:Cookie" "s:$XSS:4" id:1310;
MainRule "str:]" "msg:], possible js" "mz:BODY|URL|ARGS|$HEADERS_VAR:Cookie" "s:$XSS:4" id:1311;
MainRule "str:~" "msg:~ character" "mz:BODY|URL|ARGS|$HEADERS_VAR:Cookie" "s:$XSS:4" id:1312;
MainRule "str:`"  "msg:grave accent !" "mz:ARGS|URL|BODY|$HEADERS_VAR:Cookie" "s:$XSS:8" id:1314;
MainRule "rx:%[2|3]."  "msg:double encoding !" "mz:ARGS|URL|BODY|$HEADERS_VAR:Cookie" "s:$XSS:8" id:1315;
MainRule "rx:%3[c|e]."  "msg:double encoding !" "mz:ARGS|URL|BODY|$HEADERS_VAR:Cookie" "s:$XSS:8" id:1316;
MainRule "rx:\\\u003[c|e]"  "msg:tag encoding !" "mz:ARGS|URL|BODY|$HEADERS_VAR:Cookie" "s:$XSS:8" id:1317;
MainRule "str:&#" "msg: utf7/8 encoding" "mz:ARGS|URL|BODY|$HEADERS_VAR:Cookie" "s:$EVADE:4" id:1318;
####################################
## Evading tricks IDs: 1400-1500 ##
####################################
MainRule "str:&#" "msg: utf7/8 encoding" "mz:ARGS|BODY|URL|$HEADERS_VAR:Cookie" "s:$EVADE:4" id:1400;
MainRule "str:%U" "msg: M$ encoding" "mz:ARGS|BODY|URL|$HEADERS_VAR:Cookie" "s:$EVADE:4" id:1401;
MainRule negative "rx:multipart/form-data|application/x-www-form-urlencoded" "msg:Content is neither mulipart/x-www-form.." "mz:$HEADERS_VAR:Content-type" "s:$EVADE:4" id:1402;
#############################
## File uploads: 1500-1600 ##
#############################
MainRule "rx:.ph|.asp|.ht" "msg:asp/php file upload!" "mz:FILE_EXT" "s:$UPLOAD:8" id:1500;
MainRule "rx:.jsp" "msg:asp/php file upload!" "mz:FILE_EXT" "s:$UPLOAD:8" id:1501;
MainRule "rx:.html" "msg:asp/php file upload!" "mz:FILE_EXT" "s:$UPLOAD:8" id:1502;
MainRule "rx:.php" "msg:asp/php file upload!" "mz:FILE_EXT" "s:$UPLOAD:8" id:1503;

주: (1) nginx. conf 모든 디 렉 터 리 는 nginx 컴 파일 설치 시 기본 설정 은 < prefix > / conf / nginx. conf 입 니 다.
(2) 기 존의 naxsi 를 감안 하여core. rules 파일 에 규칙 이 부족 합 니 다. 이 문서 의 설정 규칙 을 사용 하 는 것 이 좋 습 니 다.
STEP 4: Nginx 컴 파일 설치
[qiang@localhost nginx-1.5.7]#./configure --prefix=/usr
--sbin-path=/usr/sbin/nginx
--conf-path=/etc/nginx/nginx.conf
--add-module=/home/naxsi-core-0.51-1/naxsi_src
--error-log-path=/var/log/nginx/error.log
--pid-path=/var/run/nginx/nginx.pid
--user=root
--group=root
--with-http_ssl_module
--with-http_flv_module
--with-http_gzip_static_module
--http-log-path=/var/log/nginx/access.log
--http-client-body-temp-path=/var/tmp/nginx/client
--http-proxy-temp-path=/var/tmp/nginx/proxy
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi
--with-http_stub_status_module
[root@localhost nginx-1.5.7]# make && make install

주: 상기 매개 변 수 는 실제 상황 에 따라 선택 할 수 있 지만 빨간색 을 표시 하 는 수 요 는 있 습 니 다.
다섯 번 째 단계: nginx 설치 성공 여 부 를 검증 합 니 다.
[qiang@localhost nginx-1.5.7]# nginx
nginx: [warn] low address bits of 192.168.1.65/26 are meaningless in /etc/nginx/nginx.conf:78
[qiang@localhost nginx-1.5.7]# ps -ef |grep nginx
root      3086     1  0 10:53 ?        00:00:00 nginx: master process nginx
root      3087  3086  1 10:53 ?        00:00:00 nginx: worker process
root      3088  3086  1 10:53 ?        00:00:00 nginx: worker process
root      3089  3086  1 10:53 ?        00:00:00 nginx: worker process
root      3090  3086  1 10:53 ?        00:00:00 nginx: worker process
root      3093  3073  4 10:53 pts/1    00:00:00 grep nginx

STEP 6: 필터 조건 설정
디 렉 터 리 를 nginx. conf 와 같은 디 렉 터 리 로 전환 하고 nbs. rules 파일 을 새로 만 듭 니 다.
[qiang@localhost nginx]# vim nbs.rules
##LearningMode;
#Enables learning mode--stop
SecRulesEnabled;
##Disables learning
##SecRulesDisabled;
DeniedUrl "/RequestDenied";
## check rules
CheckRule "$SQL >= 8" BLOCK;
CheckRule "$RFI >= 8" BLOCK;
CheckRule "$TRAVERSAL >= 8" BLOCK;
CheckRule "$EVADE >= 8" BLOCK;
CheckRule "$XSS >= 8" BLOCK;
############################################################
##      STOP   ALL   RULES(               )  ##
############################################################
#BasicRule wl:0;
##################################
## INTERNAL RULES IDS:1-999     ##
##################################
BasicRule wl:1,2,10,11,12,13,14;
##################################
## SQL Injections IDs:1000-1099 ##
##################################
BasicRule wl:1001,1002,1003,1004,1005,1006,1007,1008,1009,1010,1011,1012,1013,1014,1015,1016;
###############################
## OBVIOUS RFI IDs:1100-1199 ##
###############################
BasicRule wl:1100,1101,1102,1103,1104,1105,1106,1107,1108,1109;
#######################################
## Directory traversal IDs:1200-1299 ##
#######################################
BasicRule wl:1200,1202,1203,1204,1205,1206;
########################################
## Cross Site Scripting IDs:1300-1399 ##
########################################
BasicRule wl:1310,1311,1312,1313,1314,1315,1318;
####################################
## Evading tricks IDs: 1400-1500 ##
####################################
BasicRule wl:1400,1401,1402;
#############################
## File uploads: 1500-1600 ##
#############################
BasicRule wl:1500,1501,1502,1503;

주: 이 nbs. rules 파일 의 규칙 은 서로 다른 업무 응용 에 따라 제정 해 야 합 니 다.
STEP 7: nginx. conf 설정
http {
    include       naxsi_core.rules;
    include       mime.types;
    default_type  application/octet-stream;
    .......
    server {
        listen       80;
        server_name  localhost centoshost.com;
        charset utf-8;
        .......
        location /wavsep/ {
            .......
            include nbs.rules;
            .......
        }
        location /RequestDenied {
            error_page  404  /404.html;
        }

STEP 9: nginx 다시 시작
[qiang@localhost nginx]# nginx -t -c /etc/nginx/nginx.conf
nginx: [warn] low address bits of 192.168.1.65/26 are meaningless in /etc/nginx/nginx.conf:78
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[qiang@localhost nginx]# nginx -s reload
nginx: [warn] low address bits of 192.168.1.65/26 are meaningless in /etc/nginx/nginx.conf:78

10 단계: 차단 규칙 이 활성화 되 었 는 지 테스트 합 니 다.
위 규칙 은 "<", ">", SQL 의 일부 키워드 (select | union | update | delete | insert | table | from | ascii | hex | unhex | drop | waitfor) 만 걸 러 냅 니 다.
본 고 는 '몽 조 사 석' 블 로그 에서 나 온 것 으로 작가 에 게 연락 하 세 요!

좋은 웹페이지 즐겨찾기