Skip to content

Instantly share code, notes, and snippets.

@wheresalice
Last active May 3, 2025 06:49
Show Gist options
  • Select an option

  • Save wheresalice/046b13fa6b16682821aa7f50d3171168 to your computer and use it in GitHub Desktop.

Select an option

Save wheresalice/046b13fa6b16682821aa7f50d3171168 to your computer and use it in GitHub Desktop.
Crowdsec configuration for mox mailserver logs

Custom collection for handling mox mail server logs in crowdsec. The HTTP logs are parsed as a standard http access log so that the standard scenarios work, the mail logs require a custom scenario

cat acquis.yaml >> /etc/crowdsec/acquis.yaml
mkdir -p /etc/crowdsec/parsers/s01-parsers/mox
mv mox-parser.yaml /etc/crowdsec/parsers/s01-parsers/mox/mox-parser.yaml
mkdir -p /etc/crowdsec/scenarios/mox
mv mox-auth-fail-scenario.yaml /etc/crowdsec/scenarios/mox/mox-auth-fail.yaml
cscli collections install crowdsecurity/base-http-scenarios
systemctl reload crowdsec
---
filenames:
- /var/log/mail.log
labels:
type: mail
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <https://unlicense.org/>
# Custom ecenario for mox authenitcation failures
name: mox-auth-failure
type: leaky
description: "Detect failed authentication attempts on mox service"
filter: "evt.Parsed.service == 'mox' && evt.Meta.event_type == 'failed_authentication'"
leakspeed: "600s"
capacity: 1
groupby: evt.Meta.source_ip
blackhole: 1m
reprocess: true
labels:
service: mox
spoofable: 0
confidence: 3
remediation: true
filter: "evt.Line.Labels.type == 'mail'"
name: mox/mox-parser
nodes:
- grok:
pattern: '^%{TIMESTAMP_ISO8601:timestamp}.*(result=badcreds|many auth failures).*'
apply_on: message
statics:
- parsed: kv_parsed
expression: ParseKV(evt.Line.Raw, evt.Unmarshaled, "message")
- target: evt.StrTime
expression: evt.Parsed.timestamp
- meta: event_type
value: failed_authentication
- parsed: service
value: "mox"
- meta: user
expression: evt.Unmarshaled.message.address
- meta: source_ip
expression: evt.Unmarshaled.message.remoteip
- grok:
pattern: '^%{TIMESTAMP_ISO8601:timestamp}.*"http request".*'
apply_on: message
statics:
- parsed: kv_parsed
expression: ParseKV(evt.Line.Raw, evt.Unmarshaled, "message")
- target: evt.StrTime
expression: evt.Parsed.timestamp
- meta: http_status
expression: evt.Unmarshaled.message.statuscode
- parsed: request
expression: evt.Unmarshaled.message.url
- meta: http_path
expression: evt.Unmarshaled.message.url
- meta: http_verb
expression: evt.Unmarshaled.message.method
- meta: http_user_agent
expression: evt.Unmarshaled.message.useragent
- meta: target_fqdn
expression: evt.Unmarshaled.message.host
- meta: source_ip
expression: Split(evt.Unmarshaled.message.remoteaddr, ":")[0]
- meta: log_type
value: http_access-log
- meta: service
value: http
statics:
- target: evt.StrTime
expression: evt.Parsed.timestamp
onsuccess: next_stage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment