mirror of
https://github.com/yogeshojha/rengine.git
synced 2026-10-21 07:41:28 +02:00
Choosing what a report contains required editing a template. That is the wrong place for a decision made per report, and the scan launch flow already established the alternative: a saved configuration seeds the run, the run may depart from it, and the saved configuration is never touched. Three declarations put sections on the same footing as stages. SectionRole separates the content a reader asked for from the furniture around it, so a picker can offer twenty-one choices and include the cover, the contents and the reference matter without being asked. Section.order fixes the reading order, which until now was however the directories happened to sort — the executive summary came after attack paths because "a" precedes "e". Section.launch_fields names the settings worth surfacing when the report is generated rather than only in the builder, mirroring Stage.launch_fields; the findings section declares its severities, its detail depth, its roll-up and its asset cap. The estimate had to become honest for any of this to be worth showing. It counted every finding in the scan whatever the section filtered to, so dropping three severities moved nothing. It now counts through the same severity filter the section applies and prices each tier separately, from the real per-severity issue counts rather than an assumed split: 28 pages against 26 rendered for a full template, 10 against 9 for critical and high alone. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AW5pitnosX8LEFEYxH8gFS
68 lines
2.6 KiB
Python
68 lines
2.6 KiB
Python
from __future__ import annotations
|
|
|
|
from reports.base import RenderContext, Section
|
|
from reports.config import SectionConfig, flag, limit
|
|
from shared.definitions.ports import SERVICE_CLASS_LABELS
|
|
from shared.definitions.reports import SectionGroup
|
|
from shared.definitions.surface import SurfaceDimension
|
|
|
|
|
|
class ServicesConfig(SectionConfig):
|
|
max_rows: int = limit(60, title="Rows shown", minimum=5, maximum=2000)
|
|
sensitive_first: bool = flag(True, title="List sensitive services first")
|
|
hide_web: bool = flag(
|
|
False,
|
|
title="Hide services that speak HTTP",
|
|
description="Web services already appear under web assets.",
|
|
)
|
|
show_composition: bool = flag(True, title="Show the class composition")
|
|
show_banner: bool = flag(True, title="Show the software banner")
|
|
show_coverage: bool = flag(
|
|
True, title="Show what the port scan was allowed to touch"
|
|
)
|
|
|
|
|
|
class ServicesSection(Section):
|
|
name = "services"
|
|
title = "Network services"
|
|
description = "What is listening, on which address, and which of it is web."
|
|
group = SectionGroup.SURFACE.value
|
|
order = 20
|
|
launch_fields = frozenset({"max_rows"})
|
|
requires = frozenset({SurfaceDimension.SERVICES.value})
|
|
config_model = ServicesConfig
|
|
|
|
def build(self, ctx: RenderContext, cfg: ServicesConfig) -> dict | None:
|
|
rows = ctx.data.service_rows
|
|
if cfg.hide_web:
|
|
rows = [s for s in rows if not s.is_http]
|
|
if not rows:
|
|
return None
|
|
if cfg.sensitive_first:
|
|
rows = sorted(rows, key=lambda s: (not s.sensitive, s.ip, s.port))
|
|
total = len(rows)
|
|
policies: dict[str, int] = {}
|
|
for address in ctx.data.address_rows:
|
|
if address.scan_policy:
|
|
policies[address.scan_policy] = policies.get(address.scan_policy, 0) + 1
|
|
return {
|
|
"rows": rows[: cfg.max_rows],
|
|
"total": total,
|
|
"hidden": max(0, total - cfg.max_rows),
|
|
"classes": [
|
|
{
|
|
"name": f.name,
|
|
"label": SERVICE_CLASS_LABELS.get(f.name, f.name.title()),
|
|
"count": f.count,
|
|
}
|
|
for f in ctx.data.service_classes
|
|
]
|
|
if cfg.show_composition
|
|
else [],
|
|
"sensitive": len(ctx.data.sensitive_services),
|
|
"web": sum(1 for s in ctx.data.service_rows if s.is_http),
|
|
"addresses": len({s.ip for s in ctx.data.service_rows}),
|
|
"show_banner": cfg.show_banner,
|
|
"policies": policies if cfg.show_coverage else {},
|
|
}
|