mirror of
https://github.com/yogeshojha/rengine.git
synced 2026-10-20 15:21:30 +02:00
A scan no longer needs a saved engine. The launch dialog has two configuration modes: Scan Engine (default, runs a saved engine exactly as configured, shown as a pipeline and its YAML) and Custom Scan (pick the capabilities to run; dependent and supporting stages are included automatically). Targets are created on launch from typed values, the scan context is a first-class field, and "Run again" restores the engine or the selection that ran. Backend - scans.engine_id is nullable; an absent engine resolves through AdHocEngine and the run is named after its capabilities (plan_label) - ScanCreate/ScanBatchCreate accept target_value(s) (create or reuse via TargetService.ensure_targets), a per-run intensity, and preview works for a target that does not exist yet - every stage declares consumes/produces (AssetKind), group (StageGroup) and role (capability | support); the registry validates them and the catalog serves them with groups and seed_produces - stage_effects walks levels so a producer only feeds later levels and marks an unfed consumer skipped_no_input Frontend - components/scans/launch/: launch-dialog, launch-state, target-picker, plan-picker (segmented Scan Engine | Custom Scan, pipeline + YAML Config views, capability pills with full per-stage settings), stage-pill, stage-config-popover, launch-summary + what-runs, launch-context-field, launch-context-form, save-engine-dialog - utilities/launch-plan.ts resolves implied producers and following support stages; the last engine and last custom selection persist - quick-scan-fields offers presets and engines in one select; the command palette offers "Scan <value>"; scan list action is "Run again" - effect-panel drops its explanatory header; NO_CONTEXT_LABEL is "No scan context"; launch-modal and execution-preview are removed Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014erb6Jbm6v9sxPgYFBxB7E
193 lines
5.7 KiB
Python
193 lines
5.7 KiB
Python
import uuid
|
|
from datetime import datetime
|
|
|
|
from pydantic import BaseModel, ConfigDict, model_validator
|
|
from sqlalchemy import Column
|
|
from sqlalchemy.types import JSON
|
|
from sqlmodel import Field, SQLModel
|
|
|
|
from shared.definitions.constants import MAX_SCAN_BATCH
|
|
from shared.enums.scan import ScanStatus
|
|
from shared.services.scan_resolve import ResolvedScanConfig
|
|
from shared.utils.datetime import utc_now
|
|
|
|
SCAN_STATUSES = tuple(s.value for s in ScanStatus)
|
|
|
|
|
|
class Scan(SQLModel, table=True):
|
|
__tablename__ = "scans"
|
|
|
|
id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True, index=True)
|
|
project_id: uuid.UUID = Field(foreign_key="projects.id", index=True)
|
|
target_id: uuid.UUID = Field(
|
|
foreign_key="targets.id", index=True, ondelete="CASCADE"
|
|
)
|
|
engine_id: uuid.UUID | None = Field(default=None, index=True)
|
|
engine_name: str = Field(max_length=200)
|
|
context_id: uuid.UUID | None = Field(default=None)
|
|
context_name: str | None = Field(default=None, max_length=200)
|
|
schedule_id: uuid.UUID | None = Field(default=None, index=True)
|
|
schedule_type: str | None = Field(default=None, max_length=20)
|
|
execution_config: dict = Field(sa_column=Column(JSON, nullable=False))
|
|
status: str = Field(default=ScanStatus.PENDING.value, index=True)
|
|
celery_task_ids: list = Field(
|
|
default_factory=list, sa_column=Column(JSON, nullable=False)
|
|
)
|
|
subdomains_found: int = Field(default=0)
|
|
ips_found: int = Field(default=0)
|
|
open_ports_found: int = Field(default=0)
|
|
http_assets_found: int = Field(default=0)
|
|
vulnerabilities_found: int = Field(default=0)
|
|
endpoints_found: int = Field(default=0)
|
|
error: str | None = Field(default=None, max_length=2000)
|
|
created_by: uuid.UUID = Field(foreign_key="users.id")
|
|
created_at: datetime = Field(default_factory=utc_now)
|
|
started_at: datetime | None = Field(default=None)
|
|
completed_at: datetime | None = Field(default=None)
|
|
|
|
|
|
class ScanCreate(BaseModel):
|
|
"""A launch names a saved engine, or runs an ad hoc plan carried in `overrides`."""
|
|
|
|
model_config = ConfigDict(extra="forbid")
|
|
|
|
engine_id: uuid.UUID | None = None
|
|
context_id: uuid.UUID | None = None
|
|
target_id: uuid.UUID | None = None
|
|
target_value: str | None = Field(default=None, max_length=500)
|
|
overrides: dict[str, dict] = Field(default_factory=dict)
|
|
intensity: str | None = None
|
|
|
|
@model_validator(mode="after")
|
|
def _require_target(self):
|
|
if (self.target_id is None) == (not self.target_value):
|
|
msg = "Provide either target_id or target_value."
|
|
raise ValueError(msg)
|
|
return self
|
|
|
|
|
|
class ScanBatchCreate(BaseModel):
|
|
model_config = ConfigDict(extra="forbid")
|
|
|
|
engine_id: uuid.UUID | None = None
|
|
context_id: uuid.UUID | None = None
|
|
target_ids: list[uuid.UUID] = Field(default_factory=list, max_length=MAX_SCAN_BATCH)
|
|
target_values: list[str] = Field(default_factory=list, max_length=MAX_SCAN_BATCH)
|
|
overrides: dict[str, dict] = Field(default_factory=dict)
|
|
intensity: str | None = None
|
|
|
|
@model_validator(mode="after")
|
|
def _require_targets(self):
|
|
total = len(self.target_ids) + len(self.target_values)
|
|
if total == 0:
|
|
msg = "Select at least one target."
|
|
raise ValueError(msg)
|
|
if total > MAX_SCAN_BATCH:
|
|
msg = f"Select at most {MAX_SCAN_BATCH} targets."
|
|
raise ValueError(msg)
|
|
return self
|
|
|
|
|
|
class ScanRead(BaseModel):
|
|
id: uuid.UUID
|
|
project_id: uuid.UUID
|
|
target_id: uuid.UUID
|
|
engine_id: uuid.UUID | None
|
|
engine_name: str
|
|
context_id: uuid.UUID | None
|
|
context_name: str | None
|
|
schedule_id: uuid.UUID | None = None
|
|
schedule_type: str | None = None
|
|
execution_config: ResolvedScanConfig
|
|
auth_summary: str
|
|
status: str
|
|
subdomains_found: int
|
|
ips_found: int
|
|
open_ports_found: int
|
|
http_assets_found: int
|
|
vulnerabilities_found: int
|
|
endpoints_found: int
|
|
error: str | None
|
|
created_by: uuid.UUID
|
|
created_at: datetime
|
|
started_at: datetime | None
|
|
completed_at: datetime | None
|
|
duration_seconds: float | None = None
|
|
new_subdomains: int | None = None
|
|
gone_subdomains: int | None = None
|
|
prev_subdomains_found: int | None = None
|
|
is_first_scan: bool | None = None
|
|
|
|
|
|
class ScanStatusCounts(BaseModel):
|
|
pending: int = 0
|
|
running: int = 0
|
|
completed: int = 0
|
|
failed: int = 0
|
|
cancelled: int = 0
|
|
|
|
|
|
class ScanDailyCount(BaseModel):
|
|
date: str
|
|
count: int
|
|
completed: int = 0
|
|
failed: int = 0
|
|
cancelled: int = 0
|
|
running: int = 0
|
|
pending: int = 0
|
|
new_subdomains: int = 0
|
|
|
|
|
|
class ScanFacet(BaseModel):
|
|
name: str
|
|
count: int
|
|
|
|
|
|
class ScanChanges(BaseModel):
|
|
window: str
|
|
new_subdomains: int
|
|
retired_subdomains: int = 0
|
|
targets_changed: int
|
|
scans_run: int
|
|
failed_runs: int
|
|
|
|
|
|
class ScanTargetGroup(BaseModel):
|
|
target_id: uuid.UUID
|
|
target_value: str
|
|
target_type: str
|
|
scan_count: int
|
|
last_scan_at: datetime
|
|
last_status: str
|
|
running: int
|
|
trend: list[int] = []
|
|
|
|
|
|
class ScanExportRow(BaseModel):
|
|
target: str
|
|
status: str
|
|
engine: str
|
|
context: str | None
|
|
schedule_type: str | None = None
|
|
subdomains: int
|
|
ips: int
|
|
open_ports: int
|
|
vulnerabilities: int
|
|
endpoints: int
|
|
duration_seconds: float | None
|
|
started_at: datetime | None
|
|
completed_at: datetime | None
|
|
created_at: datetime
|
|
|
|
|
|
class ScanStats(BaseModel):
|
|
total: int
|
|
running: int
|
|
by_status: ScanStatusCounts
|
|
last_scan_at: datetime | None
|
|
avg_duration_seconds: float | None
|
|
success_rate: float | None
|
|
daily: list[ScanDailyCount]
|
|
engines: list[ScanFacet] = []
|
|
contexts: list[ScanFacet] = []
|