Skip to content

Commit 7bdc3b9

Browse files
authored
Fix abuseipdb tags (#2932)
* fixed abuseipdb tags * fix to similar investigation search
1 parent 72f3da4 commit 7bdc3b9

3 files changed

Lines changed: 26 additions & 12 deletions

File tree

api_app/analyzers_manager/observable_analyzers/abuseipdb.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,27 @@ def _monkeypatch(cls):
101101

102102
def _update_data_model(self, data_model) -> None:
103103
super()._update_data_model(data_model)
104+
data_model.tags = []
104105
report_data = self.report.report.get("data", {})
106+
categories_found = self.report.report.get("categories_found", {})
107+
data_model.additional_info = {"distinct_users": report_data["numDistinctUsers"]}
105108
if report_data.get("totalReports", 0):
106109
self.report: AnalyzerReport
107110
if report_data["isWhitelisted"]:
108111
evaluation = self.report.data_model_class.EVALUATIONS.TRUSTED.value
112+
data_model.additional_info["description"] = (
113+
"AbuseIPDB is a service where users can report malicious IP addresses attacking "
114+
+ "their infrastructure."
115+
+ "This IP address has been whitelisted"
116+
)
109117
else:
110118
evaluation = self.report.data_model_class.EVALUATIONS.MALICIOUS.value
119+
data_model.additional_info["description"] = (
120+
"AbuseIPDB is a service where users can report malicious IP addresses attacking "
121+
+ "their infrastructure."
122+
+ "This IP address has been categorized with some malicious "
123+
+ "categories"
124+
)
111125
data_model.evaluation = evaluation
126+
data_model.reliability = report_data["abuseConfidenceScore"] // 10
127+
data_model.tags.extend(list(categories_found.keys()))

api_app/investigations_manager/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ def investigation_for_analyzable(
106106
cls, queryset: models.QuerySet, analyzed_object_name: str
107107
) -> models.QuerySet:
108108
related_job_id_list = [
109-
job_data[0]
109+
job_data.get_root().id
110110
for job_data in Job.objects.filter(
111111
analyzable__name__icontains=analyzed_object_name
112-
).values_list("id")
112+
)
113113
]
114114
return queryset.filter(jobs__id__in=related_job_id_list).distinct()
115115

tests/api_app/test_views.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,25 +166,23 @@ def setUp(self):
166166
"tlp": Job.TLP.GREEN.value,
167167
}
168168
)
169-
self.job5, _ = Job.objects.get_or_create(
170-
**{
171-
"user": self.superuser,
172-
"analyzable": self.analyzable,
173-
"playbook_to_execute": PlaybookConfig.objects.get(name="Dns"),
174-
"tlp": Job.TLP.AMBER.value,
175-
}
176-
)
177169
self.investigation1, _ = Investigation.objects.get_or_create(
178170
name="test_investigation1", owner=self.superuser
179171
)
180172
self.investigation1.jobs.add(self.job)
181173
self.investigation2, _ = Investigation.objects.get_or_create(
182174
name="test_investigation2", owner=self.superuser
183175
)
184-
self.investigation2.jobs.add(self.job5)
176+
self.investigation2.jobs.add(self.job2)
177+
# in this way we can check we filter investagion looking for child job and not only the one in the root
178+
self.job2.add_child(
179+
user=self.superuser,
180+
analyzable=self.analyzable,
181+
playbook_to_execute=PlaybookConfig.objects.get(name="Dns"),
182+
tlp=Job.TLP.AMBER.value,
183+
)
185184

186185
def tearDown(self):
187-
self.job5.delete()
188186
self.job4.delete()
189187
self.job3.delete()
190188
self.job2.delete()

0 commit comments

Comments
 (0)