-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmodels.py
More file actions
195 lines (147 loc) · 5.21 KB
/
Copy pathmodels.py
File metadata and controls
195 lines (147 loc) · 5.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
"""Shared data models used by the scanner, GUI, history, and exporters."""
from __future__ import annotations
from dataclasses import asdict, dataclass, field
from datetime import datetime
from typing import Any
@dataclass(slots=True)
class Finding:
"""A security issue or informational note discovered during a scan."""
title: str
severity: str
description: str
recommendation: str = ""
@dataclass(slots=True)
class CertificateInfo:
"""Parsed X.509 certificate metadata."""
common_name: str = "Unknown"
organization: str = "Unknown"
country: str = "Unknown"
issuer: str = "Unknown"
valid_from: str = "Unknown"
valid_until: str = "Unknown"
days_remaining: int | None = None
signature_algorithm: str = "Unknown"
public_key_size: int | None = None
san_domains: list[str] = field(default_factory=list)
self_signed: bool = False
trusted: bool = False
hostname_valid: bool = False
ocsp_urls: list[str] = field(default_factory=list)
chain: list[str] = field(default_factory=list)
@dataclass(slots=True)
class TLSVersionResult:
"""Support status for one TLS/SSL protocol version."""
name: str
supported: bool
secure: bool
error: str = ""
@dataclass(slots=True)
class CipherInfo:
"""Information about the negotiated cipher suite."""
name: str = "Unknown"
protocol: str = "Unknown"
bits: int | None = None
encryption: str = "Unknown"
key_exchange: str = "Unknown"
forward_secrecy: bool = False
strength: str = "Unknown"
weak_reasons: list[str] = field(default_factory=list)
@dataclass(slots=True)
class HeaderResult:
"""HTTP security header status and educational explanation."""
name: str
present: bool
value: str = ""
why_it_matters: str = ""
@dataclass(slots=True)
class RedirectInfo:
"""HTTP to HTTPS redirect analysis."""
redirects_to_https: bool = False
permanent_redirect: bool = False
temporary_redirect: bool = False
loop_detected: bool = False
chain: list[str] = field(default_factory=list)
status_codes: list[int] = field(default_factory=list)
@dataclass(slots=True)
class HSTSInfo:
"""Strict-Transport-Security policy analysis."""
enabled: bool = False
max_age: int | None = None
include_subdomains: bool = False
preload: bool = False
@dataclass(slots=True)
class MixedContentInfo:
"""HTTP assets discovered on an HTTPS page."""
http_images: list[str] = field(default_factory=list)
http_css: list[str] = field(default_factory=list)
http_javascript: list[str] = field(default_factory=list)
http_fonts: list[str] = field(default_factory=list)
http_ajax: list[str] = field(default_factory=list)
@dataclass(slots=True)
class DNSInfo:
"""Best-effort DNS information."""
ipv4: list[str] = field(default_factory=list)
ipv6: list[str] = field(default_factory=list)
nameservers: list[str] = field(default_factory=list)
mx: list[str] = field(default_factory=list)
caa: list[str] = field(default_factory=list)
dnssec: str = "Unknown"
@dataclass(slots=True)
class WhoisInfo:
"""WHOIS registration information."""
registrar: str = "Unknown"
registration_date: str = "Unknown"
expiration_date: str = "Unknown"
updated_date: str = "Unknown"
@dataclass(slots=True)
class GeoIPInfo:
"""IP geolocation information."""
country: str = "Unknown"
city: str = "Unknown"
isp: str = "Unknown"
hosting_provider: str = "Unknown"
@dataclass(slots=True)
class PortStatus:
"""TCP port reachability."""
port: int
status: str
@dataclass(slots=True)
class ScoreBreakdown:
"""Point allocation for the final HTTPS score."""
certificate: int = 0
tls: int = 0
headers: int = 0
redirect: int = 0
cipher: int = 0
hsts: int = 0
ocsp: int = 0
@property
def total(self) -> int:
return sum(asdict(self).values())
@dataclass(slots=True)
class ScanResult:
"""Complete scan output."""
input_url: str
domain: str
normalized_url: str
scanned_at: str = field(default_factory=lambda: datetime.now().isoformat(timespec="seconds"))
https_enabled: bool = False
certificate: CertificateInfo = field(default_factory=CertificateInfo)
tls_versions: list[TLSVersionResult] = field(default_factory=list)
cipher: CipherInfo = field(default_factory=CipherInfo)
headers: list[HeaderResult] = field(default_factory=list)
redirect: RedirectInfo = field(default_factory=RedirectInfo)
hsts: HSTSInfo = field(default_factory=HSTSInfo)
mixed_content: MixedContentInfo = field(default_factory=MixedContentInfo)
dns: DNSInfo = field(default_factory=DNSInfo)
whois: WhoisInfo = field(default_factory=WhoisInfo)
geoip: GeoIPInfo = field(default_factory=GeoIPInfo)
ports: list[PortStatus] = field(default_factory=list)
findings: list[Finding] = field(default_factory=list)
recommendations: list[str] = field(default_factory=list)
score: ScoreBreakdown = field(default_factory=ScoreBreakdown)
overall_rating: str = "Unknown"
errors: list[str] = field(default_factory=list)
def to_dict(self) -> dict[str, Any]:
"""Return a plain dictionary that can be serialized to JSON."""
return asdict(self)