aiptx 2.0.7__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.
- aipt_v2/__init__.py +110 -0
- aipt_v2/__main__.py +24 -0
- aipt_v2/agents/AIPTxAgent/__init__.py +10 -0
- aipt_v2/agents/AIPTxAgent/aiptx_agent.py +211 -0
- aipt_v2/agents/__init__.py +46 -0
- aipt_v2/agents/base.py +520 -0
- aipt_v2/agents/exploit_agent.py +688 -0
- aipt_v2/agents/ptt.py +406 -0
- aipt_v2/agents/state.py +168 -0
- aipt_v2/app.py +957 -0
- aipt_v2/browser/__init__.py +31 -0
- aipt_v2/browser/automation.py +458 -0
- aipt_v2/browser/crawler.py +453 -0
- aipt_v2/cli.py +2933 -0
- aipt_v2/compliance/__init__.py +71 -0
- aipt_v2/compliance/compliance_report.py +449 -0
- aipt_v2/compliance/framework_mapper.py +424 -0
- aipt_v2/compliance/nist_mapping.py +345 -0
- aipt_v2/compliance/owasp_mapping.py +330 -0
- aipt_v2/compliance/pci_mapping.py +297 -0
- aipt_v2/config.py +341 -0
- aipt_v2/core/__init__.py +43 -0
- aipt_v2/core/agent.py +630 -0
- aipt_v2/core/llm.py +395 -0
- aipt_v2/core/memory.py +305 -0
- aipt_v2/core/ptt.py +329 -0
- aipt_v2/database/__init__.py +14 -0
- aipt_v2/database/models.py +232 -0
- aipt_v2/database/repository.py +384 -0
- aipt_v2/docker/__init__.py +23 -0
- aipt_v2/docker/builder.py +260 -0
- aipt_v2/docker/manager.py +222 -0
- aipt_v2/docker/sandbox.py +371 -0
- aipt_v2/evasion/__init__.py +58 -0
- aipt_v2/evasion/request_obfuscator.py +272 -0
- aipt_v2/evasion/tls_fingerprint.py +285 -0
- aipt_v2/evasion/ua_rotator.py +301 -0
- aipt_v2/evasion/waf_bypass.py +439 -0
- aipt_v2/execution/__init__.py +23 -0
- aipt_v2/execution/executor.py +302 -0
- aipt_v2/execution/parser.py +544 -0
- aipt_v2/execution/terminal.py +337 -0
- aipt_v2/health.py +437 -0
- aipt_v2/intelligence/__init__.py +194 -0
- aipt_v2/intelligence/adaptation.py +474 -0
- aipt_v2/intelligence/auth.py +520 -0
- aipt_v2/intelligence/chaining.py +775 -0
- aipt_v2/intelligence/correlation.py +536 -0
- aipt_v2/intelligence/cve_aipt.py +334 -0
- aipt_v2/intelligence/cve_info.py +1111 -0
- aipt_v2/intelligence/knowledge_graph.py +590 -0
- aipt_v2/intelligence/learning.py +626 -0
- aipt_v2/intelligence/llm_analyzer.py +502 -0
- aipt_v2/intelligence/llm_tool_selector.py +518 -0
- aipt_v2/intelligence/payload_generator.py +562 -0
- aipt_v2/intelligence/rag.py +239 -0
- aipt_v2/intelligence/scope.py +442 -0
- aipt_v2/intelligence/searchers/__init__.py +5 -0
- aipt_v2/intelligence/searchers/exploitdb_searcher.py +523 -0
- aipt_v2/intelligence/searchers/github_searcher.py +467 -0
- aipt_v2/intelligence/searchers/google_searcher.py +281 -0
- aipt_v2/intelligence/tools.json +443 -0
- aipt_v2/intelligence/triage.py +670 -0
- aipt_v2/interactive_shell.py +559 -0
- aipt_v2/interface/__init__.py +5 -0
- aipt_v2/interface/cli.py +230 -0
- aipt_v2/interface/main.py +501 -0
- aipt_v2/interface/tui.py +1276 -0
- aipt_v2/interface/utils.py +583 -0
- aipt_v2/llm/__init__.py +39 -0
- aipt_v2/llm/config.py +26 -0
- aipt_v2/llm/llm.py +514 -0
- aipt_v2/llm/memory.py +214 -0
- aipt_v2/llm/request_queue.py +89 -0
- aipt_v2/llm/utils.py +89 -0
- aipt_v2/local_tool_installer.py +1467 -0
- aipt_v2/models/__init__.py +15 -0
- aipt_v2/models/findings.py +295 -0
- aipt_v2/models/phase_result.py +224 -0
- aipt_v2/models/scan_config.py +207 -0
- aipt_v2/monitoring/grafana/dashboards/aipt-dashboard.json +355 -0
- aipt_v2/monitoring/grafana/dashboards/default.yml +17 -0
- aipt_v2/monitoring/grafana/datasources/prometheus.yml +17 -0
- aipt_v2/monitoring/prometheus.yml +60 -0
- aipt_v2/orchestration/__init__.py +52 -0
- aipt_v2/orchestration/pipeline.py +398 -0
- aipt_v2/orchestration/progress.py +300 -0
- aipt_v2/orchestration/scheduler.py +296 -0
- aipt_v2/orchestrator.py +2427 -0
- aipt_v2/payloads/__init__.py +27 -0
- aipt_v2/payloads/cmdi.py +150 -0
- aipt_v2/payloads/sqli.py +263 -0
- aipt_v2/payloads/ssrf.py +204 -0
- aipt_v2/payloads/templates.py +222 -0
- aipt_v2/payloads/traversal.py +166 -0
- aipt_v2/payloads/xss.py +204 -0
- aipt_v2/prompts/__init__.py +60 -0
- aipt_v2/proxy/__init__.py +29 -0
- aipt_v2/proxy/history.py +352 -0
- aipt_v2/proxy/interceptor.py +452 -0
- aipt_v2/recon/__init__.py +44 -0
- aipt_v2/recon/dns.py +241 -0
- aipt_v2/recon/osint.py +367 -0
- aipt_v2/recon/subdomain.py +372 -0
- aipt_v2/recon/tech_detect.py +311 -0
- aipt_v2/reports/__init__.py +17 -0
- aipt_v2/reports/generator.py +313 -0
- aipt_v2/reports/html_report.py +378 -0
- aipt_v2/runtime/__init__.py +53 -0
- aipt_v2/runtime/base.py +30 -0
- aipt_v2/runtime/docker.py +401 -0
- aipt_v2/runtime/local.py +346 -0
- aipt_v2/runtime/tool_server.py +205 -0
- aipt_v2/runtime/vps.py +830 -0
- aipt_v2/scanners/__init__.py +28 -0
- aipt_v2/scanners/base.py +273 -0
- aipt_v2/scanners/nikto.py +244 -0
- aipt_v2/scanners/nmap.py +402 -0
- aipt_v2/scanners/nuclei.py +273 -0
- aipt_v2/scanners/web.py +454 -0
- aipt_v2/scripts/security_audit.py +366 -0
- aipt_v2/setup_wizard.py +941 -0
- aipt_v2/skills/__init__.py +80 -0
- aipt_v2/skills/agents/__init__.py +14 -0
- aipt_v2/skills/agents/api_tester.py +706 -0
- aipt_v2/skills/agents/base.py +477 -0
- aipt_v2/skills/agents/code_review.py +459 -0
- aipt_v2/skills/agents/security_agent.py +336 -0
- aipt_v2/skills/agents/web_pentest.py +818 -0
- aipt_v2/skills/prompts/__init__.py +647 -0
- aipt_v2/system_detector.py +539 -0
- aipt_v2/telemetry/__init__.py +7 -0
- aipt_v2/telemetry/tracer.py +347 -0
- aipt_v2/terminal/__init__.py +28 -0
- aipt_v2/terminal/executor.py +400 -0
- aipt_v2/terminal/sandbox.py +350 -0
- aipt_v2/tools/__init__.py +44 -0
- aipt_v2/tools/active_directory/__init__.py +78 -0
- aipt_v2/tools/active_directory/ad_config.py +238 -0
- aipt_v2/tools/active_directory/bloodhound_wrapper.py +447 -0
- aipt_v2/tools/active_directory/kerberos_attacks.py +430 -0
- aipt_v2/tools/active_directory/ldap_enum.py +533 -0
- aipt_v2/tools/active_directory/smb_attacks.py +505 -0
- aipt_v2/tools/agents_graph/__init__.py +19 -0
- aipt_v2/tools/agents_graph/agents_graph_actions.py +69 -0
- aipt_v2/tools/api_security/__init__.py +76 -0
- aipt_v2/tools/api_security/api_discovery.py +608 -0
- aipt_v2/tools/api_security/graphql_scanner.py +622 -0
- aipt_v2/tools/api_security/jwt_analyzer.py +577 -0
- aipt_v2/tools/api_security/openapi_fuzzer.py +761 -0
- aipt_v2/tools/browser/__init__.py +5 -0
- aipt_v2/tools/browser/browser_actions.py +238 -0
- aipt_v2/tools/browser/browser_instance.py +535 -0
- aipt_v2/tools/browser/tab_manager.py +344 -0
- aipt_v2/tools/cloud/__init__.py +70 -0
- aipt_v2/tools/cloud/cloud_config.py +273 -0
- aipt_v2/tools/cloud/cloud_scanner.py +639 -0
- aipt_v2/tools/cloud/prowler_tool.py +571 -0
- aipt_v2/tools/cloud/scoutsuite_tool.py +359 -0
- aipt_v2/tools/executor.py +307 -0
- aipt_v2/tools/parser.py +408 -0
- aipt_v2/tools/proxy/__init__.py +5 -0
- aipt_v2/tools/proxy/proxy_actions.py +103 -0
- aipt_v2/tools/proxy/proxy_manager.py +789 -0
- aipt_v2/tools/registry.py +196 -0
- aipt_v2/tools/scanners/__init__.py +343 -0
- aipt_v2/tools/scanners/acunetix_tool.py +712 -0
- aipt_v2/tools/scanners/burp_tool.py +631 -0
- aipt_v2/tools/scanners/config.py +156 -0
- aipt_v2/tools/scanners/nessus_tool.py +588 -0
- aipt_v2/tools/scanners/zap_tool.py +612 -0
- aipt_v2/tools/terminal/__init__.py +5 -0
- aipt_v2/tools/terminal/terminal_actions.py +37 -0
- aipt_v2/tools/terminal/terminal_manager.py +153 -0
- aipt_v2/tools/terminal/terminal_session.py +449 -0
- aipt_v2/tools/tool_processing.py +108 -0
- aipt_v2/utils/__init__.py +17 -0
- aipt_v2/utils/logging.py +202 -0
- aipt_v2/utils/model_manager.py +187 -0
- aipt_v2/utils/searchers/__init__.py +269 -0
- aipt_v2/verify_install.py +793 -0
- aiptx-2.0.7.dist-info/METADATA +345 -0
- aiptx-2.0.7.dist-info/RECORD +187 -0
- aiptx-2.0.7.dist-info/WHEEL +5 -0
- aiptx-2.0.7.dist-info/entry_points.txt +7 -0
- aiptx-2.0.7.dist-info/licenses/LICENSE +21 -0
- aiptx-2.0.7.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""
|
|
2
|
+
AIPT Compliance Framework Module
|
|
3
|
+
|
|
4
|
+
Maps security findings to compliance frameworks:
|
|
5
|
+
- OWASP Top 10 2021 (A01-A10)
|
|
6
|
+
- SANS Top 25 CWEs
|
|
7
|
+
- PCI-DSS 4.0 Requirements
|
|
8
|
+
- NIST 800-53 Controls
|
|
9
|
+
- CIS Controls v8
|
|
10
|
+
|
|
11
|
+
Usage:
|
|
12
|
+
from aipt_v2.compliance import ComplianceMapper, generate_compliance_report
|
|
13
|
+
|
|
14
|
+
mapper = ComplianceMapper()
|
|
15
|
+
report = mapper.map_findings(findings, frameworks=["owasp", "pci"])
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from aipt_v2.compliance.framework_mapper import (
|
|
19
|
+
ComplianceMapper,
|
|
20
|
+
ComplianceMapping,
|
|
21
|
+
FrameworkCategory,
|
|
22
|
+
map_to_frameworks,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
from aipt_v2.compliance.owasp_mapping import (
|
|
26
|
+
OWASPMapper,
|
|
27
|
+
OWASP_TOP_10,
|
|
28
|
+
get_owasp_category,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
from aipt_v2.compliance.pci_mapping import (
|
|
32
|
+
PCIMapper,
|
|
33
|
+
PCI_DSS_REQUIREMENTS,
|
|
34
|
+
get_pci_requirement,
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
from aipt_v2.compliance.nist_mapping import (
|
|
38
|
+
NISTMapper,
|
|
39
|
+
NIST_CONTROLS,
|
|
40
|
+
get_nist_control,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
from aipt_v2.compliance.compliance_report import (
|
|
44
|
+
ComplianceReport,
|
|
45
|
+
generate_compliance_report,
|
|
46
|
+
ComplianceReportGenerator,
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
__all__ = [
|
|
50
|
+
# Mapper
|
|
51
|
+
"ComplianceMapper",
|
|
52
|
+
"ComplianceMapping",
|
|
53
|
+
"FrameworkCategory",
|
|
54
|
+
"map_to_frameworks",
|
|
55
|
+
# OWASP
|
|
56
|
+
"OWASPMapper",
|
|
57
|
+
"OWASP_TOP_10",
|
|
58
|
+
"get_owasp_category",
|
|
59
|
+
# PCI
|
|
60
|
+
"PCIMapper",
|
|
61
|
+
"PCI_DSS_REQUIREMENTS",
|
|
62
|
+
"get_pci_requirement",
|
|
63
|
+
# NIST
|
|
64
|
+
"NISTMapper",
|
|
65
|
+
"NIST_CONTROLS",
|
|
66
|
+
"get_nist_control",
|
|
67
|
+
# Reports
|
|
68
|
+
"ComplianceReport",
|
|
69
|
+
"generate_compliance_report",
|
|
70
|
+
"ComplianceReportGenerator",
|
|
71
|
+
]
|
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Compliance Report Generator
|
|
3
|
+
|
|
4
|
+
Generates compliance-specific reports from security findings.
|
|
5
|
+
Supports multiple formats and frameworks.
|
|
6
|
+
|
|
7
|
+
Usage:
|
|
8
|
+
from aipt_v2.compliance import generate_compliance_report
|
|
9
|
+
|
|
10
|
+
report = generate_compliance_report(
|
|
11
|
+
findings,
|
|
12
|
+
frameworks=["owasp", "pci"],
|
|
13
|
+
format="html"
|
|
14
|
+
)
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
import json
|
|
18
|
+
from dataclasses import dataclass, field
|
|
19
|
+
from datetime import datetime, timezone
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
from typing import List, Dict, Any, Optional
|
|
22
|
+
|
|
23
|
+
from aipt_v2.compliance.framework_mapper import ComplianceMapper, ComplianceMapping
|
|
24
|
+
from aipt_v2.compliance.owasp_mapping import OWASPMapper, OWASP_TOP_10
|
|
25
|
+
from aipt_v2.compliance.pci_mapping import PCIMapper, PCI_DSS_REQUIREMENTS
|
|
26
|
+
from aipt_v2.compliance.nist_mapping import NISTMapper, NIST_CONTROLS
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@dataclass
|
|
30
|
+
class ComplianceScore:
|
|
31
|
+
"""Compliance score for a framework."""
|
|
32
|
+
framework: str
|
|
33
|
+
total_controls: int
|
|
34
|
+
compliant_controls: int
|
|
35
|
+
non_compliant_controls: int
|
|
36
|
+
score_percentage: float
|
|
37
|
+
risk_level: str # Low, Medium, High, Critical
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@dataclass
|
|
41
|
+
class ComplianceReport:
|
|
42
|
+
"""Complete compliance report."""
|
|
43
|
+
generated_at: str
|
|
44
|
+
target: str
|
|
45
|
+
frameworks: List[str]
|
|
46
|
+
total_findings: int
|
|
47
|
+
mapped_findings: int
|
|
48
|
+
scores: Dict[str, ComplianceScore]
|
|
49
|
+
findings_by_framework: Dict[str, List[ComplianceMapping]]
|
|
50
|
+
executive_summary: str
|
|
51
|
+
remediation_priorities: List[Dict]
|
|
52
|
+
metadata: Dict[str, Any] = field(default_factory=dict)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class ComplianceReportGenerator:
|
|
56
|
+
"""
|
|
57
|
+
Generates comprehensive compliance reports.
|
|
58
|
+
|
|
59
|
+
Maps findings to frameworks and produces
|
|
60
|
+
detailed reports with scores and priorities.
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
def __init__(self):
|
|
64
|
+
self.mapper = ComplianceMapper()
|
|
65
|
+
self.owasp_mapper = OWASPMapper()
|
|
66
|
+
self.pci_mapper = PCIMapper()
|
|
67
|
+
self.nist_mapper = NISTMapper()
|
|
68
|
+
|
|
69
|
+
def generate(
|
|
70
|
+
self,
|
|
71
|
+
findings: List[Dict],
|
|
72
|
+
frameworks: List[str] = None,
|
|
73
|
+
target: str = ""
|
|
74
|
+
) -> ComplianceReport:
|
|
75
|
+
"""
|
|
76
|
+
Generate compliance report from findings.
|
|
77
|
+
|
|
78
|
+
Args:
|
|
79
|
+
findings: List of security findings
|
|
80
|
+
frameworks: Frameworks to include
|
|
81
|
+
target: Target name/URL
|
|
82
|
+
|
|
83
|
+
Returns:
|
|
84
|
+
ComplianceReport
|
|
85
|
+
"""
|
|
86
|
+
frameworks = frameworks or ["owasp", "pci", "nist"]
|
|
87
|
+
|
|
88
|
+
# Map findings
|
|
89
|
+
mappings = self.mapper.map_findings(findings, frameworks)
|
|
90
|
+
|
|
91
|
+
# Group by framework
|
|
92
|
+
findings_by_framework = self._group_by_framework(mappings, frameworks)
|
|
93
|
+
|
|
94
|
+
# Calculate scores
|
|
95
|
+
scores = {}
|
|
96
|
+
for fw in frameworks:
|
|
97
|
+
scores[fw] = self._calculate_score(fw, findings_by_framework.get(fw, []))
|
|
98
|
+
|
|
99
|
+
# Generate executive summary
|
|
100
|
+
executive_summary = self._generate_executive_summary(
|
|
101
|
+
target, scores, len(findings), len(mappings)
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
# Prioritize remediation
|
|
105
|
+
priorities = self._prioritize_remediation(mappings)
|
|
106
|
+
|
|
107
|
+
return ComplianceReport(
|
|
108
|
+
generated_at=datetime.now(timezone.utc).isoformat(),
|
|
109
|
+
target=target,
|
|
110
|
+
frameworks=frameworks,
|
|
111
|
+
total_findings=len(findings),
|
|
112
|
+
mapped_findings=len(mappings),
|
|
113
|
+
scores=scores,
|
|
114
|
+
findings_by_framework=findings_by_framework,
|
|
115
|
+
executive_summary=executive_summary,
|
|
116
|
+
remediation_priorities=priorities,
|
|
117
|
+
metadata={
|
|
118
|
+
"generator": "AIPTX Compliance Report Generator",
|
|
119
|
+
"version": "1.0"
|
|
120
|
+
}
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
def _group_by_framework(
|
|
124
|
+
self,
|
|
125
|
+
mappings: List[ComplianceMapping],
|
|
126
|
+
frameworks: List[str]
|
|
127
|
+
) -> Dict[str, List[ComplianceMapping]]:
|
|
128
|
+
"""Group mappings by framework."""
|
|
129
|
+
grouped = {fw: [] for fw in frameworks}
|
|
130
|
+
|
|
131
|
+
for mapping in mappings:
|
|
132
|
+
for fw in frameworks:
|
|
133
|
+
if fw in mapping.frameworks or fw.replace("_", "") in str(mapping.frameworks):
|
|
134
|
+
grouped[fw].append(mapping)
|
|
135
|
+
|
|
136
|
+
return grouped
|
|
137
|
+
|
|
138
|
+
def _calculate_score(
|
|
139
|
+
self,
|
|
140
|
+
framework: str,
|
|
141
|
+
mappings: List[ComplianceMapping]
|
|
142
|
+
) -> ComplianceScore:
|
|
143
|
+
"""Calculate compliance score for a framework."""
|
|
144
|
+
if framework == "owasp":
|
|
145
|
+
total_controls = 10 # A01-A10
|
|
146
|
+
controls_with_findings = len(set(
|
|
147
|
+
m.frameworks.get("owasp", type("", (), {"category_id": ""})()).category_id
|
|
148
|
+
for m in mappings if "owasp" in m.frameworks
|
|
149
|
+
))
|
|
150
|
+
elif framework == "pci":
|
|
151
|
+
total_controls = len(PCI_DSS_REQUIREMENTS)
|
|
152
|
+
controls_with_findings = len(set(
|
|
153
|
+
m.frameworks.get("pci_dss", type("", (), {"category_id": ""})()).category_id
|
|
154
|
+
for m in mappings if "pci_dss" in m.frameworks
|
|
155
|
+
))
|
|
156
|
+
elif framework == "nist":
|
|
157
|
+
total_controls = len(NIST_CONTROLS)
|
|
158
|
+
controls_with_findings = len(set(
|
|
159
|
+
m.frameworks.get("nist", type("", (), {"category_id": ""})()).category_id
|
|
160
|
+
for m in mappings if "nist" in m.frameworks
|
|
161
|
+
))
|
|
162
|
+
else:
|
|
163
|
+
total_controls = 100
|
|
164
|
+
controls_with_findings = len(mappings)
|
|
165
|
+
|
|
166
|
+
compliant = total_controls - controls_with_findings
|
|
167
|
+
score_pct = (compliant / total_controls * 100) if total_controls > 0 else 100
|
|
168
|
+
|
|
169
|
+
# Determine risk level
|
|
170
|
+
if score_pct >= 90:
|
|
171
|
+
risk_level = "Low"
|
|
172
|
+
elif score_pct >= 70:
|
|
173
|
+
risk_level = "Medium"
|
|
174
|
+
elif score_pct >= 50:
|
|
175
|
+
risk_level = "High"
|
|
176
|
+
else:
|
|
177
|
+
risk_level = "Critical"
|
|
178
|
+
|
|
179
|
+
return ComplianceScore(
|
|
180
|
+
framework=framework,
|
|
181
|
+
total_controls=total_controls,
|
|
182
|
+
compliant_controls=compliant,
|
|
183
|
+
non_compliant_controls=controls_with_findings,
|
|
184
|
+
score_percentage=round(score_pct, 1),
|
|
185
|
+
risk_level=risk_level
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
def _generate_executive_summary(
|
|
189
|
+
self,
|
|
190
|
+
target: str,
|
|
191
|
+
scores: Dict[str, ComplianceScore],
|
|
192
|
+
total_findings: int,
|
|
193
|
+
mapped_findings: int
|
|
194
|
+
) -> str:
|
|
195
|
+
"""Generate executive summary text."""
|
|
196
|
+
summary_parts = [
|
|
197
|
+
f"Compliance Assessment Report for {target or 'Target System'}",
|
|
198
|
+
"",
|
|
199
|
+
f"Assessment Date: {datetime.now().strftime('%Y-%m-%d')}",
|
|
200
|
+
f"Total Security Findings: {total_findings}",
|
|
201
|
+
f"Compliance-Mapped Findings: {mapped_findings}",
|
|
202
|
+
"",
|
|
203
|
+
"Framework Compliance Scores:",
|
|
204
|
+
]
|
|
205
|
+
|
|
206
|
+
for fw, score in scores.items():
|
|
207
|
+
summary_parts.append(
|
|
208
|
+
f" - {fw.upper()}: {score.score_percentage}% "
|
|
209
|
+
f"({score.compliant_controls}/{score.total_controls} controls compliant) "
|
|
210
|
+
f"- Risk Level: {score.risk_level}"
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
# Overall assessment
|
|
214
|
+
avg_score = sum(s.score_percentage for s in scores.values()) / len(scores) if scores else 0
|
|
215
|
+
|
|
216
|
+
summary_parts.extend([
|
|
217
|
+
"",
|
|
218
|
+
f"Overall Compliance Score: {avg_score:.1f}%",
|
|
219
|
+
"",
|
|
220
|
+
"Key Observations:"
|
|
221
|
+
])
|
|
222
|
+
|
|
223
|
+
# Add key observations based on scores
|
|
224
|
+
for fw, score in scores.items():
|
|
225
|
+
if score.non_compliant_controls > 0:
|
|
226
|
+
summary_parts.append(
|
|
227
|
+
f" - {score.non_compliant_controls} {fw.upper()} "
|
|
228
|
+
f"controls require attention"
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
return "\n".join(summary_parts)
|
|
232
|
+
|
|
233
|
+
def _prioritize_remediation(
|
|
234
|
+
self,
|
|
235
|
+
mappings: List[ComplianceMapping]
|
|
236
|
+
) -> List[Dict]:
|
|
237
|
+
"""Prioritize remediation based on risk and compliance impact."""
|
|
238
|
+
priorities = []
|
|
239
|
+
|
|
240
|
+
for mapping in mappings:
|
|
241
|
+
priority_score = mapping.risk_score
|
|
242
|
+
|
|
243
|
+
# Boost priority for PCI-DSS issues
|
|
244
|
+
if "pci_dss" in mapping.frameworks:
|
|
245
|
+
priority_score += 2
|
|
246
|
+
|
|
247
|
+
# Boost priority for critical severity
|
|
248
|
+
if mapping.severity == "critical":
|
|
249
|
+
priority_score += 3
|
|
250
|
+
elif mapping.severity == "high":
|
|
251
|
+
priority_score += 1
|
|
252
|
+
|
|
253
|
+
priorities.append({
|
|
254
|
+
"cwe_id": mapping.cwe_id,
|
|
255
|
+
"cwe_name": mapping.cwe_name,
|
|
256
|
+
"severity": mapping.severity,
|
|
257
|
+
"risk_score": mapping.risk_score,
|
|
258
|
+
"priority_score": priority_score,
|
|
259
|
+
"frameworks_affected": list(mapping.frameworks.keys()),
|
|
260
|
+
"remediation_priority": mapping.remediation_priority
|
|
261
|
+
})
|
|
262
|
+
|
|
263
|
+
# Sort by priority score descending
|
|
264
|
+
priorities.sort(key=lambda x: x["priority_score"], reverse=True)
|
|
265
|
+
|
|
266
|
+
return priorities
|
|
267
|
+
|
|
268
|
+
def to_html(self, report: ComplianceReport) -> str:
|
|
269
|
+
"""Convert report to HTML format."""
|
|
270
|
+
html = f"""<!DOCTYPE html>
|
|
271
|
+
<html>
|
|
272
|
+
<head>
|
|
273
|
+
<title>Compliance Report - {report.target}</title>
|
|
274
|
+
<style>
|
|
275
|
+
body {{ font-family: Arial, sans-serif; margin: 40px; }}
|
|
276
|
+
h1 {{ color: #333; border-bottom: 2px solid #666; }}
|
|
277
|
+
h2 {{ color: #555; margin-top: 30px; }}
|
|
278
|
+
.summary {{ background: #f5f5f5; padding: 20px; border-radius: 5px; }}
|
|
279
|
+
.score-card {{ display: inline-block; margin: 10px; padding: 15px;
|
|
280
|
+
background: #fff; border: 1px solid #ddd; border-radius: 5px; }}
|
|
281
|
+
.score-low {{ border-left: 4px solid #4CAF50; }}
|
|
282
|
+
.score-medium {{ border-left: 4px solid #FFC107; }}
|
|
283
|
+
.score-high {{ border-left: 4px solid #FF9800; }}
|
|
284
|
+
.score-critical {{ border-left: 4px solid #F44336; }}
|
|
285
|
+
table {{ width: 100%; border-collapse: collapse; margin-top: 20px; }}
|
|
286
|
+
th, td {{ border: 1px solid #ddd; padding: 10px; text-align: left; }}
|
|
287
|
+
th {{ background: #f0f0f0; }}
|
|
288
|
+
.severity-critical {{ background: #ffebee; }}
|
|
289
|
+
.severity-high {{ background: #fff3e0; }}
|
|
290
|
+
.severity-medium {{ background: #fff8e1; }}
|
|
291
|
+
.severity-low {{ background: #e8f5e9; }}
|
|
292
|
+
pre {{ background: #f5f5f5; padding: 15px; overflow-x: auto; }}
|
|
293
|
+
</style>
|
|
294
|
+
</head>
|
|
295
|
+
<body>
|
|
296
|
+
<h1>Compliance Assessment Report</h1>
|
|
297
|
+
<p><strong>Target:</strong> {report.target}</p>
|
|
298
|
+
<p><strong>Generated:</strong> {report.generated_at}</p>
|
|
299
|
+
|
|
300
|
+
<h2>Executive Summary</h2>
|
|
301
|
+
<div class="summary">
|
|
302
|
+
<pre>{report.executive_summary}</pre>
|
|
303
|
+
</div>
|
|
304
|
+
|
|
305
|
+
<h2>Compliance Scores</h2>
|
|
306
|
+
<div class="scores">
|
|
307
|
+
"""
|
|
308
|
+
|
|
309
|
+
for fw, score in report.scores.items():
|
|
310
|
+
risk_class = f"score-{score.risk_level.lower()}"
|
|
311
|
+
html += f"""
|
|
312
|
+
<div class="score-card {risk_class}">
|
|
313
|
+
<h3>{fw.upper()}</h3>
|
|
314
|
+
<p><strong>{score.score_percentage}%</strong> Compliant</p>
|
|
315
|
+
<p>{score.compliant_controls}/{score.total_controls} controls</p>
|
|
316
|
+
<p>Risk Level: <strong>{score.risk_level}</strong></p>
|
|
317
|
+
</div>
|
|
318
|
+
"""
|
|
319
|
+
|
|
320
|
+
html += """
|
|
321
|
+
</div>
|
|
322
|
+
|
|
323
|
+
<h2>Remediation Priorities</h2>
|
|
324
|
+
<table>
|
|
325
|
+
<tr>
|
|
326
|
+
<th>Priority</th>
|
|
327
|
+
<th>CWE</th>
|
|
328
|
+
<th>Severity</th>
|
|
329
|
+
<th>Frameworks</th>
|
|
330
|
+
<th>Risk Score</th>
|
|
331
|
+
</tr>
|
|
332
|
+
"""
|
|
333
|
+
|
|
334
|
+
for i, item in enumerate(report.remediation_priorities[:20], 1):
|
|
335
|
+
severity_class = f"severity-{item['severity']}"
|
|
336
|
+
html += f"""
|
|
337
|
+
<tr class="{severity_class}">
|
|
338
|
+
<td>{i}</td>
|
|
339
|
+
<td>{item['cwe_id']}: {item['cwe_name']}</td>
|
|
340
|
+
<td>{item['severity'].upper()}</td>
|
|
341
|
+
<td>{', '.join(item['frameworks_affected'])}</td>
|
|
342
|
+
<td>{item['risk_score']:.1f}</td>
|
|
343
|
+
</tr>
|
|
344
|
+
"""
|
|
345
|
+
|
|
346
|
+
html += """
|
|
347
|
+
</table>
|
|
348
|
+
|
|
349
|
+
<h2>Framework Details</h2>
|
|
350
|
+
"""
|
|
351
|
+
|
|
352
|
+
for fw, mappings in report.findings_by_framework.items():
|
|
353
|
+
html += f"""
|
|
354
|
+
<h3>{fw.upper()} Findings ({len(mappings)})</h3>
|
|
355
|
+
<table>
|
|
356
|
+
<tr>
|
|
357
|
+
<th>CWE</th>
|
|
358
|
+
<th>Category</th>
|
|
359
|
+
<th>Severity</th>
|
|
360
|
+
</tr>
|
|
361
|
+
"""
|
|
362
|
+
for m in mappings[:10]:
|
|
363
|
+
cat = m.frameworks.get(fw, m.frameworks.get(f"{fw}_dss", {}))
|
|
364
|
+
cat_id = getattr(cat, 'category_id', 'N/A') if cat else 'N/A'
|
|
365
|
+
html += f"""
|
|
366
|
+
<tr>
|
|
367
|
+
<td>{m.cwe_id}</td>
|
|
368
|
+
<td>{cat_id}</td>
|
|
369
|
+
<td>{m.severity}</td>
|
|
370
|
+
</tr>
|
|
371
|
+
"""
|
|
372
|
+
html += " </table>\n"
|
|
373
|
+
|
|
374
|
+
html += """
|
|
375
|
+
<footer style="margin-top: 40px; color: #666; font-size: 12px;">
|
|
376
|
+
<p>Generated by AIPTX Compliance Report Generator</p>
|
|
377
|
+
</footer>
|
|
378
|
+
</body>
|
|
379
|
+
</html>
|
|
380
|
+
"""
|
|
381
|
+
return html
|
|
382
|
+
|
|
383
|
+
def to_json(self, report: ComplianceReport) -> str:
|
|
384
|
+
"""Convert report to JSON format."""
|
|
385
|
+
def serialize(obj):
|
|
386
|
+
if hasattr(obj, "__dict__"):
|
|
387
|
+
return obj.__dict__
|
|
388
|
+
return str(obj)
|
|
389
|
+
|
|
390
|
+
return json.dumps({
|
|
391
|
+
"generated_at": report.generated_at,
|
|
392
|
+
"target": report.target,
|
|
393
|
+
"frameworks": report.frameworks,
|
|
394
|
+
"total_findings": report.total_findings,
|
|
395
|
+
"mapped_findings": report.mapped_findings,
|
|
396
|
+
"scores": {k: serialize(v) for k, v in report.scores.items()},
|
|
397
|
+
"executive_summary": report.executive_summary,
|
|
398
|
+
"remediation_priorities": report.remediation_priorities,
|
|
399
|
+
"metadata": report.metadata
|
|
400
|
+
}, indent=2)
|
|
401
|
+
|
|
402
|
+
def save(
|
|
403
|
+
self,
|
|
404
|
+
report: ComplianceReport,
|
|
405
|
+
output_path: str,
|
|
406
|
+
format: str = "html"
|
|
407
|
+
):
|
|
408
|
+
"""Save report to file."""
|
|
409
|
+
path = Path(output_path)
|
|
410
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
411
|
+
|
|
412
|
+
if format == "html":
|
|
413
|
+
content = self.to_html(report)
|
|
414
|
+
elif format == "json":
|
|
415
|
+
content = self.to_json(report)
|
|
416
|
+
else:
|
|
417
|
+
content = report.executive_summary
|
|
418
|
+
|
|
419
|
+
path.write_text(content)
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
# Convenience function
|
|
423
|
+
def generate_compliance_report(
|
|
424
|
+
findings: List[Dict],
|
|
425
|
+
frameworks: List[str] = None,
|
|
426
|
+
target: str = "",
|
|
427
|
+
output_format: str = "html",
|
|
428
|
+
output_path: str = None
|
|
429
|
+
) -> ComplianceReport:
|
|
430
|
+
"""
|
|
431
|
+
Generate compliance report from findings.
|
|
432
|
+
|
|
433
|
+
Args:
|
|
434
|
+
findings: List of security findings with CWE IDs
|
|
435
|
+
frameworks: Frameworks to include ("owasp", "pci", "nist")
|
|
436
|
+
target: Target name/URL
|
|
437
|
+
output_format: Output format ("html", "json", "text")
|
|
438
|
+
output_path: Optional path to save report
|
|
439
|
+
|
|
440
|
+
Returns:
|
|
441
|
+
ComplianceReport
|
|
442
|
+
"""
|
|
443
|
+
generator = ComplianceReportGenerator()
|
|
444
|
+
report = generator.generate(findings, frameworks, target)
|
|
445
|
+
|
|
446
|
+
if output_path:
|
|
447
|
+
generator.save(report, output_path, output_format)
|
|
448
|
+
|
|
449
|
+
return report
|