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.
Files changed (66) hide show
  1. targetzero/__init__.py +4 -0
  2. targetzero/__main__.py +6 -0
  3. targetzero/admins.py +109 -0
  4. targetzero/cli.py +366 -0
  5. targetzero/common/__init__.py +2 -0
  6. targetzero/common/changes.py +46 -0
  7. targetzero/common/config.py +83 -0
  8. targetzero/common/ids.py +17 -0
  9. targetzero/common/output.py +91 -0
  10. targetzero/common/resources.py +32 -0
  11. targetzero/common/roles.py +24 -0
  12. targetzero/common/schema.py +45 -0
  13. targetzero/config/approved_exposure.example.csv +4 -0
  14. targetzero/config/privileged_roles.yaml +50 -0
  15. targetzero/config/targetzero.example.yaml +57 -0
  16. targetzero/external/__init__.py +2 -0
  17. targetzero/external/dangling.py +106 -0
  18. targetzero/external/discover.py +181 -0
  19. targetzero/external/dnsinfo.py +54 -0
  20. targetzero/external/enrich.py +137 -0
  21. targetzero/external/http.py +33 -0
  22. targetzero/external/kev.py +222 -0
  23. targetzero/external/ports.py +63 -0
  24. targetzero/external/scan.py +260 -0
  25. targetzero/external/scope.py +54 -0
  26. targetzero/external/waf.py +202 -0
  27. targetzero/external/web.py +124 -0
  28. targetzero/gws/__init__.py +2 -0
  29. targetzero/gws/admins.py +230 -0
  30. targetzero/gws/changes.py +190 -0
  31. targetzero/gws/client.py +94 -0
  32. targetzero/gws/domains.py +36 -0
  33. targetzero/registers/__init__.py +2 -0
  34. targetzero/registers/exceptions.py +85 -0
  35. targetzero/registers/findings.py +108 -0
  36. targetzero/registers/inventory.py +142 -0
  37. targetzero/registers/manual_admins.py +43 -0
  38. targetzero/schemas/admins.schema.json +27 -0
  39. targetzero/schemas/alert_tests.schema.json +19 -0
  40. targetzero/schemas/config.schema.json +71 -0
  41. targetzero/schemas/exceptions.schema.json +20 -0
  42. targetzero/schemas/findings.schema.json +23 -0
  43. targetzero/schemas/inventory.schema.json +26 -0
  44. targetzero/schemas/summary.schema.json +36 -0
  45. targetzero/scorecard/__init__.py +2 -0
  46. targetzero/scorecard/scorecard.py +201 -0
  47. targetzero/templates/alert_tests.csv +1 -0
  48. targetzero/templates/exceptions.csv +1 -0
  49. targetzero/templates/findings.csv +1 -0
  50. targetzero/templates/inventory.csv +1 -0
  51. targetzero/templates/manual_admins.csv +1 -0
  52. targetzero/templates/origins.csv +1 -0
  53. targetzero/templates/recovery_page.md +51 -0
  54. targetzero/vendors/__init__.py +2 -0
  55. targetzero/vendors/cisco_asa.py +151 -0
  56. targetzero/vendors/common.py +84 -0
  57. targetzero/vendors/fortigate.py +176 -0
  58. targetzero/vendors/panos.py +141 -0
  59. targetzero/vendors/redfish.py +124 -0
  60. targetzero/vendors/vsphere.py +108 -0
  61. targetzero-0.3.2.dist-info/METADATA +116 -0
  62. targetzero-0.3.2.dist-info/RECORD +66 -0
  63. targetzero-0.3.2.dist-info/WHEEL +4 -0
  64. targetzero-0.3.2.dist-info/entry_points.txt +2 -0
  65. targetzero-0.3.2.dist-info/licenses/LICENSE +202 -0
  66. targetzero-0.3.2.dist-info/licenses/NOTICE +7 -0
@@ -0,0 +1,176 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ """Fortinet FortiGate (FortiOS) collector, offline: parses a configuration backup (.conf).
3
+
4
+ Get the file from System > Configuration > Backup, or `execute backup config`.
5
+ Encrypted backups cannot be read; make an unencrypted one and keep it safe.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import re
11
+ import shlex
12
+ from dataclasses import dataclass, field
13
+ from pathlib import Path
14
+
15
+ from targetzero.admins import record_id
16
+ from targetzero.common.ids import make_id
17
+ from targetzero.vendors.common import Device
18
+
19
+ SOURCE = "fortigate"
20
+ PRIVILEGED_PROFILES = {"super_admin", "prof_admin"}
21
+ ADMIN_SERVICES = {"http", "https", "ssh", "telnet", "snmp", "fgfm", "radius-acct", "ftm"}
22
+ MANAGEMENT = {"http", "https", "ssh", "telnet", "snmp", "fgfm"}
23
+ VERSION_LINE = re.compile(r"#config-version=([A-Za-z0-9]+)-(\d+(?:\.\d+)+)-FW-build(\d+)")
24
+
25
+
26
+ @dataclass
27
+ class Node:
28
+ settings: dict[str, list[str]] = field(default_factory=dict)
29
+ configs: dict[str, Node] = field(default_factory=dict)
30
+ edits: dict[str, Node] = field(default_factory=dict)
31
+
32
+
33
+ def parse(text: str) -> Node:
34
+ root = Node()
35
+ stack = [root]
36
+ for raw in text.splitlines():
37
+ line = raw.strip()
38
+ if not line or line.startswith("#"):
39
+ continue
40
+ try:
41
+ words = shlex.split(line, posix=True)
42
+ except ValueError:
43
+ words = line.split()
44
+ keyword, args = words[0], words[1:]
45
+ if keyword == "config":
46
+ node = stack[-1].configs.setdefault(" ".join(args), Node())
47
+ stack.append(node)
48
+ elif keyword == "edit":
49
+ node = stack[-1].edits.setdefault(" ".join(args), Node())
50
+ stack.append(node)
51
+ elif keyword in ("end", "next"):
52
+ if len(stack) > 1:
53
+ stack.pop()
54
+ elif keyword == "set" and args:
55
+ stack[-1].settings[args[0]] = args[1:]
56
+ return root
57
+
58
+
59
+ def find(node: Node, path: str) -> list[Node]:
60
+ """Every config block with this path, at any depth (covers VDOM mode)."""
61
+ found = [child for name, child in node.configs.items() if name == path]
62
+ for child in [*node.configs.values(), *node.edits.values()]:
63
+ found += find(child, path)
64
+ return found
65
+
66
+
67
+ def value(node: Node, key: str) -> str:
68
+ return " ".join(node.settings.get(key, []))
69
+
70
+
71
+ def mfa(admin: Node) -> tuple[str, str, str]:
72
+ """(mfa_class, mfa_enforced, note)."""
73
+ method = value(admin, "two-factor") or "disable"
74
+ if method in ("fortitoken", "fortitoken-cloud"):
75
+ return "mfa", "Y", f"two-factor {method}"
76
+ if method in ("email", "sms"):
77
+ return "does-not-count", "Y", f"two-factor {method}"
78
+ if value(admin, "remote-auth") == "enable":
79
+ return (
80
+ "unknown",
81
+ "unknown",
82
+ f"remote authentication ({value(admin, 'remote-group')}): "
83
+ "check MFA on the RADIUS/LDAP/TACACS+ server",
84
+ )
85
+ return "none", "N", "password only"
86
+
87
+
88
+ def trusted_hosts(admin: Node) -> list[str]:
89
+ hosts = []
90
+ for key, values in admin.settings.items():
91
+ if key.startswith("trusthost") or key.startswith("ip6-trusthost"):
92
+ joined = " ".join(values)
93
+ if joined not in ("0.0.0.0 0.0.0.0", "::/0", ""):
94
+ hosts.append(joined)
95
+ return hosts
96
+
97
+
98
+ def collect(path: Path, break_glass: set[str]) -> Device:
99
+ text = path.read_text(encoding="utf-8", errors="replace")
100
+ root = parse(text)
101
+ hostname = next(
102
+ (value(g, "hostname") for g in find(root, "system global") if value(g, "hostname")),
103
+ path.stem,
104
+ )
105
+ device = Device(vendor="Fortinet", system=hostname, product="FortiOS", file=path.name)
106
+ match = VERSION_LINE.search(text)
107
+ if match:
108
+ device.model, device.version = match.group(1), match.group(2)
109
+ else:
110
+ device.notes.append("firmware version not found in the file header")
111
+ if text.lstrip().startswith("#FGBK") or "config system admin" not in text:
112
+ device.notes.append("no 'config system admin' block: encrypted or partial backup?")
113
+
114
+ for block in find(root, "system admin"):
115
+ for name, admin in block.edits.items():
116
+ profile = value(admin, "accprofile")
117
+ mfa_class, enforced, note = mfa(admin)
118
+ hosts = trusted_hosts(admin)
119
+ notes = [
120
+ note,
121
+ f"trusted hosts: {', '.join(hosts)}" if hosts else "no trusted hosts set",
122
+ ]
123
+ device.admins.append(
124
+ {
125
+ "id": record_id(SOURCE, hostname, name, profile),
126
+ "source": SOURCE,
127
+ "system": hostname,
128
+ "account": name,
129
+ "role": profile or "?",
130
+ "account_type": "user",
131
+ "privileged": "Y" if profile in PRIVILEGED_PROFILES else "N",
132
+ "permanent": "Y",
133
+ "mfa_class": mfa_class,
134
+ "mfa_enforced": enforced,
135
+ "break_glass": "Y" if name.lower() in break_glass else "N",
136
+ "notes": "; ".join(notes),
137
+ }
138
+ )
139
+ for block in find(root, "system sso-admin"):
140
+ for name, admin in block.edits.items():
141
+ profile = value(admin, "accprofile")
142
+ device.admins.append(
143
+ {
144
+ "id": record_id(SOURCE, hostname, name, profile),
145
+ "source": SOURCE,
146
+ "system": hostname,
147
+ "account": name,
148
+ "role": profile or "?",
149
+ "account_type": "user",
150
+ "privileged": "Y" if profile in PRIVILEGED_PROFILES else "N",
151
+ "permanent": "Y",
152
+ "mfa_class": "unknown",
153
+ "mfa_enforced": "unknown",
154
+ "break_glass": "Y" if name.lower() in break_glass else "N",
155
+ "notes": "SAML single sign-on admin: check MFA at the identity provider",
156
+ }
157
+ )
158
+
159
+ for block in find(root, "system interface"):
160
+ for name, interface in block.edits.items():
161
+ role = value(interface, "role")
162
+ if role != "wan" and not name.lower().startswith("wan"):
163
+ continue
164
+ services = sorted(set(interface.settings.get("allowaccess", [])) & MANAGEMENT)
165
+ if services:
166
+ device.exposure.append(
167
+ {
168
+ "id": make_id(SOURCE, hostname, name),
169
+ "system": hostname,
170
+ "interface": name,
171
+ "zone_or_role": role or "wan (by name)",
172
+ "services": ";".join(services),
173
+ "reason": f"admin access ({', '.join(services)}) on WAN interface {name}",
174
+ }
175
+ )
176
+ return device
@@ -0,0 +1,141 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ """Palo Alto Networks PAN-OS collector, offline: parses running-config.xml.
3
+
4
+ Get the file from Device > Setup > Operations > Export named configuration
5
+ snapshot (running-config.xml).
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import re
11
+ from pathlib import Path
12
+ from xml.etree.ElementTree import Element
13
+
14
+ from defusedxml import ElementTree
15
+
16
+ from targetzero.admins import record_id
17
+ from targetzero.common.ids import make_id
18
+ from targetzero.vendors.common import Device
19
+
20
+ SOURCE = "panos"
21
+ PRIVILEGED = {"superuser", "deviceadmin", "vsysadmin"}
22
+ MANAGEMENT = ("https", "http", "ssh", "telnet", "snmp")
23
+ UNTRUST = re.compile(r"untrust|outside|internet|wan|external|public", re.IGNORECASE)
24
+
25
+
26
+ def text(element: Element | None, path: str, default: str = "") -> str:
27
+ if element is None:
28
+ return default
29
+ found = element.find(path)
30
+ return (found.text or "").strip() if found is not None and found.text else default
31
+
32
+
33
+ def role_of(user: Element) -> str:
34
+ role_based = user.find("permissions/role-based")
35
+ if role_based is None or len(role_based) == 0:
36
+ return "?"
37
+ first = role_based[0]
38
+ if first.tag == "custom":
39
+ return f"custom:{text(first, 'profile', '?')}"
40
+ return first.tag
41
+
42
+
43
+ def auth_profiles(root: Element) -> dict[str, Element]:
44
+ """Authentication profiles from every scope (shared, device, vsys)."""
45
+ return {
46
+ entry.get("name", ""): entry
47
+ for container in root.iter("authentication-profile")
48
+ for entry in container.findall("entry")
49
+ }
50
+
51
+
52
+ def mfa(user: Element, profiles: dict[str, Element]) -> tuple[str, str, str]:
53
+ if text(user, "client-certificate-only") == "yes":
54
+ return "phishing-resistant", "Y", "client certificate only"
55
+ profile_name = text(user, "authentication-profile")
56
+ if not profile_name:
57
+ return "none", "N", "local password only"
58
+ profile = profiles.get(profile_name)
59
+ if profile is None:
60
+ return "unknown", "unknown", f"authentication profile {profile_name} not found in this file"
61
+ if text(profile, "multi-factor-auth/mfa-enable") == "yes":
62
+ return "mfa", "Y", f"profile {profile_name} with multi-factor authentication"
63
+ method = profile.find("method")
64
+ kind = method[0].tag if method is not None and len(method) else "?"
65
+ if kind == "local-database":
66
+ return "none", "N", f"profile {profile_name}: local database, no MFA"
67
+ return "unknown", "unknown", f"profile {profile_name} uses {kind}: check MFA on that server"
68
+
69
+
70
+ def collect(path: Path, break_glass: set[str]) -> Device:
71
+ root = ElementTree.parse(path).getroot()
72
+ if root is None:
73
+ raise ValueError(f"{path} is empty")
74
+ hostname = text(root, "devices/entry/deviceconfig/system/hostname") or path.stem
75
+ version = root.get("detail-version") or root.get("version") or ""
76
+ device = Device(
77
+ vendor="Palo Alto Networks",
78
+ system=hostname,
79
+ product="PAN-OS",
80
+ version=version,
81
+ file=path.name,
82
+ )
83
+ profiles = auth_profiles(root)
84
+
85
+ users = root.findall("mgt-config/users/entry")
86
+ if not users:
87
+ device.notes.append("no mgt-config users: admins may be managed by Panorama")
88
+ for user in users:
89
+ name = user.get("name", "?")
90
+ role = role_of(user)
91
+ mfa_class, enforced, note = mfa(user, profiles)
92
+ device.admins.append(
93
+ {
94
+ "id": record_id(SOURCE, hostname, name, role),
95
+ "source": SOURCE,
96
+ "system": hostname,
97
+ "account": name,
98
+ "role": role,
99
+ "account_type": "user",
100
+ "privileged": "Y" if role in PRIVILEGED else "N",
101
+ "permanent": "Y",
102
+ "mfa_class": mfa_class,
103
+ "mfa_enforced": enforced,
104
+ "break_glass": "Y" if name.lower() in break_glass else "N",
105
+ "notes": note,
106
+ }
107
+ )
108
+
109
+ mgmt_profiles = {
110
+ entry.get("name", ""): [s for s in MANAGEMENT if text(entry, s) == "yes"]
111
+ for container in root.iter("interface-management-profile")
112
+ for entry in container.findall("entry")
113
+ }
114
+ zones: dict[str, str] = {}
115
+ for zone_entry in root.findall("devices/entry/vsys/entry/zone/entry"):
116
+ for member in zone_entry.findall("network/layer3/member"):
117
+ zones[(member.text or "").strip()] = zone_entry.get("name", "")
118
+ for interface in root.iter("entry"):
119
+ profile = text(interface, "layer3/interface-management-profile") or text(
120
+ interface, "interface-management-profile"
121
+ )
122
+ name = interface.get("name", "")
123
+ services = mgmt_profiles.get(profile, [])
124
+ if not services or not name:
125
+ continue
126
+ zone = zones.get(name, "")
127
+ if UNTRUST.search(zone):
128
+ device.exposure.append(
129
+ {
130
+ "id": make_id(SOURCE, hostname, name),
131
+ "system": hostname,
132
+ "interface": name,
133
+ "zone_or_role": zone,
134
+ "services": ";".join(services),
135
+ "reason": f"management profile {profile} ({', '.join(services)}) on "
136
+ f"{name} in zone {zone}",
137
+ }
138
+ )
139
+ elif not zone:
140
+ device.notes.append(f"{name} has management profile {profile} but no zone: check it")
141
+ return device
@@ -0,0 +1,124 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ """Server management cards (Dell iDRAC, HPE iLO and other Redfish BMCs), live and read-only.
3
+
4
+ Credentials come from TARGETZERO_REDFISH_USER and TARGETZERO_REDFISH_PASSWORD. Use a
5
+ read-only account. Management cards often have self-signed certificates: pass the CA with
6
+ --ca-bundle, or --insecure if you accept that risk on your own network.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import base64
12
+ import json
13
+ import os
14
+ import ssl
15
+ import urllib.request
16
+ from typing import Any
17
+
18
+ from targetzero.admins import record_id
19
+ from targetzero.common.config import ConfigError
20
+ from targetzero.vendors.common import Device
21
+
22
+ SOURCE = "redfish"
23
+ PRIVILEGED_ROLES = {"Administrator"}
24
+ MFA_KEYS = ("SecurID", "GoogleAuthenticator", "MicrosoftAuthenticator")
25
+
26
+
27
+ class Redfish:
28
+ def __init__(self, host: str, user: str, password: str, context: ssl.SSLContext) -> None:
29
+ self.base = f"https://{host}"
30
+ token = base64.b64encode(f"{user}:{password}".encode()).decode()
31
+ self.headers = {"Authorization": f"Basic {token}", "Accept": "application/json"}
32
+ self.context = context
33
+
34
+ def get(self, path: str) -> dict[str, Any]:
35
+ url = path if path.startswith("https://") else self.base + path
36
+ request = urllib.request.Request(url, headers=self.headers) # noqa: S310 (https only)
37
+ with urllib.request.urlopen(request, timeout=20, context=self.context) as response: # noqa: S310
38
+ data: dict[str, Any] = json.loads(response.read().decode("utf-8"))
39
+ return data
40
+
41
+ def members(self, path: str) -> list[dict[str, Any]]:
42
+ return [self.get(m["@odata.id"]) for m in self.get(path).get("Members", [])]
43
+
44
+
45
+ def ssl_context(ca_bundle: str | None, insecure: bool) -> ssl.SSLContext:
46
+ if insecure:
47
+ context = ssl.create_default_context()
48
+ context.check_hostname = False
49
+ context.verify_mode = ssl.CERT_NONE
50
+ return context
51
+ return ssl.create_default_context(cafile=ca_bundle)
52
+
53
+
54
+ def credentials() -> tuple[str, str]:
55
+ user = os.environ.get("TARGETZERO_REDFISH_USER", "")
56
+ password = os.environ.get("TARGETZERO_REDFISH_PASSWORD", "")
57
+ if not user or not password:
58
+ raise ConfigError("Set TARGETZERO_REDFISH_USER and TARGETZERO_REDFISH_PASSWORD")
59
+ return user, password
60
+
61
+
62
+ def mfa_settings(account_service: dict[str, Any]) -> tuple[str, str, str]:
63
+ mfa = account_service.get("MultiFactorAuth") or {}
64
+ enabled = [k for k in MFA_KEYS if (mfa.get(k) or {}).get("Enabled")]
65
+ if (mfa.get("ClientCertificate") or {}).get("Enabled"):
66
+ return "phishing-resistant", "unknown", "client certificate authentication enabled"
67
+ if enabled:
68
+ return "mfa", "unknown", f"multi-factor enabled: {', '.join(enabled)}"
69
+ directory = [
70
+ k
71
+ for k in ("LDAP", "ActiveDirectory")
72
+ if (account_service.get(k) or {}).get("ServiceEnabled")
73
+ ]
74
+ if directory:
75
+ return "unknown", "unknown", f"{'/'.join(directory)} login enabled: check MFA there"
76
+ return "none", "N", "no multi-factor authentication configured"
77
+
78
+
79
+ def collect(client: Redfish, host: str, break_glass: set[str]) -> Device:
80
+ root = client.get("/redfish/v1/")
81
+ managers = client.members(root.get("Managers", {}).get("@odata.id", "/redfish/v1/Managers"))
82
+ manager = managers[0] if managers else {}
83
+ vendor = str(root.get("Vendor") or manager.get("Manufacturer") or "")
84
+ model = str(manager.get("Model") or manager.get("Name") or "")
85
+ device = Device(
86
+ vendor=vendor,
87
+ system=host,
88
+ product=f"{vendor} {model}".strip(),
89
+ model=model,
90
+ version=str(manager.get("FirmwareVersion", "")),
91
+ file=host,
92
+ checks_exposure=False,
93
+ )
94
+ account_service = client.get(
95
+ root.get("AccountService", {}).get("@odata.id", "/redfish/v1/AccountService")
96
+ )
97
+ mfa_class, enforced, note = mfa_settings(account_service)
98
+ accounts = client.members(
99
+ account_service.get("Accounts", {}).get("@odata.id", "/redfish/v1/AccountService/Accounts")
100
+ )
101
+ for account in accounts:
102
+ name = str(account.get("UserName") or "")
103
+ if not name:
104
+ continue # empty slot (iDRAC has 16)
105
+ role = str(account.get("RoleId") or "?")
106
+ notes = [note] + ([] if account.get("Enabled", True) else ["disabled"])
107
+ device.admins.append(
108
+ {
109
+ "id": record_id(SOURCE, host, name, role),
110
+ "source": SOURCE,
111
+ "system": host,
112
+ "account": name,
113
+ "role": role,
114
+ "account_type": "user",
115
+ "privileged": "Y" if role in PRIVILEGED_ROLES else "N",
116
+ "permanent": "Y",
117
+ "mfa_class": mfa_class,
118
+ "mfa_enforced": enforced,
119
+ "break_glass": "Y" if name.lower() in break_glass else "N",
120
+ "notes": "; ".join(notes),
121
+ }
122
+ )
123
+ device.notes.append("internet exposure of the card is checked by `external scan` (443, 623)")
124
+ return device
@@ -0,0 +1,108 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ """VMware vSphere (vCenter or ESXi) collector, live and read-only. Install with [vsphere].
3
+
4
+ Lists every permission (principal, role, object) and the product version. MFA for vCenter
5
+ depends on its identity source (SSO, AD, or identity federation with an IdP), which the API
6
+ does not show: pass --mfa-via-idp when your identity source enforces MFA for these admins.
7
+
8
+ Credentials come from TARGETZERO_VSPHERE_USER and TARGETZERO_VSPHERE_PASSWORD (read-only role).
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ import os
14
+ import ssl
15
+ from typing import Any
16
+
17
+ from targetzero.common.config import ConfigError
18
+ from targetzero.common.ids import make_id
19
+ from targetzero.vendors.common import Device
20
+
21
+ SOURCE = "vsphere"
22
+ ADMIN_ROLE_IDS = {-1} # Admin
23
+ PRIVILEGED_NAMES = {"Admin", "NoCryptoAdmin", "Administrator"}
24
+
25
+
26
+ def credentials() -> tuple[str, str]:
27
+ user = os.environ.get("TARGETZERO_VSPHERE_USER", "")
28
+ password = os.environ.get("TARGETZERO_VSPHERE_PASSWORD", "")
29
+ if not user or not password:
30
+ raise ConfigError("Set TARGETZERO_VSPHERE_USER and TARGETZERO_VSPHERE_PASSWORD")
31
+ return user, password
32
+
33
+
34
+ def connect(host: str, context: ssl.SSLContext) -> Any:
35
+ try:
36
+ from pyVim.connect import SmartConnect
37
+ except ImportError as exc:
38
+ raise ConfigError(
39
+ "vSphere support is not installed: pip install 'targetzero[vsphere]'"
40
+ ) from exc
41
+ user, password = credentials()
42
+ return SmartConnect(host=host, user=user, pwd=password, sslContext=context)
43
+
44
+
45
+ def disconnect(instance: Any) -> None:
46
+ from pyVim.connect import Disconnect
47
+
48
+ Disconnect(instance)
49
+
50
+
51
+ def entity_name(entity: Any) -> str:
52
+ try:
53
+ return str(entity.name)
54
+ except Exception:
55
+ return "?"
56
+
57
+
58
+ def collect(content: Any, host: str, break_glass: set[str], *, mfa_via_idp: bool = False) -> Device:
59
+ about = content.about
60
+ device = Device(
61
+ vendor="VMware",
62
+ system=host,
63
+ product=str(about.name),
64
+ model=str(about.fullName),
65
+ version=str(about.version),
66
+ file=host,
67
+ checks_exposure=False,
68
+ )
69
+ manager = content.authorizationManager
70
+ roles = {r.roleId: r.name for r in manager.roleList}
71
+ if mfa_via_idp:
72
+ mfa_class, enforced, note = (
73
+ "mfa",
74
+ "Y",
75
+ "MFA enforced by the identity source (declared with --mfa-via-idp)",
76
+ )
77
+ else:
78
+ mfa_class, enforced, note = (
79
+ "unknown",
80
+ "unknown",
81
+ "MFA depends on the identity source: check it",
82
+ )
83
+ for permission in manager.RetrieveAllPermissions():
84
+ role = roles.get(permission.roleId, str(permission.roleId))
85
+ principal = str(permission.principal)
86
+ where = entity_name(permission.entity)
87
+ notes = [note, f"on {where}{' and below' if permission.propagate else ''}"]
88
+ if permission.group:
89
+ notes.append("group: list its members in the identity source")
90
+ device.admins.append(
91
+ {
92
+ "id": make_id(SOURCE, host, principal, role, where),
93
+ "source": SOURCE,
94
+ "system": host,
95
+ "account": principal,
96
+ "role": role,
97
+ "account_type": "user",
98
+ "privileged": "Y"
99
+ if permission.roleId in ADMIN_ROLE_IDS or role in PRIVILEGED_NAMES
100
+ else "N",
101
+ "permanent": "Y",
102
+ "mfa_class": mfa_class,
103
+ "mfa_enforced": enforced,
104
+ "break_glass": "Y" if principal.lower() in break_glass else "N",
105
+ "notes": "; ".join(notes),
106
+ }
107
+ )
108
+ return device
@@ -0,0 +1,116 @@
1
+ Metadata-Version: 2.5
2
+ Name: targetzero
3
+ Version: 0.3.2
4
+ Summary: Tooling for the Target 0 campaign: count, fix and report seven security zeros.
5
+ Project-URL: Homepage, https://github.com/wiresecurity/TargetZero
6
+ Project-URL: Issues, https://github.com/wiresecurity/TargetZero/issues
7
+ Author: Wire Security
8
+ License-Expression: Apache-2.0
9
+ License-File: LICENSE
10
+ License-File: NOTICE
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Topic :: Security
14
+ Classifier: Topic :: System :: Systems Administration
15
+ Requires-Python: >=3.11
16
+ Requires-Dist: defusedxml>=0.7.1
17
+ Requires-Dist: dnspython>=2.6
18
+ Requires-Dist: jsonschema>=4.21
19
+ Requires-Dist: pyyaml>=6.0
20
+ Provides-Extra: dev
21
+ Requires-Dist: mypy>=1.11; extra == 'dev'
22
+ Requires-Dist: pytest>=8; extra == 'dev'
23
+ Requires-Dist: ruff>=0.6; extra == 'dev'
24
+ Requires-Dist: types-defusedxml; extra == 'dev'
25
+ Requires-Dist: types-jsonschema; extra == 'dev'
26
+ Requires-Dist: types-pyyaml; extra == 'dev'
27
+ Provides-Extra: gws
28
+ Requires-Dist: google-api-python-client>=2.130; extra == 'gws'
29
+ Requires-Dist: google-auth-oauthlib>=1.2; extra == 'gws'
30
+ Requires-Dist: google-auth>=2.30; extra == 'gws'
31
+ Provides-Extra: vsphere
32
+ Requires-Dist: pyvmomi>=8.0.2; extra == 'vsphere'
33
+ Description-Content-Type: text/markdown
34
+
35
+ # TargetZero
36
+
37
+ Tooling for **Target 0**: seven security counts, each brought to zero within 15 days. Anything that cannot reach zero becomes a signed, dated exception.
38
+
39
+ | # | Target |
40
+ | --- | --- |
41
+ | 1 | Admin accounts with full, permanent access |
42
+ | 2 | Admin accounts without MFA |
43
+ | 3 | Admin accounts not monitored |
44
+ | 4 | Public IPs not behind a firewall, WAF or CDN |
45
+ | 5 | Public IPs without a technology inventory |
46
+ | 6 | Public IPs or domains with known vulnerabilities past deadline |
47
+ | 7 | Internet-facing applications without a tested recovery plan |
48
+
49
+ TargetZero counts each one from live data, helps you fix what it finds on Microsoft 365 and Google Workspace, and fills in the scorecard. It is built for small IT teams: no SIEM, no extra licences, CSV and JSON output.
50
+
51
+ > **Status: 0.3 (remediate).** Day 1 inventories plus the changes for days 6 to 10: reduce admin rights, break-glass accounts and Conditional Access on Microsoft 365, role and org unit changes on Google Workspace, WAF/CDN, dangling-DNS and enrichment checks, and collectors for Cisco ASA, iDRAC/iLO and vSphere. See [CHANGELOG.md](CHANGELOG.md).
52
+
53
+ **New to this? Start with the [step-by-step guide](docs/guide.md).** It assumes no technical background and explains what you need and what to be careful about.
54
+
55
+ ## How it works
56
+
57
+ ```
58
+ M365 / Entra ID ─ PowerShell ─┐
59
+ Google Workspace ─ Python ─────┤ output/<date>/<zero>_<source>_<name>.csv records
60
+ External checks ─ Python ─────┼─▶ output/<date>/<zero>_<source>_<name>.summary.json counts
61
+ Vendor devices ─ Python ─────┤ │
62
+ Registers (CSV, by hand) ──────┘ ▼
63
+ targetzero scorecard ─▶ scorecard.csv / .json, history.csv
64
+ ```
65
+
66
+ - **Microsoft stack in PowerShell, everything else in Python.**
67
+ - **Read-only by default.** Change scripts follow *plan → review → apply* and run as a dry run unless you pass `-Apply` / `--apply`.
68
+ - **One output contract.** Any tool can feed the scorecard by writing a valid summary; see [docs/output-contract.md](docs/output-contract.md).
69
+ - **No data leaves your machine** except calls to the platform APIs, your own systems and public reference data.
70
+
71
+ ## Quick start
72
+
73
+ Requirements: Python 3.11+ and, for the Microsoft scripts, PowerShell 7.4+.
74
+
75
+ ```bash
76
+ pip install -e . # from a clone; "pip install targetzero" once published
77
+ mkdir my-target0 && cd my-target0
78
+ targetzero init # creates targetzero.yaml and registers/
79
+ # edit targetzero.yaml: organisation, owners, break-glass accounts, scope
80
+ targetzero scorecard # builds the scorecard from today's results
81
+ ```
82
+
83
+ See [docs/quickstart.md](docs/quickstart.md) for the full walk-through.
84
+
85
+ ## What it checks and changes (0.3)
86
+
87
+ | Zero | Microsoft 365 (PowerShell) | Google Workspace (Python) | Devices and internet (Python) |
88
+ | --- | --- | --- | --- |
89
+ | 1, 2 | `Invoke-T0M365AdminInventory` | `targetzero gws admins` | `targetzero vendors fortigate\|panos\|asa FILE...`, `vendors redfish\|vsphere --host`, `registers manual-admins` |
90
+ | 1, 2 changes | `Set-T0M365RoleAssignment`, `New-T0M365BreakGlassAccount`, `New-T0M365AdminCaPolicy` | `targetzero gws apply PLAN` | |
91
+ | 3 | | | `registers/alert_tests.csv` (by hand) |
92
+ | 4 | | | `targetzero external scan --authorised`, `external waf`, vendor collectors |
93
+ | 5 | `Get-T0M365Domain` | `targetzero gws domains` | `targetzero external discover`, `external enrich`, `external dangling-dns`, `registers inventory` |
94
+ | 6 | | | `targetzero external kev`, `targetzero registers findings` |
95
+ | 7 | | | `registers/recovery/` (by hand) |
96
+
97
+ Then `targetzero scorecard` combines everything. Setup per platform: [Microsoft 365](docs/setup-m365.md), [Google Workspace](docs/setup-gws.md), [external checks](docs/external.md), [vendor collectors](docs/vendors.md).
98
+
99
+ Other commands: `targetzero init` (set up a working folder), `targetzero validate FILE...` (check summaries and registers against the schemas).
100
+
101
+ ## The Target 0 document
102
+
103
+ The campaign itself, with the reasoning, the 15-day plan and the scorecard, is in [TargetZero.pdf](TargetZero.pdf). You may share and adapt it under [CC BY 4.0](LICENSE-DOCS), with credit to Wire Security.
104
+
105
+ ## Legal
106
+
107
+ Scan and inventory only systems you own or are authorised to assess. You are responsible for the changes you apply with this tooling; review every plan before applying it.
108
+
109
+ ## Licence
110
+
111
+ Copyright 2026 Wire Security.
112
+
113
+ - Code, schemas, templates and technical docs: [Apache License, Version 2.0](LICENSE).
114
+ - The Target 0 document (`TargetZero.pdf`): [Creative Commons Attribution 4.0 International](LICENSE-DOCS).
115
+
116
+ Security issues: see [SECURITY.md](SECURITY.md). Contributions: see [CONTRIBUTING.md](CONTRIBUTING.md).