-
Notifications
You must be signed in to change notification settings - Fork 297
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
Improved Bambenek parser to better handle description #1451
base: develop
Are you sure you want to change the base?
Changes from 2 commits
debd147
e5b4372
56021be
f8dfa9b
87a11ed
4065494
ef4ec5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# -*- coding: utf-8 -*- | ||
""" IntelMQ parser for Bambenek DGA, Domain, and IP feeds """ | ||
|
||
import re | ||
from intelmq.lib.bot import ParserBot | ||
|
||
|
||
|
@@ -32,32 +33,33 @@ def parse_line(self, line, report): | |
self.tempdata.append(line) | ||
|
||
else: | ||
value = line.split(',') | ||
m = re.match(r"(?P<ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}),(?P<description>.*), \ | ||
(?P<timestamp>\d{4}-\d{2}-\d{2}[ ]\d{2}[:]\d{2}),(?P<url>.*)", line) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we change Can we |
||
values = m.groups() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That line raises an exception in the tests There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It could be my line split. I'm not sure how to break the regex line into two lines in order not to trigger the "Line too long" warning when it comes to code style checking. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just split the line like this: m = re.match(r"(?P<ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}),(?P<description>.*), "
r"(?P<timestamp>\d{4}-\d{2}-\d{2}[ ]\d{2}[:]\d{2}),(?P<url>.*)", line) |
||
event = self.new_event(report) | ||
|
||
event.add('event_description.text', value[1]) | ||
event.add('event_description.url', value[3]) | ||
event.add('event_description.text', values[1]) | ||
event.add('event_description.url', values[3]) | ||
event.add('raw', line) | ||
|
||
# last column is a url with malware named txt file link | ||
malware_name = value[-1].split('/')[-1].split('.')[0] | ||
malware_name = values[-1].split('/')[-1].split('.')[0] | ||
event.add('malware.name', self.MALWARE_NAME_MAP.get(malware_name, malware_name)) | ||
|
||
if report['feed.url'] in BambenekParserBot.IPMASTERLIST: | ||
event.add('source.ip', value[0]) | ||
event.add('time.source', value[2] + ' UTC') | ||
event.add('source.ip', values[0]) | ||
event.add('time.source', values[2] + ' UTC') | ||
event.add('classification.type', 'c2server') | ||
event.add('status', 'online') | ||
|
||
elif report['feed.url'] in BambenekParserBot.DOMMASTERLIST: | ||
event.add('source.fqdn', value[0]) | ||
event.add('time.source', value[2] + ' UTC') | ||
event.add('source.fqdn', values[0]) | ||
event.add('time.source', values[2] + ' UTC') | ||
event.add('classification.type', 'c2server') | ||
event.add('status', 'online') | ||
|
||
elif report['feed.url'] in BambenekParserBot.DGA_FEED: | ||
event.add('source.fqdn', value[0]) | ||
event.add('time.source', value[2] + ' 00:00 UTC') | ||
event.add('source.fqdn', values[0]) | ||
event.add('time.source', values[2] + ' 00:00 UTC') | ||
event.add('classification.type', 'dga domain') | ||
|
||
else: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does not seem to work with IPv6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we change
.*
(greedy) to.*?
(non-greedy) here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I'm sorry, I didn't consider IPv6. Regex for an IPv6 pattern is out of my scope.
The greedy to non-greedy works for the description group, but not for the URL group.