-
Notifications
You must be signed in to change notification settings - Fork 321
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add CrowdSec TIProvider Signed-off-by: Shivam Sandbhor <[email protected]> * Add user agent for crowdsec tiprovider Signed-off-by: Shivam Sandbhor <[email protected]> * Implement review suggestions Signed-off-by: Shivam Sandbhor <[email protected]> * Fix import error in tests Signed-off-by: Shivam Sandbhor <[email protected]> * Extraneous braces in test data in test, unneeded ioc_param item in test data for CrowdSec Added CrowdSec settings entry to test msticpyconfig.yaml and msticpyconfig-test.yaml * Adding docstring to crowdsec.py parse_results --------- Signed-off-by: Shivam Sandbhor <[email protected]> Co-authored-by: Ian Hellen <[email protected]>
- Loading branch information
Showing
7 changed files
with
234 additions
and
4 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
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,75 @@ | ||
# ------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for | ||
# license information. | ||
# -------------------------------------------------------------------------- | ||
""" | ||
CrowdSec Provider. | ||
Input can be a single IoC observable or a pandas DataFrame containing | ||
multiple observables. Processing may require an API key and | ||
processing performance may be limited to a specific number of | ||
requests per minute for the account type that you have. | ||
""" | ||
from typing import Any, Dict, Tuple | ||
|
||
from ..._version import VERSION | ||
from ..http_provider import APILookupParams | ||
from .ti_http_provider import HttpTIProvider | ||
from .ti_provider_base import ResultSeverity | ||
|
||
__version__ = VERSION | ||
__author__ = "Shivam Sandbhor" | ||
|
||
|
||
class CrowdSec(HttpTIProvider): | ||
"""CrowdSec CTI Smoke Lookup.""" | ||
|
||
_BASE_URL = "https://cti.api.crowdsec.net" | ||
|
||
_QUERIES = { | ||
"ipv4": APILookupParams( | ||
path="/v2/smoke/{observable}", | ||
headers={ | ||
"x-api-key": "{AuthKey}", | ||
"User-Agent": "crowdsec-msticpy-tiprovider/v1.0.0", | ||
}, | ||
), | ||
} | ||
_QUERIES["ipv6"] = _QUERIES["ipv4"] | ||
|
||
def parse_results(self, response: Dict) -> Tuple[bool, ResultSeverity, Any]: | ||
"""Return the details of the response.""" | ||
if self._failed_response(response): | ||
return False, ResultSeverity.information, response["RawResult"]["message"] | ||
|
||
if response["RawResult"]["scores"]["overall"]["total"] <= 2: | ||
result_severity = ResultSeverity.information | ||
elif response["RawResult"]["scores"]["overall"]["total"] <= 3: | ||
result_severity = ResultSeverity.warning | ||
else: | ||
result_severity = ResultSeverity.high | ||
|
||
return ( | ||
True, | ||
result_severity, | ||
{ | ||
"Background Noise": response["RawResult"]["background_noise_score"], | ||
"Overall Score": response["RawResult"]["scores"]["overall"]["total"], | ||
"First Seen": response["RawResult"]["history"]["first_seen"], | ||
"Last Seen": response["RawResult"]["history"]["last_seen"], | ||
"Attack Details": ",".join( | ||
[ | ||
attack_detail["label"] | ||
for attack_detail in response["RawResult"]["attack_details"] | ||
] | ||
), | ||
"Behaviors": ",".join( | ||
[ | ||
behavior["name"] | ||
for behavior in response["RawResult"]["behaviors"] | ||
] | ||
), | ||
}, | ||
) |
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