Skip to content

Commit 4073e87

Browse files
authored
[injector] feat(shodan): added feat auto-create-assets (#156)
1 parent 20a6f0a commit 4073e87

File tree

14 files changed

+218
-150
lines changed

14 files changed

+218
-150
lines changed

shodan/.env.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ OPENAEV_URL=ChangeMe
77
OPENAEV_TOKEN=ChangeMe
88

99
# INJECTOR Environment Variables
10-
INJECTOR_ID=shodan--ChangeMe
10+
INJECTOR_ID=ChangeMe
1111
INJECTOR_NAME=Shodan
1212
INJECTOR_LOG_LEVEL=error
1313

shodan/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,11 @@ then returns several sections in the report if successful:
328328
- **Section JSON** – JSON return of the response directly (In the case of a "custom query", we return the JSON directly rather than the table section.)
329329

330330
### Auto-Create Assets
331-
- Feature currently under development
331+
This feature automatically creates structured Asset objects (when auto_create_assets is enabled in the UI) from
332+
Shodan API responses by extracting hostnames, IP addresses, and platform information.
333+
It supports multiple Shodan response formats depending on the contract type and normalizes the data into a unified
334+
structure. Assets are then grouped (hostname, platform, and architecture) to prevent duplicates while merging associated
335+
IP addresses.
332336

333337
### Rate Limiting and Retry
334338

shodan/config.yml.sample

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ openaev:
22
url: 'ChangeMe'
33
token: 'ChangeMe'
44

5-
#injector:
6-
# id: 'shodan--a87488ad-2c72-4592-b429-69259d7bcef1'
5+
injector:
6+
id: 'ChangeMe'
77
# name: 'Shodan'
88
# log_level: 'error'
99

shodan/shodan/contracts/cloud_provider_asset_discovery/contract.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,34 +74,28 @@ def output_trace_config():
7474
{
7575
"title": "Hostnames",
7676
"path": "matches.hostnames",
77-
"mode": "align_to_single",
7877
},
7978
{
8079
"title": "IP",
8180
"path": "matches.ip_str",
82-
"mode": "single",
8381
},
8482
{
8583
"title": "Port",
8684
"path": "matches.port",
87-
"mode": "align_to_single",
8885
},
8986
{
9087
"title": "Cloud Provider",
9188
"path": "matches.cloud.provider",
92-
"mode": "align_to_single",
9389
},
9490
{
9591
"title": "OS",
9692
"path": "matches.os",
97-
"mode": "align_to_single",
9893
},
9994
{
10095
"title": "Vulnerabilities (score)",
10196
"path": "matches.vulns.*",
10297
"use_key": True,
10398
"extra": "matches.vulns.*.cvss",
104-
"mode": "align_to_single",
10599
},
106100
],
107101
},

shodan/shodan/contracts/critical_ports_and_exposed_admin_interface/contract.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,24 +74,20 @@ def output_trace_config():
7474
{
7575
"title": "Port",
7676
"path": "matches.port",
77-
"mode": "single",
7877
},
7978
{
8079
"title": "Hostnames",
8180
"path": "matches.hostnames",
82-
"mode": "align_to_single",
8381
},
8482
{
8583
"title": "IP",
8684
"path": "matches.ip_str",
87-
"mode": "align_to_single",
8885
},
8986
{
9087
"title": "Vulnerabilities (score)",
9188
"path": "matches.vulns.*",
9289
"use_key": True,
9390
"extra": "matches.vulns.*.cvss",
94-
"mode": "align_to_single",
9591
},
9692
],
9793
},

shodan/shodan/contracts/cve_enumeration/contract.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,20 @@ def output_trace_config():
7373
{
7474
"title": "Hostnames",
7575
"path": "matches.hostnames",
76-
"mode": "single",
7776
},
7877
{
7978
"title": "IP",
8079
"path": "matches.ip_str",
81-
"mode": "align_to_single",
8280
},
8381
{
8482
"title": "Port",
8583
"path": "matches.port",
86-
"mode": "align_to_single",
8784
},
8885
{
8986
"title": "Vulnerabilities (score)",
9087
"path": "matches.vulns.*",
9188
"use_key": True,
9289
"extra": "matches.vulns.*.cvss",
93-
"mode": "align_to_single",
9490
},
9591
],
9692
},

shodan/shodan/contracts/cve_specific_watchlist/contract.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,20 @@ def output_trace_config():
7373
{
7474
"title": "Port",
7575
"path": "data.port",
76-
"mode": "single",
7776
},
7877
{
7978
"title": "Hostnames",
8079
"path": "data.hostnames",
81-
"mode": "align_to_single",
8280
},
8381
{
8482
"title": "IP",
8583
"path": "data.ip_str",
86-
"mode": "align_to_single",
8784
},
8885
{
8986
"title": "Vulnerabilities (score)",
9087
"path": "data.vulns.*",
9188
"use_key": True,
9289
"extra": "data.vulns.*.cvss",
93-
"mode": "align_to_single",
9490
},
9591
],
9692
},

shodan/shodan/contracts/domain_discovery/contract.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,20 @@ def output_trace_config():
7373
{
7474
"title": "Hostnames",
7575
"path": "matches.hostnames",
76-
"mode": "single",
7776
},
7877
{
7978
"title": "IP",
8079
"path": "matches.ip_str",
81-
"mode": "align_to_single",
8280
},
8381
{
8482
"title": "Port",
8583
"path": "matches.port",
86-
"mode": "align_to_single",
8784
},
8885
{
8986
"title": "Vulnerabilities (score)",
9087
"path": "matches.vulns.*",
9188
"use_key": True,
9289
"extra": "matches.vulns.*.cvss",
93-
"mode": "align_to_single",
9490
},
9591
],
9692
},

shodan/shodan/contracts/ip_enumeration/contract.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def output_trace_config():
2828
"icon": "CONFIG",
2929
"title": "[CONFIG] Summary of all configurations used for the contract.",
3030
},
31-
"keys_list_to_string": ["ips", "seen_ips"],
31+
"keys_list_to_string": ["ip", "ips", "seen_ips"],
3232
"keys_to_exclude": [
3333
"expectations",
3434
"asset_ids",
@@ -72,19 +72,16 @@ def output_trace_config():
7272
{
7373
"title": "Port",
7474
"path": "matches.port",
75-
"mode": "single",
7675
},
7776
{
7877
"title": "Hostnames",
7978
"path": "matches.hostnames",
80-
"mode": "align_to_single",
8179
},
8280
{
8381
"title": "Vulnerabilities (score)",
8482
"path": "matches.vulns.*",
8583
"use_key": True,
8684
"extra": "matches.vulns.*.cvss",
87-
"mode": "align_to_single",
8885
},
8986
],
9087
},

shodan/shodan/contracts/shodan_contracts.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
ContractConfig,
1111
ContractElement,
1212
ContractExpectations,
13+
ContractOutputElement,
14+
ContractOutputType,
1315
ContractSelect,
1416
Expectation,
1517
ExpectationType,
@@ -245,7 +247,14 @@ def _base_fields(self, selector_default_value: str) -> list[ContractElement]:
245247
# -- OUTPUTS --
246248
@staticmethod
247249
def _base_outputs():
248-
return []
250+
output_assets = ContractOutputElement(
251+
type=ContractOutputType.Asset,
252+
field="found_assets",
253+
isMultiple=True,
254+
isFindingCompatible=False,
255+
labels=["shodan"],
256+
)
257+
return [output_assets]
249258

250259
def _build_contract(
251260
self,

0 commit comments

Comments
 (0)