-
-
Notifications
You must be signed in to change notification settings - Fork 529
Update abuse.ch services #2683
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
Merged
Merged
Update abuse.ch services #2683
Changes from 19 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
1952aa6
Added service_api_key parameter and migrations
fgibertoni 5d105b1
Added mb_get and mb_google
fgibertoni e92efe7
Added logging for api key
fgibertoni d9ffaf4
Fix deepsource warning
fgibertoni 4b83d49
WAD Analyzer, Closes #814 (#2655)
basedBaba bc3f6f3
Added service_api_key parameter and migrations
fgibertoni 47a3029
Added mb_get and mb_google
fgibertoni 44ad8a5
Added logging for api key
fgibertoni 73aa6d6
Fix deepsource warning
fgibertoni 14a7877
Fixed migration number
fgibertoni 6aa9364
Merge branch 'update-abuse-ch-services' of github.com:intelowlproject…
fgibertoni 5a7efd0
Removed wrongly duplicated migration
fgibertoni 7032e26
Added other analyzers to reverse_migrate
fgibertoni 40be473
Added common mixin and updated code accordingly
fgibertoni 7e2dd6f
Solved MRO
fgibertoni fa30b61
Deepsource
fgibertoni 19e2160
Made mixin compatible with ingestors
fgibertoni 2022ef9
Removed inheritance from analyzers
fgibertoni c6309fb
Added missing return statement
fgibertoni 769dcd7
Removed old configs and used a property
fgibertoni 0e25771
Left behind values
fgibertoni a6be245
Added explainatory comment
fgibertoni 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
There are no files selected for viewing
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
128 changes: 128 additions & 0 deletions
128
api_app/analyzers_manager/migrations/0146_analyzer_config_wad.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,128 @@ | ||
| from django.db import migrations | ||
| from django.db.models.fields.related_descriptors import ( | ||
| ForwardManyToOneDescriptor, | ||
| ForwardOneToOneDescriptor, | ||
| ManyToManyDescriptor, | ||
| ReverseManyToOneDescriptor, | ||
| ReverseOneToOneDescriptor, | ||
| ) | ||
|
|
||
| plugin = { | ||
| "python_module": { | ||
| "health_check_schedule": None, | ||
| "update_schedule": None, | ||
| "module": "wad.WAD", | ||
| "base_path": "api_app.analyzers_manager.observable_analyzers", | ||
| }, | ||
| "name": "WAD", | ||
| "description": "[WAD](https://github.com/CERN-CERT/WAD) (Web Application Detector) lets you analyze given URL(s) and detect technologies used by web application behind that URL, from the OS and web server level, to the programming platform and frameworks, as well as server- and client-side applications, tools and libraries.", | ||
| "disabled": False, | ||
| "soft_time_limit": 60, | ||
| "routing_key": "default", | ||
| "health_check_status": True, | ||
| "type": "observable", | ||
| "docker_based": False, | ||
| "maximum_tlp": "CLEAR", | ||
| "observable_supported": ["url"], | ||
| "supported_filetypes": [], | ||
| "run_hash": False, | ||
| "run_hash_type": "", | ||
| "not_supported_filetypes": [], | ||
| "mapping_data_model": {}, | ||
| "model": "analyzers_manager.AnalyzerConfig", | ||
| } | ||
|
|
||
| params = [] | ||
|
|
||
| values = [] | ||
|
|
||
|
|
||
| def _get_real_obj(Model, field, value): | ||
| def _get_obj(Model, other_model, value): | ||
| if isinstance(value, dict): | ||
| real_vals = {} | ||
| for key, real_val in value.items(): | ||
| real_vals[key] = _get_real_obj(other_model, key, real_val) | ||
| value = other_model.objects.get_or_create(**real_vals)[0] | ||
| # it is just the primary key serialized | ||
| else: | ||
| if isinstance(value, int): | ||
| if Model.__name__ == "PluginConfig": | ||
| value = other_model.objects.get(name=plugin["name"]) | ||
| else: | ||
| value = other_model.objects.get(pk=value) | ||
| else: | ||
| value = other_model.objects.get(name=value) | ||
| return value | ||
|
|
||
| if ( | ||
| type(getattr(Model, field)) | ||
| in [ | ||
| ForwardManyToOneDescriptor, | ||
| ReverseManyToOneDescriptor, | ||
| ReverseOneToOneDescriptor, | ||
| ForwardOneToOneDescriptor, | ||
| ] | ||
| and value | ||
| ): | ||
| other_model = getattr(Model, field).get_queryset().model | ||
| value = _get_obj(Model, other_model, value) | ||
| elif type(getattr(Model, field)) in [ManyToManyDescriptor] and value: | ||
| other_model = getattr(Model, field).rel.model | ||
| value = [_get_obj(Model, other_model, val) for val in value] | ||
| return value | ||
|
|
||
|
|
||
| def _create_object(Model, data): | ||
| mtm, no_mtm = {}, {} | ||
| for field, value in data.items(): | ||
| value = _get_real_obj(Model, field, value) | ||
| if type(getattr(Model, field)) is ManyToManyDescriptor: | ||
| mtm[field] = value | ||
| else: | ||
| no_mtm[field] = value | ||
| try: | ||
| o = Model.objects.get(**no_mtm) | ||
| except Model.DoesNotExist: | ||
| o = Model(**no_mtm) | ||
| o.full_clean() | ||
| o.save() | ||
| for field, value in mtm.items(): | ||
| attribute = getattr(o, field) | ||
| if value is not None: | ||
| attribute.set(value) | ||
| return False | ||
| return True | ||
|
|
||
|
|
||
| def migrate(apps, schema_editor): | ||
| Parameter = apps.get_model("api_app", "Parameter") | ||
| PluginConfig = apps.get_model("api_app", "PluginConfig") | ||
| python_path = plugin.pop("model") | ||
| Model = apps.get_model(*python_path.split(".")) | ||
| if not Model.objects.filter(name=plugin["name"]).exists(): | ||
| exists = _create_object(Model, plugin) | ||
| if not exists: | ||
| for param in params: | ||
| _create_object(Parameter, param) | ||
| for value in values: | ||
| _create_object(PluginConfig, value) | ||
|
|
||
|
|
||
| def reverse_migrate(apps, schema_editor): | ||
| python_path = plugin.pop("model") | ||
| Model = apps.get_model(*python_path.split(".")) | ||
| Model.objects.get(name=plugin["name"]).delete() | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| atomic = False | ||
| dependencies = [ | ||
| ("api_app", "0065_job_mpnodesearch"), | ||
| ( | ||
| "analyzers_manager", | ||
| "0145_analyzer_config_ultradns_malicious_detector", | ||
| ), | ||
| ] | ||
|
|
||
| operations = [migrations.RunPython(migrate, reverse_migrate)] |
98 changes: 98 additions & 0 deletions
98
...yzers_manager/migrations/0147_alter_analyzer_config_feodo_yaraify_urlhaus_yaraify_scan.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,98 @@ | ||
| from django.db import migrations | ||
|
|
||
|
|
||
| def migrate(apps, schema_editor): | ||
| Parameter = apps.get_model("api_app", "Parameter") | ||
| PythonModule = apps.get_model("api_app", "PythonModule") | ||
|
|
||
| # observables | ||
| observable_analyzers = [ | ||
| "urlhaus.URLHaus", | ||
| "yaraify.YARAify", | ||
| "feodo_tracker.Feodo_Tracker", | ||
| "threatfox.ThreatFox", | ||
| "mb_get.MB_GET", | ||
| "mb_google.MB_GOOGLE", | ||
| ] | ||
| for observable_analyzer in observable_analyzers: | ||
| module = PythonModule.objects.get( | ||
| module=observable_analyzer, | ||
| base_path="api_app.analyzers_manager.observable_analyzers", | ||
| ) | ||
| Parameter.objects.create( | ||
| name="service_api_key", | ||
| type="str", | ||
| description="Optional API key to connect to abuse.ch services.", | ||
| is_secret=True, | ||
| required=False, | ||
| python_module=module, | ||
| ) | ||
|
|
||
| # files | ||
| yaraify_scan_module = PythonModule.objects.get( | ||
| module="yaraify_file_scan.YARAifyFileScan", | ||
| base_path="api_app.analyzers_manager.file_analyzers", | ||
| ) | ||
| Parameter.objects.create( | ||
| name="service_api_key", | ||
| type="str", | ||
| description="Optional API key to connect to abuse.ch services.", | ||
| is_secret=True, | ||
| required=False, | ||
| python_module=yaraify_scan_module, | ||
| ) | ||
|
|
||
|
|
||
| def reverse_migrate(apps, schema_editor): | ||
| Parameter = apps.get_model("api_app", "Parameter") | ||
| PythonModule = apps.get_model("api_app", "PythonModule") | ||
|
|
||
| # observables | ||
| observable_analyzers = [ | ||
| "urlhaus.URLHaus", | ||
| "yaraify.YARAify", | ||
| "feodo_tracker.Feodo_Tracker", | ||
| "threatfox.ThreatFox", | ||
| "mb_get.MB_GET", | ||
| "mb_google.MB_GOOGLE", | ||
| ] | ||
| for observable_analyzer in observable_analyzers: | ||
| module = PythonModule.objects.get( | ||
| module=observable_analyzer, | ||
| base_path="api_app.analyzers_manager.observable_analyzers", | ||
| ) | ||
| Parameter.objects.get( | ||
| name="service_api_key", | ||
| type="str", | ||
| description="Optional API key to connect to abuse.ch services.", | ||
| is_secret=True, | ||
| required=False, | ||
| python_module=module, | ||
| ).delete() | ||
|
|
||
| # files | ||
| yaraify_scan_module = PythonModule.objects.get( | ||
| module="yaraify_file_scan.YARAifyFileScan", | ||
| base_path="api_app.analyzers_manager.file_analyzers", | ||
| ) | ||
| Parameter.objects.get( | ||
| name="service_api_key", | ||
| type="str", | ||
| description="Optional API key to connect to abuse.ch services.", | ||
| is_secret=True, | ||
| required=False, | ||
| python_module=yaraify_scan_module, | ||
| ).delete() | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| atomic = False | ||
| dependencies = [ | ||
| ("api_app", "0065_job_mpnodesearch"), | ||
| ( | ||
| "analyzers_manager", | ||
| "0146_analyzer_config_wad", | ||
| ), | ||
| ] | ||
|
|
||
| operations = [migrations.RunPython(migrate, reverse_migrate)] |
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
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.
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.