Tải bản đầy đủ (.docx) (11 trang)

NAXSI ( Hướng Dẫn Cấu Hình NAXSI Security Module Cho Nginx )

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (492.21 KB, 11 trang )

TÌM HIỂU VỀ NAXSI
Apache có một web application firewall và cũng là một security module cực mạnh là
mod_security. Nginx cũng có một security module mạnh tương tự, đó chính là NAXSI. NAXSI
là module phát triển dành riêng cho Nginx, NAXSI là viết tắt của Nginx Anti XSS and SQL
Injection. Sử dụng NAXSI cho phép bạn bảo vệ web application của bạn tốt hơn với cách viết
rules uyển chuyển, đa dạng, tốc độ xử lý nhanh.
NAXSI được viết tắt từ “Nginx Anti XSS and SQL Injection”, là một web application firewall
được phát triển dành riêng cho Nginx. NAXSI hoàn toàn open source và miễn phí. NAXSI có thể
tự động phát hiện và ngăn chặn các cuộc tấn công bằng XSS và SQL Injection vào web
application của bạn, thông qua hệ thống rules linh hoạt và bạn cũng có thể tự xây dựng thêm
rules cho NAXSI.
Cách làm việc của NAXSI rất đơn giản, NAXSI tự động đọc và phân tích các POST và GET
request gửi đến webserver. Nếu phát hiện các dấu hiệu khả nghi, như chứa các string liên quan
đến SQL Injection, XSS, thì tự động block các request từ IP đó, cách block là redirect truy cập
sang một địa chỉ URL khác.
So sánh:
Nginx usage in February 2013.
Bảng so sánh tốc độ sử lý trả về
Hoạt động của NAXSI:
Rules:
• URL : Checks on the search pattern in the URL (server path).
• ARGS: Searches for the pattern in the request arguments.
• FILE_EXT: Tests the file attachment for the search pattern.
• BODY: Checks the body of a POST request for the search pattern; can be further limited
with$BODY_VAR:VarName.
• HEADERS : Finds the search pattern in the header of a request; can be further delimited:
$HEADERS_VAR:User-Agent, $HEADERS_VAR:Cookie, $HEADERS_VAR:Content-
Type,$HEADERS_VAR:Connection, $HEADERS_VAR:Accept-Encoding.
Một vài Rules mẫu:


 MainRule "str:/manager/html/upload" "msg:DN SCAN Tomcat" "mz:URL" "s:$UWA:8"
id:42000217 ;
 MainRule "rx:type( *)=( *)[\"|']symbol[\"|']" "msg:DN APP_SERVER Possible RAILS
Exploit using type=symbol" "mz:BODY" "s:$ATTACK:8" id:42000233 ;
 MainRule "str:basic ywrtaw46ywrtaw4=" "msg:APP_SERVER Tomcat admin-admin
credentials" "mz:$URL/manager|$HEADERS_VAR:Authorization" "s:$ATTACK:8"
id:42000216 ;
 MainRule "str:http://" "msg:http:// scheme" "mz:ARGS|BODY|
$HEADERS_VAR:Cookie" "s:$RFI:8" id:1100 ;
 MainRule "str:/*" "msg:mysql comment (/*)" "mz:BODY|URL|ARGS|
$HEADERS_VAR:Cookie" "s:$SQL:8" id:1003 ;
Cài đặt:
server {
proxy_set_header Proxy-Connection "";
listen *:80;
access_log /tmp/nginx_access.log;
error_log /tmp/nginx_error.log debug;
location / {
include /etc/nginx/naxsi.rules;
proxy_pass http://x.x.x.x/;
proxy_set_header Host www.mysite.com;
}
location /RequestDenied {
return 418;
}
}
Với Proxying (With proxying).
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;


root /usr/share/nginx/html;
index index.php;

# Make site accessible from http://localhost/
server_name localhost;

location / { proxy_pass
http://localhost:8080/; proxy_set_header Host
$http_host; include
/etc/nginx/naxsi.rules; }
# Only for nginx-naxsi used with nginx-naxsi-ui : process
denied requests
location /RequestDenied {
#proxy_pass http://127.0.0.1:8080;
return 500;
}
}
Không có Proxying (Without proxying).
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;

root /usr/share/nginx/html;
index index.php;

# Make site accessible from http://localhost/
server_name localhost;

location / {

try_files $uri $uri/ =404;
include /etc/nginx/naxsi.rules; }
location ~ \.php$ {
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
include fastcgi_params;
}

# Only for nginx-naxsi used with nginx-naxsi-ui : process
denied requests location /RequestDenied
{ #proxy_pass http://127.0.0.1:8080;
return 500; }}
Cấu trúc Rules.
include file naxsi_core.rules
# Bật NAXSI module
SecRulesEnabled;
# URL trả về khi client bị block
DeniedUrl "/RequestDenied";
# Số lần phát hiện dẫn đến block
CheckRule "$SQL >= 8" BLOCK;
CheckRule "$RFI >= 8" BLOCK;
CheckRule "$TRAVERSAL >= 4" BLOCK;
CheckRule "$EVADE >= 4" BLOCK;
CheckRule "$XSS >= 8" BLOCK;
Đây là số liệu mẫu sau cuộc điều tra.
Danh sách từ 6 đến 30 ngày các cuộc tấn công:
ID | Count


42000122 | 2506 | DN SCAN WP Timthumb - Access
42000004 | 1209 | DN APP_SERVER CGI_file access
42000089 | 1202 | DN WEB_APPS XMLRPC - Access detected (misc Wordpress/Magento-
Vulns)
42000002 | 1182 | DN APP_SERVER PHP-file-access
42000227 | 977 | DN SCAN Scanner ZmEu exploit scanner
42000059 | 740 | DN WEB_APPS Possible unwanted Upload / Access To mm-forms-
community upload dir
42000003 | 337 | DN APP_SERVER ASP_file access
1007 | 296 | mysql comment ( )
42000082 | 292 | DN WEB_SERVER Tomcat - Manager - Access
42000077 | 242 | DN WEB_SERVER LIBWWW_perl-UA detected
42000071 | 187 | DN WEB_APPS PHPMYADMIN setup.php - Access
1011 | 152 | parenthesis, probable sql/xss
42000210 | 127 | DN APP_SERVER Tomcat Auth Brute Force attempt (admin)
42000020 | 121 | DN APP_SERVER ASPX_file access
42000145 | 113 | DN SCAN Scanner morfeus
42000181 | 112 | DN SCAN Scanner webster pro
42000244 | 112 | DN SCAN PHPMyAdmin - Scanner (2)
42000253 | 110 | DN WEB_SERVER possible INC - File - Access
1003 | 99 | mysql comment (/*)
1004 | 96 | mysql comment (*/)
42000169 | 86 | DN SCAN Scanner Nmap
42000243 | 80 | DN SCAN PHPMyAdmin - Scanner
1006 | 75 | mysql keyword (&&)
1302 | 72 | html open tag
42000216 | 74 | DN APP_SERVER Tomcat admin-admin login credentials
1102 | 68 | ftp:// scheme
42000073 | 63 | DN SCAN Python-urllib UA, possible Scanner
1205 | 55 | backslash

1312 | 52 | ~ character
42000065 | 50 | DN WEB_APPS Magento XMLRPC-Exploit Attempt
42000222 | 47 | DN SCAN Open-Proxy ScannerBot (webcollage-UA)
42000031 | 20 | DN SCAN Muieblackcat scanner
42000043 | 8 | DN SCAN WhatWeb Web Application Fingerprint Scanner Default
User-Agent Detected
42000126 | 8 | DN WEB_APPS WordPress Uploadify-Access
42000151 | 8 | DN SCAN Scanner whatweb
42000229 | 7 | DN APP_SERVER ColdFusion - Vuln-URL-Access administrator
42000230 | 7 | DN APP_SERVER ColdFusion - Vuln-URL-Access adminapi
42000248 | 7 | DN SCAN SQL-Injection Scanner CZxt2
Nguồn: mọi số liều đều lấy trên mạng đã được kiểm chứng.
/>infrastructure-with-the-Nginx-Naxsi-firewall.
/>

×