-
-
Notifications
You must be signed in to change notification settings - Fork 523
Spamhaus ipv6 and asn support #2761
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
Spamhaus ipv6 and asn support #2761
Conversation
70eb6f1 to
b9cd155
Compare
|
@mlodic, I have added the support for ASN and IPv6. Please review. |
|
@pranjalg1331 please use the appropriate GitHub system to ask for a review and avoid directly tagging if not strictly necessary. |
|
|
|
About reviews: Github introduced a new "moderation settings" that would prevent non-organization members to ask for reviews. I have just removed that limit. Please confirm that now you can. About URL support: like we did in many other analyzers, just extract the domain from the URL and analyze it |
|
You should also be able to tag the PR as draft instead of writing it in the name of the PR |
| url = "https://www.spamhaus.org/drop/drop_v4.json" | ||
| ipv6_url = "https://www.spamhaus.org/drop/drop_v6.json" | ||
| asn_url = "https://www.spamhaus.org/drop/asndrop.json" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use a url parameter which is the base to reuse the code + to use it for health checks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
| if self.observable_name.isdigit(): # If it's numeric, treat it as an ASN | ||
| data_type = "asn" | ||
| asn = int(self.observable_name) # Convert to integer | ||
| logger.info(f"The given observable is an ASN: {asn}") | ||
| else: | ||
| try: | ||
| ip = ipaddress.ip_address(self.observable_name) | ||
| data_type = "ipv4" if ip.version == 4 else "ipv6" | ||
| logger.info(f"The given observable is an {data_type} address.") | ||
| except ValueError: | ||
| raise ValueError(f"Invalid observable: {self.observable_name}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use this to check the observable type and then, do the related checks
from api_app.choices import Classification
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
|
I would like to accelerate this and finish this as soon as possible so @cristinaascari can finish her refactor here https://github.com/intelowlproject/IntelOwl/pull/2767/files. Please @pranjalg1331, once you have some time, prioritize this. Thanks |
Spamhaus does not work with domains either. Since it's now in the generic category too,
|
Ok so you can change those tests and make custom ones for this use case |
|
I have added a new value for Spamhaus test. |
| class Migration(migrations.Migration): | ||
| atomic = False | ||
| dependencies = [ | ||
| ("analyzers_manager", "0151_analyzer_config_ipquery"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update your migration number and its dependencies to reflect latest changes in `develop branch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
api_app/analyzers_manager/migrations/0152_alter_spamhaus_drop_supported_observable.py
Show resolved
Hide resolved
| if "generic" in observable_supported: | ||
| observable_supported.remove("generic") | ||
| obj.observable_supported = observable_supported | ||
| obj.save() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| obj.save() | |
| obj.full_clean() | |
| obj.save() |
| db_name = "drop_v4.json" | ||
| elif data_type == "ipv6": | ||
| db_name = "drop_v6.json" | ||
| else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| else: | |
| elif data_type == "asn": |
Then you can add an else clause that throws an error if the data_type is not supported, logging what was passed.
| if self.observable_classification == Classification.IP: | ||
| ip = ipaddress.ip_address(self.observable_name) | ||
| data_type = "ipv4" if ip.version == 4 else "ipv6" | ||
| logger.info(f"The given observable is an {data_type} address.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also log the observable for tracing pls
| def location(cls) -> str: | ||
| db_name = "drop_v4.json" | ||
| def location(cls, data_type: str) -> str: | ||
| print("location", data_type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why a print ?
| ): | ||
| data_type = "asn" | ||
| asn = int(self.observable_name) # Convert to integer | ||
| logger.info(f"The given observable is an ASN: {asn}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This log is still missing. This should be as on line 41-42
| matches.append(db[i]) | ||
| elif network.network_address > ip: | ||
| break | ||
| else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| else: | |
| elif data_type == "asn": |
and same logging as in location()
Signed-off-by: pranjalg1331 <[email protected]>
Signed-off-by: pranjalg1331 <[email protected]>
Signed-off-by: pranjalg1331 <[email protected]>
Signed-off-by: pranjalg1331 <[email protected]>
Signed-off-by: pranjalg1331 <[email protected]>
Signed-off-by: pranjalg1331 <[email protected]>
Signed-off-by: pranjalg1331 <[email protected]>
Signed-off-by: pranjalg1331 <[email protected]>
Signed-off-by: pranjalg1331 <[email protected]>
Signed-off-by: pranjalg1331 <[email protected]>
…supported_observable.py Co-authored-by: Federico Gibertoni <[email protected]>
Signed-off-by: pranjalg1331 <[email protected]>
Signed-off-by: pranjalg1331 <[email protected]>
3c3d2fb to
3f22e1b
Compare
|
I have made the requested changes. |
| db_url = cls.asn_url | ||
| else: | ||
| raise AnalyzerRunException( | ||
| "Invalid type provided for updating the database" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also log the value of the wrong data_type pls
|
After these small changes it's good to go by my side! Thank you |
Signed-off-by: pranjalg1331 <[email protected]>
fgibertoni
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
|
Can we merge this pr? |




(Please add to the PR name the issue/s that this PR would close if merged by using a Github keyword. Example:
<feature name>. Closes #999. If your PR is made by a single commit, please add that clause in the commit too. This is all required to automate the closure of related issues.)Description
closes #2408
Please include a summary of the change and link to the related issue.
Type of change
Please delete options that are not relevant.
Checklist
developdumpplugincommand and added it in the project as a data migration. ("How to share a plugin with the community")test_files.zipand you added the default tests for that mimetype in test_classes.py.FREE_TO_USE_ANALYZERSplaybook by following this guide.urlthat contains this information. This is required for Health Checks._monkeypatch()was used in its class to apply the necessary decorators.MockUpResponseof the_monkeypatch()method. This serves us to provide a valid sample for testing.# This file is a part of IntelOwl https://github.com/intelowlproject/IntelOwl # See the file 'LICENSE' for copying permission.Black,Flake,Isort) gave 0 errors. If you have correctly installed pre-commit, it does these checks and adjustments on your behalf.testsfolder). All the tests (new and old ones) gave 0 errors.DeepSource,Django Doctorsor other third-party linters have triggered any alerts during the CI checks, I have solved those alerts.Important Rules