Cấu hình Mod Security hạn chế truy cập trái phép đến website

Nguyễn Thành Luân 3 phút đọc

Điều kiện tiên quyết trước khi thực hiện là: “Yêu cầu hệ thống đã cài đặt modsecurity”.

  • Sau khi cài đặt xong modsecurity, file mặc định được cấu hình sẽ nằm trong thư mục /etc/httpd/conf.d/mod_security.conf bạn có thể cấu hình trực tiếp vào file cấu hình này hoặc tạo ra 1 file dành riêng để quản lý nội dung hoặc file trên URI không được phép chạy.
  • Để có thể cấu hình file riêng biệt, bạn cần thêm dòng sau vào để hệ thống include sang 1 file cấu hình khác: Include “/đường dẫn file cần tham chiếu/tên_file.conf”
  • Sau đó tiến hành tạo file với nội dung tương tự sau:
     
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    SecRule “REQUEST_URI” “dos=&ip=” “deny,log,auditlog,status:500,severity:2,id:’1010101′”
    SecRule “REQUEST_URI” “dos=” “deny,log,auditlog,status:500,severity:2,id:’1010103′”
    SecRule “REQUEST_URI” “r57.php” “deny,log,auditlog,status:500,severity:2,id:’1010104′”
    SecRule “REQUEST_URI” “c99.php” “deny,log,auditlog,status:500,severity:2,id:’1010105′”
    SecRule “REQUEST_URI” “bypass” “deny,log,auditlog,status:500,severity:2,id:’1010106′”
    SecRule “REQUEST_URI” “=mass” “deny,log,auditlog,status:500,severity:2,id:’1010107′”
    SecRule “REQUEST_URI” “deface” “deny,log,auditlog,status:500,severity:2,id:’1010108′”
    SecRule “REQUEST_URI” “=cgi” “deny,log,auditlog,status:500,severity:2,id:’1010109′”
    SecRule “REQUEST_URI” “netsploit” “deny,log,auditlog,status:500,severity:2,id:’1010110′”
    SecRule “REQUEST_URI” “=shell” “deny,log,auditlog,status:500,severity:2,id:’1010111′”
    SecRule “REQUEST_URI” “boom” “deny,log,auditlog,status:500,severity:2,id:’1010113′”
    SecRule “REQUEST_URI” “domains” “deny,log,auditlog,status:500,severity:2,id:’1010114′”
    SecRule “REQUEST_URI” “razer” “deny,log,auditlog,status:500,severity:2,id:’1010115′”
    SecRule “REQUEST_URI” “noOfBytes” “deny,log,auditlog,status:500,severity:2,id:’1010116′”
    SecRule “REQUEST_URI” “ddos” “deny,log,auditlog,status:500,severity:2,id:’1010117′”
    SecRule “REQUEST_URI” “212.php” “deny,log,auditlog,status:500,severity:2,id:’1010118′”
    SecRule “REQUEST_URI” “union” “deny,log,auditlog,status:500,severity:2,id:’1010119′”
  • Giải thích thêm về 1 dòng nêu trên: SecRule “REQUEST_URI” “dos=&ip=” “deny,log,auditlog,status:500,severity:2,id:’1010101′”
    • SecRule: Tạo 1 rule cần có cụm từ này.
    • REQUEST_URI: Thành phần sẽ áp dụng rule này là URI (trên thanh địa chỉ).
    • dos=&ip=: Dấu hiện nhận biết URI có chứa các chuỗi dạng tấn công DOS.
    • deny,log,auditlog,status:500,severity:2,id:’1010101′ : từ chối truy cập, ghi log apache, log modsec, trạng thái lỗi hiện thị, mức độ nghiêm trọng của lỗi, id lỗi. Những dấu hiện nghi ngờ bạn cần cấu hình, bạn thực hiện thao tác tương tự như ví dụ trên. Lưu ý nhớ thay đổi id vì id là duy nhất trong modsecurity.
  • Sau khi thao tác xong, cần restart lại apache để áp dụng rule mới. Thực hiện lệnh sau: systemctl restart httpd