SlideShare a Scribd company logo
Apache Mod Security
HAI, DINH
VINAHOST
Agenda   1. Regular Expression
         2. Rules Usage
         3. Default Action
         4. Chained Actions
         5. Persistent Collection and examples
         6. Transformation Function
         7. Validate Contents
Regular Expression
Regular Expression Usage

Use to match mass
strings of text, such as
particular characters,
words, or patterns of
characters
Regular Expression Usage

         Email Address Matching
         b[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}b

         IP Addresses Matching
         b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-
         9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-
         9]|[01]?[0-9][0-9]?)b


           Testing Tools: Regexpal.com, regular-expressions.info
Rules Usage
Rules Usage

 Use “|” as “OR” logical expression
       SecRule

       REQUEST_FILENAME|REQUEST_HEADERS_NAMES|REQUEST_HEADERS|!REQUE
ST_HEADERS:
       Referer "@validateByteRange 1-255“ "log,auditlog,msg:'Request Missing an Accept
Header',
       severity:'2',id:'960015',t:urlDecodeUni,phase:1“


 Use “!” as “NOT” logical expression
Rules Usage

 Use Regular Expression to make a Rule

       SecRule REQUEST_METHOD "^POST$"
       "chain,phase:2,t:none,deny,log,auditlog,status:400,msg:'POST request must have a
Content-      Length header„


 Use “:” to pick a variable from a Collection
       SecRule REQUEST_HEADERS:Content-Length "!^0?$" t:none
Default Actions
Default Actions

Use to set a            Use                     “Default” Default
“Default Behavior”      SetDefaultAction        Actions is
of Apache Mod           directive to add into   phase:2,
Security. If anything   configuration file      log,
has not been                                    auditlog,
defined happen,                                 pass
Apache will apply
Default Actions
Rules Usage

            SetDefaultAction phase:2,log,auditlog,pass.


                                           SecRule REQUEST_URI "abc"
  SecRule REQUEST_URI "abc"                   phase:2,log,auditlog,pass




SecRule REQUEST_URI "abc" nolog   SecRule REQUEST_URI "abc" phase:2,auditlog,pass
Chained Actions
Chained Actions

 Group Rules together

 Similar to “AND” logical expression in programming language

 Add “chain” action in every rule, except the last one

 Example:

  SecRule REQUEST_HEADERS "haidinhtuan"
  "chain,phase:2,nolog,deny,status:406"
  SecRule REQUEST_METHOD "GET" "t:none“
Persistent Collections
Persistent Collections


                     TX Collection only exist in a transaction.
                     After the data has been transfer
   Why               completely, variables will be remove
   Persistent
   Collection?
                     Persistent Collection can keep a record
                     of variables through several
                     transactions.
Persistent   1. Monitor user behavior based on IP Address
Collections   2. Monitor Sessions
              3. User behavior monitoring
              4. Prevent Session Hijacking Attack
              5. Detect Denial of Service (DoS) Attack
              6. Detect Brute Force Attack
Persistent Collections


        IP             SESSION                USER
 Created by using     Created by using    Created by using
 initcol directive    setsid directive     setid directive


Hold client address    Hold session      Hold user variables
     variables           variables
Persistent Collections

 Define date directory first using SecDataDir
  directive

 For example:
    SecDataDir /etc/httpd/modsec_data
Persistent Collections


  Limit Request Rate example:

     SecAction initcol:ip=%{REMOTE_ADDR},pass,auditlog
     SecAction "phase:5,deprecatevar:ip.counter=1/1,pass,auditlog"
     SecRule IP:COUNTER "@gt 60"
     "phase:2,pause:300,deny,status:403,skip:1,nolog"
     SecAction "phase:2,pass,setvar:ip.counter=+1,nolog"
Transformation
Functions
Transformation functions


 Mod Security match exactly strings and variables

 Transformation function will transform different
   string formats into a single string
Transformation functions


   By default, there are:
      lowercase

      replaceNull

      compressWhitespace
Validate Contents
Validate Contents

Check the validation of HTTP Requests

@validateByteRang   @validateDTD         @validateSchema      @validatUrlEncodin   @validateUtf8Encod
e                                                             g                    ing




Validate Byte       Validate XML files   Validate XML files   Validate URL         Validate UTF-8
Range               by DTD               by Schema            Encoding             Encoding
Validate Contents

Validate Byte Range

@validateByteRang   @validateDTD         @validateSchema      @validatUrlEncodin   @validateUtf8Encod
e                                                             g                    ing




Validate Byte       Validate XML files   Validate XML files   Validate URL         Validate UTF-8
Range               by DTD               by Schema            Encoding             Encoding
Validate Byte Range


Allow number only in Content field of Request Header

SecRule REQUEST_HEADERS:Content "@validateByteRange
48-57“ "phase:4,deny,log,status:403“
Validate Contents

Validate XML files by DTD
(Document Type Definition)
@validateByteRang   @validateDTD         @validateSchema      @validatUrlEncodin   @validateUtf8Encod
e                                                             g                    ing




Validate Byte       Validate XML files   Validate XML files   Validate URL         Validate UTF-8
Range               by DTD               by Schema            Encoding             Encoding
Validate DTD


 A Document Type Definition (DTD) is a set of
  markup declarations that define a document type for
  an SGML-family markup language (SGML, XML,
  HTML).

 It‟s define what components should be included and
  their format
Validate Contents

Validate XML files by Schema

@validateByteRang   @validateDTD         @validateSchema      @validatUrlEncodin   @validateUtf8Encod
e                                                             g                    ing




Validate Byte       Validate XML files   Validate XML files   Validate URL         Validate UTF-8
Range               by DTD               by Schema            Encoding             Encoding
Validate Schema


DTD supports only PCDATA and CDATA format.

Schema supports detailed descriptions about data in
XML files. For example: string, normalizedString,
integer, positiveInteger
Validate Contents

Validate URL Encoding

@validateByteRang   @validateDTD         @validateSchema      @validatUrlEncodin   @validateUtf8Encod
e                                                             g                    ing




Validate Byte       Validate XML files   Validate XML files   Validate URL         Validate UTF-8
Range               by DTD               by Schema            Encoding             Encoding
Validate URL Encoding

 RFC 1738 only allow ASCII in a URL

 HTML: supports ISO-8859-1 (ISO-Latin)

 HTML4: Supports Unicode characters
Validate Contents

Validate UTF-8 Encoding

@validateByteRang   @validateDTD         @validateSchema      @validatUrlEncodin   @validateUtf8Encod
e                                                             g                    ing




Validate Byte       Validate XML files   Validate XML files   Validate URL         Validate UTF-8
Range               by DTD               by Schema            Encoding             Encoding
Validate UTF-8 Encoding

 UTF-8 is used on almost every webservers to
 encode strings and compatible with ASCII

     SecRule ARGS "@validateUtf8Encoding"
Demonstrations
Steps
Thanks for joining
with me!
Apache mod security   3.1

More Related Content

What's hot (20)

PPTX
Security Features in MongoDB 2.4
MongoDB
 
PPTX
Hashicorp Vault ppt
Shrey Agarwal
 
PDF
Content Security Policy
Austin Gil
 
PPTX
Phu appsec13
drewz lin
 
PPTX
NoSQL - No Security? - The BSides Edition
Gavin Holt
 
PPTX
Owasp Indy Q2 2012 Cheat Sheet Overview
owaspindy
 
PDF
[OPD 2019] Attacking JWT tokens
OWASP
 
PPTX
Security Testing - Zap It
Manjyot Singh
 
PDF
ModSecurity and NGINX: Tuning the OWASP Core Rule Set - EMEA
NGINX, Inc.
 
PDF
Non-Invasive Elimination of Logical Access Control Vulnerabilities in Web A...
Denis Kolegov
 
PPTX
Web Cache Poisoning
KuldeepPandya5
 
PDF
Carlos García - Pentesting Active Directory [rooted2018]
RootedCON
 
PDF
Achieving Pci Compliace
Denish Patel
 
PPTX
Web_service_testing_finall
Manjyot Singh
 
PDF
Introducing Vault
Ramit Surana
 
PDF
QA: Базовое тестирование защищенности веб-приложений в рамках QA
CodeFest
 
PDF
Don't Build "Death Star" Security - O'Reilly Software Architecture Conference...
David Timothy Strauss
 
PPTX
My Bro The ELK
Tripwire
 
PPTX
Vulnerability intelligence with vulners.com / Кирилл Ермаков, Игорь Булатенко...
Ontico
 
PPTX
Beyond the Basics 4: How to secure your MongoDB database
MongoDB
 
Security Features in MongoDB 2.4
MongoDB
 
Hashicorp Vault ppt
Shrey Agarwal
 
Content Security Policy
Austin Gil
 
Phu appsec13
drewz lin
 
NoSQL - No Security? - The BSides Edition
Gavin Holt
 
Owasp Indy Q2 2012 Cheat Sheet Overview
owaspindy
 
[OPD 2019] Attacking JWT tokens
OWASP
 
Security Testing - Zap It
Manjyot Singh
 
ModSecurity and NGINX: Tuning the OWASP Core Rule Set - EMEA
NGINX, Inc.
 
Non-Invasive Elimination of Logical Access Control Vulnerabilities in Web A...
Denis Kolegov
 
Web Cache Poisoning
KuldeepPandya5
 
Carlos García - Pentesting Active Directory [rooted2018]
RootedCON
 
Achieving Pci Compliace
Denish Patel
 
Web_service_testing_finall
Manjyot Singh
 
Introducing Vault
Ramit Surana
 
QA: Базовое тестирование защищенности веб-приложений в рамках QA
CodeFest
 
Don't Build "Death Star" Security - O'Reilly Software Architecture Conference...
David Timothy Strauss
 
My Bro The ELK
Tripwire
 
Vulnerability intelligence with vulners.com / Кирилл Ермаков, Игорь Булатенко...
Ontico
 
Beyond the Basics 4: How to secure your MongoDB database
MongoDB
 

Viewers also liked (8)

PPTX
WAF in Scale
Alexey Sintsov
 
PDF
Web Intrusion Detection
Abhishek Singh
 
PDF
OWASP ModSecurity Core Rules Paranoia Mode
Christian Folini
 
KEY
mod_security introduction at study2study #3
Naoya Nakazawa
 
PDF
Mod Security
Abhishek Singh
 
PDF
Introduction to Mod security session April 2016
Rahul
 
PDF
Protecting TYPO3 With Suhosin And Modsecurity
Xavier Perseguers
 
PDF
Bypassing Web Application Firewalls
OWASP (Open Web Application Security Project)
 
WAF in Scale
Alexey Sintsov
 
Web Intrusion Detection
Abhishek Singh
 
OWASP ModSecurity Core Rules Paranoia Mode
Christian Folini
 
mod_security introduction at study2study #3
Naoya Nakazawa
 
Mod Security
Abhishek Singh
 
Introduction to Mod security session April 2016
Rahul
 
Protecting TYPO3 With Suhosin And Modsecurity
Xavier Perseguers
 
Bypassing Web Application Firewalls
OWASP (Open Web Application Security Project)
 
Ad

Similar to Apache mod security 3.1 (20)

PPTX
Syn504 unleashing the power of the net scaler policy and expressions engine...
Henrik Johansson
 
PDF
A4 xml external entites
Lenur Dzhemiliev
 
PDF
Unit 10: XML and Beyond (Sematic Web, Web Services, ...)
DSBW 2011/2002 - Carles Farré - Barcelona Tech
 
PDF
Using OpenLDAP
Wildan Maulana
 
PDF
Validating Xml
LiquidHub
 
PPTX
An introduction to PHP : PHP and Using PHP, Variables Program control and Bui...
Vigneshkumar Ponnusamy
 
PDF
An Empirical Study on the Risks of Using Off-the-Shelf Techniques for Process...
Nicolas Bettenburg
 
PPT
Web Services Security
amiable_indian
 
KEY
Pragmatic RESTful API Design: Apigee Webinar
Apigee | Google Cloud
 
PDF
Xi 3[1].6.0-example configs
debasissamal
 
PDF
Introduction to NoSQL and Couchbase
Dipti Borkar
 
PDF
Groovy Domain Specific Languages - SpringOne2GX 2012
Guillaume Laforge
 
PPTX
Regular expressions
Nicole Ryan
 
PDF
Rubyizing the devs and ops of an enterprise 1.0
yashasree
 
PPT
Dtd
nramos1921
 
PPTX
Big data, just an introduction to Hadoop and Scripting Languages
Corley S.r.l.
 
PPTX
XML's validation - DTD
videde_group
 
PDF
Xml 20111006 hurd
carishurd
 
PDF
Introduction to PHP 5.3
guestcc91d4
 
PPT
Common Gateway Interface
Balu Masulkar
 
Syn504 unleashing the power of the net scaler policy and expressions engine...
Henrik Johansson
 
A4 xml external entites
Lenur Dzhemiliev
 
Unit 10: XML and Beyond (Sematic Web, Web Services, ...)
DSBW 2011/2002 - Carles Farré - Barcelona Tech
 
Using OpenLDAP
Wildan Maulana
 
Validating Xml
LiquidHub
 
An introduction to PHP : PHP and Using PHP, Variables Program control and Bui...
Vigneshkumar Ponnusamy
 
An Empirical Study on the Risks of Using Off-the-Shelf Techniques for Process...
Nicolas Bettenburg
 
Web Services Security
amiable_indian
 
Pragmatic RESTful API Design: Apigee Webinar
Apigee | Google Cloud
 
Xi 3[1].6.0-example configs
debasissamal
 
Introduction to NoSQL and Couchbase
Dipti Borkar
 
Groovy Domain Specific Languages - SpringOne2GX 2012
Guillaume Laforge
 
Regular expressions
Nicole Ryan
 
Rubyizing the devs and ops of an enterprise 1.0
yashasree
 
Big data, just an introduction to Hadoop and Scripting Languages
Corley S.r.l.
 
XML's validation - DTD
videde_group
 
Xml 20111006 hurd
carishurd
 
Introduction to PHP 5.3
guestcc91d4
 
Common Gateway Interface
Balu Masulkar
 
Ad

More from Hai Dinh Tuan (9)

PDF
Equal Cost Multipath Routing in FOKUS OpenSDNCore
Hai Dinh Tuan
 
PDF
Traffic Engineering in Software-Defined Networks
Hai Dinh Tuan
 
PDF
Inicio - Uncover Your Passion
Hai Dinh Tuan
 
PDF
Ultra Wideband Technology
Hai Dinh Tuan
 
PPTX
Effective presentation
Hai Dinh Tuan
 
PPTX
Apache http server
Hai Dinh Tuan
 
PPTX
Apache http server 2
Hai Dinh Tuan
 
PPTX
Resource space
Hai Dinh Tuan
 
PPTX
Ossec – host based intrusion detection system
Hai Dinh Tuan
 
Equal Cost Multipath Routing in FOKUS OpenSDNCore
Hai Dinh Tuan
 
Traffic Engineering in Software-Defined Networks
Hai Dinh Tuan
 
Inicio - Uncover Your Passion
Hai Dinh Tuan
 
Ultra Wideband Technology
Hai Dinh Tuan
 
Effective presentation
Hai Dinh Tuan
 
Apache http server
Hai Dinh Tuan
 
Apache http server 2
Hai Dinh Tuan
 
Resource space
Hai Dinh Tuan
 
Ossec – host based intrusion detection system
Hai Dinh Tuan
 

Apache mod security 3.1

  • 1. Apache Mod Security HAI, DINH VINAHOST
  • 2. Agenda 1. Regular Expression 2. Rules Usage 3. Default Action 4. Chained Actions 5. Persistent Collection and examples 6. Transformation Function 7. Validate Contents
  • 4. Regular Expression Usage Use to match mass strings of text, such as particular characters, words, or patterns of characters
  • 5. Regular Expression Usage Email Address Matching b[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}b IP Addresses Matching b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0- 9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0- 9]|[01]?[0-9][0-9]?)b Testing Tools: Regexpal.com, regular-expressions.info
  • 7. Rules Usage  Use “|” as “OR” logical expression SecRule REQUEST_FILENAME|REQUEST_HEADERS_NAMES|REQUEST_HEADERS|!REQUE ST_HEADERS: Referer "@validateByteRange 1-255“ "log,auditlog,msg:'Request Missing an Accept Header', severity:'2',id:'960015',t:urlDecodeUni,phase:1“  Use “!” as “NOT” logical expression
  • 8. Rules Usage  Use Regular Expression to make a Rule SecRule REQUEST_METHOD "^POST$" "chain,phase:2,t:none,deny,log,auditlog,status:400,msg:'POST request must have a Content- Length header„  Use “:” to pick a variable from a Collection SecRule REQUEST_HEADERS:Content-Length "!^0?$" t:none
  • 10. Default Actions Use to set a Use “Default” Default “Default Behavior” SetDefaultAction Actions is of Apache Mod directive to add into phase:2, Security. If anything configuration file log, has not been auditlog, defined happen, pass Apache will apply Default Actions
  • 11. Rules Usage SetDefaultAction phase:2,log,auditlog,pass. SecRule REQUEST_URI "abc" SecRule REQUEST_URI "abc" phase:2,log,auditlog,pass SecRule REQUEST_URI "abc" nolog SecRule REQUEST_URI "abc" phase:2,auditlog,pass
  • 13. Chained Actions  Group Rules together  Similar to “AND” logical expression in programming language  Add “chain” action in every rule, except the last one  Example: SecRule REQUEST_HEADERS "haidinhtuan" "chain,phase:2,nolog,deny,status:406" SecRule REQUEST_METHOD "GET" "t:none“
  • 15. Persistent Collections TX Collection only exist in a transaction. After the data has been transfer Why completely, variables will be remove Persistent Collection? Persistent Collection can keep a record of variables through several transactions.
  • 16. Persistent 1. Monitor user behavior based on IP Address Collections 2. Monitor Sessions 3. User behavior monitoring 4. Prevent Session Hijacking Attack 5. Detect Denial of Service (DoS) Attack 6. Detect Brute Force Attack
  • 17. Persistent Collections IP SESSION USER Created by using Created by using Created by using initcol directive setsid directive setid directive Hold client address Hold session Hold user variables variables variables
  • 18. Persistent Collections  Define date directory first using SecDataDir directive  For example: SecDataDir /etc/httpd/modsec_data
  • 19. Persistent Collections Limit Request Rate example: SecAction initcol:ip=%{REMOTE_ADDR},pass,auditlog SecAction "phase:5,deprecatevar:ip.counter=1/1,pass,auditlog" SecRule IP:COUNTER "@gt 60" "phase:2,pause:300,deny,status:403,skip:1,nolog" SecAction "phase:2,pass,setvar:ip.counter=+1,nolog"
  • 21. Transformation functions  Mod Security match exactly strings and variables  Transformation function will transform different string formats into a single string
  • 22. Transformation functions By default, there are:  lowercase  replaceNull  compressWhitespace
  • 24. Validate Contents Check the validation of HTTP Requests @validateByteRang @validateDTD @validateSchema @validatUrlEncodin @validateUtf8Encod e g ing Validate Byte Validate XML files Validate XML files Validate URL Validate UTF-8 Range by DTD by Schema Encoding Encoding
  • 25. Validate Contents Validate Byte Range @validateByteRang @validateDTD @validateSchema @validatUrlEncodin @validateUtf8Encod e g ing Validate Byte Validate XML files Validate XML files Validate URL Validate UTF-8 Range by DTD by Schema Encoding Encoding
  • 26. Validate Byte Range Allow number only in Content field of Request Header SecRule REQUEST_HEADERS:Content "@validateByteRange 48-57“ "phase:4,deny,log,status:403“
  • 27. Validate Contents Validate XML files by DTD (Document Type Definition) @validateByteRang @validateDTD @validateSchema @validatUrlEncodin @validateUtf8Encod e g ing Validate Byte Validate XML files Validate XML files Validate URL Validate UTF-8 Range by DTD by Schema Encoding Encoding
  • 28. Validate DTD  A Document Type Definition (DTD) is a set of markup declarations that define a document type for an SGML-family markup language (SGML, XML, HTML).  It‟s define what components should be included and their format
  • 29. Validate Contents Validate XML files by Schema @validateByteRang @validateDTD @validateSchema @validatUrlEncodin @validateUtf8Encod e g ing Validate Byte Validate XML files Validate XML files Validate URL Validate UTF-8 Range by DTD by Schema Encoding Encoding
  • 30. Validate Schema DTD supports only PCDATA and CDATA format. Schema supports detailed descriptions about data in XML files. For example: string, normalizedString, integer, positiveInteger
  • 31. Validate Contents Validate URL Encoding @validateByteRang @validateDTD @validateSchema @validatUrlEncodin @validateUtf8Encod e g ing Validate Byte Validate XML files Validate XML files Validate URL Validate UTF-8 Range by DTD by Schema Encoding Encoding
  • 32. Validate URL Encoding RFC 1738 only allow ASCII in a URL HTML: supports ISO-8859-1 (ISO-Latin) HTML4: Supports Unicode characters
  • 33. Validate Contents Validate UTF-8 Encoding @validateByteRang @validateDTD @validateSchema @validatUrlEncodin @validateUtf8Encod e g ing Validate Byte Validate XML files Validate XML files Validate URL Validate UTF-8 Range by DTD by Schema Encoding Encoding
  • 34. Validate UTF-8 Encoding UTF-8 is used on almost every webservers to encode strings and compatible with ASCII SecRule ARGS "@validateUtf8Encoding"
  • 36. Steps

Editor's Notes

  • #5: Testbằngtrang regexpal.com
  • #14: Disruptive Actions: allow, block, deny, drop, pass, proxy, redirectSecRule REQUEST_HEADERS "haidinhtuan" "chain,phase:2,nolog"SecRule REQUEST_METHOD "GET" "t:none, deny,status:406“
  • #16: Mởlại file config, phần TX collectionTế Segoe UI vẫncóthểsửdungjchotiếngviêtk
  • #20: Demotrựctiếp