-
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
Support Shadowserver Vulnerable SMTP server feed, fix #1984 #2037
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3afe5b0
ENH: support Shadowserver Vulnerable SMTP server feed
monoidic b07b3a8
Update intelmq/bots/parsers/shadowserver/_config.py
monoidic dddba08
FIX: update scan_smtp{,_vulnerable}
monoidic 6586d2e
DOC: add vulnerable SMTP to docs
monoidic 8eedb7b
ENH TST: add test for scan_http_vulnerable, better filename match
monoidic 4ab22f7
TST: fix test_broken applying Vulnerable-HTTP to scan_http filename
monoidic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
intelmq/tests/bots/parsers/shadowserver/test_scan_http_vulnerable.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# SPDX-FileCopyrightText: 2021 Mikk Margus Möll <[email protected]> | ||
# | ||
# SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
# -*- coding: utf-8 -*- | ||
|
||
import os | ||
import unittest | ||
|
||
import intelmq.lib.test as test | ||
import intelmq.lib.utils as utils | ||
from intelmq.bots.parsers.shadowserver.parser import ShadowserverParserBot | ||
|
||
with open(os.path.join(os.path.dirname(__file__), | ||
'testdata/scan_http_vulnerable.csv')) as handle: | ||
EXAMPLE_FILE = handle.read() | ||
EXAMPLE_LINES = EXAMPLE_FILE.splitlines() | ||
|
||
EXAMPLE_REPORT = {'feed.name': 'Vulnerable HTTP', | ||
"raw": utils.base64_encode(EXAMPLE_FILE), | ||
"__type": "Report", | ||
"time.observation": "2021-08-01T09:00:00+00:00", | ||
"extra.file_name": "2021-08-01-scan_http_vulnerable-test-test.csv", | ||
} | ||
EVENTS = [{'__type': 'Event', | ||
'feed.name': 'Vulnerable HTTP', | ||
'classification.taxonomy': 'other', | ||
'classification.type': 'other', | ||
'classification.identifier': 'accessible-http', | ||
'extra.http': 'HTTP/1.1', | ||
'extra.http_code': 401, | ||
'extra.http_reason': 'Unauthorized', | ||
'extra.content_type': 'text/html; charset=%s', | ||
'extra.connection': 'close', | ||
'extra.server': 'mini_httpd/1.28 04Feb2018', | ||
'extra.http_date': '2000-11-25T20:21:50+00:00', | ||
'protocol.transport': 'tcp', | ||
'extra.tag': 'basic-auth,http', | ||
'extra.www_authenticate': 'Basic realm="Managed Switch"', | ||
'raw': utils.base64_encode('\n'.join([EXAMPLE_LINES[0], | ||
EXAMPLE_LINES[1]])), | ||
'source.asn': 1234, | ||
'source.geolocation.cc': 'EE', | ||
'source.geolocation.city': 'TARTU', | ||
'source.geolocation.region': 'TARTUMAA', | ||
'source.ip': '210.181.42.1', | ||
'source.port': 8000, | ||
'time.observation': '2021-08-01T09:00:00+00:00"', | ||
'time.source': '2021-08-01T07:00:24+00:00'}, | ||
{'__type': 'Event', | ||
'feed.name': 'Vulnerable HTTP', | ||
'classification.taxonomy': 'other', | ||
'classification.type': 'other', | ||
'classification.identifier': 'accessible-http', | ||
'extra.http': 'HTTP/1.1', | ||
'extra.http_code': 401, | ||
'extra.http_reason': 'Unauthorized', | ||
'extra.server': 'Web Server', | ||
'extra.content_type': 'text/html; charset=ISO-8859-1', | ||
'extra.connection': 'close', | ||
'extra.http_date': '2021-08-01T10:02:39+00:00', | ||
'extra.tag': 'basic-auth,http', | ||
'extra.www_authenticate': 'Basic realm="streaming_server"', | ||
'protocol.transport': 'tcp', | ||
'raw': utils.base64_encode('\n'.join([EXAMPLE_LINES[0], | ||
EXAMPLE_LINES[2]])), | ||
'source.reverse_dns': 'host.invalid', | ||
'source.asn': 5678, | ||
'source.geolocation.cc': 'EE', | ||
'source.geolocation.city': 'TALLINN', | ||
'source.geolocation.region': 'HARJUMAA', | ||
'source.ip': '22.23.35.23', | ||
'source.port': 8000, | ||
'time.observation': '2021-08-01T09:00:00+00:00"', | ||
'time.source': '2021-08-01T07:02:32+00:00'}, | ||
] | ||
|
||
|
||
class TestShadowserverParserBot(test.BotTestCase, unittest.TestCase): | ||
""" | ||
A TestCase for a ShadowserverParserBot. | ||
""" | ||
|
||
@classmethod | ||
def set_bot(cls): | ||
cls.bot_reference = ShadowserverParserBot | ||
cls.default_input_message = EXAMPLE_REPORT | ||
|
||
def test_event(self): | ||
""" Test if correct Event has been produced. """ | ||
self.run_bot() | ||
for i, EVENT in enumerate(EVENTS): | ||
self.assertMessageEqual(i, EVENT) | ||
|
||
|
||
if __name__ == '__main__': # pragma: no cover | ||
unittest.main() |
88 changes: 88 additions & 0 deletions
88
intelmq/tests/bots/parsers/shadowserver/test_scan_smtp_vulnerable.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# SPDX-FileCopyrightText: 2021 Mikk Margus Möll <[email protected]> | ||
# | ||
# SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
# -*- coding: utf-8 -*- | ||
|
||
import os | ||
import unittest | ||
|
||
import intelmq.lib.test as test | ||
import intelmq.lib.utils as utils | ||
from intelmq.bots.parsers.shadowserver.parser import ShadowserverParserBot | ||
|
||
with open(os.path.join(os.path.dirname(__file__), | ||
'testdata/scan_smtp_vulnerable.csv')) as handle: | ||
EXAMPLE_FILE = handle.read() | ||
EXAMPLE_LINES = EXAMPLE_FILE.splitlines() | ||
|
||
EXAMPLE_REPORT = {'feed.name': 'Vulnerable SMTP', | ||
"raw": utils.base64_encode(EXAMPLE_FILE), | ||
"__type": "Report", | ||
"time.observation": "2021-07-08T00:00:00+00:00", | ||
"extra.file_name": "2021-07-08-scan_smtp_vulnerable-test-test.csv", | ||
} | ||
|
||
EVENTS = [{'__type': 'Event', | ||
'feed.name': 'Vulnerable SMTP', | ||
'classification.taxonomy': 'vulnerable', | ||
'classification.type': 'vulnerable-system', | ||
'extra.banner': '220 smtp-server.invalid ESMTP Exim 4.80 Wed, 11 Jun 2021 ' | ||
'10:00:00 +0300|', | ||
'extra.protocol': 'tcp', | ||
'classification.identifier': 'vulnerable-smtp', | ||
'extra.tag': 'smtp;21nails', | ||
'protocol.application': 'smtp', | ||
'raw': utils.base64_encode('\n'.join([EXAMPLE_LINES[0], | ||
EXAMPLE_LINES[1]])), | ||
'source.reverse_dns': 'smtp-server.invalid', | ||
'source.asn': 12345, | ||
'source.geolocation.cc': 'EE', | ||
'source.geolocation.city': 'TALLINN', | ||
'source.geolocation.region': 'HARJUMAA', | ||
'source.ip': '1.2.3.4', | ||
'source.port': 25, | ||
'time.observation': '2021-07-08T00:00:00+00:00', | ||
'time.source': '2021-07-08T11:58:42+00:00'}, | ||
{'__type': 'Event', | ||
'feed.name': 'Vulnerable SMTP', | ||
'classification.taxonomy': 'vulnerable', | ||
'classification.type': 'vulnerable-system', | ||
'extra.banner': '220 smtp-out.invalid, ESMTP EXIM 4.86_2|', | ||
'extra.protocol': 'tcp', | ||
'classification.identifier': 'vulnerable-smtp', | ||
'extra.tag': 'smtp;21nails', | ||
'protocol.application': 'smtp', | ||
'raw': utils.base64_encode('\n'.join([EXAMPLE_LINES[0], | ||
EXAMPLE_LINES[2]])), | ||
'source.reverse_dns': 'smtp-out.invalid', | ||
'source.asn': 23456, | ||
'source.geolocation.cc': 'EE', | ||
'source.geolocation.city': 'TALLINN', | ||
'source.geolocation.region': 'HARJUMAA', | ||
'source.ip': '5.6.7.8', | ||
'source.port': 25, | ||
'time.observation': '2021-07-08T00:00:00+00:00', | ||
'time.source': '2021-07-08T11:58:44+00:00'}, | ||
] | ||
|
||
|
||
class TestShadowserverParserBot(test.BotTestCase, unittest.TestCase): | ||
""" | ||
A TestCase for a ShadowserverParserBot. | ||
""" | ||
|
||
@classmethod | ||
def set_bot(cls): | ||
cls.bot_reference = ShadowserverParserBot | ||
cls.default_input_message = EXAMPLE_REPORT | ||
|
||
def test_event(self): | ||
""" Test if correct Event has been produced. """ | ||
self.run_bot() | ||
for i, EVENT in enumerate(EVENTS): | ||
self.assertMessageEqual(i, EVENT) | ||
|
||
|
||
if __name__ == '__main__': # pragma: no cover | ||
unittest.main() |
3 changes: 3 additions & 0 deletions
3
intelmq/tests/bots/parsers/shadowserver/testdata/scan_http_vulnerable.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
"timestamp","ip","protocol","port","hostname","tag","asn","geo","region","city","naics","sic","http","http_code","http_reason","content_type","connection","www_authenticate","set_cookie","server","content_length","transfer_encoding","http_date" | ||
"2021-08-01 07:00:24","210.181.42.1","tcp",8000,,"basic-auth,http",1234,"EE","TARTUMAA","TARTU",,,"HTTP/1.1",401,"Unauthorized","text/html; charset=%s","close","Basic realm=""Managed Switch""",,"mini_httpd/1.28 04Feb2018",,,"Sat, 25 Nov 2000 20:21:50 GMT" | ||
"2021-08-01 07:02:32","22.23.35.23","tcp",8000,"host.invalid","basic-auth,http",5678,"EE","HARJUMAA","TALLINN",,,"HTTP/1.1",401,"Unauthorized","text/html; charset=ISO-8859-1","close","Basic realm=""streaming_server""",,"Web Server",,,"Thu, 01 Aug 2021 10:02:39 GMT" |
2 changes: 2 additions & 0 deletions
2
intelmq/tests/bots/parsers/shadowserver/testdata/scan_http_vulnerable.csv.license
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
SPDX-FileCopyrightText: 2021 Mikk Margus Möll <[email protected]> | ||
SPDX-License-Identifier: AGPL-3.0-or-later |
3 changes: 3 additions & 0 deletions
3
intelmq/tests/bots/parsers/shadowserver/testdata/scan_smtp_vulnerable.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
"timestamp","ip","protocol","port","hostname","tag","asn","geo","region","city","naics","sic","banner" | ||
"2021-07-08 11:58:42","1.2.3.4","tcp",25,"smtp-server.invalid","smtp;21nails",12345,"EE","HARJUMAA","TALLINN",,,"220 smtp-server.invalid ESMTP Exim 4.80 Wed, 11 Jun 2021 10:00:00 +0300|" | ||
"2021-07-08 11:58:44","5.6.7.8","tcp",25,"smtp-out.invalid","smtp;21nails",23456,"EE","HARJUMAA","TALLINN",,,"220 smtp-out.invalid, ESMTP EXIM 4.86_2|" |
2 changes: 2 additions & 0 deletions
2
intelmq/tests/bots/parsers/shadowserver/testdata/scan_smtp_vulnerable.csv.license
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
SPDX-FileCopyrightText: 2021 Mikk Margus Möll <[email protected]> | ||
SPDX-License-Identifier: AGPL-3.0-or-later |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Good catch, thanks!