-
-
Notifications
You must be signed in to change notification settings - Fork 625
Deprecate and remove TalosReputation. Closes #3451 #3559
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
Open
cipherBT
wants to merge
1
commit into
intelowlproject:develop
Choose a base branch
from
cipherBT:fix-issue-3451-v2
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+137
−105
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
api_app/analyzers_manager/migrations/0180_remove_talos_reputation.py
This file contains hidden or 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,86 @@ | ||
| # This file is a part of IntelOwl https://github.com/intelowlproject/IntelOwl | ||
| # See the file 'LICENSE' for copying permission. | ||
|
|
||
|
|
||
| from django.db import migrations | ||
|
|
||
|
|
||
| def _cleanup_schedule(schedule, field_name, PeriodicTask, PythonModule, is_crontab): | ||
| """Delete a schedule if it is no longer referenced by any task or module.""" | ||
| if schedule is None: | ||
| return | ||
| still_used = PeriodicTask.objects.filter(**{field_name: schedule}).exists() | ||
| if not still_used and is_crontab: | ||
| still_used = ( | ||
| PythonModule.objects.filter(update_schedule=schedule).exists() | ||
| or PythonModule.objects.filter(health_check_schedule=schedule).exists() | ||
| ) | ||
| if not still_used: | ||
| try: | ||
| schedule.delete() | ||
| except Exception: | ||
| pass # Another model (e.g. IngestorConfig) may still reference this schedule | ||
|
|
||
|
|
||
| def remove_talos_forward(apps, schema_editor): | ||
| AnalyzerConfig = apps.get_model("analyzers_manager", "AnalyzerConfig") | ||
| PythonModule = apps.get_model("api_app", "PythonModule") | ||
| PeriodicTask = apps.get_model("django_celery_beat", "PeriodicTask") | ||
| IntervalSchedule = apps.get_model("django_celery_beat", "IntervalSchedule") | ||
| CrontabSchedule = apps.get_model("django_celery_beat", "CrontabSchedule") | ||
| SolarSchedule = apps.get_model("django_celery_beat", "SolarSchedule") | ||
| ClockedSchedule = apps.get_model("django_celery_beat", "ClockedSchedule") | ||
|
|
||
| # Identify Talos PythonModule instances first | ||
| module_qs = PythonModule.objects.filter( | ||
| module="talos.Talos", | ||
| base_path="api_app.analyzers_manager.observable_analyzers", | ||
| ) | ||
|
|
||
| # Remove all analyzer configs referencing these modules | ||
| AnalyzerConfig.objects.filter(python_module__in=module_qs).delete() | ||
|
|
||
| for module in module_qs: | ||
| update_task_id = getattr(module, "update_task_id", None) | ||
| if update_task_id is not None: | ||
| try: | ||
| task = PeriodicTask.objects.get(id=update_task_id) | ||
| except PeriodicTask.DoesNotExist: | ||
| task = None | ||
| if task is not None: | ||
| schedule_data = ( | ||
| ("interval", IntervalSchedule, task.interval), | ||
| ("crontab", CrontabSchedule, task.crontab), | ||
| ("solar", SolarSchedule, task.solar), | ||
| ("clocked", ClockedSchedule, task.clocked), | ||
| ) | ||
| task.delete() | ||
| for field_name, schedule_model, schedule in schedule_data: | ||
| _cleanup_schedule( | ||
| schedule, | ||
| field_name, | ||
| PeriodicTask, | ||
| PythonModule, | ||
| is_crontab=(schedule_model is CrontabSchedule), | ||
| ) | ||
| # Capture modules own schedule before deletion | ||
| module_schedules = [ | ||
| getattr(module, attr, None) | ||
| for attr in ("update_schedule", "health_check_schedule") | ||
| ] | ||
| module.delete() | ||
| # Clean up orphaned CrontabSchedules from the module | ||
| for sched in module_schedules: | ||
| _cleanup_schedule(sched, "crontab", PeriodicTask, PythonModule, is_crontab=True) | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("analyzers_manager", "0179_add_local_db_models_tor_danmeuk"), | ||
cipherBT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ] | ||
cipherBT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| operations = [ | ||
| migrations.RunPython( | ||
| remove_talos_forward, reverse_code=migrations.RunPython.noop | ||
| ), | ||
| ] | ||
This file contains hidden or 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,67 +1,21 @@ | ||
| # This file is a part of IntelOwl https://github.com/intelowlproject/IntelOwl | ||
| # See the file 'LICENSE' for copying permission. | ||
|
|
||
| import logging | ||
| import os | ||
|
|
||
| import requests | ||
| from django.conf import settings | ||
|
|
||
| from api_app.analyzers_manager import classes | ||
| """ | ||
| Minimal stub kept so that historical data migration | ||
| 0002_0116_analyzer_config_talosreputation can still import the module | ||
| path during full_clean(). The analyzer itself is removed; migration | ||
| 0180_remove_talos_reputation deletes the DB rows. | ||
cipherBT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """ | ||
|
|
||
| from api_app.analyzers_manager.classes import ObservableAnalyzer | ||
| from api_app.analyzers_manager.exceptions import AnalyzerRunException | ||
cipherBT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| db_name = "talos_ip_blacklist.txt" | ||
| database_location = f"{settings.MEDIA_ROOT}/{db_name}" | ||
|
|
||
|
|
||
| class Talos(classes.ObservableAnalyzer): | ||
| class Talos(ObservableAnalyzer): | ||
| def run(self): | ||
| result = {"found": False} | ||
| if not os.path.isfile(database_location) and not self.update(): | ||
| raise AnalyzerRunException("Failed extraction of talos db") | ||
|
|
||
| if not os.path.exists(database_location): | ||
| raise AnalyzerRunException(f"database location {database_location} does not exist") | ||
|
|
||
| with open(database_location, "r", encoding="utf-8") as f: | ||
| db = f.read() | ||
|
|
||
| db_list = db.split("\n") | ||
| if self.observable_name in db_list: | ||
| result["found"] = True | ||
|
|
||
| return result | ||
| raise AnalyzerRunException("TalosReputation has been deprecated and removed.") | ||
cipherBT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @classmethod | ||
| def update(cls) -> bool: | ||
| try: | ||
| logger.info("starting download of db from talos") | ||
| url = "https://snort.org/downloads/ip-block-list" | ||
| r = requests.get(url) | ||
| r.raise_for_status() | ||
|
|
||
| with open(database_location, "w", encoding="utf-8") as f: | ||
| f.write(r.content.decode()) | ||
|
|
||
| if not os.path.exists(database_location): | ||
| return False | ||
| logger.info("ended download of db from talos") | ||
| return True | ||
| except Exception as e: | ||
| logger.exception(e) | ||
|
|
||
| def update(cls): | ||
| return False | ||
|
|
||
| def _do_create_data_model(self): | ||
| return super()._do_create_data_model() | ||
|
|
||
| def _update_data_model(self, data_model): | ||
| super()._update_data_model(data_model) | ||
| found = self.report.report.get("found", False) | ||
| if found: | ||
| data_model.external_references.append( | ||
| f"https://www.talosintelligence.com/reputation_center/lookup?search={self.report.job.analyzable.name}" | ||
| ) | ||
| data_model.evaluation = self.EVALUATIONS.MALICIOUS.value | ||
40 changes: 40 additions & 0 deletions
40
api_app/playbooks_manager/migrations/0067_remove_talos_from_playbooks.py
This file contains hidden or 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,40 @@ | ||
| # This file is a part of IntelOwl https://github.com/intelowlproject/IntelOwl | ||
| # See the file 'LICENSE' for copying permission. | ||
|
|
||
|
|
||
| from django.db import migrations | ||
|
|
||
|
|
||
| def remove_talos_from_playbooks(apps, schema_editor): | ||
| PlaybookConfig = apps.get_model("playbooks_manager", "PlaybookConfig") | ||
| AnalyzerConfig = apps.get_model("analyzers_manager", "AnalyzerConfig") | ||
|
|
||
| try: | ||
| talos_analyzer = AnalyzerConfig.objects.get(name="TalosReputation") | ||
| except AnalyzerConfig.DoesNotExist: | ||
| talos_analyzer = None | ||
|
|
||
| if talos_analyzer is not None: | ||
| for playbook in PlaybookConfig.objects.filter(analyzers=talos_analyzer): | ||
| playbook.analyzers.remove(talos_analyzer) | ||
|
|
||
| # Also scrub runtime_configuration if present | ||
| for playbook in PlaybookConfig.objects.all(): | ||
| rc = playbook.runtime_configuration | ||
| if isinstance(rc, dict) and "analyzers" in rc and "TalosReputation" in rc["analyzers"]: | ||
| del rc["analyzers"]["TalosReputation"] | ||
| playbook.runtime_configuration = rc | ||
| playbook.save(update_fields=["runtime_configuration"]) | ||
cipherBT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("playbooks_manager", "0066_link_crawl_visualizer_to_playbook"), | ||
| ("analyzers_manager", "0179_add_local_db_models_tor_danmeuk"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.RunPython( | ||
| remove_talos_from_playbooks, reverse_code=migrations.RunPython.noop | ||
| ), | ||
| ] | ||
This file contains hidden or 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 hidden or 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
25 changes: 0 additions & 25 deletions
25
tests/api_app/analyzers_manager/unit_tests/observable_analyzers/test_talos.py
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.