-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5248c57
commit e0ceddd
Showing
14 changed files
with
176 additions
and
174 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
File renamed without changes.
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,53 @@ | ||
import polars as pl | ||
|
||
from heidgaf.inspectors import Inspector, InspectorConfig | ||
|
||
|
||
class DomainInspector(Inspector): | ||
"""Inspects domains based features. | ||
Args: | ||
Tester (Tester): Configuration. | ||
""" | ||
KEY_SECOND_LEVEL_DOMAIN = "secondleveldomain_frequency" | ||
KEY_THIRD_LEVEL_DOMAIN = "thirdleveldomain_frequency" | ||
KEY_FQDN = "fqdn_frequency" | ||
|
||
def __init__(self, config: InspectorConfig) -> None: | ||
super().__init__(config) | ||
|
||
def update_threshold(threshould, tpr, fpr): | ||
pass | ||
|
||
def run(self, data: pl.DataFrame) -> pl.DataFrame: | ||
"""Runs tester for domain name based features. | ||
Args: | ||
data (pl.DataFrame): Proprocessed data. | ||
Returns: | ||
pl.DataFrame: Anomalies. | ||
""" | ||
min_date = data.select(["timestamp"]).min().item() | ||
max_date = data.select(["timestamp"]).max().item() | ||
|
||
# Filter data with no errors | ||
df = data.filter(pl.col("query") != "|").filter( | ||
pl.col("query").str.split(".").list.len() != 1 | ||
) | ||
|
||
# Check anomalies in FQDN | ||
warnings = self.update_count(df, min_date, max_date, "fqdn", self.KEY_FQDN) | ||
self.warnings(data, warnings, "fqdn") | ||
|
||
# Check anomalies in second level | ||
warnings = self.update_count( | ||
df, min_date, max_date, "secondleveldomain", self.KEY_SECOND_LEVEL_DOMAIN | ||
) | ||
self.warnings(data, warnings, "secondleveldomain") | ||
|
||
# Check anomalies in third level | ||
warnings = self.update_count( | ||
df, min_date, max_date, "thirdleveldomain", self.KEY_THIRD_LEVEL_DOMAIN | ||
) | ||
self.warnings(data, warnings, "thirdleveldomain") |
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
Oops, something went wrong.