-
-
Notifications
You must be signed in to change notification settings - Fork 451
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #156 from intelowlproject/develop
Quark, Pulsedive, Python 3.7, Docs update, Fix in active_dns
- Loading branch information
Showing
25 changed files
with
555 additions
and
469 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,20 @@ | ||
.gitignore | ||
.git | ||
.vscode | ||
.lgtm.yml | ||
.travis.yml | ||
__pycache__ | ||
venv/ | ||
.env | ||
env_file_app | ||
env_file_app_template | ||
env_file_postgres | ||
env_file_postgres_template | ||
env_file_integrations | ||
venv/ | ||
env_file_integrations_template | ||
env_file_app_travis | ||
docs/ | ||
integrations/ | ||
settings/ldap_config.py | ||
docker-compose-override.yml | ||
docker-compose* | ||
*.quark.log |
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
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
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,13 @@ | ||
from api_app.script_analyzers.classes import FileAnalyzer | ||
|
||
|
||
class QuarkEngine(FileAnalyzer): | ||
def run(self): | ||
from quark.report import Report | ||
|
||
# new report object | ||
report = Report() | ||
# start analysis | ||
report.analysis(self.filepath, "/opt/deploy/quark-rules") | ||
# return json report | ||
return report.get_report("json") |
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
92 changes: 92 additions & 0 deletions
92
api_app/script_analyzers/observable_analyzers/pulsedive.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,92 @@ | ||
import logging | ||
import requests | ||
import time | ||
|
||
from api_app.exceptions import AnalyzerRunException | ||
from api_app.script_analyzers.classes import ObservableAnalyzer | ||
from intel_owl import secrets | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Pulsedive(ObservableAnalyzer): | ||
base_url: str = "https://pulsedive.com/api" | ||
max_tries: int = 10 | ||
poll_distance: int = 10 | ||
|
||
def set_config(self, additional_config_params): | ||
self.api_key_name = additional_config_params.get( | ||
"api_key_name", "PULSEDIVE_API_KEY" | ||
) | ||
self.__api_key = secrets.get_secret(self.api_key_name) | ||
active_scan = additional_config_params.get("active_scan", True) | ||
self.probe = 1 if active_scan else 0 | ||
|
||
def run(self): | ||
result = {} | ||
if not self.__api_key: | ||
warning = f"No API key retrieved with name: {self.api_key_name}" | ||
logger.info( | ||
f"{warning}. Continuing without API key..." f" <- {self.__repr__()}" | ||
) | ||
self.report["errors"].append(warning) | ||
else: | ||
default_param = f"&key={self.__api_key}" | ||
|
||
# headers = {"Key": self.__api_key, "Accept": "application/json"} | ||
# 1. query to info.php to check if the indicator is already in the database | ||
params = f"indicator={self.observable_name}" | ||
if self.__api_key: | ||
params += default_param | ||
resp = requests.get(f"{self.base_url}/info.php?{params}") | ||
resp.raise_for_status() | ||
result = resp.json() | ||
e = result.get("error", None) | ||
if e == "Indicator not found.": | ||
# 2. submit new scan to analyze.php | ||
params = f"value={self.observable_name}&probe={self.probe}" | ||
if self.__api_key: | ||
params += default_param | ||
headers = { | ||
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8" | ||
} | ||
resp = requests.post( | ||
f"{self.base_url}/analyze.php", data=params, headers=headers | ||
) | ||
resp.raise_for_status() | ||
qid = resp.json().get("qid", None) | ||
# 3. retrieve result using qid after waiting for 10 seconds | ||
params = f"qid={qid}" | ||
if self.__api_key: | ||
params += default_param | ||
result = self.__poll_for_result(params) | ||
if result.get("data", None): | ||
result = result["data"] | ||
|
||
return result | ||
|
||
def __poll_for_result(self, params): | ||
result = {} | ||
url = f"{self.base_url}/analyze.php?{params}" | ||
obj_repr = self.__repr__() | ||
for chance in range(self.max_tries): | ||
logger.info( | ||
f"polling request #{chance+1} for observable: {self.observable_name}" | ||
f" <- {obj_repr}" | ||
) | ||
time.sleep(self.poll_distance) | ||
resp = requests.get(url) | ||
resp.raise_for_status() | ||
resp_json = resp.json() | ||
status = resp_json.get("status", None) | ||
if status == "done": | ||
result = resp_json | ||
break | ||
elif status == "processing": | ||
continue | ||
else: | ||
err = resp_json.get("error", "Report not found.") | ||
raise AnalyzerRunException(err) | ||
|
||
return result |
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
Oops, something went wrong.