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

[ThreatMatch] Added Beautifulsoup parsing and cleaned up code #3047

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions external-import/threatmatch/src/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pycti==6.4.7
beautifulsoup4==4.12.3
29 changes: 5 additions & 24 deletions external-import/threatmatch/src/threatmatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import requests
import yaml
from bs4 import BeautifulSoup
from pycti import OpenCTIConnectorHelper, get_config_variable


Expand Down Expand Up @@ -50,13 +51,6 @@ def __init__(self):
False,
True,
)
# self.threatmatch_import_reports = get_config_variable(
# "THREATMATCH_IMPORT_REPORTS",
# ["threatmatch", "import_reports"],
# config,
# False,
# True,
# )
self.threatmatch_import_iocs = get_config_variable(
"THREATMATCH_IMPORT_IOCS",
["threatmatch", "import_iocs"],
Expand Down Expand Up @@ -103,10 +97,12 @@ def _get_item(self, token, type, item_id):
if r.status_code != 200:
self.helper.log_error(str(r.text))
return []
# if 'error' in r.json():
# return []
if r.status_code == 200:
data = r.json()["objects"]
for object in data:
object["description"] = BeautifulSoup(
object["description"], "html.parser"
).get_text()
return data

def _process_list(self, work_id, token, type, list):
Expand Down Expand Up @@ -215,21 +211,6 @@ def run(self):
self._process_list(
work_id, token, "alerts", data.get("list")
)
# if self.threatmatch_import_reports:
# r = requests.get(
# self.threatmatch_url + "/api/reports/all",
# headers=headers,
# json={
# "mode": "compact",
# "date_since": import_from_date,
# },
# )
# if r.status_code != 200:
# self.helper.log_error(str(r.text))
# data = r.json()
# self._process_list(
# work_id, token, "reports", data.get("list")
# )
if self.threatmatch_import_iocs:
response = requests.get(
self.threatmatch_url + "/api/taxii/groups",
Expand Down