-
Notifications
You must be signed in to change notification settings - Fork 59
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
Port internetnl bit → nibble #4026
Draft
originalsouth
wants to merge
17
commits into
feature/nibbles
Choose a base branch
from
feature/nibbles-internetnl
base: feature/nibbles
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.
Draft
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
89cf4f0
DEMO
originalsouth abb845d
DEMO2
originalsouth 8f13d8f
Merge branch 'feature/nibbles' into feature/nibbles-https-availability
originalsouth 6c51943
Make precommit happy
originalsouth 1439194
Merge remote-tracking branch 'origin/main' into feature/nibbles-https…
originalsouth ca29c3e
Finalize
originalsouth 9e2d961
Merge branch 'feature/nibbles' into feature/nibbles-https-availability
originalsouth 2373d0c
Close the corners
originalsouth 368bf69
Fix unit test
originalsouth d5980ee
Merge remote-tracking branch 'origin/feature/nibbles' into feature/ni…
originalsouth b848816
Init
originalsouth 681d050
Integrate feedback
originalsouth 3e6c87e
Fix nibble
originalsouth 99cc00c
Fix nibble test
originalsouth 90a84dc
Merge remote-tracking branch 'origin/feature/nibbles-https-availabili…
originalsouth 2ca65dd
or-join ftw
originalsouth ff021ea
Nail internetnl (almost)
originalsouth 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 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from collections.abc import Iterator | ||
|
||
from octopoes.models import OOI | ||
from octopoes.models.ooi.findings import Finding, KATFindingType | ||
from octopoes.models.ooi.network import IPAddress, IPPort | ||
from octopoes.models.ooi.web import Website | ||
|
||
|
||
def nibble(ipaddress: IPAddress, ipport80: IPPort, website: Website, port443s: int) -> Iterator[OOI]: | ||
_ = ipaddress | ||
_ = ipport80 | ||
if port443s < 1: | ||
ft = KATFindingType(id="KAT-HTTPS-NOT-AVAILABLE") | ||
yield ft | ||
yield Finding( | ||
ooi=website.reference, | ||
finding_type=ft.reference, | ||
description="HTTP port is open, but HTTPS port is not open", | ||
) |
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,66 @@ | ||
from nibbles.definitions import NibbleDefinition, NibbleParameter | ||
from octopoes.models import Reference | ||
from octopoes.models.ooi.network import IPAddress, IPPort | ||
from octopoes.models.ooi.web import Website | ||
|
||
|
||
def query(targets: list[Reference | None]) -> str: | ||
def pull(statements: list[str]) -> str: | ||
return f""" | ||
{{ | ||
:query {{ | ||
:find [(pull ?ipaddress [*]) (pull ?ipport80 [*]) (pull ?website [*]) (- (count ?ipport443) 1)] | ||
:where [ | ||
{" ".join(statements)} | ||
] | ||
}} | ||
}} | ||
""" | ||
|
||
base_query = [ | ||
""" | ||
[?website :Website/ip_service ?ip_service] | ||
[?ipservice :IPService/ip_port ?ipport80] | ||
[?ipport80 :IPPort/port 80] | ||
[?ipport80 :IPPort/address ?ipaddress] | ||
(or | ||
(and [?ipport443 :IPPort/address ?ipaddress][?ipport443 :IPPort/port 443]) | ||
[(identity nil) ?ipport443] | ||
) | ||
""" | ||
] | ||
|
||
ref_queries = [ | ||
f'[?ipaddress :IPAddress/primary_key "{str(targets[0])}"]', | ||
f'[?ipport80 :IPPort/primary_key "{str(targets[1])}"]', | ||
f'[?website :Website/primary_key "{str(targets[2])}"]', | ||
] | ||
|
||
sgn = "".join(str(int(isinstance(target, Reference))) for target in targets) | ||
if sgn == "1000": | ||
return pull(ref_queries[0:1] + base_query) | ||
elif sgn == "0100": | ||
if int(str(targets[1]).split("|")[-1]) == 80: | ||
return pull(ref_queries[1:2] + base_query) | ||
else: | ||
return pull(base_query) | ||
elif sgn == "0010": | ||
return pull(ref_queries[2:3] + base_query) | ||
elif sgn == "1110": | ||
return pull(ref_queries + base_query) | ||
else: | ||
return pull(base_query) | ||
|
||
|
||
NIBBLE = NibbleDefinition( | ||
id="https_availability", | ||
signature=[ | ||
NibbleParameter( | ||
object_type=IPAddress, parser="[*][?object_type == 'IPAddressV6' || object_type == 'IPAddressV4'][]" | ||
), | ||
NibbleParameter(object_type=IPPort, parser="[*][?object_type == 'IPPort'][]"), | ||
NibbleParameter(object_type=Website, parser="[*][?object_type == 'Website'][]"), | ||
NibbleParameter(object_type=int, parser="[*][-1][]"), | ||
], | ||
query=query, | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from collections.abc import Iterator | ||
|
||
from octopoes.models import OOI | ||
from octopoes.models.ooi.dns.zone import Hostname | ||
from octopoes.models.ooi.findings import Finding, KATFindingType | ||
|
||
|
||
def nibble(hostname: Hostname, findings: list[Finding]) -> Iterator[OOI]: | ||
result = "\n".join([str(finding.description) for finding in findings]) | ||
|
||
if result: | ||
ft = KATFindingType(id="KAT-INTERNETNL") | ||
yield ft | ||
yield Finding( | ||
finding_type=ft.reference, | ||
ooi=hostname.reference, | ||
description=f"This hostname has at least one website with the following finding(s): {result}", | ||
) |
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,101 @@ | ||
from nibbles.definitions import NibbleDefinition, NibbleParameter | ||
from octopoes.models import Reference | ||
from octopoes.models.ooi.dns.zone import Hostname, Network | ||
from octopoes.models.ooi.findings import Finding | ||
|
||
finding_types = [ | ||
"KAT-WEBSERVER-NO-IPV6", | ||
"KAT-NAMESERVER-NO-TWO-IPV6", | ||
"KAT-NO-DNSSEC", | ||
"KAT-INVALID-DNSSEC", | ||
"KAT-NO-HSTS", | ||
"KAT-NO-CSP", | ||
"KAT-NO-X-FRAME-OPTIONS", | ||
"KAT-NO-X-CONTENT-TYPE-OPTIONS", | ||
"KAT-CSP-VULNERABILITIES", | ||
"KAT-HSTS-VULNERABILITIES", | ||
"KAT-NO-CERTIFICATE", | ||
"KAT-HTTPS-NOT-AVAILABLE", | ||
"KAT-SSL-CERT-HOSTNAME-MISMATCH", | ||
"KAT-HTTPS-REDIRECT", | ||
] | ||
|
||
|
||
def or_finding_types() -> str: | ||
clauses = "".join([f'[?finding :Finding/finding_type "{ft}"]' for ft in finding_types]) | ||
return f"(or {clauses})" | ||
|
||
|
||
def query(targets: list[Reference | None]) -> str: | ||
def pull(statements: list[str]) -> str: | ||
return f""" | ||
{{ | ||
:query {{ | ||
:find [ | ||
(pull ?hostname [*]) | ||
(pull ?website [*]) | ||
(pull ?finding [*]) | ||
] | ||
:where [ | ||
{" ".join(statements)} | ||
] | ||
}} | ||
}} | ||
""" | ||
|
||
base_query = [ | ||
""" | ||
[?hostname :object_type "Hostname"] | ||
[?website :Website/hostname ?hostname] | ||
(or-join [?finding] | ||
[?finding :Finding/ooi ?hostname] | ||
(and | ||
[?hostnamehttpurl :HostnameHTTPURL/netloc ?hostname] | ||
[?finding :Finding/ooi ?hostnamehttpurl] | ||
) | ||
[?finding :Finding/ooi ?website] | ||
(and | ||
[?resource :HTTPResource/website ?website] | ||
[?finding :Finding/ooi ?resource] | ||
) | ||
(and | ||
[?header :HTTPHeader/resource ?resource] | ||
[?resource :HTTPResource/website ?website] | ||
[?finding :Finding/ooi ?header] | ||
) | ||
) | ||
""" | ||
] | ||
|
||
sgn = "".join(str(int(isinstance(target, Reference))) for target in targets) | ||
ref_query = ["[?hostname :Hostname/primary_key]"] | ||
if sgn == "100": | ||
ref_query = [f'[?hostname :Hostname/primary_key "{str(targets[0])}"]'] | ||
elif sgn == "010": | ||
ref_query = [f'[?hostname :Hostname/primary_key "{str(targets[1]).split("|")[-1]}"]'] | ||
elif sgn == "001": | ||
tokens = str(targets[2]).split("|")[1:-1] | ||
target_reference = Reference.from_str("|".join(tokens)) | ||
if tokens[0] == "Hostname": | ||
hostname = target_reference.tokenized | ||
elif tokens[0] in {"HostnameHTTPURL", "Website"}: | ||
hostname = target_reference.tokenized.hostname | ||
elif tokens[0] == "HTTPResource": | ||
hostname = target_reference.tokenized.website.hostname | ||
elif tokens[0] == "HTTPHeader": | ||
hostname = target_reference.tokenized.resource.website.hostname | ||
else: | ||
raise ValueError() | ||
hostname_pk = Hostname(name=hostname.name, network=Network(name=hostname.network.name).reference).reference | ||
ref_query = [f'[?hostname :Hostname/primary_key "{str(hostname_pk)}"]'] | ||
return pull(ref_query + base_query) | ||
|
||
|
||
NIBBLE = NibbleDefinition( | ||
id="internet_nl", | ||
signature=[ | ||
NibbleParameter(object_type=Hostname, parser="[*][?object_type == 'Hostname'][]"), | ||
NibbleParameter(object_type=list[Finding], parser="[[*][?object_type == 'Finding'][]]", additional={Finding}), | ||
], | ||
query=query, | ||
) |
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.
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.
probably not what you wanted to commit?
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.
I'm leaving it till the draft is completed.
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.
Context: these are branches we pass back and forth a lot so we want to directly in the test we are working on