Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions docs/deployment/database-audit.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,19 @@ Use the database's native audit facility first. Then pick one of two paths into
[ASVS pack](../security/asvs-logging-pack.md) policy `BWR-PACK-ASVS-DB-AUDIT` selects them,
and they land in `BowerSecurity_CL` beside the application events.

Bower doesn't ship a parser for any of these formats yet. The
[file tail](file-tail-source.md) and [syslog](syslog-source.md) sources plus a
[custom parser](../developer-integration/custom-log-parser.md) are the building blocks;
each format still needs its own signed parser, privacy fixtures and samples before it counts
as supported.
Bower ships four signed parsers in `packs/owasp-asvs-app-logging/parsers/` for self-managed
database audit streams:

- `pgaudit-jsonlog.json` — PostgreSQL 15+ `jsonlog` `AUDIT:` and password-failure records
- `mysql-audit-json.json` — MySQL Enterprise Audit and Percona `audit_log_filter` JSON records
- `mongodb-audit-json.json` — MongoDB Enterprise / Atlas JSON audit records
- `sqlserver-audit-33205.json` — SQL Server Audit Windows Event ID `33205` via the Windows Event Log source

Pair them with the [file tail](file-tail-source.md), [syslog](syslog-source.md) or
[Windows Event Log](windows-event-log-source.md) source. Every parser maps only allow-listed
security metadata (`actor.username`, `source.ipAddress`, `target.name`, `labels.dbEngine`,
`labels.dbStatementClass`) and drops raw SQL or command statements before redaction and
persistence. Cosmos DB continues to use Azure native diagnostic settings (path 1).

## The `database_audit` event

Expand Down
7 changes: 6 additions & 1 deletion packs/owasp-asvs-app-logging/pack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: bower.security/v1
kind: Pack
metadata:
id: owasp-asvs-app-logging
version: 1.0.0
version: 1.1.0
name: OWASP ASVS 5.0 application security logging
description: >-
Starter pack for the security events OWASP ASVS 5.0 chapter V16 asks applications to
Expand All @@ -28,6 +28,11 @@ policies:
- policies/errors-and-control-failures.yaml
- policies/database-audit.yaml
privacyProfile: privacy.yaml
parsers:
- parsers/pgaudit-jsonlog.json
- parsers/mysql-audit-json.json
- parsers/mongodb-audit-json.json
- parsers/sqlserver-audit-33205.json
detections:
- detections/mfa-factor-removed.yml
- detections/authorisation-stale-grant.yml
Expand Down
99 changes: 99 additions & 0 deletions packs/owasp-asvs-app-logging/parsers/mongodb-audit-json.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{
"version": "1.0",
"format": "Json",
"fields": [
{ "sourceName": "atype", "type": "Text", "ocsfPath": null, "asimField": null, "sensitive": false },
{ "sourceName": "uuid", "type": "Text", "ocsfPath": "metadata.uid", "asimField": "EventOriginalUid", "sensitive": false },
{ "sourceName": "result", "type": "WholeNumber", "ocsfPath": null, "asimField": null, "sensitive": false },
{ "sourceName": "event_id", "type": "Text", "ocsfPath": "metadata.uid", "asimField": "EventOriginalUid", "sensitive": true },
{ "sourceName": "event_time", "type": "DateTime", "ocsfPath": "time", "asimField": "TimeGenerated", "sensitive": true },
{ "sourceName": "event_category", "type": "Text", "ocsfPath": "category_name", "asimField": "EventType", "sensitive": true },
{ "sourceName": "event_action", "type": "Text", "ocsfPath": "activity_name", "asimField": "EventSubType", "sensitive": true },
{ "sourceName": "event_result", "type": "Text", "ocsfPath": "status", "asimField": "EventResult", "sensitive": true },
{ "sourceName": "actor_user", "type": "Text", "ocsfPath": "actor.user.name", "asimField": "TargetUsername", "sensitive": true },
{ "sourceName": "source_ip", "type": "IpAddress", "ocsfPath": "src_endpoint.ip", "asimField": "SrcIpAddr", "sensitive": true },
{ "sourceName": "target_type", "type": "Text", "ocsfPath": null, "asimField": null, "sensitive": false },
{ "sourceName": "target_name", "type": "Text", "ocsfPath": "database.name", "asimField": "TargetAppName", "sensitive": true },
{ "sourceName": "db_engine", "type": "Text", "ocsfPath": null, "asimField": null, "sensitive": false },
{ "sourceName": "statement_class", "type": "Text", "ocsfPath": null, "asimField": null, "sensitive": false },
{ "sourceName": "reason", "type": "Text", "ocsfPath": "status_detail", "asimField": "EventResultDetails", "sensitive": true },
{ "sourceName": "matched", "type": "Text", "ocsfPath": null, "asimField": null, "sensitive": true }
],
"runtime": {
"applicationName": "mongodb-audit",
"environment": "production",
"eventCategory": "administrative-activity",
"eventType": "database_audit",
"eventAction": "db.dcl",
"eventResult": "success",
"transforms": [
".event_time = parse_timestamp(coalesce(.ts.\"$date\", .ts), \"rfc3339\")",
".event_id = concat(\"mongodb-audit-\", coalesce(.uuid.\"$binary\", .uuid, .event_time))",
".u0 = at(.users, 0)",
".actor_user = coalesce(.u0.user, .param.user)",
".ipm = regex_extract(.remote.ip, '^(?<ip>[0-9A-Fa-f.:]{2,45})$')",
".source_ip = .ipm.ip",
".target_type = \"database\"",
".target_name = coalesce(.param.ns, .param.db, .u0.db, \"admin\")",
".db_engine = \"mongodb\"",
".statement_class = .atype",
".ma = lookup(\"actions\", .atype)",
".matched = \"ignored\"",
"if .ma != null && .actor_user != null { .matched = \"yes\"; .event_category = lookup(\"categories\", .atype); .event_action = .ma; .event_result = \"success\"; .reason = .atype }",
"if .matched == \"yes\" && .result != 0 { .event_result = \"failure\"; .reason = concat(\"MongoResult_\", to_string(.result)) }",
"if .matched == \"yes\" && .atype == \"authenticate\" && .result != 0 { .event_action = \"db.logon_failure\" }",
"del(.u0)",
"del(.ipm)",
"del(.ma)"
],
"tables": {
"actions": {
"authenticate": "db.logon",
"logout": "db.logoff",
"createUser": "db.dcl",
"dropUser": "db.dcl",
"grantRolesToUser": "db.dcl",
"revokeRolesFromUser": "db.dcl",
"createRole": "db.dcl",
"dropRole": "db.dcl",
"createCollection": "db.ddl",
"dropCollection": "db.ddl",
"dropDatabase": "db.ddl",
"authCheck": "db.sensitive_read",
"shutdown": "db.privileged"
},
"categories": {
"authenticate": "authentication",
"logout": "authentication",
"createUser": "administrative-activity",
"dropUser": "administrative-activity",
"grantRolesToUser": "administrative-activity",
"revokeRolesFromUser": "administrative-activity",
"createRole": "administrative-activity",
"dropRole": "administrative-activity",
"createCollection": "administrative-activity",
"dropCollection": "administrative-activity",
"dropDatabase": "administrative-activity",
"authCheck": "data-access",
"shutdown": "administrative-activity"
}
},
"match": {
"matched": "yes"
},
"fields": {
"eventId": "event_id",
"timeGenerated": "event_time",
"eventCategory": "event_category",
"eventAction": "event_action",
"eventResult": "event_result",
"actor.username": "actor_user",
"source.ipAddress": "source_ip",
"target.type": "target_type",
"target.name": "target_name",
"labels.dbEngine": "db_engine",
"labels.dbStatementClass": "statement_class",
"eventOutcomeReason": "reason"
}
}
}
111 changes: 111 additions & 0 deletions packs/owasp-asvs-app-logging/parsers/mysql-audit-json.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
{
"version": "1.0",
"format": "Json",
"fields": [
{ "sourceName": "timestamp", "type": "Text", "ocsfPath": "time", "asimField": "TimeGenerated", "sensitive": false },
{ "sourceName": "id", "type": "Text", "ocsfPath": "metadata.uid", "asimField": "EventOriginalUid", "sensitive": false },
{ "sourceName": "class", "type": "Text", "ocsfPath": null, "asimField": null, "sensitive": false },
{ "sourceName": "event", "type": "Text", "ocsfPath": null, "asimField": null, "sensitive": false },
{ "sourceName": "user", "type": "Text", "ocsfPath": "actor.user.name", "asimField": "TargetUsername", "sensitive": true },
{ "sourceName": "ip", "type": "Text", "ocsfPath": "src_endpoint.ip", "asimField": "SrcIpAddr", "sensitive": true },
{ "sourceName": "db", "type": "Text", "ocsfPath": "database.name", "asimField": "TargetAppName", "sensitive": false },
{ "sourceName": "command", "type": "Text", "ocsfPath": null, "asimField": null, "sensitive": false },
{ "sourceName": "status", "type": "WholeNumber", "ocsfPath": null, "asimField": null, "sensitive": false },
{ "sourceName": "event_id", "type": "Text", "ocsfPath": "metadata.uid", "asimField": "EventOriginalUid", "sensitive": false },
{ "sourceName": "event_time", "type": "DateTime", "ocsfPath": "time", "asimField": "TimeGenerated", "sensitive": false },
{ "sourceName": "event_category", "type": "Text", "ocsfPath": "category_name", "asimField": "EventType", "sensitive": true },
{ "sourceName": "event_action", "type": "Text", "ocsfPath": "activity_name", "asimField": "EventSubType", "sensitive": true },
{ "sourceName": "event_result", "type": "Text", "ocsfPath": "status", "asimField": "EventResult", "sensitive": true },
{ "sourceName": "actor_user", "type": "Text", "ocsfPath": "actor.user.name", "asimField": "TargetUsername", "sensitive": true },
{ "sourceName": "source_ip", "type": "IpAddress", "ocsfPath": "src_endpoint.ip", "asimField": "SrcIpAddr", "sensitive": true },
{ "sourceName": "target_type", "type": "Text", "ocsfPath": null, "asimField": null, "sensitive": false },
{ "sourceName": "target_name", "type": "Text", "ocsfPath": "database.name", "asimField": "TargetAppName", "sensitive": true },
{ "sourceName": "db_engine", "type": "Text", "ocsfPath": null, "asimField": null, "sensitive": false },
{ "sourceName": "statement_class", "type": "Text", "ocsfPath": null, "asimField": null, "sensitive": true },
{ "sourceName": "reason", "type": "Text", "ocsfPath": "status_detail", "asimField": "EventResultDetails", "sensitive": true },
{ "sourceName": "matched", "type": "Text", "ocsfPath": null, "asimField": null, "sensitive": true }
],
"runtime": {
"applicationName": "mysql-audit",
"environment": "production",
"eventCategory": "data-access",
"eventType": "database_audit",
"eventAction": "db.ddl",
"eventResult": "success",
"transforms": [
".event_time = parse_timestamp(.timestamp, \"rfc3339\")",
".event_id = concat(\"mysql-audit-\", to_string(.id))",
".actor_user = coalesce(.account.user, .user)",
".ipm = regex_extract(coalesce(.ip, .connection_data.ip), '^(?<ip>[0-9A-Fa-f.:]{2,45})$')",
".source_ip = .ipm.ip",
".target_type = \"database\"",
".target_name = coalesce(.db, .table_access_data.db, .connection_data.db, \"mysql\")",
".db_engine = \"mysql\"",
".cmd = upper(coalesce(.command, .general_data.sql_command, .event, \"\"))",
".st = coalesce(.status, .connection_data.status, .general_data.status, 0)",
".matched = \"ignored\"",
"if .class == \"connection\" && .event == \"connect\" && .actor_user != null { .matched = \"yes\"; .event_category = \"authentication\"; .statement_class = \"CONNECT\" }",
"if .matched == \"yes\" && .class == \"connection\" && .event == \"connect\" && .st == 0 { .event_action = \"db.logon\"; .event_result = \"success\"; .reason = \"ConnectSucceeded\" }",
"if .matched == \"yes\" && .class == \"connection\" && .event == \"connect\" && .st != 0 { .event_action = \"db.logon_failure\"; .event_result = \"failure\"; .reason = concat(\"MySqlStatus_\", to_string(.st)) }",
"if .class == \"connection\" && .event == \"disconnect\" && .actor_user != null { .matched = \"yes\"; .event_category = \"authentication\"; .event_action = \"db.logoff\"; .event_result = \"success\"; .statement_class = \"DISCONNECT\"; .reason = \"Disconnect\" }",
"if .matched == \"ignored\" && lookup(\"actions\", .cmd) != null && .actor_user != null { .matched = \"yes\"; .event_action = lookup(\"actions\", .cmd); .event_category = lookup(\"categories\", .cmd); .statement_class = .cmd; .event_result = \"success\"; .reason = .cmd }",
"if .matched == \"yes\" && .class != \"connection\" && .st != 0 { .event_action = \"db.query_error\"; .event_category = \"data-access\"; .event_result = \"failure\"; .reason = concat(\"MySqlStatus_\", to_string(.st)) }",
"del(.ipm)",
"del(.cmd)",
"del(.st)"
],
"tables": {
"actions": {
"CREATE_TABLE": "db.ddl",
"ALTER_TABLE": "db.ddl",
"DROP_TABLE": "db.ddl",
"CREATE_DB": "db.ddl",
"DROP_DB": "db.ddl",
"GRANT": "db.dcl",
"REVOKE": "db.dcl",
"CREATE_USER": "db.dcl",
"DROP_USER": "db.dcl",
"ALTER_USER": "db.dcl",
"SELECT": "db.sensitive_read",
"READ": "db.sensitive_read",
"INSERT": "db.sensitive_write",
"UPDATE": "db.sensitive_write",
"DELETE": "db.sensitive_write"
},
"categories": {
"CREATE_TABLE": "administrative-activity",
"ALTER_TABLE": "administrative-activity",
"DROP_TABLE": "administrative-activity",
"CREATE_DB": "administrative-activity",
"DROP_DB": "administrative-activity",
"GRANT": "administrative-activity",
"REVOKE": "administrative-activity",
"CREATE_USER": "administrative-activity",
"DROP_USER": "administrative-activity",
"ALTER_USER": "administrative-activity",
"SELECT": "data-access",
"READ": "data-access",
"INSERT": "data-access",
"UPDATE": "data-access",
"DELETE": "data-access"
}
},
"match": {
"matched": "yes"
},
"fields": {
"eventId": "event_id",
"timeGenerated": "event_time",
"eventCategory": "event_category",
"eventAction": "event_action",
"eventResult": "event_result",
"actor.username": "actor_user",
"source.ipAddress": "source_ip",
"target.type": "target_type",
"target.name": "target_name",
"labels.dbEngine": "db_engine",
"labels.dbStatementClass": "statement_class",
"eventOutcomeReason": "reason"
}
}
}
84 changes: 84 additions & 0 deletions packs/owasp-asvs-app-logging/parsers/pgaudit-jsonlog.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"version": "1.0",
"format": "Json",
"fields": [
{ "sourceName": "timestamp", "type": "Text", "ocsfPath": "time", "asimField": "TimeGenerated", "sensitive": false },
{ "sourceName": "session_id", "type": "Text", "ocsfPath": "metadata.uid", "asimField": "EventOriginalUid", "sensitive": false },
{ "sourceName": "session_line_num", "type": "WholeNumber", "ocsfPath": null, "asimField": null, "sensitive": false },
{ "sourceName": "user", "type": "Text", "ocsfPath": "actor.user.name", "asimField": "TargetUsername", "sensitive": true },
{ "sourceName": "dbname", "type": "Text", "ocsfPath": "database.name", "asimField": "TargetAppName", "sensitive": false },
{ "sourceName": "remote_host", "type": "Text", "ocsfPath": "src_endpoint.ip", "asimField": "SrcIpAddr", "sensitive": true },
{ "sourceName": "error_severity", "type": "Text", "ocsfPath": "severity", "asimField": "EventSeverity", "sensitive": false },
{ "sourceName": "message", "type": "Text", "ocsfPath": "message", "asimField": "EventMessage", "sensitive": true },
{ "sourceName": "event_id", "type": "Text", "ocsfPath": "metadata.uid", "asimField": "EventOriginalUid", "sensitive": false },
{ "sourceName": "event_time", "type": "DateTime", "ocsfPath": "time", "asimField": "TimeGenerated", "sensitive": false },
{ "sourceName": "event_category", "type": "Text", "ocsfPath": "category_name", "asimField": "EventType", "sensitive": true },
{ "sourceName": "event_action", "type": "Text", "ocsfPath": "activity_name", "asimField": "EventSubType", "sensitive": true },
{ "sourceName": "event_result", "type": "Text", "ocsfPath": "status", "asimField": "EventResult", "sensitive": true },
{ "sourceName": "target_type", "type": "Text", "ocsfPath": null, "asimField": null, "sensitive": false },
{ "sourceName": "target_name", "type": "Text", "ocsfPath": "database.name", "asimField": "TargetAppName", "sensitive": false },
{ "sourceName": "source_ip", "type": "IpAddress", "ocsfPath": "src_endpoint.ip", "asimField": "SrcIpAddr", "sensitive": true },
{ "sourceName": "db_engine", "type": "Text", "ocsfPath": null, "asimField": null, "sensitive": false },
{ "sourceName": "statement_class", "type": "Text", "ocsfPath": null, "asimField": null, "sensitive": true },
{ "sourceName": "reason", "type": "Text", "ocsfPath": "status_detail", "asimField": "EventResultDetails", "sensitive": true },
{ "sourceName": "matched", "type": "Text", "ocsfPath": null, "asimField": null, "sensitive": true }
],
"runtime": {
"applicationName": "postgresql-pgaudit",
"environment": "production",
"eventCategory": "data-access",
"eventType": "database_audit",
"eventAction": "db.ddl",
"eventResult": "success",
"transforms": [
".event_time = parse_timestamp(.timestamp, \"rfc3339\")",
".event_id = concat(\"pgaudit-\", coalesce(.session_id, \"unknown\"), \"-\", coalesce(to_string(.session_line_num), \"0\"))",
".m = regex_extract(.message, '^AUDIT: (?:SESSION|OBJECT),[0-9]+,[0-9]+,(?<class>READ|WRITE|FUNCTION|ROLE|DDL|MISC|MISC_SET),(?<command>[A-Z0-9_ ]+),')",
".ipm = regex_extract(.remote_host, '^(?<ip>[0-9A-Fa-f.:]{2,45})$')",
".source_ip = .ipm.ip",
".target_type = \"database\"",
".target_name = coalesce(.dbname, \"postgres\")",
".db_engine = \"postgresql\"",
"if .m.class != null && .user != null { .matched = \"yes\"; .statement_class = .m.class; .event_action = coalesce(lookup(\"actions\", .m.class), \"db.privileged\"); .event_category = coalesce(lookup(\"categories\", .m.class), \"administrative-activity\"); .event_result = \"success\"; .reason = .m.command } else if contains(.message, \"password authentication failed\") && .user != null { .matched = \"yes\"; .statement_class = \"AUTH\"; .event_action = \"db.logon_failure\"; .event_category = \"authentication\"; .event_result = \"failure\"; .reason = \"PasswordAuthenticationFailed\" } else { .matched = \"ignored\" }",
"del(.m)",
"del(.ipm)"
],
"tables": {
"actions": {
"DDL": "db.ddl",
"ROLE": "db.dcl",
"READ": "db.sensitive_read",
"WRITE": "db.sensitive_write",
"FUNCTION": "db.privileged",
"MISC": "db.privileged",
"MISC_SET": "db.audit_config"
},
"categories": {
"DDL": "administrative-activity",
"ROLE": "administrative-activity",
"READ": "data-access",
"WRITE": "data-access",
"FUNCTION": "administrative-activity",
"MISC": "administrative-activity",
"MISC_SET": "administrative-activity"
}
},
"match": {
"matched": "yes"
},
"fields": {
"eventId": "event_id",
"timeGenerated": "event_time",
"eventCategory": "event_category",
"eventAction": "event_action",
"eventResult": "event_result",
"actor.username": "user",
"source.ipAddress": "source_ip",
"target.type": "target_type",
"target.name": "target_name",
"labels.dbEngine": "db_engine",
"labels.dbStatementClass": "statement_class",
"eventOutcomeReason": "reason"
}
}
}
Loading