Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Fix the port_scan_enrichment alert plugin (#1547)
Browse files Browse the repository at this point in the history
  • Loading branch information
arcrose committed Apr 15, 2020
1 parent d005603 commit d4c3514
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
16 changes: 9 additions & 7 deletions alerts/plugins/port_scan_enrichment.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class message(object):

def __init__(self):
# Run plugin on portscan alerts
self.registration = 'portscan'
self.registration = ['portscan']

config = _load_config(CONFIG_FILE)

Expand Down Expand Up @@ -185,15 +185,17 @@ def enrich(alert, search_fn, search_window, max_connections):
for hit in results.get('hits', [])
]

alert['details'] = {
'recentconnections': []
}
details = alert.get('details', {})

for event in take(events, max_connections):
alert['details']['recentconnections'].append({
details['recentconnections'] = [
{
'destinationipaddress': event['details']['destinationipaddress'],
'destinationport': event['details']['destinationport'],
'timestamp': event['timestamp']
})
}
for event in take(events, max_connections)
]

alert['details'] = details

return alert
6 changes: 5 additions & 1 deletion tests/alerts/plugins/test_port_scan_enrichment.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ def test_alert_enriched(self):
},
}
}
]
],
'details': {
'something': 'original'
}
}

search_window = {
Expand All @@ -81,3 +84,4 @@ def test_alert_enriched(self):
assert enriched['details']['recentconnections'][0]['destinationipaddress'] in ['1.2.3.4', '4.3.2.1']
assert enriched['details']['recentconnections'][0]['destinationport'] in [80, 443]
assert enriched['details']['recentconnections'][0]['timestamp'] == EXAMPLE_TIMESTAMP
assert enriched['details']['something'] == 'original'

0 comments on commit d4c3514

Please sign in to comment.