Skip to content

Commit 1d00670

Browse files
enhance: change -3 to -4 to handle outliers in timebased bf (#1649)
1 parent 827ee0e commit 1d00670

File tree

4 files changed

+35
-14
lines changed

4 files changed

+35
-14
lines changed

.tests/ssh-time-based-bf/scenario.assert

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,17 @@ results[0].Overflow.Alert.Events[2].GetMeta("service") == "ssh"
2828
results[0].Overflow.Alert.Events[2].GetMeta("source_ip") == "10.0.0.101"
2929
results[0].Overflow.Alert.Events[2].GetMeta("target_user") == "oracle"
3030
results[0].Overflow.Alert.Events[2].GetMeta("timestamp") == "2026-09-30T11:40:00Z"
31+
basename(results[0].Overflow.Alert.Events[3].GetMeta("datasource_path")) == "ssh-time-based-bf.log"
32+
results[0].Overflow.Alert.Events[3].GetMeta("datasource_type") == "file"
33+
results[0].Overflow.Alert.Events[3].GetMeta("log_type") == "ssh_failed-auth"
34+
results[0].Overflow.Alert.Events[3].GetMeta("machine") == "server"
35+
results[0].Overflow.Alert.Events[3].GetMeta("service") == "ssh"
36+
results[0].Overflow.Alert.Events[3].GetMeta("source_ip") == "10.0.0.101"
37+
results[0].Overflow.Alert.Events[3].GetMeta("target_user") == "postgres"
38+
results[0].Overflow.Alert.Events[3].GetMeta("timestamp") == "2026-09-30T12:00:00Z"
3139
results[0].Overflow.Alert.GetScenario() == "crowdsecurity/ssh-time-based-bf_user-enum"
3240
results[0].Overflow.Alert.Remediation == false
33-
results[0].Overflow.Alert.GetEventsCount() == 3
41+
results[0].Overflow.Alert.GetEventsCount() == 4
3442
"10.0.0.101" in results[1].Overflow.GetSources()
3543
results[1].Overflow.Sources["10.0.0.101"].IP == "10.0.0.101"
3644
results[1].Overflow.Sources["10.0.0.101"].Range == ""
@@ -60,6 +68,14 @@ results[1].Overflow.Alert.Events[2].GetMeta("service") == "ssh"
6068
results[1].Overflow.Alert.Events[2].GetMeta("source_ip") == "10.0.0.101"
6169
results[1].Overflow.Alert.Events[2].GetMeta("target_user") == "oracle"
6270
results[1].Overflow.Alert.Events[2].GetMeta("timestamp") == "2026-09-30T11:40:00Z"
71+
basename(results[1].Overflow.Alert.Events[3].GetMeta("datasource_path")) == "ssh-time-based-bf.log"
72+
results[1].Overflow.Alert.Events[3].GetMeta("datasource_type") == "file"
73+
results[1].Overflow.Alert.Events[3].GetMeta("log_type") == "ssh_failed-auth"
74+
results[1].Overflow.Alert.Events[3].GetMeta("machine") == "server"
75+
results[1].Overflow.Alert.Events[3].GetMeta("service") == "ssh"
76+
results[1].Overflow.Alert.Events[3].GetMeta("source_ip") == "10.0.0.101"
77+
results[1].Overflow.Alert.Events[3].GetMeta("target_user") == "postgres"
78+
results[1].Overflow.Alert.Events[3].GetMeta("timestamp") == "2026-09-30T12:00:00Z"
6379
results[1].Overflow.Alert.GetScenario() == "crowdsecurity/ssh-time-based-bf"
6480
results[1].Overflow.Alert.Remediation == false
65-
results[1].Overflow.Alert.GetEventsCount() == 3
81+
results[1].Overflow.Alert.GetEventsCount() == 4

.tests/ssh-time-based-bf/ssh-time-based-bf.log

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ Sep 30 10:12:00 server sshd[12347]: Invalid user guest from 10.0.0.100 port 5676
44
Sep 30 11:00:00 server sshd[12348]: Invalid user root from 10.0.0.101 port 56765
55
Sep 30 11:20:00 server sshd[12349]: Invalid user mysql from 10.0.0.101 port 56766
66
Sep 30 11:40:00 server sshd[12350]: Invalid user oracle from 10.0.0.101 port 56767
7-
Sep 30 12:00:00 server sshd[12351]: Invalid user postgres from 10.0.0.102 port 56768
8-
Sep 30 12:10:00 server sshd[12352]: Invalid user jenkins from 10.0.0.102 port 56769
9-
Sep 30 12:15:00 server sshd[12353]: Accepted password for jenkins from 10.0.0.102 port 56770 ssh2
10-
Sep 30 12:20:00 server sshd[12354]: Invalid user admin from 10.0.0.102 port 56771
7+
Sep 30 12:00:00 server sshd[12351]: Invalid user postgres from 10.0.0.101 port 56768
8+
Sep 30 12:30:00 server sshd[12352]: Invalid user admin from 10.0.0.102 port 56769
9+
Sep 30 12:40:00 server sshd[12353]: Invalid user test from 10.0.0.102 port 56770
10+
Sep 30 12:45:00 server sshd[12354]: Accepted password for test from 10.0.0.102 port 56771 ssh2
11+
Sep 30 12:50:00 server sshd[12355]: Invalid user guest from 10.0.0.102 port 56772
12+
Sep 30 13:00:00 server sshd[12356]: Invalid user root from 10.0.0.103 port 56773
13+
Sep 30 13:00:02 server sshd[12357]: Invalid user admin from 10.0.0.103 port 56774
14+
Sep 30 13:00:04 server sshd[12358]: Invalid user test from 10.0.0.103 port 56775
15+
Sep 30 14:00:04 server sshd[12359]: Invalid user guest from 10.0.0.103 port 56776

scenarios/crowdsecurity/ssh-time-based-bf.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Detect time-based ssh bruteforce attempts that evade traditional rate limiting with false positive reduction:
22

33
- Uses conditional type with capacity -1 (unlimited)
4-
- Triggers when at least 3 failed authentication attempts occur
4+
- Triggers when at least 4 failed authentication attempts occur
55
- Median interval between failed attempts exceeds 10 minutes
66
- **False positive reduction**: Uses `cancel_on` to cancel bucket if user successfully authenticates
77
- Prevents "forgot password" scenarios from triggering alerts
@@ -14,10 +14,10 @@ Detect time-based ssh bruteforce attempts that evade traditional rate limiting w
1414
- Requires `crowdsecurity/sshd-success-logs` parser for cancel_on functionality
1515

1616
**Two variants:**
17-
1. **ssh-time-based-bf**: Standard bruteforce detection (3 failed logins from same IP)
18-
2. **ssh-time-based-bf_user-enum**: User enumeration detection (3 distinct usernames from same IP)
17+
1. **ssh-time-based-bf**: Standard bruteforce detection (4 failed logins from same IP)
18+
2. **ssh-time-based-bf_user-enum**: User enumeration detection (4 distinct usernames from same IP)
1919

2020
This scenario complements the standard ssh-bf (capacity 5, leakspeed 10s) and ssh-slow-bf (capacity 10, leakspeed 60s) scenarios with no overlap:
2121
- ssh-bf catches 5 failures within ~50 seconds (rate-based)
2222
- ssh-slow-bf catches 10 failures within ~10 minutes (rate-based)
23-
- ssh-time-based-bf catches 3 failures with median interval >10 minutes (time-pattern-based, naturally capped by 2h leakspeed)
23+
- ssh-time-based-bf catches 4 failures with median interval >10 minutes (time-pattern-based, naturally capped by 2h leakspeed)

scenarios/crowdsecurity/ssh-time-based-bf.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ capacity: -1
88
cancel_on: "evt.Meta.log_type == 'auth_success'"
99
condition: |
1010
let failedAuths = filter(queue.Queue, {#.Meta.log_type == 'ssh_failed-auth'});
11-
len(failedAuths) >= 3 &&
12-
MedianInterval(map(failedAuths[-3:], {#.Time})) > duration("10m")
11+
len(failedAuths) >= 4 &&
12+
MedianInterval(map(failedAuths[-4:], {#.Time})) > duration("10m")
1313
leakspeed: 2h
1414
blackhole: 5m
1515
reprocess: true
@@ -34,8 +34,8 @@ capacity: -1
3434
cancel_on: "evt.Meta.log_type == 'auth_success'"
3535
condition: |
3636
let failedAuths = filter(queue.Queue, {#.Meta.log_type == 'ssh_failed-auth'});
37-
len(failedAuths) >= 3 &&
38-
MedianInterval(map(failedAuths[-3:], {#.Time})) > duration("10m")
37+
len(failedAuths) >= 4 &&
38+
MedianInterval(map(failedAuths[-4:], {#.Time})) > duration("10m")
3939
leakspeed: 2h
4040
blackhole: 5m
4141
reprocess: true

0 commit comments

Comments
 (0)