1.ModSecurity四大原则:灵活性、被动性、可预测性、功能质量而不是数量。
2.Audit log directives
Directive |
Description |
SecAuditEngine | 控制审计日志引擎;可能的值:打开、关闭或仅关联 |
SecAuditLog | 审计日志文件的路径 |
SecAuditLog2 | 另一个审计日志文件的路径(副本) |
SecAuditLogParts | 指定将记录事务的哪个部分。 |
SecAuditLogRelevantStatus | 指定哪些响应状态将被认为是相关的。 |
SecAuditLogStorageDir | 将存储并发审计日志文件的路径。 |
SecAuditLogType | 指定要使用的审计日志的类型:串行或并发。 |
3.Audit log parts
Part letter | Description |
A | 审计日志头(强制) |
B | 请求头 |
C | 请求体 |
D | 预订的 |
E | 响应体 |
F | 响应头 |
G | 预订的 |
H | 审计日志拖车,其中包含其他数据 |
I | 紧凑的请求体替代(对C部分),不包括文件 |
J | 预订的 |
K | 包含与事务匹配的所有规则的列表。 |
Z | 最后边界(强制性) |
4.common mlogc problems
Error message | Description |
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
Directive | Description |
SecUploadDir | 指定存储被截获文件的位置。 |
SecUploadFileMode | 指定将用于存储文件的权限。 |
SecUploadKeepFiles | 指定是否存储上传的文件(On,Off,RelevantOnly) |
6.Rule language directives
Directive | Description |
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
Variable | Description |
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
Operator | Description |
@beginsWith | Begins with |
@contains | Contains |
@endsWith | Ends with |
@rx | Regular pattern match |
@pm | Parallel matching |
@pmFromFile(@pmf in v2.6) | Parallel matching,with arguments from a file |
@streq | String equal to |
@Within | Within |
16.Numerical operators
Operator | Description |
@eq | Equal |
@ge | Greater or equal |
@gt | Greater than |
@le | Less or equal |
@lt | Less 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
Action | Description |
id | 为规则分配唯一ID |
phase | 运行规则的阶段 |
msg | 消息串 |
rev | 版次 |
severity | 严重 |
tag | 标签 |
22.Variable actions
Action | Description |
capture | 将结果捕获到一个或多个变量中 |
deprecatevar | 随着时间的推移减少数值变量值 |
expirevar | 在一个时间段后删除变量 |
initcol | 创建一个新的持久集合 |
setenv | 设置或删除环境变量 |
setvar | 设置、删除、增加或减少变量 |
setuid | 将当前事务与应用程序用户ID(用户名)关联 |
setsid | 将当前事务与应用程序会话ID关联 |
23.Logging actions
Action | Description |
auditlog | 将当前事务记录到审计日志 |
log | Log error message; implies auditlog |
logdata | 日志提供的数据作为错误消息的一部分 |
noauditlog | 不要将当前事务记录到审核日志 |
nolog | Do not log error message; implies noauditlog |
sanitiseArg | 从审计日志中删除请求参数 |
sanitiseMatched | 删除审计日志中发生匹配的参数 |
sanitiseRequestHeader | 从审计日志中删除请求标头 |
sanifiseResponseHeader | 从审计日志中删除响应头 |
24.Special actions
Action | Description |
ctl | 更改当前事务的配置 |
multiMatch | 激活多匹配,其中操作符在每次转换后运行 |
t | 指定转换函数,以便在匹配前应用于变量。 |
25.Miscellaneous actions
Action | Description |
append | 将内容追加到响应正文 |
exec | 执行外部脚本 |
pause | 暂停事务 |
prepend | 对响应体的准备内容 |
status | 指定响应状态码使用deny和redirect |
xmlns | 指定用于XPath表达式的名称空间 |