Book description
Prevent web application hacking with this easy to use guide
Secure your system by knowing exactly how a hacker would break into it
Covers writing rules in-depth and Modsecurity rule language elements such as variables, actions, and request phases
Covers the common attacks in use on the Web, and ways to find the geographical location of an attacker and send alert emails when attacks are discovered
Packed with many real-life examples for better understanding
In Detail
With more than 67% of web servers running Apache and web-based attacks becoming more and more prevalent, web security has become a critical area for web site managers. Most existing tools work on the TCP/IP level, failing to use the specifics of the HTTP protocol in their operation. Mod_security is a module running on Apache, which will help you overcome the security threats prevalent in the online world.
A complete guide to using ModSecurity, this book will show you how to secure your web application and server, and does so by using real-world examples of attacks currently in use. It will help you learn about SQL injection, cross-site scripting attacks, cross-site request forgeries, null byte attacks, and many more so that you know how attackers operate. Using clear, step-by-step instructions this book starts by teaching you how to install and set up ModSecurity, before diving into the rule language with examples. It assumes no prior knowledge of ModSecurity, so as long as you are familiar with basic Linux administration, you can start to learn right away.
Real-life case studies are used to illustrate the dangers on the Web today – you will for example learn how the recent worm that hit Twitter works, and how you could have used ModSecurity to stop it in its tracks. The mechanisms behind these and other attacks are described in detail, and you will learn everything you need to know to make sure your server and web application remain unscathed on the increasingly dangerous web. Have you ever wondered how attackers figure out the exact web server version running on a system? They use a technique called HTTP fingerprinting, and you will learn about this in depth and how to defend against it by flying your web server under a ""false flag"".
The last part of the book shows you how to really lock down a web application by implementing a positive security model that only allows through requests that conform to a specific, pre-approved model, and denying anything that is even the slightest bit out of line.
Table of contents
- ModSecurity 2.5
- Credits
- About the Author
- About the Reviewers
- Preface
- 1. Installation and Configuration
-
2. Writing Rules
- SecRule syntax
- Creating chained rules
- Rule IDs
- An introduction to regular expressions
- Simple string matching
- Matching numbers
- More about collections
- Transformation functions
- Other operators
- Phases and rule ordering
- Actions—what to do when a rule matches
- SecAction
- Using the ctl action to control the rule engine
- Macro expansion
- SecRule in practice
- Executing shell scripts
- Injecting data into responses
- Inspecting uploaded files
-
3. Performance
- A typical HTTP request
- A real-world performance test
- Optimizing performance
- Summary
- 4. Audit Logging
- 5. Virtual Patching
-
6. Blocking Common Attacks
- HTTP fingerprinting
- Blocking proxied requests
- Cross-site scripting
- Cross-site request forgeries
- Shell command execution attempts
- Null byte attacks
- Source code revelation
- Directory traversal attacks
- Blog spam
- SQL injection
- Website defacement
- Brute force attacks
- Directory indexing
- Detecting the real IP address of an attacker
- Summary
- 7. Chroot Jails
- 8. REMO
-
9. Protecting a Web Application
- Considerations before beginning
- The web application
- Groundwork
- Step 1: Identifying user actions
- Step 2: Getting detailed information on each action
- Step 3: Writing rules
- Step 4: Testing the new ruleset
- Actions
- Blocking what's allowed—denying everything else
- Cookies
- Headers
- Securing the "Start New Topic" action
- The ruleset so far
- The finished ruleset
- Alternative approaches
- Keeping everything up to date
- Summary
-
A. Directives and Variables
-
Directives
- SecAction
- SecArgumentSeparator
- SecAuditEngine
- SecAuditLog
- SecAuditLog2
- SecAuditLogParts
- SecAuditLogRelevantStatus
- SecAuditLogStorageDir
- SecAuditLogType
- SecCacheTransformations (deprecated/experimental)
- SecChrootDir
- SecComponentSignature
- SecContentInjection
- SecCookieFormat
- SecDataDir
- SecDebugLog
- SecDebugLogLevel
- SecDefaultAction
- SecGeoLookupDb
- SecGuardianLog
- SecMarker
- SecPdfProtect
- SecPdfProtectMethod
- SecPdfProtectSecret
- SecPdfProtectTimeout
- SecPdfProtectTokenName
- SeqRequestBodyAccess
- SecRequestBodyLimit
- SecRequestBodyNoFilesLimit
- SecRequestBodyInMemoryLimit
- SecResponseBodyLimit
- SecResponseBodyLimitAction
- SecResponseBodyMimeType
- SecResponseBodyMimeTypesClear
- SecResponseBodyAccess
- SecRule
- SecRuleInheritance
- SecRuleEngine
- SecRuleRemoveById
- SecRuleRemoveByMsg
- 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
- 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
- USERID
- WEBAPPID
- WEBSERVER_ERROR_LOG
- XML
-
Directives
-
B. Regular Expressions
- What is a regular expression?
- Regular expression flavors
- Example of a regular expression
- The Dot character
- Quantifiers—star, plus, and question mark
- Alternation
- Backreferences
- Non-capturing parentheses
- Character classes
- Anchors
- Lazy quantifiers
- Debugging regular expressions
- Additional resources
- Our email address regex
- Summary
Product information
- Title: ModSecurity 2.5
- Author(s):
- Release date: November 2009
- Publisher(s): Packt Publishing
- ISBN: 9781847194749
You might also like
book
Web Security for Developers
The world has changed. Today, every time you make a site live, you’re opening it up …
video
Elasticsearch 8 and the Elastic Stack: In-Depth and Hands-On
Learn all the latest techniques to search, analyze, and visualize big data with Elasticsearch, Kibana, Logstash, …
video
Red Hat Certified System Administrator (RHCSA) RHEL 9
14+ Hours of Video Instruction Get intensive, hands-on RHEL 9 training with Sander van Vugt in …
video
Practical Python: Learn Python Basics Step by Step - Python 3
Python is one of the most popular programming languages and gives a lot of scope and …