targetzero 0.3.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- targetzero/__init__.py +4 -0
- targetzero/__main__.py +6 -0
- targetzero/admins.py +109 -0
- targetzero/cli.py +366 -0
- targetzero/common/__init__.py +2 -0
- targetzero/common/changes.py +46 -0
- targetzero/common/config.py +83 -0
- targetzero/common/ids.py +17 -0
- targetzero/common/output.py +91 -0
- targetzero/common/resources.py +32 -0
- targetzero/common/roles.py +24 -0
- targetzero/common/schema.py +45 -0
- targetzero/config/approved_exposure.example.csv +4 -0
- targetzero/config/privileged_roles.yaml +50 -0
- targetzero/config/targetzero.example.yaml +57 -0
- targetzero/external/__init__.py +2 -0
- targetzero/external/dangling.py +106 -0
- targetzero/external/discover.py +181 -0
- targetzero/external/dnsinfo.py +54 -0
- targetzero/external/enrich.py +137 -0
- targetzero/external/http.py +33 -0
- targetzero/external/kev.py +222 -0
- targetzero/external/ports.py +63 -0
- targetzero/external/scan.py +260 -0
- targetzero/external/scope.py +54 -0
- targetzero/external/waf.py +202 -0
- targetzero/external/web.py +124 -0
- targetzero/gws/__init__.py +2 -0
- targetzero/gws/admins.py +230 -0
- targetzero/gws/changes.py +190 -0
- targetzero/gws/client.py +94 -0
- targetzero/gws/domains.py +36 -0
- targetzero/registers/__init__.py +2 -0
- targetzero/registers/exceptions.py +85 -0
- targetzero/registers/findings.py +108 -0
- targetzero/registers/inventory.py +142 -0
- targetzero/registers/manual_admins.py +43 -0
- targetzero/schemas/admins.schema.json +27 -0
- targetzero/schemas/alert_tests.schema.json +19 -0
- targetzero/schemas/config.schema.json +71 -0
- targetzero/schemas/exceptions.schema.json +20 -0
- targetzero/schemas/findings.schema.json +23 -0
- targetzero/schemas/inventory.schema.json +26 -0
- targetzero/schemas/summary.schema.json +36 -0
- targetzero/scorecard/__init__.py +2 -0
- targetzero/scorecard/scorecard.py +201 -0
- targetzero/templates/alert_tests.csv +1 -0
- targetzero/templates/exceptions.csv +1 -0
- targetzero/templates/findings.csv +1 -0
- targetzero/templates/inventory.csv +1 -0
- targetzero/templates/manual_admins.csv +1 -0
- targetzero/templates/origins.csv +1 -0
- targetzero/templates/recovery_page.md +51 -0
- targetzero/vendors/__init__.py +2 -0
- targetzero/vendors/cisco_asa.py +151 -0
- targetzero/vendors/common.py +84 -0
- targetzero/vendors/fortigate.py +176 -0
- targetzero/vendors/panos.py +141 -0
- targetzero/vendors/redfish.py +124 -0
- targetzero/vendors/vsphere.py +108 -0
- targetzero-0.3.2.dist-info/METADATA +116 -0
- targetzero-0.3.2.dist-info/RECORD +66 -0
- targetzero-0.3.2.dist-info/WHEEL +4 -0
- targetzero-0.3.2.dist-info/entry_points.txt +2 -0
- targetzero-0.3.2.dist-info/licenses/LICENSE +202 -0
- targetzero-0.3.2.dist-info/licenses/NOTICE +7 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""Build the Target 0 scorecard from the count summaries of one run date.
|
|
3
|
+
|
|
4
|
+
Rules:
|
|
5
|
+
- A count with no summary is "no data", never zero.
|
|
6
|
+
- Items covered by a valid exception are not in "today"; they are shown as
|
|
7
|
+
excepted items, and the exceptions themselves as open exceptions.
|
|
8
|
+
- The first count seen for each target becomes its Day 1 baseline.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import csv
|
|
14
|
+
import json
|
|
15
|
+
from dataclasses import asdict, dataclass, field
|
|
16
|
+
from datetime import UTC, date, datetime
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
from typing import Any
|
|
19
|
+
|
|
20
|
+
from targetzero.common.config import Config
|
|
21
|
+
from targetzero.common.output import write_csv
|
|
22
|
+
from targetzero.common.schema import validate_summary
|
|
23
|
+
from targetzero.registers.exceptions import ExceptionRecord, load_exceptions
|
|
24
|
+
|
|
25
|
+
TARGETS = {
|
|
26
|
+
1: "Admins with full, permanent access",
|
|
27
|
+
2: "Admins without MFA",
|
|
28
|
+
3: "Admins not monitored",
|
|
29
|
+
4: "Public IPs not behind firewall, WAF or CDN",
|
|
30
|
+
5: "Public IPs without inventory",
|
|
31
|
+
6: "Public IPs or domains with known vulnerabilities past deadline",
|
|
32
|
+
7: "Internet-facing apps without tested recovery page",
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
ROW_FIELDS = (
|
|
36
|
+
"zero",
|
|
37
|
+
"target",
|
|
38
|
+
"day_1",
|
|
39
|
+
"today",
|
|
40
|
+
"excepted_items",
|
|
41
|
+
"open_exceptions",
|
|
42
|
+
"status",
|
|
43
|
+
"owner",
|
|
44
|
+
"sources",
|
|
45
|
+
)
|
|
46
|
+
HISTORY_FIELDS = ("run_date", "zero", "today", "excepted_items", "open_exceptions", "status")
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@dataclass
|
|
50
|
+
class Row:
|
|
51
|
+
zero: int
|
|
52
|
+
target: str
|
|
53
|
+
owner: str
|
|
54
|
+
day_1: int | None = None
|
|
55
|
+
today: int | None = None
|
|
56
|
+
excepted_items: int = 0
|
|
57
|
+
open_exceptions: int = 0
|
|
58
|
+
status: str = "no data"
|
|
59
|
+
sources: list[str] = field(default_factory=list)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@dataclass
|
|
63
|
+
class Scorecard:
|
|
64
|
+
organisation: str
|
|
65
|
+
run_date: str
|
|
66
|
+
generated_at: str
|
|
67
|
+
rows: list[Row]
|
|
68
|
+
exception_gaps: list[dict[str, Any]]
|
|
69
|
+
summary_problems: list[dict[str, Any]]
|
|
70
|
+
baseline: dict[str, dict[str, Any]] = field(default_factory=dict, repr=False)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _load_summaries(directory: Path) -> tuple[list[dict[str, Any]], list[dict[str, Any]]]:
|
|
74
|
+
summaries, problems = [], []
|
|
75
|
+
for path in sorted(directory.glob("*.summary.json")):
|
|
76
|
+
try:
|
|
77
|
+
data = json.loads(path.read_text(encoding="utf-8"))
|
|
78
|
+
except (OSError, json.JSONDecodeError) as exc:
|
|
79
|
+
problems.append({"file": path.name, "problems": [str(exc)]})
|
|
80
|
+
continue
|
|
81
|
+
errors = validate_summary(data)
|
|
82
|
+
if errors:
|
|
83
|
+
problems.append({"file": path.name, "problems": errors, "zero": data.get("zero")})
|
|
84
|
+
else:
|
|
85
|
+
summaries.append(data)
|
|
86
|
+
return summaries, problems
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _load_baseline(path: Path) -> dict[str, dict[str, Any]]:
|
|
90
|
+
if path.exists():
|
|
91
|
+
data: dict[str, dict[str, Any]] = json.loads(path.read_text(encoding="utf-8"))
|
|
92
|
+
return data
|
|
93
|
+
return {}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def build(config: Config, run_date: date) -> Scorecard:
|
|
97
|
+
directory = config.output_dir / run_date.isoformat()
|
|
98
|
+
summaries, summary_problems = _load_summaries(directory) if directory.exists() else ([], [])
|
|
99
|
+
exceptions = load_exceptions(
|
|
100
|
+
config.registers_dir / "exceptions.csv",
|
|
101
|
+
run_date,
|
|
102
|
+
config.threshold("exception_max_days", 90),
|
|
103
|
+
)
|
|
104
|
+
valid: dict[int, list[ExceptionRecord]] = {}
|
|
105
|
+
for record in exceptions:
|
|
106
|
+
if record.valid and record.zero:
|
|
107
|
+
valid.setdefault(record.zero, []).append(record)
|
|
108
|
+
|
|
109
|
+
baseline = _load_baseline(config.output_dir / "baseline.json")
|
|
110
|
+
rows = []
|
|
111
|
+
for zero, target in TARGETS.items():
|
|
112
|
+
row = Row(zero=zero, target=target, owner=config.owner(zero))
|
|
113
|
+
mine = [s for s in summaries if s["zero"] == zero]
|
|
114
|
+
broken = [p for p in summary_problems if p.get("zero") == zero]
|
|
115
|
+
if mine:
|
|
116
|
+
items = {i["id"] for s in mine for i in s["items"]}
|
|
117
|
+
covered = {i for e in valid.get(zero, []) for i in e.items} & items
|
|
118
|
+
row.today = len(items - covered)
|
|
119
|
+
row.excepted_items = len(covered)
|
|
120
|
+
row.sources = sorted(f"{s['source']}/{s['name']}" for s in mine)
|
|
121
|
+
if broken or not all(s["complete"] for s in mine):
|
|
122
|
+
row.status = "incomplete"
|
|
123
|
+
else:
|
|
124
|
+
row.status = "zero" if row.today == 0 else "open"
|
|
125
|
+
if str(zero) not in baseline:
|
|
126
|
+
baseline[str(zero)] = {"date": run_date.isoformat(), "count": row.today}
|
|
127
|
+
elif broken:
|
|
128
|
+
row.status = "incomplete"
|
|
129
|
+
row.open_exceptions = len(valid.get(zero, []))
|
|
130
|
+
if str(zero) in baseline:
|
|
131
|
+
row.day_1 = int(baseline[str(zero)]["count"])
|
|
132
|
+
rows.append(row)
|
|
133
|
+
|
|
134
|
+
return Scorecard(
|
|
135
|
+
organisation=config.organisation,
|
|
136
|
+
run_date=run_date.isoformat(),
|
|
137
|
+
generated_at=datetime.now(UTC).isoformat(timespec="seconds"),
|
|
138
|
+
rows=rows,
|
|
139
|
+
exception_gaps=[
|
|
140
|
+
{"id": e.id, "zero": e.zero, "problems": e.problems} for e in exceptions if not e.valid
|
|
141
|
+
],
|
|
142
|
+
summary_problems=summary_problems,
|
|
143
|
+
baseline=baseline,
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def _csv_row(row: Row) -> dict[str, Any]:
|
|
148
|
+
values = asdict(row)
|
|
149
|
+
values["sources"] = ";".join(row.sources)
|
|
150
|
+
return {k: values[k] for k in ROW_FIELDS}
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def write(config: Config, card: Scorecard) -> list[Path]:
|
|
154
|
+
directory = config.output_dir / card.run_date
|
|
155
|
+
directory.mkdir(parents=True, exist_ok=True)
|
|
156
|
+
csv_path = write_csv(directory / "scorecard.csv", [_csv_row(r) for r in card.rows], ROW_FIELDS)
|
|
157
|
+
json_path = directory / "scorecard.json"
|
|
158
|
+
data = asdict(card)
|
|
159
|
+
del data["baseline"]
|
|
160
|
+
json_path.write_text(json.dumps(data, indent=2) + "\n", encoding="utf-8")
|
|
161
|
+
baseline_path = config.output_dir / "baseline.json"
|
|
162
|
+
baseline_path.write_text(
|
|
163
|
+
json.dumps(card.baseline, indent=2, sort_keys=True) + "\n", encoding="utf-8"
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
# History: one row per target per run date; re-running a date replaces its rows.
|
|
167
|
+
history_path = config.output_dir / "history.csv"
|
|
168
|
+
history: list[dict[str, Any]] = []
|
|
169
|
+
if history_path.exists():
|
|
170
|
+
with history_path.open(newline="", encoding="utf-8") as handle:
|
|
171
|
+
history = [r for r in csv.DictReader(handle) if r["run_date"] != card.run_date]
|
|
172
|
+
history += [
|
|
173
|
+
{"run_date": card.run_date, **{k: v for k, v in _csv_row(r).items() if k in HISTORY_FIELDS}}
|
|
174
|
+
for r in card.rows
|
|
175
|
+
]
|
|
176
|
+
history.sort(key=lambda r: (r["run_date"], int(r["zero"])))
|
|
177
|
+
write_csv(history_path, history, HISTORY_FIELDS)
|
|
178
|
+
return [csv_path, json_path, history_path, baseline_path]
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def render_text(card: Scorecard) -> str:
|
|
182
|
+
def show(value: int | None) -> str:
|
|
183
|
+
return "-" if value is None else str(value)
|
|
184
|
+
|
|
185
|
+
lines = [
|
|
186
|
+
f"Target 0 scorecard - {card.organisation} - {card.run_date}",
|
|
187
|
+
"",
|
|
188
|
+
f"{'#':<2} {'Target':<64} {'Day 1':>5} {'Today':>5} {'Exc.':>4} Status",
|
|
189
|
+
]
|
|
190
|
+
for r in card.rows:
|
|
191
|
+
lines.append(
|
|
192
|
+
f"{r.zero:<2} {r.target:<64} {show(r.day_1):>5} {show(r.today):>5} "
|
|
193
|
+
f"{r.open_exceptions:>4} {r.status}"
|
|
194
|
+
)
|
|
195
|
+
if card.exception_gaps:
|
|
196
|
+
lines += ["", "Exceptions that are gaps (not counted as exceptions):"]
|
|
197
|
+
lines += [f" {g['id']}: {'; '.join(g['problems'])}" for g in card.exception_gaps]
|
|
198
|
+
if card.summary_problems:
|
|
199
|
+
lines += ["", "Summaries that were rejected:"]
|
|
200
|
+
lines += [f" {p['file']}: {'; '.join(p['problems'])}" for p in card.summary_problems]
|
|
201
|
+
return "\n".join(lines)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
id,system,account,test_time,alert_received,received_at,received_by,notes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
id,zero,items,description,compensating_control,accepted_by,signed_date,expiry_date,notes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
id,asset_id,vulnerability,title,severity,published,deadline,status,action,owner,closed_date,notes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
id,asset,type,ip,owner,purpose,product,version,vendor_supported,eol_date,behind_waf,internet_facing_app,status,last_reviewed,notes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
id,source,system,account,role,account_type,privileged,permanent,end_date,mfa_class,mfa_enforced,separate_admin_account,break_glass,last_logon,last_verified,notes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
host,origin_ip,notes
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
---
|
|
2
|
+
app_id: "" # id of the inventory row, e.g. inventory:shop.example.com
|
|
3
|
+
application: ""
|
|
4
|
+
owner: ""
|
|
5
|
+
status: draft # draft | complete | tested
|
|
6
|
+
shutdown_tested: "" # YYYY-MM-DD of the last shutdown test
|
|
7
|
+
last_reviewed: "" # YYYY-MM-DD
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Recovery page: <application>
|
|
11
|
+
|
|
12
|
+
Hostnames:
|
|
13
|
+
Hosted by:
|
|
14
|
+
Vendor or provider contact (including after hours):
|
|
15
|
+
|
|
16
|
+
## 1. Shut down (target: under 15 minutes)
|
|
17
|
+
|
|
18
|
+
| Question | Answer |
|
|
19
|
+
| --- | --- |
|
|
20
|
+
| Who decides? | |
|
|
21
|
+
| Who executes? | |
|
|
22
|
+
| How (firewall rule, DNS change, hosting panel, kill switch)? | |
|
|
23
|
+
| Phone numbers, including after hours | |
|
|
24
|
+
| Last tested on | |
|
|
25
|
+
|
|
26
|
+
## 2. Rotate secrets (target: under 24 hours)
|
|
27
|
+
|
|
28
|
+
| Secret (password, API key, certificate, service account) | Used for | Who can change it | Order |
|
|
29
|
+
| --- | --- | --- | --- |
|
|
30
|
+
| | | | |
|
|
31
|
+
|
|
32
|
+
## 3. Rebuild (target: within the agreed recovery time)
|
|
33
|
+
|
|
34
|
+
| Question | Answer |
|
|
35
|
+
| --- | --- |
|
|
36
|
+
| Agreed recovery time | |
|
|
37
|
+
| Where are the backups? | |
|
|
38
|
+
| Where is the configuration? | |
|
|
39
|
+
| Last tested restore | |
|
|
40
|
+
| Who can rebuild it? | |
|
|
41
|
+
|
|
42
|
+
## 4. Change crypto (target: under 30 days)
|
|
43
|
+
|
|
44
|
+
| Question | Answer |
|
|
45
|
+
| --- | --- |
|
|
46
|
+
| Certificates in use (issuer, expiry, key type and size) | |
|
|
47
|
+
| TLS versions and settings | |
|
|
48
|
+
| Who can change them? | |
|
|
49
|
+
| Does the vendor support newer algorithms? | |
|
|
50
|
+
|
|
51
|
+
A plan that has never been tested counts as missing.
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""Cisco ASA collector, offline: parses `show running-config` saved as text.
|
|
3
|
+
|
|
4
|
+
Save it with `more system:running-config` or `show running-config` in a terminal session that
|
|
5
|
+
logs to a file, or copy it from ASDM (File > Show Running Configuration in New Window).
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import re
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
from targetzero.admins import record_id
|
|
14
|
+
from targetzero.common.ids import make_id
|
|
15
|
+
from targetzero.vendors.common import Device
|
|
16
|
+
|
|
17
|
+
SOURCE = "asa"
|
|
18
|
+
UNTRUSTED = re.compile(r"outside|internet|wan|untrust|external|public", re.IGNORECASE)
|
|
19
|
+
USER = re.compile(r"^username (\S+) (?:password|nopassword)\b.*?(?:privilege (\d+))?\s*$")
|
|
20
|
+
ACCESS = re.compile(r"^(ssh|http|telnet) (\S+) (\S+) (\S+)\s*$")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def parse_interfaces(lines: list[str]) -> dict[str, int]:
|
|
24
|
+
"""nameif -> security-level."""
|
|
25
|
+
levels: dict[str, int] = {}
|
|
26
|
+
nameif = ""
|
|
27
|
+
for line in lines:
|
|
28
|
+
if line.startswith("interface "):
|
|
29
|
+
nameif = ""
|
|
30
|
+
elif line.startswith(" nameif "):
|
|
31
|
+
nameif = line.split()[1]
|
|
32
|
+
levels.setdefault(nameif, 100)
|
|
33
|
+
elif line.startswith(" security-level ") and nameif:
|
|
34
|
+
levels[nameif] = int(line.split()[1])
|
|
35
|
+
return levels
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def console_auth(lines: list[str]) -> dict[str, list[str]]:
|
|
39
|
+
"""'ssh' / 'http' -> server groups used for console login, e.g. ['ISE', 'LOCAL']."""
|
|
40
|
+
auth: dict[str, list[str]] = {}
|
|
41
|
+
for line in lines:
|
|
42
|
+
words = line.split()
|
|
43
|
+
if words[:2] == ["aaa", "authentication"] and len(words) >= 5 and words[3] == "console":
|
|
44
|
+
auth[words[2]] = words[4:]
|
|
45
|
+
return auth
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def collect(path: Path, break_glass: set[str]) -> Device:
|
|
49
|
+
lines = path.read_text(encoding="utf-8", errors="replace").splitlines()
|
|
50
|
+
hostname = next((ln.split()[1] for ln in lines if ln.startswith("hostname ")), path.stem)
|
|
51
|
+
version = next((m.group(1) for ln in lines if (m := re.match(r"^ASA Version (\S+)", ln))), "")
|
|
52
|
+
device = Device(
|
|
53
|
+
vendor="Cisco",
|
|
54
|
+
system=hostname,
|
|
55
|
+
product="Adaptive Security Appliance (ASA)",
|
|
56
|
+
version=version,
|
|
57
|
+
file=path.name,
|
|
58
|
+
)
|
|
59
|
+
if not version:
|
|
60
|
+
device.notes.append("'ASA Version' line not found: is this a running-config?")
|
|
61
|
+
|
|
62
|
+
vpn_only: set[str] = set()
|
|
63
|
+
current = ""
|
|
64
|
+
for line in lines:
|
|
65
|
+
if line.startswith("username ") and line.endswith(" attributes"):
|
|
66
|
+
current = line.split()[1]
|
|
67
|
+
elif line.startswith(" service-type remote-access") and current:
|
|
68
|
+
vpn_only.add(current)
|
|
69
|
+
elif not line.startswith(" "):
|
|
70
|
+
current = ""
|
|
71
|
+
|
|
72
|
+
auth = console_auth(lines)
|
|
73
|
+
groups = sorted({g for methods in auth.values() for g in methods if g != "LOCAL"})
|
|
74
|
+
if groups:
|
|
75
|
+
local_class, local_enforced = "unknown", "unknown"
|
|
76
|
+
local_note = (
|
|
77
|
+
f"console login through {', '.join(groups)}; local account is the fallback; "
|
|
78
|
+
"check MFA on that server"
|
|
79
|
+
)
|
|
80
|
+
else:
|
|
81
|
+
local_class, local_enforced, local_note = "none", "N", "local password only"
|
|
82
|
+
|
|
83
|
+
for line in lines:
|
|
84
|
+
match = USER.match(line)
|
|
85
|
+
if not match or match.group(1) in vpn_only:
|
|
86
|
+
continue
|
|
87
|
+
name, level = match.group(1), int(match.group(2) or 2)
|
|
88
|
+
role = f"privilege {level}"
|
|
89
|
+
device.admins.append(
|
|
90
|
+
{
|
|
91
|
+
"id": record_id(SOURCE, hostname, name, role),
|
|
92
|
+
"source": SOURCE,
|
|
93
|
+
"system": hostname,
|
|
94
|
+
"account": name,
|
|
95
|
+
"role": role,
|
|
96
|
+
"account_type": "user",
|
|
97
|
+
"privileged": "Y" if level == 15 else "N",
|
|
98
|
+
"permanent": "Y",
|
|
99
|
+
"mfa_class": local_class,
|
|
100
|
+
"mfa_enforced": local_enforced,
|
|
101
|
+
"break_glass": "Y" if name.lower() in break_glass else "N",
|
|
102
|
+
"notes": local_note,
|
|
103
|
+
}
|
|
104
|
+
)
|
|
105
|
+
for group in groups:
|
|
106
|
+
account = f"{group} (remote admins)"
|
|
107
|
+
device.admins.append(
|
|
108
|
+
{
|
|
109
|
+
"id": record_id(SOURCE, hostname, account, "remote"),
|
|
110
|
+
"source": SOURCE,
|
|
111
|
+
"system": hostname,
|
|
112
|
+
"account": account,
|
|
113
|
+
"role": "remote",
|
|
114
|
+
"account_type": "user",
|
|
115
|
+
"privileged": "Y",
|
|
116
|
+
"permanent": "Y",
|
|
117
|
+
"mfa_class": "unknown",
|
|
118
|
+
"mfa_enforced": "unknown",
|
|
119
|
+
"break_glass": "N",
|
|
120
|
+
"notes": f"admins who log in through AAA server group {group}: "
|
|
121
|
+
"list them and check MFA",
|
|
122
|
+
}
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
levels = parse_interfaces(lines)
|
|
126
|
+
http_server = any(ln.strip() == "http server enable" for ln in lines)
|
|
127
|
+
allowed: dict[tuple[str, str], list[str]] = {}
|
|
128
|
+
for line in lines:
|
|
129
|
+
match = ACCESS.match(line)
|
|
130
|
+
if not match:
|
|
131
|
+
continue
|
|
132
|
+
service, network, mask, nameif = match.groups()
|
|
133
|
+
if service == "http" and not http_server:
|
|
134
|
+
continue
|
|
135
|
+
if nameif in levels and (levels[nameif] == 0 or UNTRUSTED.search(nameif)):
|
|
136
|
+
anywhere = network == mask == "0.0.0.0" # noqa: S104 (config text, not a bind)
|
|
137
|
+
source = "anywhere" if anywhere else f"{network}/{mask}"
|
|
138
|
+
allowed.setdefault((nameif, service), []).append(source)
|
|
139
|
+
for (nameif, service), sources in sorted(allowed.items()):
|
|
140
|
+
label = {"http": "https (ASDM)"}.get(service, service)
|
|
141
|
+
device.exposure.append(
|
|
142
|
+
{
|
|
143
|
+
"id": make_id(SOURCE, hostname, nameif, service),
|
|
144
|
+
"system": hostname,
|
|
145
|
+
"interface": nameif,
|
|
146
|
+
"zone_or_role": f"security-level {levels[nameif]}",
|
|
147
|
+
"services": label,
|
|
148
|
+
"reason": f"{label} management on {nameif} from {', '.join(sources)}",
|
|
149
|
+
}
|
|
150
|
+
)
|
|
151
|
+
return device
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""Shared output for vendor collectors.
|
|
3
|
+
|
|
4
|
+
Each collector returns, per config file, a Device: its admin records (unified
|
|
5
|
+
admin format), its management exposure findings (Zero 4) and a device record
|
|
6
|
+
(product and version, used by `targetzero external kev`).
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from collections.abc import Sequence
|
|
12
|
+
from dataclasses import dataclass, field
|
|
13
|
+
from datetime import date
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
|
|
16
|
+
from targetzero.admins import write_admin_outputs
|
|
17
|
+
from targetzero.common.config import Config
|
|
18
|
+
from targetzero.common.output import run_dir, write_csv, write_summary
|
|
19
|
+
|
|
20
|
+
DEVICE_FIELDS = ("id", "vendor", "system", "product", "model", "version", "file")
|
|
21
|
+
EXPOSURE_FIELDS = ("id", "system", "interface", "zone_or_role", "services", "reason")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass
|
|
25
|
+
class Device:
|
|
26
|
+
vendor: str
|
|
27
|
+
system: str
|
|
28
|
+
product: str
|
|
29
|
+
model: str = ""
|
|
30
|
+
version: str = ""
|
|
31
|
+
file: str = ""
|
|
32
|
+
admins: list[dict[str, str]] = field(default_factory=list)
|
|
33
|
+
exposure: list[dict[str, str]] = field(default_factory=list)
|
|
34
|
+
notes: list[str] = field(default_factory=list)
|
|
35
|
+
# False for collectors that cannot see interface exposure (it is then left to the scan).
|
|
36
|
+
checks_exposure: bool = True
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def write_outputs(
|
|
40
|
+
config: Config,
|
|
41
|
+
run_date: date,
|
|
42
|
+
source: str,
|
|
43
|
+
devices: Sequence[Device],
|
|
44
|
+
tool: str,
|
|
45
|
+
notes: Sequence[str] = (),
|
|
46
|
+
) -> list[Path]:
|
|
47
|
+
"""All devices of one vendor go into one set of files: pass every config file in one run."""
|
|
48
|
+
directory = run_dir(config.output_dir, run_date)
|
|
49
|
+
all_notes = [*notes, *(f"{d.system}: {n}" for d in devices for n in d.notes)]
|
|
50
|
+
records = [a for d in devices for a in d.admins]
|
|
51
|
+
paths = write_admin_outputs(
|
|
52
|
+
directory, source=source, records=records, tool=tool, run_date=run_date, notes=all_notes
|
|
53
|
+
)
|
|
54
|
+
exposure = [e for d in devices for e in d.exposure]
|
|
55
|
+
record_file = f"4_{source}_mgmt-exposure.csv"
|
|
56
|
+
if any(d.checks_exposure for d in devices):
|
|
57
|
+
paths.append(write_csv(directory / record_file, exposure, EXPOSURE_FIELDS))
|
|
58
|
+
paths.append(
|
|
59
|
+
write_summary(
|
|
60
|
+
directory,
|
|
61
|
+
zero=4,
|
|
62
|
+
source=source,
|
|
63
|
+
name="mgmt-exposure",
|
|
64
|
+
tool=tool,
|
|
65
|
+
run_date=run_date,
|
|
66
|
+
items=[{"id": e["id"], "reason": e["reason"]} for e in exposure],
|
|
67
|
+
notes=all_notes,
|
|
68
|
+
record_file=record_file,
|
|
69
|
+
)
|
|
70
|
+
)
|
|
71
|
+
devices_rows = [
|
|
72
|
+
{
|
|
73
|
+
"id": f"device:{source}/{d.system.lower()}",
|
|
74
|
+
"vendor": d.vendor,
|
|
75
|
+
"system": d.system,
|
|
76
|
+
"product": d.product,
|
|
77
|
+
"model": d.model,
|
|
78
|
+
"version": d.version,
|
|
79
|
+
"file": d.file,
|
|
80
|
+
}
|
|
81
|
+
for d in devices
|
|
82
|
+
]
|
|
83
|
+
paths.append(write_csv(directory / f"devices_{source}.csv", devices_rows, DEVICE_FIELDS))
|
|
84
|
+
return paths
|