web-scanner 2.1.4__tar.gz → 2.2.0__tar.gz
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.
- {web_scanner-2.1.4 → web_scanner-2.2.0}/PKG-INFO +42 -24
- {web_scanner-2.1.4 → web_scanner-2.2.0}/README.md +41 -23
- {web_scanner-2.1.4 → web_scanner-2.2.0}/webscanner/__init__.py +1 -1
- {web_scanner-2.1.4 → web_scanner-2.2.0}/webscanner/colors.py +3 -0
- {web_scanner-2.1.4 → web_scanner-2.2.0}/webscanner/core/context.py +7 -0
- {web_scanner-2.1.4 → web_scanner-2.2.0}/webscanner/core/scanner.py +33 -2
- {web_scanner-2.1.4 → web_scanner-2.2.0}/webscanner/modules/dns.py +80 -0
- web_scanner-2.2.0/webscanner/modules/security.py +314 -0
- {web_scanner-2.1.4 → web_scanner-2.2.0}/webscanner/modules/seo.py +46 -7
- {web_scanner-2.1.4 → web_scanner-2.2.0}/webscanner/net/http.py +27 -0
- web_scanner-2.2.0/webscanner/net/version_check.py +81 -0
- {web_scanner-2.1.4 → web_scanner-2.2.0}/webscanner/ui/activity.py +51 -3
- {web_scanner-2.1.4 → web_scanner-2.2.0}/webscanner/ui/app.py +77 -4
- {web_scanner-2.1.4 → web_scanner-2.2.0}/webscanner/ui/export.py +54 -5
- {web_scanner-2.1.4 → web_scanner-2.2.0}/webscanner/ui/tables.py +5 -1
- web_scanner-2.1.4/webscanner/modules/security.py +0 -124
- {web_scanner-2.1.4 → web_scanner-2.2.0}/.gitignore +0 -0
- {web_scanner-2.1.4 → web_scanner-2.2.0}/LICENSE +0 -0
- {web_scanner-2.1.4 → web_scanner-2.2.0}/app.py +0 -0
- {web_scanner-2.1.4 → web_scanner-2.2.0}/pyproject.toml +0 -0
- {web_scanner-2.1.4 → web_scanner-2.2.0}/requirements.txt +0 -0
- {web_scanner-2.1.4 → web_scanner-2.2.0}/webscanner/__main__.py +0 -0
- {web_scanner-2.1.4 → web_scanner-2.2.0}/webscanner/cli.py +0 -0
- {web_scanner-2.1.4 → web_scanner-2.2.0}/webscanner/core/__init__.py +0 -0
- {web_scanner-2.1.4 → web_scanner-2.2.0}/webscanner/core/models.py +0 -0
- {web_scanner-2.1.4 → web_scanner-2.2.0}/webscanner/core/module.py +0 -0
- {web_scanner-2.1.4 → web_scanner-2.2.0}/webscanner/helpers.py +0 -0
- {web_scanner-2.1.4 → web_scanner-2.2.0}/webscanner/modules/__init__.py +0 -0
- {web_scanner-2.1.4 → web_scanner-2.2.0}/webscanner/modules/headers.py +0 -0
- {web_scanner-2.1.4 → web_scanner-2.2.0}/webscanner/modules/links.py +0 -0
- {web_scanner-2.1.4 → web_scanner-2.2.0}/webscanner/modules/sitemap.py +0 -0
- {web_scanner-2.1.4 → web_scanner-2.2.0}/webscanner/modules/ssl.py +0 -0
- {web_scanner-2.1.4 → web_scanner-2.2.0}/webscanner/modules/subdomains.py +0 -0
- {web_scanner-2.1.4 → web_scanner-2.2.0}/webscanner/modules/tech.py +0 -0
- {web_scanner-2.1.4 → web_scanner-2.2.0}/webscanner/modules/whois.py +0 -0
- {web_scanner-2.1.4 → web_scanner-2.2.0}/webscanner/net/__init__.py +0 -0
- {web_scanner-2.1.4 → web_scanner-2.2.0}/webscanner/net/agents.py +0 -0
- {web_scanner-2.1.4 → web_scanner-2.2.0}/webscanner/net/data/public_suffix_list.dat +0 -0
- {web_scanner-2.1.4 → web_scanner-2.2.0}/webscanner/net/psl.py +0 -0
- {web_scanner-2.1.4 → web_scanner-2.2.0}/webscanner/ui/__init__.py +0 -0
- {web_scanner-2.1.4 → web_scanner-2.2.0}/webscanner/ui/app.tcss +0 -0
- {web_scanner-2.1.4 → web_scanner-2.2.0}/webscanner/ui/data/countries.json +0 -0
- {web_scanner-2.1.4 → web_scanner-2.2.0}/webscanner/ui/widgets.py +0 -0
- {web_scanner-2.1.4 → web_scanner-2.2.0}/webscanner/ui/worldmap.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: web-scanner
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.2.0
|
|
4
4
|
Summary: An async Textual TUI for website reconnaissance — DNS, WHOIS, TLS, security, tech-stack and SEO, with no paid APIs.
|
|
5
5
|
Project-URL: Homepage, https://github.com/iamramizk/web-scanner
|
|
6
6
|
Project-URL: Repository, https://github.com/iamramizk/web-scanner
|
|
@@ -55,7 +55,7 @@ Description-Content-Type: text/markdown
|
|
|
55
55
|
_An async Textual TUI for website reconnaissance — DNS, WHOIS, TLS, security, tech-stack and SEO, with no paid APIs._
|
|
56
56
|
|
|
57
57
|
[](https://www.python.org/downloads/)
|
|
58
|
-
[](https://pypi.org/project/web-scanner/)
|
|
59
59
|
[](https://github.com/iamramizk/web-scanner/releases/latest)
|
|
60
60
|
|
|
61
61
|
</div>
|
|
@@ -69,13 +69,14 @@ a server-status panel that stay pinned in place.
|
|
|
69
69
|
resolvers for blocklist checks, the system `whois`, and stdlib `ssl`/`socket`. Country
|
|
70
70
|
borders are embedded (Natural Earth), so even the map needs no tile service.
|
|
71
71
|
|
|
72
|
-

|
|
73
|
+
|
|
74
|
+

|
|
73
75
|
|
|
74
76
|
## Contents
|
|
75
77
|
|
|
76
78
|
- [Features](#features)
|
|
77
79
|
- [Installation](#installation)
|
|
78
|
-
- [From source (development)](#from-source-development)
|
|
79
80
|
- [Usage](#usage)
|
|
80
81
|
- [Updating](#updating)
|
|
81
82
|
- [Keys](#keys)
|
|
@@ -84,26 +85,41 @@ borders are embedded (Natural Earth), so even the map needs no tile service.
|
|
|
84
85
|
|
|
85
86
|
Ten tabs, scanned concurrently and rendered live as each module finishes:
|
|
86
87
|
|
|
87
|
-
- **DNS** —
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
-
|
|
91
|
-
|
|
92
|
-
- **
|
|
93
|
-
|
|
94
|
-
-
|
|
95
|
-
|
|
96
|
-
-
|
|
97
|
-
|
|
98
|
-
|
|
88
|
+
- **DNS** — records plus email authentication, folded into one tab.
|
|
89
|
+
- A / AAAA / NS / CNAME / SOA / MX / TXT / CAA / DS / DNSKEY records
|
|
90
|
+
- DMARC (`_dmarc`) and DKIM (probes ~40 selectors, each labelled with its email provider)
|
|
91
|
+
- SPF `all` qualifier, and an **Email Spoofing** verdict (Protected / Weak / Vulnerable)
|
|
92
|
+
computed from DMARC enforcement, not SPF alone
|
|
93
|
+
- **Whois** — parsed system `whois`, with rich gTLD and ccTLD field support.
|
|
94
|
+
- Registrar, registration / expiry dates, nameservers
|
|
95
|
+
- Per-contact details where published
|
|
96
|
+
- **Subdomains** — discovered natively, no third-party enumeration services.
|
|
97
|
+
- TLS certificate SANs
|
|
98
|
+
- `socket` probes of common subdomains
|
|
99
|
+
- **SSL** — the live TLS certificate, parsed from the handshake.
|
|
100
|
+
- Issuer, subject, SANs
|
|
101
|
+
- Validity window, trust and expiry
|
|
102
|
+
- **Security** — four checks, each a sub-table.
|
|
103
|
+
- **WAF detection** — passive header/cookie fingerprinting plus an active probe that
|
|
104
|
+
sends obvious attack payloads to see if it gets blocked (names Cloudflare, Sucuri,
|
|
105
|
+
Akamai, ModSecurity, …)
|
|
106
|
+
- **Open ports** — TCP connect scan of common ports
|
|
107
|
+
- **HTTP security headers** — CSP, HSTS, X-Frame-Options, … present or not
|
|
108
|
+
- **Blocklists** — status across public filtering resolvers (AdGuard, CleanBrowsing,
|
|
109
|
+
Cloudflare, Google, OpenDNS, Quad9)
|
|
99
110
|
- **Headers** — the full set of HTTP response headers.
|
|
100
|
-
- **Tech** — technology-stack detection via [Wappalyzer](https://github.com/tunetheweb/wappalyzer)
|
|
101
|
-
|
|
102
|
-
- **SEO** — page
|
|
103
|
-
|
|
104
|
-
-
|
|
105
|
-
|
|
106
|
-
-
|
|
111
|
+
- **Tech** — technology-stack detection via [Wappalyzer](https://github.com/tunetheweb/wappalyzer).
|
|
112
|
+
- Each technology with its category, confidence, groups and version
|
|
113
|
+
- **SEO** — everything on-page that search engines read.
|
|
114
|
+
- Title / description with length hints, H1–H3, social links
|
|
115
|
+
- Top keyword n-grams (1 / 2 / 3-word)
|
|
116
|
+
- `robots.txt` and declared sitemaps
|
|
117
|
+
- JSON-LD structured data
|
|
118
|
+
- **Sitemap** — the site's URLs as a clickable path tree, no crawling.
|
|
119
|
+
- Discovered from `sitemap.xml`, recursing into nested sitemap indexes
|
|
120
|
+
- Rebuilt into a folder tree keyed by URL path
|
|
121
|
+
- **Links** — links found on the page, with their anchor text.
|
|
122
|
+
- Internal and external, split into sub-tables
|
|
107
123
|
|
|
108
124
|
Alongside the tabs, three fixed panels:
|
|
109
125
|
|
|
@@ -112,7 +128,9 @@ Alongside the tabs, three fixed panels:
|
|
|
112
128
|
- **Country map** — real country outlines auto-framed around the server's location, drawn
|
|
113
129
|
with braille characters (`+` / `-` to zoom).
|
|
114
130
|
- **Server** — online status and response time, the final URL after redirects, IP,
|
|
115
|
-
geolocation, ISP, AS, hosting provider and detected CMS (name and version).
|
|
131
|
+
geolocation, ISP, AS, hosting provider and detected CMS (name and version). When many
|
|
132
|
+
sites share the server's IP, it flags the address as shared and counts how many distinct
|
|
133
|
+
domains resolve to it (via a free reverse-IP lookup).
|
|
116
134
|
|
|
117
135
|
Requests to the site being scanned wear a **coherent desktop-Chrome identity** — a real
|
|
118
136
|
User-Agent plus the headers Chrome actually sends beside it — picked once per scan and
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
_An async Textual TUI for website reconnaissance — DNS, WHOIS, TLS, security, tech-stack and SEO, with no paid APIs._
|
|
6
6
|
|
|
7
7
|
[](https://www.python.org/downloads/)
|
|
8
|
-
[](https://pypi.org/project/web-scanner/)
|
|
9
9
|
[](https://github.com/iamramizk/web-scanner/releases/latest)
|
|
10
10
|
|
|
11
11
|
</div>
|
|
@@ -19,13 +19,14 @@ a server-status panel that stay pinned in place.
|
|
|
19
19
|
resolvers for blocklist checks, the system `whois`, and stdlib `ssl`/`socket`. Country
|
|
20
20
|
borders are embedded (Natural Earth), so even the map needs no tile service.
|
|
21
21
|
|
|
22
|
-

|
|
23
|
+
|
|
24
|
+

|
|
23
25
|
|
|
24
26
|
## Contents
|
|
25
27
|
|
|
26
28
|
- [Features](#features)
|
|
27
29
|
- [Installation](#installation)
|
|
28
|
-
- [From source (development)](#from-source-development)
|
|
29
30
|
- [Usage](#usage)
|
|
30
31
|
- [Updating](#updating)
|
|
31
32
|
- [Keys](#keys)
|
|
@@ -34,26 +35,41 @@ borders are embedded (Natural Earth), so even the map needs no tile service.
|
|
|
34
35
|
|
|
35
36
|
Ten tabs, scanned concurrently and rendered live as each module finishes:
|
|
36
37
|
|
|
37
|
-
- **DNS** —
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
-
|
|
41
|
-
|
|
42
|
-
- **
|
|
43
|
-
|
|
44
|
-
-
|
|
45
|
-
|
|
46
|
-
-
|
|
47
|
-
|
|
48
|
-
|
|
38
|
+
- **DNS** — records plus email authentication, folded into one tab.
|
|
39
|
+
- A / AAAA / NS / CNAME / SOA / MX / TXT / CAA / DS / DNSKEY records
|
|
40
|
+
- DMARC (`_dmarc`) and DKIM (probes ~40 selectors, each labelled with its email provider)
|
|
41
|
+
- SPF `all` qualifier, and an **Email Spoofing** verdict (Protected / Weak / Vulnerable)
|
|
42
|
+
computed from DMARC enforcement, not SPF alone
|
|
43
|
+
- **Whois** — parsed system `whois`, with rich gTLD and ccTLD field support.
|
|
44
|
+
- Registrar, registration / expiry dates, nameservers
|
|
45
|
+
- Per-contact details where published
|
|
46
|
+
- **Subdomains** — discovered natively, no third-party enumeration services.
|
|
47
|
+
- TLS certificate SANs
|
|
48
|
+
- `socket` probes of common subdomains
|
|
49
|
+
- **SSL** — the live TLS certificate, parsed from the handshake.
|
|
50
|
+
- Issuer, subject, SANs
|
|
51
|
+
- Validity window, trust and expiry
|
|
52
|
+
- **Security** — four checks, each a sub-table.
|
|
53
|
+
- **WAF detection** — passive header/cookie fingerprinting plus an active probe that
|
|
54
|
+
sends obvious attack payloads to see if it gets blocked (names Cloudflare, Sucuri,
|
|
55
|
+
Akamai, ModSecurity, …)
|
|
56
|
+
- **Open ports** — TCP connect scan of common ports
|
|
57
|
+
- **HTTP security headers** — CSP, HSTS, X-Frame-Options, … present or not
|
|
58
|
+
- **Blocklists** — status across public filtering resolvers (AdGuard, CleanBrowsing,
|
|
59
|
+
Cloudflare, Google, OpenDNS, Quad9)
|
|
49
60
|
- **Headers** — the full set of HTTP response headers.
|
|
50
|
-
- **Tech** — technology-stack detection via [Wappalyzer](https://github.com/tunetheweb/wappalyzer)
|
|
51
|
-
|
|
52
|
-
- **SEO** — page
|
|
53
|
-
|
|
54
|
-
-
|
|
55
|
-
|
|
56
|
-
-
|
|
61
|
+
- **Tech** — technology-stack detection via [Wappalyzer](https://github.com/tunetheweb/wappalyzer).
|
|
62
|
+
- Each technology with its category, confidence, groups and version
|
|
63
|
+
- **SEO** — everything on-page that search engines read.
|
|
64
|
+
- Title / description with length hints, H1–H3, social links
|
|
65
|
+
- Top keyword n-grams (1 / 2 / 3-word)
|
|
66
|
+
- `robots.txt` and declared sitemaps
|
|
67
|
+
- JSON-LD structured data
|
|
68
|
+
- **Sitemap** — the site's URLs as a clickable path tree, no crawling.
|
|
69
|
+
- Discovered from `sitemap.xml`, recursing into nested sitemap indexes
|
|
70
|
+
- Rebuilt into a folder tree keyed by URL path
|
|
71
|
+
- **Links** — links found on the page, with their anchor text.
|
|
72
|
+
- Internal and external, split into sub-tables
|
|
57
73
|
|
|
58
74
|
Alongside the tabs, three fixed panels:
|
|
59
75
|
|
|
@@ -62,7 +78,9 @@ Alongside the tabs, three fixed panels:
|
|
|
62
78
|
- **Country map** — real country outlines auto-framed around the server's location, drawn
|
|
63
79
|
with braille characters (`+` / `-` to zoom).
|
|
64
80
|
- **Server** — online status and response time, the final URL after redirects, IP,
|
|
65
|
-
geolocation, ISP, AS, hosting provider and detected CMS (name and version).
|
|
81
|
+
geolocation, ISP, AS, hosting provider and detected CMS (name and version). When many
|
|
82
|
+
sites share the server's IP, it flags the address as shared and counts how many distinct
|
|
83
|
+
domains resolve to it (via a free reverse-IP lookup).
|
|
66
84
|
|
|
67
85
|
Requests to the site being scanned wear a **coherent desktop-Chrome identity** — a real
|
|
68
86
|
User-Agent plus the headers Chrome actually sends beside it — picked once per scan and
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
GREEN = "green"
|
|
4
4
|
RED = "#FF6C64"
|
|
5
|
+
#: matches the app's primary theme blue ($primary, textual-dark) — progress bar,
|
|
6
|
+
#: selected-tab chip, keybar hints.
|
|
7
|
+
BLUE = "#0178D4"
|
|
5
8
|
#: muted value/secondary text — matches the unselected-tab colour
|
|
6
9
|
#: ($text-muted = white @ 60% over the dark theme bg).
|
|
7
10
|
MUTED = "#9D9D9D"
|
|
@@ -38,6 +38,13 @@ class ScanContext:
|
|
|
38
38
|
geo: dict[str, Any] | None = None
|
|
39
39
|
fetch_error: str | None = None
|
|
40
40
|
|
|
41
|
+
#: Whether the IP is shared by many sites (reverse-IP lookup). ``None`` until the
|
|
42
|
+
#: lookup resolves — and stays None on any error/rate-limit, so the panel shows
|
|
43
|
+
#: nothing rather than guess. ``shared_ip_count`` is the unique-domain tally shown
|
|
44
|
+
#: alongside. Filled by AsyncScanner concurrently with the modules, never prefetch.
|
|
45
|
+
ip_shared: bool | None = None
|
|
46
|
+
shared_ip_count: int | None = None
|
|
47
|
+
|
|
41
48
|
@classmethod
|
|
42
49
|
def from_target(cls, target: str) -> "ScanContext":
|
|
43
50
|
domain, url = helpers.normalise(target)
|
|
@@ -16,7 +16,7 @@ import asyncio
|
|
|
16
16
|
import time
|
|
17
17
|
from collections.abc import Callable, Iterable
|
|
18
18
|
|
|
19
|
-
from ..net import http
|
|
19
|
+
from ..net import http, psl
|
|
20
20
|
from .context import ScanContext
|
|
21
21
|
from .models import ModuleResult, ModuleStatus, ScanEvent
|
|
22
22
|
from .module import ScanModule
|
|
@@ -24,6 +24,11 @@ from .module import ScanModule
|
|
|
24
24
|
EventCallback = Callable[[ScanEvent], None]
|
|
25
25
|
|
|
26
26
|
PREFETCH = "__prefetch__"
|
|
27
|
+
SHARED_IP = "__shared_ip__"
|
|
28
|
+
|
|
29
|
+
#: Unique registrable domains (eTLD+1) on the IP before we call it "shared". A single
|
|
30
|
+
#: company's handful of vanity domains stays under it; shared hosting / CDN IPs clear it.
|
|
31
|
+
SHARED_IP_THRESHOLD = 10
|
|
27
32
|
|
|
28
33
|
|
|
29
34
|
def _is_empty(data: object) -> bool:
|
|
@@ -81,6 +86,29 @@ class AsyncScanner:
|
|
|
81
86
|
|
|
82
87
|
await asyncio.gather(_fetch(), _geo(), _tls())
|
|
83
88
|
|
|
89
|
+
async def _shared_ip(self) -> None:
|
|
90
|
+
"""Flag a shared IP on the Server panel via a reverse-IP lookup.
|
|
91
|
+
|
|
92
|
+
Runs concurrently with the modules, *never* in the prefetch barrier: it's a
|
|
93
|
+
slow third-party API no module depends on, so joining prefetch would let it
|
|
94
|
+
stall all ten. Failure-isolated and best-effort — any error leaves
|
|
95
|
+
``ip_shared`` None (the panel shows nothing). Emits ``SHARED_IP`` only on a
|
|
96
|
+
real result, so the UI refreshes the panel just once, when it lands.
|
|
97
|
+
"""
|
|
98
|
+
if not self.ctx.ip:
|
|
99
|
+
return
|
|
100
|
+
try:
|
|
101
|
+
hosts = await asyncio.to_thread(http.reverse_ip_lookup, self.ctx.ip)
|
|
102
|
+
if hosts is None:
|
|
103
|
+
return
|
|
104
|
+
domains = {psl.registrable_domain(h) for h in hosts}
|
|
105
|
+
domains.discard("")
|
|
106
|
+
self.ctx.shared_ip_count = len(domains)
|
|
107
|
+
self.ctx.ip_shared = len(domains) >= SHARED_IP_THRESHOLD
|
|
108
|
+
self._emit(SHARED_IP, ModuleStatus.DONE)
|
|
109
|
+
except Exception: # noqa: BLE001 - best effort, must never break the scan
|
|
110
|
+
pass
|
|
111
|
+
|
|
84
112
|
async def _run_module(self, module: ScanModule) -> ModuleResult:
|
|
85
113
|
self._emit(module.name, ModuleStatus.RUNNING)
|
|
86
114
|
start = time.perf_counter()
|
|
@@ -100,5 +128,8 @@ class AsyncScanner:
|
|
|
100
128
|
self._emit(PREFETCH, ModuleStatus.RUNNING)
|
|
101
129
|
await self.prefetch()
|
|
102
130
|
self._emit(PREFETCH, ModuleStatus.DONE)
|
|
103
|
-
await asyncio.gather(
|
|
131
|
+
await asyncio.gather(
|
|
132
|
+
self._shared_ip(),
|
|
133
|
+
*(self._run_module(m) for m in self.modules),
|
|
134
|
+
)
|
|
104
135
|
return self.results
|
|
@@ -9,10 +9,12 @@ when found (no "present: yes/no" noise).
|
|
|
9
9
|
from __future__ import annotations
|
|
10
10
|
|
|
11
11
|
import asyncio
|
|
12
|
+
import re
|
|
12
13
|
from typing import Any
|
|
13
14
|
|
|
14
15
|
import pydig
|
|
15
16
|
|
|
17
|
+
from ..colors import GREEN, RED
|
|
16
18
|
from ..core.module import ScanModule
|
|
17
19
|
from ..core.context import ScanContext
|
|
18
20
|
|
|
@@ -63,6 +65,77 @@ def _is_dkim(records: list[str]) -> bool:
|
|
|
63
65
|
return any(("dkim1" in r.lower() or "p=" in r.lower()) for r in records)
|
|
64
66
|
|
|
65
67
|
|
|
68
|
+
# ---- email-spoofing assessment -------------------------------------------
|
|
69
|
+
#
|
|
70
|
+
# A *configuration* verdict from what DNS already tells us — the same thing MXToolbox /
|
|
71
|
+
# dmarcian report, not a live send test. The load-bearing insight: **DMARC enforcement,
|
|
72
|
+
# not SPF, is what stops visible (From-header) spoofing.** SPF only authenticates the
|
|
73
|
+
# envelope/return-path, so a domain with a perfect `-all` SPF but no DMARC (or `p=none`)
|
|
74
|
+
# is still spoofable in a way the recipient sees. So the verdict keys off DMARC policy,
|
|
75
|
+
# with SPF only breaking the tie when DMARC is absent.
|
|
76
|
+
|
|
77
|
+
_ALL_MECHANISM = re.compile(r"([~+?-])all\b", re.I)
|
|
78
|
+
_DMARC_TAG = re.compile(r"\b(p|sp|pct)\s*=\s*([^;]+)", re.I)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _spf_qualifier(txt_records: list[str]) -> str | None:
|
|
82
|
+
"""The qualifier of the SPF record's ``all`` mechanism (``-all``/``~all``/``?all``/
|
|
83
|
+
``+all``), or ``None`` if there's no ``v=spf1`` record or it carries no ``all``."""
|
|
84
|
+
for record in txt_records:
|
|
85
|
+
if record.strip().lower().startswith("v=spf1"):
|
|
86
|
+
if match := _ALL_MECHANISM.search(record):
|
|
87
|
+
return f"{match.group(1)}all"
|
|
88
|
+
return None # SPF present but no `all` — treat as no explicit policy
|
|
89
|
+
return None
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _dmarc_policy(dmarc_records: list[str]) -> tuple[str | None, int]:
|
|
93
|
+
"""``(policy, pct)`` from the first DMARC record — policy is ``p=`` lower-cased
|
|
94
|
+
(``reject``/``quarantine``/``none``) or ``None``; ``pct`` defaults to 100."""
|
|
95
|
+
for record in dmarc_records:
|
|
96
|
+
tags = {m.group(1).lower(): m.group(2).strip() for m in _DMARC_TAG.finditer(record)}
|
|
97
|
+
policy = tags.get("p", "").lower() or None
|
|
98
|
+
try:
|
|
99
|
+
pct = int(tags.get("pct", "100"))
|
|
100
|
+
except ValueError:
|
|
101
|
+
pct = 100
|
|
102
|
+
return policy, pct
|
|
103
|
+
return None, 100
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def assess_spoofing(
|
|
107
|
+
txt_records: list[str], dmarc_records: list[str], has_dkim: bool
|
|
108
|
+
) -> tuple[str, str]:
|
|
109
|
+
"""``(verdict, reason)`` — verdict is ``Protected`` / ``Weak`` / ``Vulnerable``.
|
|
110
|
+
|
|
111
|
+
Pure (no ctx, no I/O) so it's unit-testable like the activity-line catalogue.
|
|
112
|
+
"""
|
|
113
|
+
spf = _spf_qualifier(txt_records)
|
|
114
|
+
policy, pct = _dmarc_policy(dmarc_records)
|
|
115
|
+
|
|
116
|
+
if policy in ("reject", "quarantine"):
|
|
117
|
+
if pct < 100:
|
|
118
|
+
return "Weak", f"DMARC p={policy} but only pct={pct}"
|
|
119
|
+
label = "Protected" if policy == "reject" else "Protected (quarantine)"
|
|
120
|
+
return label, f"DMARC p={policy}"
|
|
121
|
+
if policy == "none":
|
|
122
|
+
return "Weak", "DMARC p=none — monitoring only, mail still delivered"
|
|
123
|
+
# No enforcing DMARC — SPF alone can't stop From-header spoofing.
|
|
124
|
+
if spf == "-all":
|
|
125
|
+
return "Weak", "SPF -all but no DMARC policy"
|
|
126
|
+
if spf:
|
|
127
|
+
return "Vulnerable", f"no DMARC and SPF {spf} (not enforcing)"
|
|
128
|
+
return "Vulnerable", "no DMARC policy and no SPF record"
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def _verdict_cell(verdict: str, reason: str) -> str:
|
|
132
|
+
"""Colour the verdict verb (green Protected, else red — Weak and Vulnerable are both
|
|
133
|
+
spoofable) with the reason kept alongside. A value with ``[/]`` renders via markup in
|
|
134
|
+
``_value_cell``."""
|
|
135
|
+
colour = GREEN if verdict.startswith("Protected") else RED
|
|
136
|
+
return f"[{colour}]{verdict}[/] — {reason}"
|
|
137
|
+
|
|
138
|
+
|
|
66
139
|
class DnsModule(ScanModule):
|
|
67
140
|
name = "dns"
|
|
68
141
|
label = "DNS"
|
|
@@ -100,4 +173,11 @@ class DnsModule(ScanModule):
|
|
|
100
173
|
f"{s} ({DKIM_SELECTORS[s]})" if DKIM_SELECTORS[s] else s
|
|
101
174
|
for s in found
|
|
102
175
|
]
|
|
176
|
+
|
|
177
|
+
# Derived email-spoofing verdict from the records above (no extra network work).
|
|
178
|
+
# SPF sits inside the TXT records; surface its `all` qualifier, then the verdict.
|
|
179
|
+
if (spf := _spf_qualifier(out.get("TXT", []))) is not None:
|
|
180
|
+
out["SPF"] = [spf]
|
|
181
|
+
verdict, reason = assess_spoofing(out.get("TXT", []), dmarc_records, bool(found))
|
|
182
|
+
out["Email Spoofing"] = [_verdict_cell(verdict, reason)]
|
|
103
183
|
return out
|