-
Notifications
You must be signed in to change notification settings - Fork 385
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
GreyNoise - Update API to new version 3 #911
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2d2730c
GreyNoise analyzer v3
danielbrownevoss ab032eb
Merge pull request #1 from Nclose-ZA/greynoise_analyzer_v3
markus-nclose 079e983
Rename file to not be the same name as pip module
danielbrownevoss a7162b5
Match up the JSON to the filename
danielbrownevoss 5cdd640
Add unseen taxonomy
danielbrownevoss a931f79
Merge pull request #2 from Nclose-ZA/greynoise_analyzer_v3
markus-nclose 7353cb2
Make levels lower case
danielbrownevoss edd5892
Merge pull request #3 from Nclose-ZA/greynoise_analyzer_v3
markus-nclose 22cbf34
Merge remote-tracking branch 'upstream/master'
danielbrownevoss df62189
Added integration_name as requested by upstream devs
danielbrownevoss 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 was deleted.
Oops, something went wrong.
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,132 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
from collections import defaultdict, OrderedDict | ||
|
||
from cortexutils.analyzer import Analyzer | ||
from greynoise import GreyNoise | ||
import requests | ||
|
||
|
||
class GreyNoiseAnalyzer(Analyzer): | ||
""" | ||
GreyNoise API docs: https://developer.greynoise.io/reference#noisecontextip-1 | ||
""" | ||
|
||
def run(self): | ||
|
||
if self.data_type == "ip": | ||
api_key = self.get_param('config.key', None) | ||
api_client = GreyNoise(api_key=api_key, timeout=30) | ||
try: | ||
self.report(api_client.ip(self.get_data())) | ||
except Exception as e: | ||
self.error('Unable to query GreyNoise API\n{}'.format(e)) | ||
else: | ||
self.notSupported() | ||
|
||
def summary(self, raw): | ||
""" | ||
Return two taxonomies | ||
|
||
Examples: | ||
|
||
Input | ||
{ | ||
"seen": True, | ||
"actor": "SCANNER1", | ||
"classification": "benign", | ||
"tags": ['a', 'b', 'c'] | ||
} | ||
Output | ||
GreyNoise:tags = 3 (Safe) | ||
GreyNoise:actor = SCANNER1 (Safe) | ||
|
||
Input | ||
{ | ||
"seen": True, | ||
"actor": "SCANNER1", | ||
"classification": "unknown", | ||
"tags": ['a', 'b', 'c'] | ||
} | ||
Output | ||
GreyNoise:tags = 3 (Suspicious) | ||
GreyNoise:classification = unknown (Info) | ||
|
||
Input | ||
{ | ||
"seen": True, | ||
"actor": "SCANNER1", | ||
"classification": "unknown", | ||
"tags": ['a', 'b'] | ||
} | ||
Output | ||
GreyNoise:tags = 2 (Info) | ||
GreyNoise:classification = unknown (Info) | ||
|
||
Input | ||
{ | ||
"seen": True, | ||
"actor": "SCANNER1", | ||
"classification": "malicious", | ||
"tags": ['a', 'b', 'c'] | ||
} | ||
Output | ||
GreyNoise:tags = 3 (Malicious) | ||
GreyNoise:classification = malicious (Malicious) | ||
|
||
Input | ||
{ | ||
"seen": "False" | ||
} | ||
Output | ||
GreyNoise:Seen last 60 days = False (Info) | ||
""" | ||
|
||
|
||
classification_level_map = { | ||
'benign': lambda x: 'safe', | ||
'unknown': lambda tag_count: 'info' if (not tag_count) or (tag_count <= 2) else 'suspicious', | ||
'malicious': lambda x: 'malicious' | ||
} | ||
|
||
try: | ||
taxonomies = [] | ||
|
||
seen = raw.get('seen', False) | ||
if seen: | ||
tag_count = len(raw.get('tags', [])) | ||
classification = raw.get('classification', 'unknown') | ||
actor = raw.get('actor') | ||
|
||
t1_level = classification_level_map.get(classification)(tag_count) | ||
t1_namespace = 'GreyNoise' | ||
t1_predicate = 'tags' | ||
t1_value = tag_count | ||
# print('{}:{} = {} ({})'.format(t1_namespace, t1_predicate, t1_value, t1_level)) | ||
taxonomies.append(self.build_taxonomy(t1_level, t1_namespace, t1_predicate, t1_value)) | ||
|
||
t2_level = classification_level_map.get(classification)(None) | ||
t2_namespace = 'GreyNoise' | ||
t2_predicate = 'actor' if classification == 'benign' else 'classification' | ||
t2_value = actor if classification == 'benign' else classification | ||
# print('{}:{} = {} ({})'.format(t2_namespace, t2_predicate, t2_value, t2_level)) | ||
taxonomies.append(self.build_taxonomy(t2_level, t2_namespace, t2_predicate, t2_value)) | ||
else: | ||
taxonomies.append( | ||
self.build_taxonomy( | ||
classification_level_map.get('unknown')(None), | ||
'GreyNoise', | ||
'Seen last 60 days', | ||
False | ||
) | ||
) | ||
|
||
return {"taxonomies": taxonomies} | ||
|
||
except Exception as e: | ||
self.error('Summary failed\n{}'.format(e.message)) | ||
|
||
|
||
if __name__ == '__main__': | ||
GreyNoiseAnalyzer().run() |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
cortexutils | ||
requests | ||
greynoise |
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.
@markus-nclose : can we also get an integration name passed here?
Example:
api_client = GreyNoise(api_key=api_key, integration_name="greynoise-cortex-analyzer-v3.0")
We're working to set this up as our standard going forward.
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.
Added as requested above, looks like the only use is in the user-agent header?
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.
Thanks, yes that is correct, this is essentially a user-agent string for us to see on the backend. It helps us understand the adoption and use of integrations with our service and we can also proactively let users know there is a new version available if we see high usage of older versions.