subscout 1.0.0__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.
subscout/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ """subscout - subdomain enumeration, liveness checking, IP analysis and Shodan lookup."""
2
+
3
+ __version__ = "1.0.0"
subscout/__main__.py ADDED
@@ -0,0 +1,3 @@
1
+ from subscout.cli import main
2
+
3
+ raise SystemExit(main())
subscout/cli.py ADDED
@@ -0,0 +1,233 @@
1
+ """Command-line interface: ``subscout {enum,live,resolve,shodan,scan}``."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import os
7
+ import sys
8
+ from collections.abc import Sequence
9
+ from importlib import resources
10
+ from pathlib import Path
11
+
12
+ from subscout import __version__, fileio, ipinfo, livecheck, shodan_lookup, ui
13
+ from subscout.engine import METHODS, enumerate_domain
14
+ from subscout.models import SourceError
15
+
16
+ DEFAULT_OUT = Path("output")
17
+ EXT = {"csv": "csv", "json": "json", "jsonl": "jsonl"}
18
+
19
+
20
+ def default_wordlist() -> Path:
21
+ return Path(str(resources.files("subscout") / "data" / "top1000subdomains.txt"))
22
+
23
+
24
+ def _common(p: argparse.ArgumentParser) -> None:
25
+ p.add_argument("-t", "--threads", type=int, default=20, help="worker threads (default: 20)")
26
+ p.add_argument("-v", "--verbose", action="store_true", help="also show failed attempts")
27
+
28
+
29
+ def _fmt(p: argparse.ArgumentParser) -> None:
30
+ p.add_argument("-f", "--format", choices=fileio.FORMATS,
31
+ help="output format (default: from the -o extension, else csv)")
32
+
33
+
34
+ def build_parser() -> argparse.ArgumentParser:
35
+ parser = argparse.ArgumentParser(
36
+ prog="subscout",
37
+ description="Subdomain recon pipeline: discover -> live check -> IP analysis -> Shodan. "
38
+ "Only scan domains you own or are authorised to test.",
39
+ epilog="Use '-' as the input/output path to read stdin / write stdout. "
40
+ "Status messages always go to stderr, so pipes stay clean.",
41
+ )
42
+ parser.add_argument("-V", "--version", action="version", version=f"%(prog)s {__version__}")
43
+ # Global flags are accepted both before and after the subcommand.
44
+ glob = argparse.ArgumentParser(add_help=False)
45
+ for target, default in ((parser, False), (glob, argparse.SUPPRESS)):
46
+ target.add_argument("--no-banner", action="store_true", default=default,
47
+ help="don't print the banner")
48
+ target.add_argument("--no-color", action="store_true", default=default,
49
+ help="disable coloured output")
50
+ target.add_argument("-q", "--quiet", action="store_true", default=default,
51
+ help="only print results and errors")
52
+ sub = parser.add_subparsers(dest="command", required=True, metavar="command")
53
+
54
+ p = sub.add_parser("enum", parents=[glob], help="discover subdomains (brute-force / CertSpotter / VirusTotal)")
55
+ p.add_argument("-d", "--domain", required=True, help="target domain, e.g. example.com")
56
+ p.add_argument("-m", "--method", choices=METHODS, default="both",
57
+ help="brute | certspotter | virustotal | both (brute+certspotter, default) | all")
58
+ p.add_argument("-w", "--wordlist", type=Path, help="wordlist for brute-force (default: bundled top-1000)")
59
+ p.add_argument("-o", "--output", type=Path, help="output file or '-' (default: output/results.<fmt>)")
60
+ p.add_argument("-k", "--apikey", default=os.environ.get("VT_API_KEY"),
61
+ help="VirusTotal API key (or set VT_API_KEY)")
62
+ p.add_argument("--no-wildcard-filter", action="store_true", help="keep wildcard-DNS results")
63
+ _fmt(p)
64
+ _common(p)
65
+ p.set_defaults(func=cmd_enum)
66
+
67
+ p = sub.add_parser("live", parents=[glob], help="keep only subdomains that answer over HTTP/HTTPS")
68
+ p.add_argument("-i", "--input", required=True, type=Path, help="subdomain list / results file / '-' for stdin")
69
+ p.add_argument("-o", "--output", type=Path, help="output file or '-' (default: output/live_subdomains.txt)")
70
+ p.add_argument("--timeout", type=float, default=3, help="request timeout in seconds (default: 3)")
71
+ _fmt(p)
72
+ _common(p)
73
+ p.set_defaults(func=cmd_live)
74
+
75
+ p = sub.add_parser("resolve", parents=[glob], help="resolve IPs, classify Public/Private, find shared origins")
76
+ p.add_argument("-i", "--input", required=True, type=Path, help="subdomain list / results file / '-' for stdin")
77
+ p.add_argument("-o", "--output", type=Path, help="output file or '-' (default: output/ip_results.<fmt>)")
78
+ _fmt(p)
79
+ p.set_defaults(func=cmd_resolve)
80
+
81
+ p = sub.add_parser("shodan", parents=[glob], help="look up public IPs on Shodan (open ports, CVEs)")
82
+ p.add_argument("-i", "--input", required=True, type=Path, help="output of 'resolve' / '-' for stdin")
83
+ p.add_argument("-o", "--output", type=Path, help="output file or '-' (default: output/shodan_results.<fmt>)")
84
+ p.add_argument("-k", "--apikey", default=os.environ.get("SHODAN_API_KEY"),
85
+ help="Shodan API key (or set SHODAN_API_KEY)")
86
+ _fmt(p)
87
+ p.set_defaults(func=cmd_shodan)
88
+
89
+ p = sub.add_parser("scan", parents=[glob], help="run the full pipeline: enum -> live -> resolve [-> shodan]")
90
+ p.add_argument("-d", "--domain", required=True)
91
+ p.add_argument("-m", "--method", choices=METHODS, default="both")
92
+ p.add_argument("-w", "--wordlist", type=Path)
93
+ p.add_argument("-O", "--outdir", type=Path, default=DEFAULT_OUT, help="output directory (default: output/)")
94
+ p.add_argument("-k", "--apikey", default=os.environ.get("VT_API_KEY"), help="VirusTotal API key")
95
+ p.add_argument("--shodan-key", default=os.environ.get("SHODAN_API_KEY"),
96
+ help="Shodan API key; enables the Shodan step")
97
+ p.add_argument("--timeout", type=float, default=3)
98
+ p.add_argument("--no-wildcard-filter", action="store_true")
99
+ _fmt(p)
100
+ _common(p)
101
+ p.set_defaults(func=cmd_scan)
102
+ return parser
103
+
104
+
105
+ # ------------------------------------------------------------------ helpers
106
+ def _target(output: Path | None, default_name: str, fmt: str | None) -> tuple[Path, str]:
107
+ """Resolve (path, format) for an output; ``default_name`` is like 'results' (extension added)."""
108
+ f = fileio.detect_format(output, fmt)
109
+ return (output if output else DEFAULT_OUT / f"{default_name}.{EXT[f]}"), f
110
+
111
+
112
+ def _saved(what: str, path: Path) -> None:
113
+ if str(path) != fileio.STDIO:
114
+ ui.done(f"{what} saved to {path}")
115
+
116
+
117
+ def _live_name(fmt: str) -> str:
118
+ return "live_subdomains.txt" if fmt == "csv" else f"live_subdomains.{EXT[fmt]}"
119
+
120
+
121
+ def _live_target(output: Path | None, fmt: str | None) -> tuple[Path, str]:
122
+ f = fileio.detect_format(output, fmt)
123
+ return (output if output else DEFAULT_OUT / _live_name(f)), f
124
+
125
+
126
+ # ----------------------------------------------------------------- commands
127
+ def _enum(args: argparse.Namespace, output: Path, fmt: str):
128
+ wl = args.wordlist or default_wordlist()
129
+ words = fileio.read_wordlist(wl) if args.method in ("brute", "both", "all") else []
130
+ findings = enumerate_domain(
131
+ args.domain, args.method, words, threads=args.threads, verbose=args.verbose,
132
+ api_key=args.apikey, filter_wildcard=not args.no_wildcard_filter,
133
+ )
134
+ for f in findings:
135
+ ui.found(f"{f.subdomain:<45} {f.ip or '(unresolved)':<39} [{','.join(sorted(f.sources))}]")
136
+ fileio.write_findings(findings, output, fmt)
137
+ _saved(f"{len(findings)} subdomain(s)", output)
138
+ return findings
139
+
140
+
141
+ def cmd_enum(args: argparse.Namespace) -> int:
142
+ out, fmt = _target(args.output, "results", args.format)
143
+ _enum(args, out, fmt)
144
+ return 0
145
+
146
+
147
+ def _live(subs: list[str], args: argparse.Namespace, output: Path, fmt: str) -> list[str]:
148
+ ui.info(f"Checking {len(subs)} subdomain(s) for liveness...")
149
+ live = livecheck.filter_live(subs, args.threads, args.timeout, args.verbose)
150
+ fileio.write_lines(live, output, fmt)
151
+ _saved(f"{len(live)} live subdomain(s)", output)
152
+ return live
153
+
154
+
155
+ def cmd_live(args: argparse.Namespace) -> int:
156
+ out, fmt = _live_target(args.output, args.format)
157
+ _live(fileio.read_subdomains(args.input), args, out, fmt)
158
+ return 0
159
+
160
+
161
+ def _resolve(subs: list[str], output: Path, fmt: str) -> None:
162
+ rows, by_ip = ipinfo.extract_ips(subs)
163
+ fileio.write_table(fileio.IP_HEADER, ipinfo.shared_rows(rows, by_ip), output, fmt,
164
+ list_cols=["Shared_With"])
165
+ _saved("IP results", output)
166
+
167
+
168
+ def cmd_resolve(args: argparse.Namespace) -> int:
169
+ out, fmt = _target(args.output, "ip_results", args.format)
170
+ _resolve(fileio.read_subdomains(args.input), out, fmt)
171
+ return 0
172
+
173
+
174
+ def _shodan(ip_file: Path, key: str | None, output: Path, fmt: str) -> int:
175
+ if not key:
176
+ ui.error("Shodan needs an API key (-k/--apikey or SHODAN_API_KEY).")
177
+ return 1
178
+ ips = fileio.read_public_ips(ip_file)
179
+ if not ips:
180
+ ui.warn("No public IPs to look up.")
181
+ return 0
182
+ results = shodan_lookup.lookup(ips, key)
183
+ fileio.write_table(fileio.SHODAN_HEADER, shodan_lookup.to_rows(results), output, fmt,
184
+ list_cols=["Open Ports", "CVEs"])
185
+ _saved("Shodan results", output)
186
+ return 0
187
+
188
+
189
+ def cmd_shodan(args: argparse.Namespace) -> int:
190
+ out, fmt = _target(args.output, "shodan_results", args.format)
191
+ return _shodan(args.input, args.apikey, out, fmt)
192
+
193
+
194
+ def cmd_scan(args: argparse.Namespace) -> int:
195
+ d: Path = args.outdir
196
+ fmt = args.format or "csv"
197
+ findings = _enum(args, d / f"results.{EXT[fmt]}", fmt)
198
+ if not findings:
199
+ ui.warn("Nothing found; stopping.")
200
+ return 0
201
+ live = _live([f.subdomain for f in findings], args, d / _live_name(fmt), fmt)
202
+ if not live:
203
+ ui.warn("No live subdomains; stopping.")
204
+ return 0
205
+ ip_path = d / f"ip_results.{EXT[fmt]}"
206
+ _resolve(live, ip_path, fmt)
207
+ if args.shodan_key:
208
+ return _shodan(ip_path, args.shodan_key, d / f"shodan_results.{EXT[fmt]}", fmt)
209
+ return 0
210
+
211
+
212
+ # --------------------------------------------------------------------- main
213
+ def main(argv: Sequence[str] | None = None) -> int:
214
+ """Exit codes: 0 ok, 1 runtime error (bad input, API failure), 2 usage error, 130 interrupted."""
215
+ args = build_parser().parse_args(argv)
216
+ ui.setup(no_color=args.no_color, quiet=args.quiet)
217
+ if not args.no_banner and sys.stderr.isatty():
218
+ ui.banner()
219
+ try:
220
+ return args.func(args)
221
+ except FileNotFoundError as exc:
222
+ ui.error(f"File not found: {exc.filename}")
223
+ return 1
224
+ except (SourceError, ValueError) as exc:
225
+ ui.error(str(exc))
226
+ return 1
227
+ except KeyboardInterrupt:
228
+ ui.error("Interrupted.")
229
+ return 130
230
+
231
+
232
+ if __name__ == "__main__":
233
+ sys.exit(main())