-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
241 lines (196 loc) · 8.13 KB
/
cli.py
File metadata and controls
241 lines (196 loc) · 8.13 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#!/usr/bin/env python3
"""
IronVeil CLI — Command-line interface for casino/iGaming security audits.
Usage:
ironveil audit <target_url> [options]
ironveil report <audit_id> [options]
ironveil config [show|validate|init]
ironveil version
"""
import sys
import logging
from typing import Optional
import click
from ironveil import __version__, configure_logging
from ironveil.core.config import Config, ConfigNotFoundError
from ironveil.core.engine import AuditEngine, AuditResult
from ironveil.reporting.html_report import HtmlReportGenerator
from ironveil.reporting.json_export import JsonExporter, SarifExporter
@click.group()
@click.option("--verbose", "-v", is_flag=True, help="Enable debug logging")
@click.option("--quiet", "-q", is_flag=True, help="Suppress non-error output")
@click.option("--config", "-c", "config_path", type=click.Path(), default=None,
help="Path to configuration file")
@click.pass_context
def cli(ctx: click.Context, verbose: bool, quiet: bool, config_path: Optional[str]) -> None:
"""IronVeil — Casino & iGaming Security Audit Framework"""
ctx.ensure_object(dict)
level = "DEBUG" if verbose else ("ERROR" if quiet else "INFO")
configure_logging(level)
try:
ctx.obj["config"] = Config(config_path=config_path)
except ConfigNotFoundError as exc:
if config_path:
click.echo(f"Error: {exc}", err=True)
sys.exit(1)
ctx.obj["config"] = Config(auto_discover=False)
@cli.command()
@click.argument("target_url")
@click.option("--output", "-o", type=click.Path(), default="./reports",
help="Output directory for reports")
@click.option("--format", "-f", "report_format", type=click.Choice(["html", "json", "sarif", "all"]),
default="all", help="Report format")
@click.option("--headless/--no-headless", default=True, help="Run browser in headless mode")
@click.option("--proxy", "-p", type=str, default=None, help="Proxy URL")
@click.option("--timeout", "-t", type=int, default=300, help="Session timeout in seconds")
@click.option("--profile", type=click.Choice(["casual", "focused", "slow", "aggressive"]),
default="casual", help="Timing profile")
@click.option("--skip-detection", is_flag=True, help="Skip detection analysis phase")
@click.option("--skip-evasion", is_flag=True, help="Skip evasion testing phase")
@click.option("--skip-platform", is_flag=True, help="Skip platform analysis phase")
@click.pass_context
def audit(
ctx: click.Context,
target_url: str,
output: str,
report_format: str,
headless: bool,
proxy: Optional[str],
timeout: int,
profile: str,
skip_detection: bool,
skip_evasion: bool,
skip_platform: bool,
) -> None:
"""Run a security audit against a target casino/iGaming platform."""
config: Config = ctx.obj["config"]
# Apply CLI overrides
config.set("general.output_dir", output)
config.set("browser.headless", headless)
config.set("session.session_timeout", timeout)
if proxy:
config.set("session.proxy_list_file", None)
# Direct proxy override handled by session
if skip_detection:
config.set("detection.bot_detection_tests", False)
config.set("detection.behavioral_analysis", False)
config.set("detection.fingerprint_analysis", False)
config.set("detection.captcha_analysis", False)
if skip_evasion:
config.set("evasion.human_simulation", False)
config.set("evasion.fingerprint_spoofing", False)
config.set("evasion.timing_evasion", False)
if skip_platform:
config.set("platform.api_probing", False)
config.set("platform.integrity_checks", False)
click.echo(f"IronVeil v{__version__}")
click.echo(f"Target: {target_url}")
click.echo(f"Profile: {profile}")
click.echo(f"Output: {output}")
click.echo("—" * 50)
engine = AuditEngine(config)
def on_finding(finding, **_):
icon = {"critical": "!!", "high": "!", "medium": "*", "low": "-", "info": "."}
click.echo(f" [{icon.get(finding.severity, '?')}] {finding.title}")
engine.register_hook("on_finding", on_finding)
try:
result = engine.run(target_url)
except KeyboardInterrupt:
click.echo("\nAudit interrupted by user.")
sys.exit(130)
except Exception as exc:
click.echo(f"\nAudit failed: {exc}", err=True)
sys.exit(1)
# Generate reports
_generate_reports(result, output, report_format)
# Summary
click.echo("—" * 50)
click.echo(f"Audit complete: {len(result.findings)} findings")
click.echo(f"Risk score: {result.risk_score:.1f}/10")
click.echo(f"Duration: {result.duration_seconds:.0f}s")
click.echo(f"Reports saved to: {output}/")
@cli.command()
@click.argument("report_path", type=click.Path(exists=True))
@click.option("--format", "-f", "output_format", type=click.Choice(["html", "json", "sarif"]),
default="html", help="Convert to format")
@click.option("--output", "-o", type=click.Path(), default=None, help="Output file path")
def report(report_path: str, output_format: str, output: Optional[str]) -> None:
"""Convert or view an existing audit report."""
import json as json_mod
try:
with open(report_path, "r", encoding="utf-8") as fh:
data = json_mod.load(fh)
except Exception as exc:
click.echo(f"Error reading report: {exc}", err=True)
sys.exit(1)
click.echo(f"Report: {report_path}")
click.echo(f"Audit ID: {data.get('audit', {}).get('id', 'unknown')}")
click.echo(f"Target: {data.get('audit', {}).get('target_url', 'unknown')}")
click.echo(f"Findings: {data.get('summary', {}).get('total_findings', 0)}")
click.echo(f"Risk Score: {data.get('summary', {}).get('risk_score', 0)}")
@cli.group()
def config() -> None:
"""Manage IronVeil configuration."""
pass
@config.command("show")
@click.pass_context
def config_show(ctx: click.Context) -> None:
"""Display the current configuration."""
import yaml
cfg: Config = ctx.obj["config"]
click.echo(f"Source: {cfg.source_file or 'built-in defaults'}")
click.echo("—" * 50)
click.echo(yaml.dump(cfg.as_dict(), default_flow_style=False, sort_keys=True))
@config.command("validate")
@click.pass_context
def config_validate(ctx: click.Context) -> None:
"""Validate the current configuration."""
cfg: Config = ctx.obj["config"]
warnings = cfg.validate()
if warnings:
click.echo("Configuration warnings:")
for w in warnings:
click.echo(f" - {w}")
sys.exit(1)
else:
click.echo("Configuration is valid.")
@config.command("init")
@click.option("--path", "-p", type=click.Path(), default="./ironveil.yaml",
help="Output path for config file")
def config_init(path: str) -> None:
"""Create a default configuration file."""
import shutil
from pathlib import Path
default_src = Path(__file__).parent / "config" / "default.yaml"
if default_src.exists():
shutil.copy2(default_src, path)
click.echo(f"Configuration file created: {path}")
else:
import yaml
cfg = Config(auto_discover=False)
with open(path, "w", encoding="utf-8") as fh:
yaml.dump(cfg.as_dict(), fh, default_flow_style=False, sort_keys=True)
click.echo(f"Configuration file created: {path}")
@cli.command()
def version() -> None:
"""Display the IronVeil version."""
click.echo(f"IronVeil v{__version__}")
def _generate_reports(result: AuditResult, output_dir: str, fmt: str) -> None:
"""Generate reports in the requested format(s)."""
if fmt in ("html", "all"):
gen = HtmlReportGenerator(output_dir)
path = gen.generate(result)
click.echo(f" HTML report: {path}")
if fmt in ("json", "all"):
exp = JsonExporter(output_dir, pretty=True, include_raw=True)
path = exp.export(result)
click.echo(f" JSON report: {path}")
if fmt in ("sarif", "all"):
sarif = SarifExporter(output_dir)
path = sarif.export(result)
click.echo(f" SARIF report: {path}")
def main() -> None:
"""Entry point."""
cli(obj={})
if __name__ == "__main__":
main()