学习"ModSecrity Handbook"之摘录

1.ModSecurity四大原则:灵活性、被动性、可预测性、功能质量而不是数量。

2.Audit log directives

Directive

Description
SecAuditEngine控制审计日志引擎;可能的值:打开、关闭或仅关联
SecAuditLog审计日志文件的路径
SecAuditLog2另一个审计日志文件的路径(副本)
SecAuditLogParts指定将记录事务的哪个部分。
SecAuditLogRelevantStatus指定哪些响应状态将被认为是相关的。
SecAuditLogStorageDir将存储并发审计日志文件的路径。
SecAuditLogType指定要使用的审计日志的类型:串行或并发。
  

3.Audit log parts

Part letterDescription
A审计日志头(强制)
B请求头
C请求体
D预订的
E响应体
F响应头
G预订的
H审计日志拖车,其中包含其他数据
I紧凑的请求体替代(对C部分),不包括文件
J预订的
K包含与事务匹配的所有规则的列表。
Z最后边界(强制性)

4.common mlogc problems

Error messageDescription
couldn't connect to host无法到达服务器。这可能意味着服务器本身已经故障,但是它还可能表明存在网络问题。您可以研究curl返回代码,以确定问题的确切原因。
Possible SSL negotiation error最常见的情况是,此消息将意味着您将mlogc配置为提交明文,但是远程服务器使用SSL。确保ConsoleURI参数开始于"https://".
Unauthorized凭据不正确。检查SensorUsername和SensorPassword参数。
For input string:"0,0"      

远程服务器可以使用任何响应状态代码指示内部错误。除了200和409,但这些错误被视为瞬态错误

。ModSecurity社区控制台存在一个长期存在的问题,它用500代码响应一个无效的审计日志条目。 

500响应代码的使用会使mlogc暂停并尝试再次传递,结果却再次看到控制台失败。

这一过程无限期地继续下去,目前唯一的解决办法是追查违规行为。 审核传感器上的日志条目并手动删除它。

5.File upload directives

DirectiveDescription
SecUploadDir指定存储被截获文件的位置。
SecUploadFileMode指定将用于存储文件的权限。
SecUploadKeepFiles指定是否存储上传的文件(On,Off,RelevantOnly)

6.Rule language directives

DirectiveDescription
SecAction执行无条件的动作。这个指令本质上是一个始终匹配的规则。
SecDefaultAction指定默认动作列表,该列表将在随后的规则中使用
SecMarker创建一个标记,该标记可与skipAfter 操作一起使用。标记创建了一个规则,该规则不执行任何操作,但是为其分配了一个ID。
SecRule创建规则
SecRuleInheritance控制规则是否在子配置上下文中继承。
SecRuleRemoveById使用给定的ID移除规则。
SecRuleScript创建使用Lua实现的规则。
SecRuleRemoveByMsg移除其消息与给定正则表达式匹配的规则。
SecRuleUpdataActionById将规则的操作列表替换为给定的ID,并将提供的动作替换为list

7.SecRule VARIABLES OPERATOR [TRANSFORMATION_FUNCTION, ACTIONS]

8.Request variables

VariableDescription
ARGS请求参数(只读集合)
ARGS_COMBINED_SIZE所有请求参数的合计大小
ARGS_NAMES请求参数的名称(集合)
ARGS_GET查询字符串参数(只读集合)
ARGS_GET_NAMES查询字符串参数名称(只读集合)
ARGS_POST请求体参数(只读集合)
ARGS_POST_NAMES请求体参数的名称(只读集合)
FILES文件名(只读集合)
FILES_COMBINED_SIZE所有上传文件的组合大小
FILE_NAMES文件参数名称(只读集合)
FILES_SIZES文件大小列表(只读集合)
FILES_TMPNAMES临时文件名列表(只读集合)
PATH_INFO额外路径信息
QUERY_STRING请求的查询字符串
REMOTE_USER远程用户
REQUEST_BASENAME请求URI basename
REQUEST_BODY请求体
REQUEST_COOKIES请求cookie(只读集合)
REQUEST_COOKIES_NAMES请求cookie的名称(只读集合)
REQUEST_FILENAME请求URI文件名/路径
REQUEST_HEADERS请求头(集合,只读)
REQUEST_HEADERS_NAMES请求头的名称(只读集合)
REQUEST_LINE请求行
REQUEST_METHOD请求方法
REQUEST_PROTOCOL请求协议
REQUEST_URI请求URI,转换为排除主机名
REQUEST_URI_RAW请求URI,正如它在请求中显示的那样

9.Server variables

Variable                                       Description

AUTH_TYPE                                 Authentication type

REMOTE_ADDR                           Remote address

REMOTE_HOST                            Remote host

REMOTE_PORT                            Remote port

SCRIPT_BASENAME                     Script basename

SCRIPT_FILENAME                       Script filename/path

SCRIPT_GID                                  Script group ID

SCRIPT_GROUPNAME                  Script group name

SCRIPT_MODE                              Script  permissions

SCRIPT_UID                                   Script user ID

SCRIPT_USERNAME                       Script user name

SERVER_ADDR                               Server address

SERVER_NAME                               Server name

SERVER_PORT                                 Server port

10.Response variables

Variable                                               Description

RESPONSE_BODY                                  Response body 

RESPONSE_CONTENT_LENGTH             Response content length 

RESPONSE_CONTENT_TYPE                   Response content type

RESPONSE_HEADERS                             Response headers (read-only collection) 

RESPONSE_HEADERS_NAMES                Response headers’ names (read-only collection) 

RESPONSE_PROTOCOL                           Response protocol

RESPONSE_STATUS                                 Response status code

11.Miscellaneous variables

Variable                                             Description

HIGHEST_SEVERITY                             Highest severity encountered

MATCHED_VAR                                   Contents of the last variable that matched

MATCHED_VAR_NAME                        Name of the last variable that match

MODSEC_BUILD                                   ModSecurity build version (e.g., 02050102)

SESSIONID                                            Session ID associated with current transaction

USERID                                                  User ID associated with current transaction

WEBAPPID                                             Web application ID associated with current transaction

WEBSERVER_ERROR_LOG                      Error messages generated by Apache during current transaction

12.Request body parsing variables

Variable                                                               Description

MULTIPART_BOUNDARY_QUOTED                      Multipart parsing error: quoted boundary encountered

MULTIPART_BOUNDARY_WHITESPACE               Multipart parsing error: whitespace in boundary

MULTIPART_CRLF_LF_LINES                                  Multipart parsing error: mixed line endings used 

MULTIPART_DATA_BEFORE                                   Multipart parsing error: seen data before first boundary 

MULTIPART_DATA_AFTER                                     Multipart parsing error: seen data after last boundary 

MULTIPART_HEADER_FOLDING                            Multipart parsing error: header folding used 

MULTIPART_LF_LINE                                              Multipart parsing error: LF line ending detected 

MULTIPART_SEMICOLON_MISSING                      Multipart parsing error: missing semicolon before boundary

MULTIPART_STRICT_ERROR                                   At least one multipart error except 

MULTIPART_UNMATCHED_BOUNDARY                occurred

MULTIPART_UNMATCHED_BOUNDARY                Multipart parsing error: unmatched boundary detected (prone to 

                                                                                false positives)

REQBODY_PROCESSOR                                          Request processor that handled request body

REQBODY_PROCESSOR_ERROR                             Request processor error flag (0 or 1) 

REQBODY_PROCESSOR_ERROR_MSG                    Request processor

13.Special collections

Variable                      Description

ENV                             Environment variables (read-only collection, although it’s possible to use set- var to change it)

GEO                             Geo lookup information from the last @geoLookup invocation (read-only collec- tion)

GLOBAL                       Global information, shared by all processes (read/write collection)

IP                                  IP address data storage (read/write collection)

TX                                 Transient transaction data (read/write collection)

RULE                             Current rule metadata (read-only  collection)

SESSION                        Session data storage (read/write collection)

USER                              User data storage (read/write collection)

XML                                XML DOM tree (read-only collection)

14.Time variables

Variable                              Description

TIME                                     Time (HH:MM:SS)

TIME_DAY                             Day of the month (1-31)

TIME_EPOCH                         Seconds since January 1, 1970 (e.g., 1251029017)

TIME_HOUR                           Hour of the day (0-23)

TIME_MIN                              Minute of the hour (0-59)

TIME_MON                            Month of the year (0-11)

TIME_SEC                               Second of the minute (0-59)

TIME_WDAY                           Week day (0-6)

TIME_YEAR                             Year

15.String matching operators

OperatorDescription
@beginsWithBegins with
@containsContains
@endsWithEnds with
@rxRegular pattern match
@pmParallel matching
@pmFromFile(@pmf in v2.6)Parallel matching,with arguments from a file
@streqString equal to
@WithinWithin

16.Numerical operators

OperatorDescription
@eqEqual
@geGreater or equal
@gtGreater than
@leLess or equal
@ltLess than

17.Validation operators验证运算

Operator                                                         Description

@validateByteRange                                        Validates that parameter consists only of allowed byte values

@validateDTD                                                  Validates XML payload against a DTD

@validateSchema                                             Validates XML payload against a Schema

@validateUrlEncoding                                      Validates an URL-encoded string

@validateUtf8Encoding                                    Validates an UTF-8 encoded string

18.miscellaneous operators

Operator                                         Description

@geoLookup                                   Determines the physical location of an IP address

@inspectFile                                     Invokes an external script to inspect a file

@rbl                                                  Looks parameter against a RBL (real-time block list)

@verifyCC                                         Checks if the parameter is a valid credit card number

19.Disruptive actions

Action                              Description

allow                                 Stop processing of one or more remaining phases

block                                 Indicates that a rule wants to block

deny                                  Block transaction with an error page

drop                                  Close network connection

pass                                   Do not block, go to the next rule

proxy                                 Proxy request to a backend web server

redirect                              Redirect request to some other web server

20.Flow actions

Action                               Description

chain                                  将两个或多个规则连接到单个逻辑规则中。

skip                                    跳过下面的一个或多个规则

skipAfter                            跳到具有提供ID的规则或标记

21.Metadata actions

ActionDescription
id为规则分配唯一ID
phase运行规则的阶段
msg消息串
rev版次
severity严重
tag标签

22.Variable actions

ActionDescription
capture将结果捕获到一个或多个变量中
deprecatevar随着时间的推移减少数值变量值
expirevar在一个时间段后删除变量
initcol创建一个新的持久集合
setenv设置或删除环境变量
setvar设置、删除、增加或减少变量
setuid将当前事务与应用程序用户ID(用户名)关联
setsid将当前事务与应用程序会话ID关联

23.Logging actions

ActionDescription
auditlog将当前事务记录到审计日志
log

Log error message; implies auditlog

logdata日志提供的数据作为错误消息的一部分
noauditlog不要将当前事务记录到审核日志
nolog

Do not log error message; implies noauditlog

sanitiseArg从审计日志中删除请求参数
sanitiseMatched删除审计日志中发生匹配的参数
sanitiseRequestHeader从审计日志中删除请求标头
sanifiseResponseHeader从审计日志中删除响应头

24.Special actions

ActionDescription
ctl更改当前事务的配置
multiMatch激活多匹配,其中操作符在每次转换后运行
t指定转换函数,以便在匹配前应用于变量。

25.Miscellaneous actions

ActionDescription
append将内容追加到响应正文
exec执行外部脚本
pause暂停事务
prepend对响应体的准备内容
status指定响应状态码使用deny和redirect
xmlns指定用于XPath表达式的名称空间
26.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ModSecurity Handbook is the definitive guide to ModSecurity, a popular open source web application firewall. Written by Ivan Ristic, who designed and wrote much of ModSecurity, this book will teach you everything you need to know to monitor the activity on your web sites and protect them from attack. Situated between your web sites and the world, web application firewalls provide an additional security layer, monitoring everything that comes in and everything that goes out. They enable you to perform many advanced activities, such as real-time application security monitoring, access control, virtual patching, HTTP traffic logging, continuous passive security assessment, and web application hardening. They can be very effective in preventing application security attacks, such as cross-site scripting, SQL injection, remote file inclusion, and others. Considering that most web sites today suffer from one problem or another, ModSecurity Handbook will help anyone who has a web site to run. The topics covered include: Installation and configuration of ModSecurity Logging of complete HTTP traffic Rule writing IP address, session, and user tracking Session management hardening Whitelisting, blacklisting, and IP reputation management Advanced blocking strategies Integration with other Apache modules Working with rule sets Virtual patching Performance considerations Content injection XML inspection Writing rules in Lua Extending ModSecurity in C The book is suitable for all reader levels: it contains step-by-step installation and configuration instructions for those just starting out, as well as detailed explanations of the internals and discussion of advanced techniques for seasoned users. A comprehensive reference manual is included in the second part of the book. Digital version of ModSecurity Handbook (PDF or EPUB) can be obtained directly from the author, at feistyduck.com.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值