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

Fix/sekoiaio analyzer #1216

Merged
merged 2 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -20,14 +20,14 @@
"configurationItems": [
{
"name": "api_key",
"description": "Intelligence center API key",
"description": "API key",
"type": "string",
"multi": false,
"required": true
},
{
"name": "url",
"description": "Intelligence center URL",
"description": "Base URL (default to https://app.sekoia.io)",
"type": "string",
"multi": false,
"required": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
"configurationItems": [
{
"name": "api_key",
"description": "Intelligence center API key",
"description": "API key",
"type": "string",
"multi": false,
"required": true
},
{
"name": "url",
"description": "Intelligence center URL",
"description": "Base URL (default to https://app.sekoia.io)",
"type": "string",
"multi": false,
"required": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
"configurationItems": [
{
"name": "api_key",
"description": "Intelligence center API key",
"description": "API key",
"type": "string",
"multi": false,
"required": true
},
{
"name": "url",
"description": "Intelligence center URL",
"description": "Base URL (default to https://app.sekoia.io)",
"type": "string",
"multi": false,
"required": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


class IntelligenceCenterAnalyzer(Analyzer):

TYPES_MAPPING = {
"url": "url",
"domain": "domain-name",
Expand All @@ -22,15 +21,21 @@ class IntelligenceCenterAnalyzer(Analyzer):
@property
def url(self):
if self.service == "observables":
return "{}/api/v2/inthreat/observables/search?with_indicated_threats=1".format(self.base_url)
return (
"{}/api/v2/inthreat/observables/search?with_indicated_threats=1".format(
self.base_url
)
)
path = ""
if self.service == "context":
path = "/context"
return "{}/api/v2/inthreat/indicators{}".format(self.base_url, path)

def __init__(self):
Analyzer.__init__(self)
self.service = self.get_param("config.service", None, "Service parameter is missing")
self.service = self.get_param(
"config.service", None, "Service parameter is missing"
)
self.api_key = self.get_param("config.api_key", None, "Missing Api Key")
self.base_url = self.get_param("config.url", self.DEFAULT_URL)
if not self.base_url:
Expand All @@ -48,15 +53,25 @@ def summary(self, raw):

taxonomies = []
if count == 0:
taxonomies.append(self.build_taxonomy("safe", "SEKOIA", self.service, value))
taxonomies.append(
self.build_taxonomy("safe", "SEKOIA", self.service, value)
)
elif self.service == "observables":
has_threats = any(res.get("x_ic_indicated_threats") for res in raw["results"])
has_threats = any(
res.get("x_ic_indicated_threats") for res in raw["results"]
)
if has_threats:
taxonomies.append(self.build_taxonomy("malicious", "SEKOIA", self.service, value))
else;
taxonomies.append(self.build_taxonomy("safe", "SEKOIA", self.service, value))
taxonomies.append(
self.build_taxonomy("malicious", "SEKOIA", self.service, value)
)
else:
taxonomies.append(
self.build_taxonomy("safe", "SEKOIA", self.service, value)
)
else:
taxonomies.append(self.build_taxonomy("malicious", "SEKOIA", self.service, value))
taxonomies.append(
self.build_taxonomy("malicious", "SEKOIA", self.service, value)
)

return {"taxonomies": taxonomies}

Expand Down Expand Up @@ -95,13 +110,17 @@ def perform_request(self, payload):
)
if ex.response.status_code == 429:
self.error("Quota exhausted.")
self.error("API returned with the error code {}".format(str(ex.response.status_code)))
self.error(
"API returned with the error code {}".format(
str(ex.response.status_code)
)
)

def _send_request(self, payload):
headers = {"Authorization": "Bearer {}".format(self.api_key)}
if self.service == "observables":
response = requests.post(self.url, json=payload, headers=headers)
else:
else:
response = requests.get(self.url, params=payload, headers=headers)
response.raise_for_status()
return response.json()["items"]
Expand Down