REQUEST_HEADERS:User-Agent: The variable this rule is inspecting — specifically, the User-Agent header in the incoming HTTP request headers.
"(?i)(curl|wget|python|httpclient|libwww|scrapy|nmap|sql)": This is a regular expression (regex) pattern to match against the User-Agent header.
(?i) means case-insensitive matching.
The pattern looks for any of the words:
curl
wget
python
httpclient
libwww
scrapy
nmap
sql
What this means:
The rule is looking for HTTP requests whose User-Agent matches any of these keywords, which are commonly associated with automated tools, bots, scanners, or scripts:
curl and wget: command-line tools used for transferring data.
python: common for Python HTTP scripts.
httpclient and libwww: HTTP client libraries.
scrapy: a scraping framework.
nmap: a network scanner.
sql: could indicate SQL injection tools or scanners.
Such User-Agent strings might indicate automated or malicious requests.
Typical use:
This rule would be used in ModSecurity to detect and potentially block requests from common scraping tools, scanners, or bots by inspecting their User-Agent headers.
Note:
The line you provided is just a matching part. Typically, a full ModSecurity rule has an action part as well, e.g.:
This would block the request, log it, and provide a message.
In summary:
The rule checks if the User-Agent header contains any keywords commonly used by automated tools/scrapers and can be used to filter or block such traffic.
User
Is it using ".*" not necessary at start and end of string?
The error message tells you ModSecurity expected an action but got wrong syntax near a ' (single quote), specifically in the rule at line 3, column 60 in your file ip-check.conf.
Blocking at phase 1 (early) helps prevent further processing or logging sensitive data.
Rule 2
apache
SecRule REQUEST_URI "@rx (?i)(README(\.md)?|config\.ini|\.env|passwords?.txt|secret\.bak)$" \
"id:180002,phase:1,deny,status:200,t:none,msg:'auth data leak',tag:'auth-data-leak'"
Breakdown:
Variables scanned:
Only REQUEST_URI
Operator:
Case-insensitive regex looking for URIs ending with any of the following:
README or README.md
config.ini
.env
password.txt or passwords.txt (matches singular or plural)
secret.bak
Actions:
id:180002
phase:1 (request headers phase)
deny
status:200
t:none
msg:'auth data leak'
tag:'auth-data-leak'
Purpose:
This rule focuses on blocking requests targeting files associated with authentication or secrets, such as password lists (password.txt), secret backups (secret.bak), or environment files.
It's narrower in scope compared to the first rule but emphasizes files that may contain credentials.
Note: The regex has a trailing > (maybe a typo or part of pattern to detect HTML tags). I'll proceed assuming it's intentional.
Breakdown:
Variable scanned:
RESPONSE_BODY (the body of the outgoing HTTP response)
Operator:
Case-insensitive regex looking for words indicating error messages or sensitive application info such as:
mysql
password or passwd
can't connect
error
exception
trace
fatal
undefined
denied
unauthorized
This tries to detect potential application error messages or sensitive information leakage in the response.
Actions:
id:180003
phase:4: This phase runs after the response is generated and just before sending it to client (response body inspection)
deny: Block the response
status:200: Reply with status code 200 (OK), again likely to silently block or confuse attacker
t:none: No transformation
msg:'appinfo leak'
ctl:auditLogParts=+E: Add the response body to audit logs (E stands for response body). This helps diagnostics.
tag:'application-info-leak'
Purpose:
Detects leaks of sensitive application info in responses, such as unhandled error messages or database errors.
Such leaks might reveal internal implementation details that attackers could use to find vulnerabilities.
It blocks the response in phase 4.
Overall summary
Rule ID
When (Phase)
What it Inspects
What it Detects
Action
Reason/Purpose
180001
1 (early req)
URI, arg names and values
Access to config/backup/log-type files
Deny (block), status 200
Prevent expose of config data files
180002
1 (early req)
URI
Access to specific sensitive files
Deny (block), status 200
Prevent auth/secret info leakage
180003
4 (response)
Response body
Error messages and sensitive app info
Deny (block), status 200, log body
Prevent info leaks in responses
Notes:
Returning status 200 (OK) upon denial is a design choice to avoid giving standard error codes like 403 (Forbidden) that might inform attackers of blocked resources.
These rules are part of a defensive security posture to prevent confidential data leaks and detect malicious probing.
The use of t:none means no input transformations, assuming input is already normalized or you want exact matching.
Tagging the rules help correlate similar security events in logs.
If you want I can also help you craft or improve these rules, explain phases in more detail, or how to tune the status codes!
Matches utl_inaddr.get_host_name function call where the argument is an IP address, optionally enclosed in single quotes, e.g.:
code
utl_inaddr.get_host_name('127.0.0.1')
Breaking down:
utl_inaddr\.get_host_name: literal function name
\s*\(\s*: opening parenthesis with optional spaces before/after
'?': optional single quote
\d{1,3}(\.\d{1,3}){3}: IP address pattern — four groups of 1-3 digits separated by dots
'?': optional single quote
\s*\): optional spaces and closing parenthesis
Looks well constructed and escaped.
3. Actions and modifiers
id:123456 and id:123457: unique rule IDs — good.
phase:2: trigger during request body processing — appropriate for inspecting parameters.
deny: block matched request.
status:403: return HTTP 403 Forbidden — this is standard.
t:none: disable transformations (no encoding normalization).
msg:'Oracle time based': logged message — good.
tag:'sqli-time-based': for grouping the alert category.
capture: enables capturing the matched part into TX.MATCHED_VAR.
ctl:auditLogParts=+E: adds matched entity to audit logs — good for forensics.
4. Possible minor improvements or considerations:
Regex performance:
The first regex uses .* which can be greedy and sometimes cause performance issues for large inputs. A safer pattern is to replace .* with [^;]* or non-greedy .*? if you want to avoid backtracking issues.
For example:
regex
select\s+.*?from\s+dual
Otherwise, if performance testing is OK, this is fine.
Use of ARGS_NAMES variable:
You are inspecting parameter names (ARGS_NAMES) as well as values (ARGS).
Typically, SQLi payloads occur in values, rarely in parameter names — inspecting names might increase false positives (though low).
It's a choice based on how strict you want to be.
Coverage: REQUEST_HEADERS
Good to check if attackers put payload in custom headers (like X-Forwarded-For).
status:403 with deny
This is correct and standard practice.
Escaping regex
You correctly escaped the dot in utl_inaddr\.get_host_name — good.
Quote usage in regex
Optional '?' in second regex is a good touch, handles with or without quotes.