SlideShare a Scribd company logo
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




              1




                            2




Kiện toàn bảo mật Web với ModSecurity
        Sử Hoàng Sơn | Email: shson.stttt@vinhlong.gov.vn
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!


                        Thực trạng
                  2
- Hầu hết các ứng dụng do nhiều đơn vị phát
triển với nhiều công nghệ khác nhau.
- Sử dụng các sản 2phẩm của bên thứ 3 mà
không biết chất lượng.
- Cần rất nhiều thời gian và nhân lực để kiểm
tra độ an toàn.
- Thói quen, tư duy người lập trình chưa quan
tâm nhiều đến an toàn sản phẩm, chưa có bộ
phận phụ trách an toàn sản phẩm.
ModSecurity Web Intrusion Detection and Prevention               2
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!



                  Vấn đề cần làm
                  3

- Công tác an toàn sản phẩm cần làm sớm
  càng tốt.
                    2
- Bằng tất cả mọi cách cải tiến độ an toàn các
  ứng dụng đang có (không dễ).
- Nhiều khả năng chúng ta phải tăng cường
  an ninh từ bên ngoài.
- Đặt các ứng dụng không an toàn vào môi
  trường an toàn.

ModSecurity Web Intrusion Detection and Prevention               3
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!


                     Yêu cầu
               với công tác quản trị
                4



       Monitoring: biết chuyện gì đang xãy ra.
                              2

       Detection: phát hiện khi bị tấn công.

       Prevention: ngăn chặn được tấn công.

       Assessment: phát hiện trước vấn đề trước
       khi bị tấn công


ModSecurity Web Intrusion Detection and Prevention               4
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




                  5




                              2

 Một số thiết bị bảo mật thường gặp




ModSecurity Web Intrusion Detection and Prevention               5
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!


             Packet Filter Firewall
                  6




                              2




ModSecurity Web Intrusion Detection and Prevention               6
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!



               Packet Filter Firewall
                7

- Tạo ACL cơ bản dựa trên: Source IP,
Destination IP, Port, Service, Protocol.
                     2
- Nội dung và ngữ cảnh (mối liên hệ với các
gói khác) bị bỏ qua.
- Thông tin địa chỉ trong một gói có thể bị
xuyên tạc hoặc bị đánh lừa bởi người gửi.
- Packet chuyển qua có thể chứa thông tin
khai thác của Attacker.
ModSecurity Web Intrusion Detection and Prevention               7
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!


Network Intrusion Detect System (NIDS)
                  8




                              2




ModSecurity Web Intrusion Detection and Prevention               8
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!


Network Intrusion Detect System (NIDS)
                  9
 - Chỉ xác định và cảnh báo không ngăn chặn
 được tấn công.
                              2
 - Không phân tích được nội dung đã mã hóa
 (SSL).
 - Không thể làm một Gateway Application.
 - Dễ dẫn đến Fail Positive khi áp dụng để xử
 lý data mức Application

ModSecurity Web Intrusion Detection and Prevention               9
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




           10




       ModSecurity
                       2
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!



                       GIỚI THIỆU
                  11

- ModSecurity là một Opensource web application firewall.
-Tác giả: Ivan Ristic.
                           2
- Phát triển dành cho Web Server Apache, Ngix, hiện
version 2.7 đã có cho IIS.
- Sử dụng giấy phép GPL,hoàn toàn miễn phí.
- Kết hợp Mod_proxy trở thành Reverse Proxy bảo
vệ cho nhiều máy chủ web.
- Hoạt động dựa trên Rule.


ModSecurity Web Intrusion Detection and Prevention               11
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!


                         Mô hình
                  12




                              2




ModSecurity Web Intrusion Detection and Prevention               12
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!


           Mô hình kết hợp Reverse Proxy
                  13




                              2




Thuận lợi:
- Tạo một điểm duy nhất cho việc truy cập
- Che đậy mô hình mạng với bên ngoài
- Tập trung dễ giám sát và quản lý

ModSecurity Web Intrusion Detection and Prevention               13
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!

                            Chức năng
- Request filtering: phân tích và cản lọc (filter) các request gửi
                  14
đến Web Server trước khi chúng được đưa đến các modules
khác để xử lý.
- Understanding of the HTTP protocol: hiểu được giao thức
HTTP. Có khả năng cản lọc 2  dựa trên các thông tin ở HTTP
Header hay có thể xem xét đến từng thông số, cookies của các
request...
- POST payload analysis: phân tích nội dung (payload) của
POST requests.
- Audit logging: Khả năng ghi lại các Request (bao gồm cả
POST) để người quản trị có thể theo dõi nếu cần.
- HTTPS filtering: phân tích HTTPS.



ModSecurity Web Intrusion Detection and Prevention               14
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!

     Mô hình xử lý Apache + ModSecurity
                  15




                              2




ModSecurity Web Intrusion Detection and Prevention               15
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!


                    Các giai đoạn xử lý
                  16
    1. Phase Request Header
    2. Phase Request Body
                      2
       + application/x-www-form-urlencoded
       + multipart/form-data
       + text/xml
    3. Phase Response Header
    4. Phase Response Body
    5. Phase logging
ModSecurity Web Intrusion Detection and Prevention               16
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!

                       Cú pháp Rule
         SecRule Target Operator [Actions]
             17


- Target: Quy định cụ thể mục tiêu của request hoặc
response muốn kiểm tra. 2
- Operator: xác định phương pháp và so khớp dữ
liệu để kích hoạt Action. Thường dùng Regular
expressions để tạo Pattern.
- Actions: các hành động được thực hiện nếu
 phù hợp (matching) rule. Action có thể là allow hoặc
 deny các request; và quy định cụ thể các
status code khi response cho client...

ModSecurity Web Intrusion Detection and Prevention               17
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!

                   Biến và Collection
-Truy cập các thông số trong request, response
             18
thông qua Biến hoặc Collection.
Collection:-
ENV, FILES, FILES_NAMES, FILES_SIZES,
                     2
FILES_TMPNAMES, GEO, IP,
REQUEST_COOKIES,
REQUEST_COOKIES_NAMES,
REQUEST_HEADERS,
REQUEST_HEADERS_NAMES,
RESPONSE_HEADERS,
RESPONSE_HEADERS_NAMES, SESSION, TX,
USER…
ModSecurity Web Intrusion Detection and Prevention               18
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




                  19




                              2

   Chặn một số tấn công cơ bản




ModSecurity Web Intrusion Detection and Prevention
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!

            Ngăn chặn HTTP Fingerprinting
 Đánh lừa các20
              công cụ HTTP Fingerprinting,
cung cấp các thông tin không chính xác cho Hacker
# Thay đổi chử ký Server
                                 2
SecServerSignature “My-server/1.0“

# Từ chối request không chứa host header
SecRule &REQUEST_HEADERS:Host "@eq 0" "phase:1,deny"

# Từ chối request không chứa request header
SecRule &REQUEST_HEADERS:Accept "@eq 0" phase:1,deny"

# Chỉ cho phép GET HEAD va POST
SecRule REQUEST_METHOD !^(get|head|post)$ phase:1,t:lowerCase,deny"

#Chỉ cho phép HTTP version 1.0 và 1.1
SecRule REQUEST_PROTOCOL !^http/1.(0|1)$ “ phase:1,t:lowercase,deny"


ModSecurity Web Intrusion Detection and Prevention                      20
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!


           CROSS-SITE SCRIPTING (XSS)
                  21
Cross-Site Scripting hay còn được gọi tắt là XSS
là một kĩ thuật tấn công bằng cách chèn vào các
                              2

website động (ASP, PHP, CGI, JSP ...) những thẻ
HTML hay những đoạn mã script nguy hiểm có thể
gây nguy hại cho những người sử dụng khác.
Các đoạn mã hầu hết được viết bằng Client Script
(Javascript, Jscript hoặc thậm chí DHML,HTML…)
ModSecurity Web Intrusion Detection and Prevention               21
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!


    Chặn CROSS-SITE SCRIPTING (XSS)
                       22
     Script fragment               Regular expression
     <script                       <script
     eval(                         evals*(
                              2
     onMouseOver                   onmouseover
     onMouseOut                    onmouseout
     onMouseDown                   onmousedown
     onMouseMove                   onmousemove
     onClick                       onclick
     onDblClick                    ondblclick
     onFocus                       onfocus
 SecRule ARGS "<script" "deny,t:lowercase"

ModSecurity Web Intrusion Detection and Prevention               22
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!


      TẤN CÔNG DIRECTORY TRAVERSAL
                    23
-URL hợp lệ: http://example.com/getpage.php?page=1
-URL attack=http://example.com/getpage.php?page=../../../etc/passwd
    Nếu không cấu hình để cản lọc hoặc cơ chế cấp quyền
Không đúng thì hacker sẽ lấy được thông tin từ file
                          2
/etc/passwd. Hacker có thể không chèn trực tiếp biến ../
mà thực hiện chèn các biến đã được mã hoá như
%2e%2e%2f, khi giải mã thì vẫn là ../
Danh sách các chuỗi chúng ta cần chặn:
       ../
       ..%2f
       %2e%2e/
       %2e%2e%2f
       %2e./
 ModSecurity Web Intrusion Detection and Prevention               23
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!


         CHẶN DIRECTORY TRAVERSAL
                   24

  Chúng ta có thể sử dụng t:urlDecode của
  ModSecurity để chuyển tất cả chuỗi được mã
                    2

  hoá thành giá trị gốc của nó.


  Rule để chặn hình thức tấn công này:


SecRule REQUEST_URI "../" "t:urlDecode,deny"

 ModSecurity Web Intrusion Detection and Prevention               24
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!


           TẤN CÔNG SQL INJECTION
  Hacker chèn các25 khóa SQL vào dữ liệu để làm sai lệch câu
                   từ
  lệnh SQL, và nếu dữ liệu không được lọc thì khả năng bị tấn
  công SQL Injection là rất cao
                               2
SELECT * FROM user WHERE username = '%s‘ AND password = '%s';

SELECT * FROM products WHERE id = 1; DROP TABLE products;

SELECT * FROM user WHERE username = '‘ OR ‘1’=‘1’ AND
password = '' OR '1'='1';

SELECT LOAD_FILE("/etc/passwd");
SELECT “Du lieu can ghi” INTO OUTFILE “test.txt";

 ModSecurity Web Intrusion Detection and Prevention               25
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!


               CHẶN SQL INJECTION
                    26

   SQL code                          Regular expression
   UNION SELECT                      unions+select
                                2
   UNION ALL SELECT                  unions+alls+select
   INTO OUTFILE                      intos+outfile
   DROP TABLE                        drops+table
   ALTER TABLE                       alters+table
   LOAD_FILE                         load_file
   SELECT *                          selects+*
SecRule ARGS "intos+outfile" "t:lowercase,deny,msg: 'SQL Injection'"

 ModSecurity Web Intrusion Detection and Prevention                26
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!


           CHỐNG THỰC THI LỆNH SHELL
                    27
                                    Các Lệnh , chương trình,
                                    đường dẫn thông thường:
                                    - rm
                                    - ls
                                2   - kill
                                    - mail
                                    - sendmail
                                    - cat
                                    - echo
                                    - /bin/
                                    - /etc/
                                    - /tmp/
SecRule ARGS “rm|ls|kill(send)?mail|cat|echo|/bin/|/etc/|/tmp/)” “deny”

 ModSecurity Web Intrusion Detection and Prevention                  27
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!


                CHỐNG BRUTE FORCE
- Là hình thức tấn công Hacker liên tục đoán username,password,
                    28

email … và tiến hành đăng nhập thử cho đến khi thành công.
- Cách tốt nhất để ngăn tấn công dạng này là giới hạn số lần đăng
                                2
nhập thất bại
# Khóa 5 phút sau 3 lần thất bại
<LocationMatch ^/login>
# Khởi tạo collection với IP của User
SecAction "initcol:ip=%{REMOTE_ADDR},pass,nolog"
# Phát hiện đăng nhập sai với “Username does not exist”
SecRule RESPONSE_BODY "Username does not exist“
"phase:4,pass,setvar:ip.failed_logins=+1,expirevar:ip.failed_logins=300"
# khóa với số lần đăng nhập thất bại =3
SecRule IP:FAILED_LOGINS "@gt 3" deny
</Location>
  ModSecurity Web Intrusion Detection and Prevention                28
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!

Thực hiện các shell scripts & Giởi email cảnh báo
 SecRule ARGS 29
               "drop table" "deny,t:lowercase,
 setenv:HOSTNAME=%{SERVER_NAME},
 setenv:REMOTEIP=%{REMOTE_ADDR},
 setenv:REQUESTURI=%{REQUEST_URI},
                      2
 exec:/usr/local/bin/email.sh"
#!/bin/sh
echo "Phat hien sql injection
Server: $HOSTNAME
Attacking IP: $REMOTEIP
Request URI: $REQUESTURI
Time: `date '+%D %H:%M'`
"|mail –s 'ModSecurity Alert' <a
href="mailto:suhoangson@gmail.com">suhoangson@gmail.co
m</a>
echo Done.

ModSecurity Web Intrusion Detection and Prevention               29
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!


                       Core Rule Set
                  30
Tập các Rule viết sẵn với nhiều dạng patterm:
- Real-time Blacklist Lookups IP từ các hãng danh tiếng
- Phát hiện Web-based Malsware dựa vào Google Safe Browsing
                              2
API
- Chống DoS HTTP Flooding
- Chống các dạng tấn công cơ bản
- Phát hiện : bots, crawlers, scanners độc hại khác
- Kết hợp Antivirut kiểm tra các File upload lên web application
- Chặn các thông báo sai từ ứng dụng
- Ẩn các thông báo lỗi từ Server


ModSecurity Web Intrusion Detection and Prevention                 30
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!


                       Thách thức
                  31
- Tỉ lệ Fail Positive vẫn có thể xãy ra.
- Viết Rule cần có nhiều kinh nghiệm về HTTP Protocol ,
Regular expressions… và2am hiểu các dạng tấn công.
- Hiệu xuất đáp ứng khi kết hợp Reverse Proxy bảo vệ
nhiều site.
-Khó khăn trong việc thống nhất các nhà phát triển web
tránh xung đột giửa Patterm với các giá trị đặc biệt do
người lập trình đưa vào. Hoặc thiết lập cách nhập liệu đặc
biệt cho các từ nhạy cảm.


ModSecurity Web Intrusion Detection and Prevention               31
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




                   32   Question ?
               Thank You!!!
                               2
Reference:
--ModSecurity Handbook: Ivan Ristic
- ModSecurity 2.5: Magus Mischel
- http://www.packtpub.com/article/
    + blocking-common-attacks-using-modsecurity-2.5-part1
    + blocking-common-attacks-using-modsecurity-2.5-part2
    + blocking-common-attacks-using-modsecurity-2.5-part3
- hvaonline.net
- Core Rule Set:
https://github.com/FireFart/owasp-modsecurity-crs

 ModSecurity Web Intrusion Detection and Prevention               32

More Related Content

PDF
SBC 2012 - SSL/TLS Attacks & Defenses (Lê Quốc Nhật Đông)
PDF
SBC 2012 - Linux Hardening (Mẫn Thắng)
PDF
SBC 2012 - Software Exploitation (Nguyễn Chấn Việt)
PDF
SBC 2012 - Phát hiện tấn công DDoS sử dụng mạng Neural (Trần Nguyên Ngọc)
PDF
SBC 2012 - Tổng quan về bảo mật trong Cloud (Lê Vĩnh Đạt)
PDF
SBC 2012 - Lỗ hổng trong cài đặt giao thức OAuth và nguy cơ với người dùng (N...
PDF
SBC 2012 - Windows Security (Lương Trung Thành)
PDF
SBC 2012 - Information Gathering (Lương Trung Thành)
SBC 2012 - SSL/TLS Attacks & Defenses (Lê Quốc Nhật Đông)
SBC 2012 - Linux Hardening (Mẫn Thắng)
SBC 2012 - Software Exploitation (Nguyễn Chấn Việt)
SBC 2012 - Phát hiện tấn công DDoS sử dụng mạng Neural (Trần Nguyên Ngọc)
SBC 2012 - Tổng quan về bảo mật trong Cloud (Lê Vĩnh Đạt)
SBC 2012 - Lỗ hổng trong cài đặt giao thức OAuth và nguy cơ với người dùng (N...
SBC 2012 - Windows Security (Lương Trung Thành)
SBC 2012 - Information Gathering (Lương Trung Thành)

What's hot (13)

PDF
SBC 2012 - Penetration Testting với Backtrack 5 (Nguyễn Phương Trường Anh + N...
PDF
SBC 2012 - Database Security (Nguyễn Thanh Tùng)
PDF
Security Bootcamp 2013 - Định hướng công việc ngành ATTT - Nguyễn Hải Long
PPTX
Trần Anh Khoa - Kautilya và Powershell trong kỹ thuật tấn công tiếp cận
PDF
SBC 2012 - Một số thuật toán phân lớp và ứng dụng trong IDS (Nguyễn Đình Chiểu)
PDF
Security Bootcamp 2013 - Mô hình ứng dụng hội chẩn mã độc trực tuyến trong ...
PPT
Hướng nghiên cứu mới cho ngành mật mã nước nhà - TS Hồ Ngọc Duy
PDF
Khai thác lỗi phần mềm thi chứng chỉ của Microsoft - Phạm Đình Thắng
PDF
Security Bootcamp 2013 penetration testing (basic)
PDF
Security Bootcamp 2013 - OWASP TOP 10- 2013
PDF
Luc Nguyen - Hiem họa an toan tu cac modem internet cua cac ISP tại Viet Nam
PDF
Tấn công và khai thác mạng máy tính theo mô hình thường trực cao cấp APT - Lê...
PPTX
Thu 6 04 advance penetration test with armitage
SBC 2012 - Penetration Testting với Backtrack 5 (Nguyễn Phương Trường Anh + N...
SBC 2012 - Database Security (Nguyễn Thanh Tùng)
Security Bootcamp 2013 - Định hướng công việc ngành ATTT - Nguyễn Hải Long
Trần Anh Khoa - Kautilya và Powershell trong kỹ thuật tấn công tiếp cận
SBC 2012 - Một số thuật toán phân lớp và ứng dụng trong IDS (Nguyễn Đình Chiểu)
Security Bootcamp 2013 - Mô hình ứng dụng hội chẩn mã độc trực tuyến trong ...
Hướng nghiên cứu mới cho ngành mật mã nước nhà - TS Hồ Ngọc Duy
Khai thác lỗi phần mềm thi chứng chỉ của Microsoft - Phạm Đình Thắng
Security Bootcamp 2013 penetration testing (basic)
Security Bootcamp 2013 - OWASP TOP 10- 2013
Luc Nguyen - Hiem họa an toan tu cac modem internet cua cac ISP tại Viet Nam
Tấn công và khai thác mạng máy tính theo mô hình thường trực cao cấp APT - Lê...
Thu 6 04 advance penetration test with armitage
Ad

Similar to Security Bootcamp 2012 - Bảo vệ Web App với Mod Security (Sử Hoàng Sơn) (20)

PDF
Slide đào tạo ATTT.pdf
PPTX
Web application-security
PPTX
Giới thiệu một số công cụ ATTT thực hành tấn công mạng
PPSX
Linux web hosting (Thuyet trinh)
PPSX
Linux web hosting (Thuyet trinh)
PPTX
Apache http server 2
PPTX
Bảo mật ứng dụng web
PPTX
Báo cáo thực tập hàng tuần - Các chuẩn bảo mật web (OWASP)
PDF
Tim hieu lo hong web va cach phong chong
PPTX
Báo cáo hàng tuần - Các chuẩn bảo mật web (OWASP)
PPTX
Trung tâm đào tạo
DOCX
metasploitable example attacks list.docx
PDF
Nghien cuu ma nguon mo openvpn
DOC
Bao cao tttn an ninh web
PPTX
Slide bao cao cuoi ki
PPTX
Slide bao cao giua ki
PPTX
Ossec – host based intrusion detection system
DOCX
báo cáo thực tập Athena - tuần1
PPTX
Go micro framework to build microservices
PPTX
Chuyên đề về hàm băm nguyên cứu hash fution
Slide đào tạo ATTT.pdf
Web application-security
Giới thiệu một số công cụ ATTT thực hành tấn công mạng
Linux web hosting (Thuyet trinh)
Linux web hosting (Thuyet trinh)
Apache http server 2
Bảo mật ứng dụng web
Báo cáo thực tập hàng tuần - Các chuẩn bảo mật web (OWASP)
Tim hieu lo hong web va cach phong chong
Báo cáo hàng tuần - Các chuẩn bảo mật web (OWASP)
Trung tâm đào tạo
metasploitable example attacks list.docx
Nghien cuu ma nguon mo openvpn
Bao cao tttn an ninh web
Slide bao cao cuoi ki
Slide bao cao giua ki
Ossec – host based intrusion detection system
báo cáo thực tập Athena - tuần1
Go micro framework to build microservices
Chuyên đề về hàm băm nguyên cứu hash fution
Ad

More from Security Bootcamp (20)

PDF
Ẩn mình kết nối C&C - Xu hướng tấn công và cách phòng thủ
PPTX
AI-ttacks - Nghiên cứu về một số tấn công vào các mô hình học máy và AI
PPTX
Human and AI - Balancing Innovation and Data Privacy in the Age of Cyber Threats
PPTX
Robustness of Deep learning mode ls.pptx
PPTX
DLL Sideloading cho mọi nhà - Security Bootcamp 2024
PDF
Let the Hunt Begin - Security Bootcamp 2024
PDF
Detection as Code - Effective Approach to manage & optimize SOC Development
PDF
Quản trị rủi ro nguồn mở tại các doanh nghiệp phần mềm Việt Nam
PDF
Phân tích một chiến dịch ransomware: Từ lan truyền đến tống tiền
PDF
CyberJutsu - The Joern-ey of Static Code Analysis.pdf
PPTX
Security in the AI and Web3 era - Veramine
PDF
ĐỂ AI ĐƯỢC AN TOÀN, MINH BẠCH, CÓ TRÁCH NHIỆM VÀ ‘NHÂN TÍNH’ HƠN
PDF
Modern Security Operations - Building and leading modern SOC
PDF
Humanity and AI: Balancing Innovation and Data Privacy in the Age of Cyber Th...
PPTX
SBC2024_AI TRONG CYBER SECURITY_final.pptx
PPTX
Cyber GenAI – Another Chatbot? - Trellix
PDF
Akamai_ API Security Best Practices - Real-world attacks and breaches
PPTX
How to steal a drone Drone Hijacking - VNPT Cyber Immunity
PDF
Empowering Malware Analysis with IDA AppCall
PDF
Detection of Spreading Process on many assets over the network
Ẩn mình kết nối C&C - Xu hướng tấn công và cách phòng thủ
AI-ttacks - Nghiên cứu về một số tấn công vào các mô hình học máy và AI
Human and AI - Balancing Innovation and Data Privacy in the Age of Cyber Threats
Robustness of Deep learning mode ls.pptx
DLL Sideloading cho mọi nhà - Security Bootcamp 2024
Let the Hunt Begin - Security Bootcamp 2024
Detection as Code - Effective Approach to manage & optimize SOC Development
Quản trị rủi ro nguồn mở tại các doanh nghiệp phần mềm Việt Nam
Phân tích một chiến dịch ransomware: Từ lan truyền đến tống tiền
CyberJutsu - The Joern-ey of Static Code Analysis.pdf
Security in the AI and Web3 era - Veramine
ĐỂ AI ĐƯỢC AN TOÀN, MINH BẠCH, CÓ TRÁCH NHIỆM VÀ ‘NHÂN TÍNH’ HƠN
Modern Security Operations - Building and leading modern SOC
Humanity and AI: Balancing Innovation and Data Privacy in the Age of Cyber Th...
SBC2024_AI TRONG CYBER SECURITY_final.pptx
Cyber GenAI – Another Chatbot? - Trellix
Akamai_ API Security Best Practices - Real-world attacks and breaches
How to steal a drone Drone Hijacking - VNPT Cyber Immunity
Empowering Malware Analysis with IDA AppCall
Detection of Spreading Process on many assets over the network

Security Bootcamp 2012 - Bảo vệ Web App với Mod Security (Sử Hoàng Sơn)

  • 1. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 1 2 Kiện toàn bảo mật Web với ModSecurity Sử Hoàng Sơn | Email: shson.stttt@vinhlong.gov.vn
  • 2. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Thực trạng 2 - Hầu hết các ứng dụng do nhiều đơn vị phát triển với nhiều công nghệ khác nhau. - Sử dụng các sản 2phẩm của bên thứ 3 mà không biết chất lượng. - Cần rất nhiều thời gian và nhân lực để kiểm tra độ an toàn. - Thói quen, tư duy người lập trình chưa quan tâm nhiều đến an toàn sản phẩm, chưa có bộ phận phụ trách an toàn sản phẩm. ModSecurity Web Intrusion Detection and Prevention 2
  • 3. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Vấn đề cần làm 3 - Công tác an toàn sản phẩm cần làm sớm càng tốt. 2 - Bằng tất cả mọi cách cải tiến độ an toàn các ứng dụng đang có (không dễ). - Nhiều khả năng chúng ta phải tăng cường an ninh từ bên ngoài. - Đặt các ứng dụng không an toàn vào môi trường an toàn. ModSecurity Web Intrusion Detection and Prevention 3
  • 4. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Yêu cầu với công tác quản trị 4 Monitoring: biết chuyện gì đang xãy ra. 2 Detection: phát hiện khi bị tấn công. Prevention: ngăn chặn được tấn công. Assessment: phát hiện trước vấn đề trước khi bị tấn công ModSecurity Web Intrusion Detection and Prevention 4
  • 5. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 5 2 Một số thiết bị bảo mật thường gặp ModSecurity Web Intrusion Detection and Prevention 5
  • 6. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Packet Filter Firewall 6 2 ModSecurity Web Intrusion Detection and Prevention 6
  • 7. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Packet Filter Firewall 7 - Tạo ACL cơ bản dựa trên: Source IP, Destination IP, Port, Service, Protocol. 2 - Nội dung và ngữ cảnh (mối liên hệ với các gói khác) bị bỏ qua. - Thông tin địa chỉ trong một gói có thể bị xuyên tạc hoặc bị đánh lừa bởi người gửi. - Packet chuyển qua có thể chứa thông tin khai thác của Attacker. ModSecurity Web Intrusion Detection and Prevention 7
  • 8. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Network Intrusion Detect System (NIDS) 8 2 ModSecurity Web Intrusion Detection and Prevention 8
  • 9. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Network Intrusion Detect System (NIDS) 9 - Chỉ xác định và cảnh báo không ngăn chặn được tấn công. 2 - Không phân tích được nội dung đã mã hóa (SSL). - Không thể làm một Gateway Application. - Dễ dẫn đến Fail Positive khi áp dụng để xử lý data mức Application ModSecurity Web Intrusion Detection and Prevention 9
  • 10. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 10 ModSecurity 2
  • 11. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! GIỚI THIỆU 11 - ModSecurity là một Opensource web application firewall. -Tác giả: Ivan Ristic. 2 - Phát triển dành cho Web Server Apache, Ngix, hiện version 2.7 đã có cho IIS. - Sử dụng giấy phép GPL,hoàn toàn miễn phí. - Kết hợp Mod_proxy trở thành Reverse Proxy bảo vệ cho nhiều máy chủ web. - Hoạt động dựa trên Rule. ModSecurity Web Intrusion Detection and Prevention 11
  • 12. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Mô hình 12 2 ModSecurity Web Intrusion Detection and Prevention 12
  • 13. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Mô hình kết hợp Reverse Proxy 13 2 Thuận lợi: - Tạo một điểm duy nhất cho việc truy cập - Che đậy mô hình mạng với bên ngoài - Tập trung dễ giám sát và quản lý ModSecurity Web Intrusion Detection and Prevention 13
  • 14. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Chức năng - Request filtering: phân tích và cản lọc (filter) các request gửi 14 đến Web Server trước khi chúng được đưa đến các modules khác để xử lý. - Understanding of the HTTP protocol: hiểu được giao thức HTTP. Có khả năng cản lọc 2 dựa trên các thông tin ở HTTP Header hay có thể xem xét đến từng thông số, cookies của các request... - POST payload analysis: phân tích nội dung (payload) của POST requests. - Audit logging: Khả năng ghi lại các Request (bao gồm cả POST) để người quản trị có thể theo dõi nếu cần. - HTTPS filtering: phân tích HTTPS. ModSecurity Web Intrusion Detection and Prevention 14
  • 15. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Mô hình xử lý Apache + ModSecurity 15 2 ModSecurity Web Intrusion Detection and Prevention 15
  • 16. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Các giai đoạn xử lý 16 1. Phase Request Header 2. Phase Request Body 2 + application/x-www-form-urlencoded + multipart/form-data + text/xml 3. Phase Response Header 4. Phase Response Body 5. Phase logging ModSecurity Web Intrusion Detection and Prevention 16
  • 17. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Cú pháp Rule SecRule Target Operator [Actions] 17 - Target: Quy định cụ thể mục tiêu của request hoặc response muốn kiểm tra. 2 - Operator: xác định phương pháp và so khớp dữ liệu để kích hoạt Action. Thường dùng Regular expressions để tạo Pattern. - Actions: các hành động được thực hiện nếu phù hợp (matching) rule. Action có thể là allow hoặc deny các request; và quy định cụ thể các status code khi response cho client... ModSecurity Web Intrusion Detection and Prevention 17
  • 18. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Biến và Collection -Truy cập các thông số trong request, response 18 thông qua Biến hoặc Collection. Collection:- ENV, FILES, FILES_NAMES, FILES_SIZES, 2 FILES_TMPNAMES, GEO, IP, REQUEST_COOKIES, REQUEST_COOKIES_NAMES, REQUEST_HEADERS, REQUEST_HEADERS_NAMES, RESPONSE_HEADERS, RESPONSE_HEADERS_NAMES, SESSION, TX, USER… ModSecurity Web Intrusion Detection and Prevention 18
  • 19. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 19 2 Chặn một số tấn công cơ bản ModSecurity Web Intrusion Detection and Prevention
  • 20. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Ngăn chặn HTTP Fingerprinting Đánh lừa các20 công cụ HTTP Fingerprinting, cung cấp các thông tin không chính xác cho Hacker # Thay đổi chử ký Server 2 SecServerSignature “My-server/1.0“ # Từ chối request không chứa host header SecRule &REQUEST_HEADERS:Host "@eq 0" "phase:1,deny" # Từ chối request không chứa request header SecRule &REQUEST_HEADERS:Accept "@eq 0" phase:1,deny" # Chỉ cho phép GET HEAD va POST SecRule REQUEST_METHOD !^(get|head|post)$ phase:1,t:lowerCase,deny" #Chỉ cho phép HTTP version 1.0 và 1.1 SecRule REQUEST_PROTOCOL !^http/1.(0|1)$ “ phase:1,t:lowercase,deny" ModSecurity Web Intrusion Detection and Prevention 20
  • 21. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! CROSS-SITE SCRIPTING (XSS) 21 Cross-Site Scripting hay còn được gọi tắt là XSS là một kĩ thuật tấn công bằng cách chèn vào các 2 website động (ASP, PHP, CGI, JSP ...) những thẻ HTML hay những đoạn mã script nguy hiểm có thể gây nguy hại cho những người sử dụng khác. Các đoạn mã hầu hết được viết bằng Client Script (Javascript, Jscript hoặc thậm chí DHML,HTML…) ModSecurity Web Intrusion Detection and Prevention 21
  • 22. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Chặn CROSS-SITE SCRIPTING (XSS) 22 Script fragment Regular expression <script <script eval( evals*( 2 onMouseOver onmouseover onMouseOut onmouseout onMouseDown onmousedown onMouseMove onmousemove onClick onclick onDblClick ondblclick onFocus onfocus SecRule ARGS "<script" "deny,t:lowercase" ModSecurity Web Intrusion Detection and Prevention 22
  • 23. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! TẤN CÔNG DIRECTORY TRAVERSAL 23 -URL hợp lệ: http://example.com/getpage.php?page=1 -URL attack=http://example.com/getpage.php?page=../../../etc/passwd Nếu không cấu hình để cản lọc hoặc cơ chế cấp quyền Không đúng thì hacker sẽ lấy được thông tin từ file 2 /etc/passwd. Hacker có thể không chèn trực tiếp biến ../ mà thực hiện chèn các biến đã được mã hoá như %2e%2e%2f, khi giải mã thì vẫn là ../ Danh sách các chuỗi chúng ta cần chặn: ../ ..%2f %2e%2e/ %2e%2e%2f %2e./ ModSecurity Web Intrusion Detection and Prevention 23
  • 24. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! CHẶN DIRECTORY TRAVERSAL 24 Chúng ta có thể sử dụng t:urlDecode của ModSecurity để chuyển tất cả chuỗi được mã 2 hoá thành giá trị gốc của nó. Rule để chặn hình thức tấn công này: SecRule REQUEST_URI "../" "t:urlDecode,deny" ModSecurity Web Intrusion Detection and Prevention 24
  • 25. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! TẤN CÔNG SQL INJECTION Hacker chèn các25 khóa SQL vào dữ liệu để làm sai lệch câu từ lệnh SQL, và nếu dữ liệu không được lọc thì khả năng bị tấn công SQL Injection là rất cao 2 SELECT * FROM user WHERE username = '%s‘ AND password = '%s'; SELECT * FROM products WHERE id = 1; DROP TABLE products; SELECT * FROM user WHERE username = '‘ OR ‘1’=‘1’ AND password = '' OR '1'='1'; SELECT LOAD_FILE("/etc/passwd"); SELECT “Du lieu can ghi” INTO OUTFILE “test.txt"; ModSecurity Web Intrusion Detection and Prevention 25
  • 26. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! CHẶN SQL INJECTION 26 SQL code Regular expression UNION SELECT unions+select 2 UNION ALL SELECT unions+alls+select INTO OUTFILE intos+outfile DROP TABLE drops+table ALTER TABLE alters+table LOAD_FILE load_file SELECT * selects+* SecRule ARGS "intos+outfile" "t:lowercase,deny,msg: 'SQL Injection'" ModSecurity Web Intrusion Detection and Prevention 26
  • 27. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! CHỐNG THỰC THI LỆNH SHELL 27 Các Lệnh , chương trình, đường dẫn thông thường: - rm - ls 2 - kill - mail - sendmail - cat - echo - /bin/ - /etc/ - /tmp/ SecRule ARGS “rm|ls|kill(send)?mail|cat|echo|/bin/|/etc/|/tmp/)” “deny” ModSecurity Web Intrusion Detection and Prevention 27
  • 28. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! CHỐNG BRUTE FORCE - Là hình thức tấn công Hacker liên tục đoán username,password, 28 email … và tiến hành đăng nhập thử cho đến khi thành công. - Cách tốt nhất để ngăn tấn công dạng này là giới hạn số lần đăng 2 nhập thất bại # Khóa 5 phút sau 3 lần thất bại <LocationMatch ^/login> # Khởi tạo collection với IP của User SecAction "initcol:ip=%{REMOTE_ADDR},pass,nolog" # Phát hiện đăng nhập sai với “Username does not exist” SecRule RESPONSE_BODY "Username does not exist“ "phase:4,pass,setvar:ip.failed_logins=+1,expirevar:ip.failed_logins=300" # khóa với số lần đăng nhập thất bại =3 SecRule IP:FAILED_LOGINS "@gt 3" deny </Location> ModSecurity Web Intrusion Detection and Prevention 28
  • 29. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Thực hiện các shell scripts & Giởi email cảnh báo SecRule ARGS 29 "drop table" "deny,t:lowercase, setenv:HOSTNAME=%{SERVER_NAME}, setenv:REMOTEIP=%{REMOTE_ADDR}, setenv:REQUESTURI=%{REQUEST_URI}, 2 exec:/usr/local/bin/email.sh" #!/bin/sh echo "Phat hien sql injection Server: $HOSTNAME Attacking IP: $REMOTEIP Request URI: $REQUESTURI Time: `date '+%D %H:%M'` "|mail –s 'ModSecurity Alert' <a href="mailto:suhoangson@gmail.com">suhoangson@gmail.co m</a> echo Done. ModSecurity Web Intrusion Detection and Prevention 29
  • 30. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Core Rule Set 30 Tập các Rule viết sẵn với nhiều dạng patterm: - Real-time Blacklist Lookups IP từ các hãng danh tiếng - Phát hiện Web-based Malsware dựa vào Google Safe Browsing 2 API - Chống DoS HTTP Flooding - Chống các dạng tấn công cơ bản - Phát hiện : bots, crawlers, scanners độc hại khác - Kết hợp Antivirut kiểm tra các File upload lên web application - Chặn các thông báo sai từ ứng dụng - Ẩn các thông báo lỗi từ Server ModSecurity Web Intrusion Detection and Prevention 30
  • 31. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Thách thức 31 - Tỉ lệ Fail Positive vẫn có thể xãy ra. - Viết Rule cần có nhiều kinh nghiệm về HTTP Protocol , Regular expressions… và2am hiểu các dạng tấn công. - Hiệu xuất đáp ứng khi kết hợp Reverse Proxy bảo vệ nhiều site. -Khó khăn trong việc thống nhất các nhà phát triển web tránh xung đột giửa Patterm với các giá trị đặc biệt do người lập trình đưa vào. Hoặc thiết lập cách nhập liệu đặc biệt cho các từ nhạy cảm. ModSecurity Web Intrusion Detection and Prevention 31
  • 32. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 32 Question ? Thank You!!! 2 Reference: --ModSecurity Handbook: Ivan Ristic - ModSecurity 2.5: Magus Mischel - http://www.packtpub.com/article/ + blocking-common-attacks-using-modsecurity-2.5-part1 + blocking-common-attacks-using-modsecurity-2.5-part2 + blocking-common-attacks-using-modsecurity-2.5-part3 - hvaonline.net - Core Rule Set: https://github.com/FireFart/owasp-modsecurity-crs ModSecurity Web Intrusion Detection and Prevention 32