Skip to content

Commit 85384fe

Browse files
committed
Encode possible binary characters from user input in audit logs
1 parent 032ccae commit 85384fe

File tree

3 files changed

+63
-4
lines changed

3 files changed

+63
-4
lines changed

src/operators/operator.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,15 @@ std::string Operator::resolveMatchMessage(Transaction *t,
112112
if (m_couldContainsMacro == false) {
113113
ret = "Matched \"Operator `" + m_op + "' with parameter `" +
114114
utils::string::limitTo(200, m_param) +
115-
"' against variable `" + key + "' (Value: `" +
115+
"' against variable `" + utils::string::toHexIfNeeded(key) + "' (Value: `" +
116116
utils::string::limitTo(100,
117117
utils::string::toHexIfNeeded(value)) + \
118118
"' )";
119119
} else {
120120
std::string p(m_string->evaluate(t));
121121
ret = "Matched \"Operator `" + m_op + "' with parameter `" +
122122
utils::string::limitTo(200, p) +
123-
"' against variable `" + key + "' (Value: `" +
123+
"' against variable `" + utils::string::toHexIfNeeded(key) + "' (Value: `" +
124124
utils::string::limitTo(100,
125125
utils::string::toHexIfNeeded(value)) +
126126
"' )";

src/transaction.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,7 +1610,7 @@ std::string Transaction::toJSON(int parts) {
16101610

16111611
if (parts & audit_log::AuditLog::CAuditLogPart) {
16121612
// FIXME: check for the binary content size.
1613-
LOGFY_ADD("body", this->m_requestBody.str());
1613+
LOGFY_ADD("body", utils::string::toHexIfNeeded(this->m_requestBody.str()));
16141614
}
16151615

16161616
/* request headers */
@@ -1712,7 +1712,7 @@ std::string Transaction::toJSON(int parts) {
17121712
LOGFY_ADD("ruleId", std::to_string(a.m_rule.m_ruleId));
17131713
LOGFY_ADD("file", a.m_rule.getFileName());
17141714
LOGFY_ADD("lineNumber", std::to_string(a.m_rule.getLineNumber()));
1715-
LOGFY_ADD("data", a.m_data);
1715+
LOGFY_ADD("data", utils::string::toHexIfNeeded(a.m_data));
17161716
LOGFY_ADD("severity", std::to_string(a.m_severity));
17171717
LOGFY_ADD("ver", a.m_rule.m_ver);
17181718
LOGFY_ADD("rev", a.m_rule.m_rev);

test/test-cases/regression/auditlog.json

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,5 +536,64 @@
536536
"SecAuditLogType Serial",
537537
"SecAuditLogRelevantStatus \"^(?:5|4(?!04))\""
538538
]
539+
},
540+
{
541+
"enabled": 1,
542+
"version_min": 300000,
543+
"version_max": 0,
544+
"title": "auditlog : Binary char from input",
545+
"client": {
546+
"ip": "200.249.12.31",
547+
"port": 2313
548+
},
549+
"server": {
550+
"ip": "200.249.12.31",
551+
"port": 80
552+
},
553+
"request": {
554+
"headers": {
555+
"Host": "www.modsecurity.org",
556+
"User-Agent": "Mozilla\/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.5) Gecko\/20091102 Firefox\/3.5.5 (.NET CLR 3.5.30729)",
557+
"Accept": "text\/html,application\/xhtml+xml,application\/xml;q=0.9,*\/*;q=0.8",
558+
"Accept-Language": "en-us,en;q=0.5",
559+
"Accept-Encoding": "gzip,deflate",
560+
"Accept-Charset": "ISO-8859-1,utf-8;q=0.7,*;q=0.7",
561+
"Keep-Alive": "300",
562+
"Connection": "keep-alive",
563+
"Pragma": "no-cache",
564+
"Cache-Control": "no-cache"
565+
},
566+
"uri": "\/?%ADd+allow%3d1+%ADd+auto",
567+
"method": "GET",
568+
"http_version": 1.1,
569+
"body": ""
570+
},
571+
"response": {
572+
"headers": {
573+
"Content-Type": "plain\/text\n\r"
574+
},
575+
"body": [
576+
"test"
577+
]
578+
},
579+
"expected": {
580+
"audit_log": "\"match\":\"Matched \\\\\"Operator `ValidateUtf8Encoding' with parameter `' against variable `ARGS_NAMES:\\\\\\\\xadd allow=1 \\\\\\\\xadd auto' \\(Value: `\\\\\\\\xadd allow=1 \\\\\\\\xadd auto' \\)\"",
581+
"debug_log": "",
582+
"error_log": "",
583+
"http_code": 403
584+
},
585+
"rules": [
586+
"SecRuleEngine On",
587+
"SecRule REQUEST_FILENAME|ARGS|ARGS_NAMES \"@validateUtf8Encoding\" \"id:920250,phase:2,deny,t:none,msg:'UTF8 Encoding Abuse Attack Attempt',logdata:'%{MATCHED_VAR}'",
588+
"SecAuditEngine RelevantOnly",
589+
"SecAuditLogParts ABHJZ",
590+
"SecAuditLogFormat JSON",
591+
"SecAuditLogStorageDir /tmp/test",
592+
"SecAuditLog /tmp/audit_test_prefix.log",
593+
"SecAuditLogDirMode 0766",
594+
"SecAuditLogFileMode 0600",
595+
"SecAuditLogType Serial",
596+
"SecAuditLogRelevantStatus \"^(?:5|4(?!04))\""
597+
]
539598
}
540599
]

0 commit comments

Comments
 (0)