Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E2E tests: Fix Brute Force tests #3235

Merged
merged 3 commits into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
- name: Search alert in alerts log
become: true
lineinfile:
path: /var/ossec/logs/alerts/alerts.json
regexp: "{{ custom_regex }}"
state: absent
check_mode: true
changed_when: false
register: alert
until: alert.found != 0
retries: "{{ attempts }}"
delay: "{{ time_btw_attempts }}"
3 changes: 2 additions & 1 deletion tests/end_to_end/data/env_requirements.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"agent": {
"instances": 1,
"distros": [
"Windows"
"Windows",
"Ubuntu"
]
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
- name: Configure local environment
hosts: localhost
hosts: ubuntu-agent
become: true
tasks:

# Install hydra to attempt the RDP brute force attack
- name: Install hydra
package:
name: hydra
name: hydra=9.2-1ubuntu1
state: present
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
tasks_from: truncate_alert_json.yaml

- name: Generate events
hosts: localhost
hosts: ubuntu-agent
tasks:

- name: Attempt a RDP brute force attack
Expand All @@ -22,18 +22,22 @@
- test_user
- test_user
- test_user
register: result
failed_when:
- "'0 valid password found' not in result.stdout"

- name: Wait for alert
wait_for:
timeout: 5

- name: Get alerts file
hosts: managers
tasks:

- name: Search alert in alerts log
include_role:
name: manage_alerts
tasks_from: search_alert.yaml
vars:
ts: \d+-\d+-\d+T\d+:\d+:\d+\.\d+[+|-]\d+
jmv74211 marked this conversation as resolved.
Show resolved Hide resolved
custom_regex: "{\"timestamp\":\"{{ ts }}\",\"rule\":{\"level\":{{ rule_level }},\
jmv74211 marked this conversation as resolved.
Show resolved Hide resolved
\"description\":\"{{ rule_description }}\",\"id\":\"{{ rule_id }}\".*"
attempts: 15
time_btw_attempts: 2

- name: Get alert json
include_role:
name: manage_alerts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@
rule.description: Multiple Windows logon failures.
extra:
mitre_technique: Brute Force
extra_vars:
rule_id: 60204
rule_level: 10
rule_description: Multiple Windows logon failures.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
responses:
(.*)continue connecting(.*): 'yes'
(?i)password: 1
timeout: 5
timeout: 15
loop:
- test_user
- test_user
Expand All @@ -33,14 +33,23 @@
failed_when:
- "'Permission denied' not in result.stdout"

- name: Wait for alert
wait_for:
timeout: 5

- name: Get alerts file
hosts: managers
vars:
ts:
jmv74211 marked this conversation as resolved.
Show resolved Hide resolved
tasks:

- name: Search alert in alerts log
include_role:
name: manage_alerts
tasks_from: search_alert.yaml
vars:
ts: \d+-\d+-\d+T\d+:\d+:\d+\.\d+[+|-]\d+
custom_regex: "{\"timestamp\":\"{{ ts }}\",\"rule\":{\"level\":{{ rule_level }},\
jmv74211 marked this conversation as resolved.
Show resolved Hide resolved
\"description\":\"{{ rule_description }}\",\"id\":\"{{ rule_id }}\".*"
attempts: 15
time_btw_attempts: 2

- name: Get alert json
include_role:
name: manage_alerts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@
rule.description: "sshd: brute force trying to get access to the system. Non existent user."
extra:
mitre_technique: Brute Force
extra_vars:
rule_id: 5712
rule_level: 10
rule_description: "sshd: brute force trying to get access to the system. Non existent user."