-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ add Shodan InternetDB boefje (#2615)
Co-authored-by: Jan Klopper <[email protected]> Co-authored-by: originalsouth <[email protected]> Co-authored-by: Ammar <[email protected]>
- Loading branch information
1 parent
2137b58
commit 870b4fe
Showing
12 changed files
with
152 additions
and
25 deletions.
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 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
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
Empty file.
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,10 @@ | ||
{ | ||
"id": "shodan_internetdb", | ||
"name": "'Shodan InternetDB", | ||
"description": "Use Shodan InternetDB to find open ports with vulnerabilities that are found on an IP.", | ||
"consumes": [ | ||
"IPAddressV4", | ||
"IPAddressV6" | ||
], | ||
"scan_level": 1 | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions
30
boefjes/boefjes/plugins/kat_shodan_internetdb/description.md
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,30 @@ | ||
# Shodan InternetDB | ||
|
||
Fast IP Lookups for Open Ports and Vulnerabilities. Only free for non-commercial use. The API gets updated once a week. | ||
|
||
See: https://internetdb.shodan.io/, https://internetdb.shodan.io/docs | ||
|
||
## Return Schema: | ||
|
||
``` | ||
{ | ||
"cpes": [ | ||
"string" | ||
], | ||
"hostnames": [ | ||
"string" | ||
], | ||
"ip": "string", | ||
"ports": [ | ||
0 | ||
], | ||
"tags": [ | ||
"string" | ||
], | ||
"vulns": [ | ||
"string" | ||
] | ||
} | ||
``` | ||
|
||
Tags are discarded in the normalizer. |
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 ipaddress import ip_address | ||
|
||
import requests | ||
|
||
from boefjes.job_models import BoefjeMeta | ||
|
||
REQUEST_TIMEOUT = 60 | ||
|
||
|
||
def run(boefje_meta: BoefjeMeta) -> list[tuple[set, bytes | str]]: | ||
"""Make request to InternetDB.""" | ||
ip = boefje_meta.arguments["input"]["address"] | ||
if ip_address(ip).is_private: | ||
return [({"info/boefje"}, "Skipping private IP address")] | ||
response = requests.get(f"https://internetdb.shodan.io/{ip}", timeout=REQUEST_TIMEOUT) | ||
response.raise_for_status() | ||
|
||
return [(set(), response.content)] |
54 changes: 54 additions & 0 deletions
54
boefjes/boefjes/plugins/kat_shodan_internetdb/normalize.py
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,54 @@ | ||
import json | ||
import logging | ||
from collections.abc import Iterable | ||
|
||
from boefjes.plugins.helpers import cpe_to_name_version | ||
from octopoes.models import OOI, Reference | ||
from octopoes.models.ooi.dns.records import DNSPTRRecord | ||
from octopoes.models.ooi.dns.zone import Hostname | ||
from octopoes.models.ooi.findings import CVEFindingType, Finding | ||
from octopoes.models.ooi.network import Network | ||
from octopoes.models.ooi.software import Software, SoftwareInstance | ||
|
||
DNS_PTR_STR = ".in-addr.arpa" | ||
|
||
|
||
def run(input_ooi: dict, raw: bytes) -> Iterable[OOI]: | ||
"""Normalize InternetDB output.""" | ||
result = json.loads(raw) | ||
input_ooi_reference = Reference.from_str(input_ooi["primary_key"]) | ||
input_ooi_str = input_ooi["address"] | ||
|
||
if not result: | ||
logging.info("No InternetDB results available for normalization.") | ||
elif "detail" in result: | ||
if result["detail"] == "No information available": | ||
logging.info("No information available for IP.") | ||
else: | ||
logging.warning("Unexpected detail: %s", result["detail"]) | ||
else: | ||
for hostname in result["hostnames"]: | ||
hostname_ooi = Hostname(name=hostname, network=Network(name=input_ooi["network"]["name"]).reference) | ||
yield hostname_ooi | ||
if hostname.endswith(DNS_PTR_STR): | ||
yield DNSPTRRecord(hostname=hostname_ooi.reference, value=hostname, address=input_ooi_reference) | ||
|
||
# ruff: noqa: ERA001 | ||
# for port in result["ports"]: | ||
# yield IPPort(address=input_ooi_reference, port=int(port), state=PortState("open")) | ||
|
||
for cve in result["vulns"]: | ||
finding_type = CVEFindingType(id=cve) | ||
finding = Finding( | ||
finding_type=finding_type.reference, | ||
ooi=input_ooi_reference, | ||
proof=f"https://internetdb.shodan.io/{input_ooi_str}", | ||
) | ||
yield finding_type | ||
yield finding | ||
|
||
for cpe in result["cpes"]: | ||
name, version = cpe_to_name_version(cpe=cpe) | ||
software = Software(name=name, version=version, cpe=cpe) | ||
yield software | ||
yield SoftwareInstance(software=software.reference, ooi=input_ooi_reference) |
16 changes: 16 additions & 0 deletions
16
boefjes/boefjes/plugins/kat_shodan_internetdb/normalizer.json
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,16 @@ | ||
{ | ||
"id": "kat_shodan_internetdb_normalize", | ||
"name": "Shodan InternetDB normalizer", | ||
"consumes": [ | ||
"boefje/shodan_internetdb" | ||
], | ||
"produces": [ | ||
"Finding", | ||
"IPPort", | ||
"Hostname", | ||
"CVEFindingType", | ||
"DNSPTRRecord", | ||
"Software", | ||
"SoftwareInstance" | ||
] | ||
} |
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