Hello @mainevent_07 !
I managed to make it work locally, but I don’t know exactly what went wrong on your side, so let me detail my setup and hopefully you’ll figure out what was wrong in yours
On the parser side, I modified it a bit so that the timestamp is correctly captured (it allows to test scenarios etc on “cold” logs) :
filter: "evt.Line.Labels.type == 'vpnserver'"
#debug: true
onsuccess: next_stage
name: crowdsecurity/vpnserver-logs
description: "Parse vpnserver logs"
grok:
pattern: '%{TIMESTAMP_ISO8601:time_local} IPsec IKE Session \(IKE SA\) \d+ \(Client: \d+\) \(%{IP:src_ip}:.*A new IKE SA \(Main Mode\) is created. Initiator Cookie:'
apply_on: message
statics:
- meta: log_type
value: vpnserver_ipsec
- meta: source_ip
expression: "evt.Parsed.src_ip"
- target: evt.StrTime
expression: evt.Parsed.time_local
ps: note I captured the timestamp at the beginning of the lines and put it into evt.StrTime
so that dateparse-enrich can deal with it
On the scenario, there was a mismatch between the event type produced by the parser and the one expected by the scenario :
type: leaky
name: bruteforce-by-range
#debug: true
description: "Detect ipsec bruteforce from range"
filter: "evt.Meta.SourceRange != '' && evt.Meta.log_type == 'vpnserver_ipsec'"
groupby: "evt.Meta.SourceRange"
distinct: "evt.Meta.source_ip"
leakspeed: "30s"
capacity: 5
blackhole: 1m
labels:
service: vpn
type: range_bruteforce
remediation: true
scope:
type: Range
expression: evt.Meta.SourceRange
And when it comes to the profile, I simply add the profile your created to my local one :
name: default_range_remediation
debug: true
filters:
- Alert.Remediation == true && Alert.GetScope() == "Range"
decisions:
- type: ban
duration: 1h
on_success: break
---
name: default_ip_remediation
#debug: true
filters:
- Alert.Remediation == true && Alert.GetScope() == "Ip"
decisions:
- type: ban
duration: 4h
on_success: break
With those, I was able to process logs and get the expected decision. Given the log
2021-12-06 13:01:36.969 IPsec IKE Session (IKE SA) 3825548 (Client: 633372) (141.210.0.32:34821 -> 92.242.43.237:4500): A new IKE SA (Main Mode) is created. Initiator Cookie: 0xC9832C40B1D51852, Responder Cookie: 0x3BAA831BBA7A12B4, DH Group: MODP 1024 (Group 2), Hash Algorithm: SHA-1, Cipher Algorithm: 3DES-CBC, Cipher Key Size: 192 bits, Lifetime: 4294967295 Kbytes or 1 seconds
2021-12-06 13:01:36.969 IPsec IKE Session (IKE SA) 3825548 (Client: 633372) (141.210.0.33:34821 -> 92.242.43.237:4500): A new IKE SA (Main Mode) is created. Initiator Cookie: 0xC9832C40B1D51852, Responder Cookie: 0x3BAA831BBA7A12B4, DH Group: MODP 1024 (Group 2), Hash Algorithm: SHA-1, Cipher Algorithm: 3DES-CBC, Cipher Key Size: 192 bits, Lifetime: 4294967295 Kbytes or 1 seconds
2021-12-06 13:01:36.969 IPsec IKE Session (IKE SA) 3825548 (Client: 633372) (141.210.0.34:34821 -> 92.242.43.237:4500): A new IKE SA (Main Mode) is created. Initiator Cookie: 0xC9832C40B1D51852, Responder Cookie: 0x3BAA831BBA7A12B4, DH Group: MODP 1024 (Group 2), Hash Algorithm: SHA-1, Cipher Algorithm: 3DES-CBC, Cipher Key Size: 192 bits, Lifetime: 4294967295 Kbytes or 1 seconds
2021-12-06 13:01:36.969 IPsec IKE Session (IKE SA) 3825548 (Client: 633372) (141.210.0.35:34821 -> 92.242.43.237:4500): A new IKE SA (Main Mode) is created. Initiator Cookie: 0xC9832C40B1D51852, Responder Cookie: 0x3BAA831BBA7A12B4, DH Group: MODP 1024 (Group 2), Hash Algorithm: SHA-1, Cipher Algorithm: 3DES-CBC, Cipher Key Size: 192 bits, Lifetime: 4294967295 Kbytes or 1 seconds
2021-12-06 13:01:36.969 IPsec IKE Session (IKE SA) 3825548 (Client: 633372) (141.210.0.36:34821 -> 92.242.43.237:4500): A new IKE SA (Main Mode) is created. Initiator Cookie: 0xC9832C40B1D51852, Responder Cookie: 0x3BAA831BBA7A12B4, DH Group: MODP 1024 (Group 2), Hash Algorithm: SHA-1, Cipher Algorithm: 3DES-CBC, Cipher Key Size: 192 bits, Lifetime: 4294967295 Kbytes or 1 seconds
2021-12-06 13:01:36.969 IPsec IKE Session (IKE SA) 3825548 (Client: 633372) (141.210.0.37:34821 -> 92.242.43.237:4500): A new IKE SA (Main Mode) is created. Initiator Cookie: 0xC9832C40B1D51852, Responder Cookie: 0x3BAA831BBA7A12B4, DH Group: MODP 1024 (Group 2), Hash Algorithm: SHA-1, Cipher Algorithm: 3DES-CBC, Cipher Key Size: 192 bits, Lifetime: 4294967295 Kbytes or 1 seconds
2021-12-06 13:01:36.969 IPsec IKE Session (IKE SA) 3825548 (Client: 633372) (141.210.0.38:34821 -> 92.242.43.237:4500): A new IKE SA (Main Mode) is created. Initiator Cookie: 0xC9832C40B1D51852, Responder Cookie: 0x3BAA831BBA7A12B4, DH Group: MODP 1024 (Group 2), Hash Algorithm: SHA-1, Cipher Algorithm: 3DES-CBC, Cipher Key Size: 192 bits, Lifetime: 4294967295 Kbytes or 1 seconds
2021-12-06 13:01:36.969 IPsec IKE Session (IKE SA) 3825548 (Client: 633372) (141.210.0.39:34821 -> 92.242.43.237:4500): A new IKE SA (Main Mode) is created. Initiator Cookie: 0xC9832C40B1D51852, Responder Cookie: 0x3BAA831BBA7A12B4, DH Group: MODP 1024 (Group 2), Hash Algorithm: SHA-1, Cipher Algorithm: 3DES-CBC, Cipher Key Size: 192 bits, Lifetime: 4294967295 Kbytes or 1 seconds
2021-12-06 13:01:36.969 IPsec IKE Session (IKE SA) 3825548 (Client: 633372) (141.210.0.32:34821 -> 92.242.43.237:4500): A new IKE SA (Main Mode) is created. Initiator Cookie: 0xC9832C40B1D51852, Responder Cookie: 0x3BAA831BBA7A12B4, DH Group: MODP 1024 (Group 2), Hash Algorithm: SHA-1, Cipher Algorithm: 3DES-CBC, Cipher Key Size: 192 bits, Lifetime: 4294967295 Kbytes or 1 seconds
2021-12-06 13:01:36.969 IPsec IKE Session (IKE SA) 3825548 (Client: 633372) (141.210.0.33:34821 -> 92.242.43.237:4500): A new IKE SA (Main Mode) is created. Initiator Cookie: 0xC9832C40B1D51852, Responder Cookie: 0x3BAA831BBA7A12B4, DH Group: MODP 1024 (Group 2), Hash Algorithm: SHA-1, Cipher Algorithm: 3DES-CBC, Cipher Key Size: 192 bits, Lifetime: 4294967295 Kbytes or 1 seconds
2021-12-06 13:01:36.969 IPsec IKE Session (IKE SA) 3825548 (Client: 633372) (141.210.0.34:34821 -> 92.242.43.237:4500): A new IKE SA (Main Mode) is created. Initiator Cookie: 0xC9832C40B1D51852, Responder Cookie: 0x3BAA831BBA7A12B4, DH Group: MODP 1024 (Group 2), Hash Algorithm: SHA-1, Cipher Algorithm: 3DES-CBC, Cipher Key Size: 192 bits, Lifetime: 4294967295 Kbytes or 1 seconds
2021-12-06 13:01:36.969 IPsec IKE Session (IKE SA) 3825548 (Client: 633372) (141.210.0.35:34821 -> 92.242.43.237:4500): A new IKE SA (Main Mode) is created. Initiator Cookie: 0xC9832C40B1D51852, Responder Cookie: 0x3BAA831BBA7A12B4, DH Group: MODP 1024 (Group 2), Hash Algorithm: SHA-1, Cipher Algorithm: 3DES-CBC, Cipher Key Size: 192 bits, Lifetime: 4294967295 Kbytes or 1 seconds
2021-12-06 13:01:36.969 IPsec IKE Session (IKE SA) 3825548 (Client: 633372) (141.210.0.36:34821 -> 92.242.43.237:4500): A new IKE SA (Main Mode) is created. Initiator Cookie: 0xC9832C40B1D51852, Responder Cookie: 0x3BAA831BBA7A12B4, DH Group: MODP 1024 (Group 2), Hash Algorithm: SHA-1, Cipher Algorithm: 3DES-CBC, Cipher Key Size: 192 bits, Lifetime: 4294967295 Kbytes or 1 seconds
2021-12-06 13:01:36.969 IPsec IKE Session (IKE SA) 3825548 (Client: 633372) (141.210.0.37:34821 -> 92.242.43.237:4500): A new IKE SA (Main Mode) is created. Initiator Cookie: 0xC9832C40B1D51852, Responder Cookie: 0x3BAA831BBA7A12B4, DH Group: MODP 1024 (Group 2), Hash Algorithm: SHA-1, Cipher Algorithm: 3DES-CBC, Cipher Key Size: 192 bits, Lifetime: 4294967295 Kbytes or 1 seconds
2021-12-06 13:01:36.969 IPsec IKE Session (IKE SA) 3825548 (Client: 633372) (141.210.0.38:34821 -> 92.242.43.237:4500): A new IKE SA (Main Mode) is created. Initiator Cookie: 0xC9832C40B1D51852, Responder Cookie: 0x3BAA831BBA7A12B4, DH Group: MODP 1024 (Group 2), Hash Algorithm: SHA-1, Cipher Algorithm: 3DES-CBC, Cipher Key Size: 192 bits, Lifetime: 4294967295 Kbytes or 1 seconds
2021-12-06 13:01:36.969 IPsec IKE Session (IKE SA) 3825548 (Client: 633372) (141.210.0.39:34821 -> 92.242.43.237:4500): A new IKE SA (Main Mode) is created. Initiator Cookie: 0xC9832C40B1D51852, Responder Cookie: 0x3BAA831BBA7A12B4, DH Group: MODP 1024 (Group 2), Hash Algorithm: SHA-1, Cipher Algorithm: 3DES-CBC, Cipher Key Size: 192 bits, Lifetime: 4294967295 Kbytes or 1 seconds
2021-12-06 13:01:36.969 IPsec IKE Session (IKE SA) 3825548 (Client: 633372) (141.210.0.40:34821 -> 92.242.43.237:4500): A new IKE SA (Main Mode) is created. Initiator Cookie: 0xC9832C40B1D51852, Responder Cookie: 0x3BAA831BBA7A12B4, DH Group: MODP 1024 (Group 2), Hash Algorithm: SHA-1, Cipher Algorithm: 3DES-CBC, Cipher Key Size: 192 bits, Lifetime: 4294967295 Kbytes or 1 seconds
note : I updated the timestamp to be “now” so that I can see the decision with cscli (if the log is too old, the decision will be deleted immediately as it expired - the log timestamp is what matter in cold logs).
I get the expected results :
./crowdsec -c dev.yaml -dsn file:///home/bui/Downloads/to_cs_community/vpn.log -type vpnserver
INFO[06-12-2021 13:55:08] Range 141.210.0.0/16 performed 'bruteforce-by-range' (6 events over 0s) at 2021-12-06 13:01:36.969 +0000 UTC
INFO[06-12-2021 13:55:09] (test/crowdsec) bruteforce-by-range by range 141.210.0.0/16 (US/237) : 1h ban on Range 141.210.0.0/16
and from cscli
:
▶ ./cscli -c dev.yaml decisions list
+----+----------+----------------------+---------------------+--------+---------+------------------------+--------+-------------------+----------+
| ID | SOURCE | SCOPE:VALUE | REASON | ACTION | COUNTRY | AS | EVENTS | EXPIRATION | ALERT ID |
+----+----------+----------------------+---------------------+--------+---------+------------------------+--------+-------------------+----------+
| 5 | crowdsec | Range:141.210.0.0/16 | bruteforce-by-range | ban | US | 237 Merit Network Inc. | 6 | 1h6m22.970722723s | 5 |
+----+----------+----------------------+---------------------+--------+---------+------------------------+--------+-------------------+----------+
Please let me know if you need some further help and/or if you figured it out
and btw, what VPN server is it ? would you mind contributing your parser to the GitHub - crowdsecurity/hub: Main repository for crowdsec scenarios/parsers ? It would be super useful !
Cheers,