ModSecurity Handbook
Table of Contents
Preface
Audience
Contents of This Book
Updates
Conventions
Acknowledgements
Part I: User Guide
Chapter 1: Introduction
Brief History
Understanding ModSecurity
What ModSecurity Does
What Rules Look Like
Transaction Lifecycle
Lifecycle Example
File Upload Example
Impact of ModSecurity on Web Server
Embedded vs. Reverse Proxy Mode
Missing from ModSecurity
Resources
General Resources
Developer Resources
Related Projects
Chapter 2: Installation
Installation from Source
Downloading Releases
Downloading from Repository
Compilation under Unix
Compile-time options
Installation from Binaries
Fedora Core, CentOS, and Red Hat Enterprise Linux
Debian and Ubuntu
Installation on Windows
Chapter 3: Configuration
Folder Locations
Configuration Layout
Adding ModSecurity to Apache
Powering Up
Request Body Handling
Response Body Handling
Filesystem Locations
File Uploads
Debug Log
Audit Log
Miscellaneous Options
Default Rule Match Policy
Handling Parsing Errors
Verifying Installation
Chapter 4: Logging
Debug Log
Debugging in Production
Audit Log
Audit Log Entry Example
Concurrent Audit Log
Remote Logging
Configuring Mlogc
Activating Mlogc
Troubleshooting Mlogc
File Upload Interception
Storing Files
Inspecting Files
Integrating with ClamAV
Guardian Log
Advanced Logging Configuration
Increasing Logging from a Rule
Dynamically Altering Logging Configuration
Removing Sensitive Data from Audit Logs
Selective Audit Logging
Chapter 5: Rule Language Overview
Anatomy of a Rule
Variables
Request variables
Server variables
Response variables
Miscellaneous variables
Parsing flags
Collections
Time variables
Operators
String matching operators
Numerical operators
Validation operators
Miscellaneous operators
Actions
Disruptive actions
Flow actions
Metadata actions
Variable actions
Logging actions
Special actions
Miscellaneous actions
Chapter 6: Rule Language Tutorial
Introducing simple rules and operators
Working with variables
Combining rules into chains
Operator negation
Variable counting
Using actions
Understanding action defaults
Actions in chained rules
Unconditional rules
Using transformation functions
Blocking
Changing rule flow
Smarter skipping
If-then-else
Controlling logging
Capturing data
Variable manipulation
Variable expansion
Recording data in alerts
Adding meta data
Chapter 7: Rule Configuration
Apache Configuration Syntax
Breaking lines
Directives and parameters
Spreading configuration across files
Container directives
Configuration contexts
Configuration merging
Configuration Inheritance
Configuration inheritance
Rule inheritance
SecDefaultAction inheritance anomaly
Rule Manipulation
Removing rules at configure-time
Updating rules at configure-time
Excluding rules at run-time
Chapter 8: Persistent Storage
Manipulating Collection Records
Creating records
Application namespaces
Initializing records
Controlling record longevity
Deleting records
Detecting very old records
Collection Variables
Built-in variables
Variable expiry
Variable value depreciation
Implementation Details
Retrieving records
Storing a collection
Record Limits
Applied Persistence
Periodic alerting
Denial of service attack detection
Brute force attack detection
Session Management
Initializing Sessions
Blocking Sessions
Forcing Session Regeneration
Restricting Session Life Time
Detecting Session Hijacking
User Management
Detecting Users Sign In
Detecting Users Sign Out
Chapter 9: Practical Rule Writing
Whitelisting
Whitelisting theory
Whitelisting mechanics
Granular whitelisting
Complete whitelisting example
Virtual Patching
Reputation Management
Organizing Rule Sets
Using Rule Sets
Integration with other Apache modules
Conditional logging
Header manipulation
Securing session cookies
Advanced Blocking
Making the most of regular expressions
How ModSecurity Compiles Patterns
Changing how patterns are compiled
Common pattern problems
Regular Expression Denial of Service
Resources
Performance tips
Chapter 10: Content Injection
Writing Content Injection Rules
Communicating back to the server
Interrupting page rendering
Using external JavaScript code
Communicating with Users
Chapter 11: Writing Rules in Lua
Rule Language Integration
Lua Rules Skeleton
Accessing Variables
Logging
Lua Actions
Chapter 12: Handling XML
XML Parsing
DTD Validation
XML Schema Validation
XML Namespaces
XPath Expressions
XPath and Namespaces
XML Inspection Framework
Chapter 13: Extending Rule Language
Extension Template
Adding a Transformation Function
Adding an Operator
Adding a Variable
Part II: Reference Documentation
Chapter 14: Reference Manual
Configuration Directives
SecAction
SecArgumentSeparator
SecAuditEngine
SecAuditLog
SecAuditLog2
SecAuditLogDirMode
SecAuditLogFileMode
SecAuditLogParts
SecAuditLogRelevantStatus
SecAuditLogStorageDir
SecAuditLogType
SecCacheTransformations (Deprecated/Experimental)
SecChrootDir
SecComponentSignature
SecContentInjection
SecCookieFormat
SecDataDir
SecDebugLog
SecDebugLogLevel
SecDefaultAction
SecGeoLookupDb
SecGuardianLog
SecMarker
SecPdfProtect (Obsolete)
SecPdfProtectMethod (Obsolete)
SecPdfProtectSecret (Obsolete)
SecPdfProtectTimeout (Obsolete)
SecPdfProtectTokenName (Obsolete)
SecRequestBodyAccess
SecRequestBodyLimit
SecRequestBodyNoFilesLimit
SecRequestBodyInMemoryLimit
SecResponseBodyLimit
SecResponseBodyLimitAction
SecResponseBodyMimeType
SecResponseBodyMimeTypesClear
SecResponseBodyAccess
SecRule
Variables in rules
Collections
Operators in rules
Operator negation
Actions in rules
SecRuleInheritance
SecRuleEngine
SecRuleRemoveById
SecRuleRemoveByMsg
SecRuleScript (Experimental)
SecRuleUpdateActionById
SecServerSignature
SecTmpDir
SecUploadDir
SecUploadFileMode
SecUploadKeepFiles
SecWebAppId
Variables
ARGS
ARGS_COMBINED_SIZE
ARGS_NAMES
ARGS_GET
ARGS_GET_NAMES
ARGS_POST
ARGS_POST_NAMES
AUTH_TYPE
DURATION
ENV
FILES
FILES_COMBINED_SIZE
FILES_NAMES
FILES_SIZES
FILES_TMPNAMES
GEO
HIGHEST_SEVERITY
MATCHED_VAR
MATCHED_VAR_NAME
MODSEC_BUILD
MULTIPART_CRLF_LF_LINES
MULTIPART_STRICT_ERROR
MULTIPART_UNMATCHED_BOUNDARY
PATH_INFO
QUERY_STRING
REMOTE_ADDR
REMOTE_HOST
REMOTE_PORT
REMOTE_USER
REQBODY_PROCESSOR
REQBODY_PROCESSOR_ERROR
REQBODY_PROCESSOR_ERROR_MSG
REQUEST_BASENAME
REQUEST_BODY
REQUEST_COOKIES
REQUEST_COOKIES_NAMES
REQUEST_FILENAME
REQUEST_HEADERS
REQUEST_HEADERS_NAMES
REQUEST_LINE
REQUEST_METHOD
REQUEST_PROTOCOL
REQUEST_URI
REQUEST_URI_RAW
RESPONSE_BODY
RESPONSE_CONTENT_LENGTH
RESPONSE_CONTENT_TYPE
RESPONSE_HEADERS
RESPONSE_HEADERS_NAMES
RESPONSE_PROTOCOL
RESPONSE_STATUS
RULE
SCRIPT_BASENAME
SCRIPT_FILENAME
SCRIPT_GID
SCRIPT_GROUPNAME
SCRIPT_MODE
SCRIPT_UID
SCRIPT_USERNAME
SERVER_ADDR
SERVER_NAME
SERVER_PORT
SESSION
SESSIONID
TIME
TIME_DAY
TIME_EPOCH
TIME_HOUR
TIME_MIN
TIME_MON
TIME_SEC
TIME_WDAY
TIME_YEAR
TX
URLENCODED_ERROR
USERID
WEBAPPID
WEBSERVER_ERROR_LOG
XML
Transformation functions
base64Decode
base64Encode
compressWhitespace
cssDecode
escapeSeqDecode
hexDecode
hexEncode
htmlEntityDecode
jsDecode
length
lowercase
md5
none
normalizePath
normalizePathWin
parityEven7bit
parityOdd7bit
parityZero7bit
removeNulls
removeWhitespace
replaceComments
replaceNulls
urlDecode
urlDecodeUni
urlEncode
sha1
trimLeft
trimRight
trim
Actions
allow
append
auditlog
block
capture
chain
ctl
deny
deprecatevar
drop
exec
expirevar
id
initcol
log
logdata
msg
multiMatch
noauditlog
nolog
pass
pause
phase
prepend
proxy
redirect
rev
sanitiseArg
sanitiseMatched
sanitiseRequestHeader
sanitiseResponseHeader
severity
setuid
setsid
setenv
setvar
skip
skipAfter
status
t
tag
xmlns
Operators
beginsWith
contains
endsWith
eq
ge
geoLookup
gt
inspectFile
le
lt
pm
pmFromFile
rbl
rx
streq
validateByteRange
validateDTD
validateSchema
validateUrlEncoding
validateUtf8Encoding
verifyCC
within
Chapter 15: Data Formats Guide
Alerts
Alert Action Description
Alert Justification Description
Meta-data
Escaping
Alerts in the Apache Error Log
Alerts in Audit Logs
Audit Log
Parts
Audit Log Header (A)
Request Headers (B)
Request Body (C)
Intended Response Headers (D)
Intended Response Body (E)
Response Headers (F)
Response Body (G)
Audit Log Trailer (H)
Action
Apache-Error
Message
Producer
Response-Body-Transformed
Sanitised-Args
Sanitised-Request-Headers
Sanitised-Response-Headers
Server
Stopwatch
WebApp-Info
Reduced Multipart Request Body (I)
Multipart Files Information (J)
Matched Rules (K)
Audit Log Footer (Z)
Storage Formats
Serial Audit Log Format
Concurrent Audit Log Format
Transport Protocol
Request Headers Information
Index
空白页面