aiptx 2.0.2__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.

Potentially problematic release.


This version of aiptx might be problematic. Click here for more details.

Files changed (165) hide show
  1. aipt_v2/__init__.py +110 -0
  2. aipt_v2/__main__.py +24 -0
  3. aipt_v2/agents/AIPTxAgent/__init__.py +10 -0
  4. aipt_v2/agents/AIPTxAgent/aiptx_agent.py +211 -0
  5. aipt_v2/agents/__init__.py +24 -0
  6. aipt_v2/agents/base.py +520 -0
  7. aipt_v2/agents/ptt.py +406 -0
  8. aipt_v2/agents/state.py +168 -0
  9. aipt_v2/app.py +960 -0
  10. aipt_v2/browser/__init__.py +31 -0
  11. aipt_v2/browser/automation.py +458 -0
  12. aipt_v2/browser/crawler.py +453 -0
  13. aipt_v2/cli.py +321 -0
  14. aipt_v2/compliance/__init__.py +71 -0
  15. aipt_v2/compliance/compliance_report.py +449 -0
  16. aipt_v2/compliance/framework_mapper.py +424 -0
  17. aipt_v2/compliance/nist_mapping.py +345 -0
  18. aipt_v2/compliance/owasp_mapping.py +330 -0
  19. aipt_v2/compliance/pci_mapping.py +297 -0
  20. aipt_v2/config.py +288 -0
  21. aipt_v2/core/__init__.py +43 -0
  22. aipt_v2/core/agent.py +630 -0
  23. aipt_v2/core/llm.py +395 -0
  24. aipt_v2/core/memory.py +305 -0
  25. aipt_v2/core/ptt.py +329 -0
  26. aipt_v2/database/__init__.py +14 -0
  27. aipt_v2/database/models.py +232 -0
  28. aipt_v2/database/repository.py +384 -0
  29. aipt_v2/docker/__init__.py +23 -0
  30. aipt_v2/docker/builder.py +260 -0
  31. aipt_v2/docker/manager.py +222 -0
  32. aipt_v2/docker/sandbox.py +371 -0
  33. aipt_v2/evasion/__init__.py +58 -0
  34. aipt_v2/evasion/request_obfuscator.py +272 -0
  35. aipt_v2/evasion/tls_fingerprint.py +285 -0
  36. aipt_v2/evasion/ua_rotator.py +301 -0
  37. aipt_v2/evasion/waf_bypass.py +439 -0
  38. aipt_v2/execution/__init__.py +23 -0
  39. aipt_v2/execution/executor.py +302 -0
  40. aipt_v2/execution/parser.py +544 -0
  41. aipt_v2/execution/terminal.py +337 -0
  42. aipt_v2/health.py +437 -0
  43. aipt_v2/intelligence/__init__.py +85 -0
  44. aipt_v2/intelligence/auth.py +520 -0
  45. aipt_v2/intelligence/chaining.py +775 -0
  46. aipt_v2/intelligence/cve_aipt.py +334 -0
  47. aipt_v2/intelligence/cve_info.py +1111 -0
  48. aipt_v2/intelligence/rag.py +239 -0
  49. aipt_v2/intelligence/scope.py +442 -0
  50. aipt_v2/intelligence/searchers/__init__.py +5 -0
  51. aipt_v2/intelligence/searchers/exploitdb_searcher.py +523 -0
  52. aipt_v2/intelligence/searchers/github_searcher.py +467 -0
  53. aipt_v2/intelligence/searchers/google_searcher.py +281 -0
  54. aipt_v2/intelligence/tools.json +443 -0
  55. aipt_v2/intelligence/triage.py +670 -0
  56. aipt_v2/interface/__init__.py +5 -0
  57. aipt_v2/interface/cli.py +230 -0
  58. aipt_v2/interface/main.py +501 -0
  59. aipt_v2/interface/tui.py +1276 -0
  60. aipt_v2/interface/utils.py +583 -0
  61. aipt_v2/llm/__init__.py +39 -0
  62. aipt_v2/llm/config.py +26 -0
  63. aipt_v2/llm/llm.py +514 -0
  64. aipt_v2/llm/memory.py +214 -0
  65. aipt_v2/llm/request_queue.py +89 -0
  66. aipt_v2/llm/utils.py +89 -0
  67. aipt_v2/models/__init__.py +15 -0
  68. aipt_v2/models/findings.py +295 -0
  69. aipt_v2/models/phase_result.py +224 -0
  70. aipt_v2/models/scan_config.py +207 -0
  71. aipt_v2/monitoring/grafana/dashboards/aipt-dashboard.json +355 -0
  72. aipt_v2/monitoring/grafana/dashboards/default.yml +17 -0
  73. aipt_v2/monitoring/grafana/datasources/prometheus.yml +17 -0
  74. aipt_v2/monitoring/prometheus.yml +60 -0
  75. aipt_v2/orchestration/__init__.py +52 -0
  76. aipt_v2/orchestration/pipeline.py +398 -0
  77. aipt_v2/orchestration/progress.py +300 -0
  78. aipt_v2/orchestration/scheduler.py +296 -0
  79. aipt_v2/orchestrator.py +2284 -0
  80. aipt_v2/payloads/__init__.py +27 -0
  81. aipt_v2/payloads/cmdi.py +150 -0
  82. aipt_v2/payloads/sqli.py +263 -0
  83. aipt_v2/payloads/ssrf.py +204 -0
  84. aipt_v2/payloads/templates.py +222 -0
  85. aipt_v2/payloads/traversal.py +166 -0
  86. aipt_v2/payloads/xss.py +204 -0
  87. aipt_v2/prompts/__init__.py +60 -0
  88. aipt_v2/proxy/__init__.py +29 -0
  89. aipt_v2/proxy/history.py +352 -0
  90. aipt_v2/proxy/interceptor.py +452 -0
  91. aipt_v2/recon/__init__.py +44 -0
  92. aipt_v2/recon/dns.py +241 -0
  93. aipt_v2/recon/osint.py +367 -0
  94. aipt_v2/recon/subdomain.py +372 -0
  95. aipt_v2/recon/tech_detect.py +311 -0
  96. aipt_v2/reports/__init__.py +17 -0
  97. aipt_v2/reports/generator.py +313 -0
  98. aipt_v2/reports/html_report.py +378 -0
  99. aipt_v2/runtime/__init__.py +44 -0
  100. aipt_v2/runtime/base.py +30 -0
  101. aipt_v2/runtime/docker.py +401 -0
  102. aipt_v2/runtime/local.py +346 -0
  103. aipt_v2/runtime/tool_server.py +205 -0
  104. aipt_v2/scanners/__init__.py +28 -0
  105. aipt_v2/scanners/base.py +273 -0
  106. aipt_v2/scanners/nikto.py +244 -0
  107. aipt_v2/scanners/nmap.py +402 -0
  108. aipt_v2/scanners/nuclei.py +273 -0
  109. aipt_v2/scanners/web.py +454 -0
  110. aipt_v2/scripts/security_audit.py +366 -0
  111. aipt_v2/telemetry/__init__.py +7 -0
  112. aipt_v2/telemetry/tracer.py +347 -0
  113. aipt_v2/terminal/__init__.py +28 -0
  114. aipt_v2/terminal/executor.py +400 -0
  115. aipt_v2/terminal/sandbox.py +350 -0
  116. aipt_v2/tools/__init__.py +44 -0
  117. aipt_v2/tools/active_directory/__init__.py +78 -0
  118. aipt_v2/tools/active_directory/ad_config.py +238 -0
  119. aipt_v2/tools/active_directory/bloodhound_wrapper.py +447 -0
  120. aipt_v2/tools/active_directory/kerberos_attacks.py +430 -0
  121. aipt_v2/tools/active_directory/ldap_enum.py +533 -0
  122. aipt_v2/tools/active_directory/smb_attacks.py +505 -0
  123. aipt_v2/tools/agents_graph/__init__.py +19 -0
  124. aipt_v2/tools/agents_graph/agents_graph_actions.py +69 -0
  125. aipt_v2/tools/api_security/__init__.py +76 -0
  126. aipt_v2/tools/api_security/api_discovery.py +608 -0
  127. aipt_v2/tools/api_security/graphql_scanner.py +622 -0
  128. aipt_v2/tools/api_security/jwt_analyzer.py +577 -0
  129. aipt_v2/tools/api_security/openapi_fuzzer.py +761 -0
  130. aipt_v2/tools/browser/__init__.py +5 -0
  131. aipt_v2/tools/browser/browser_actions.py +238 -0
  132. aipt_v2/tools/browser/browser_instance.py +535 -0
  133. aipt_v2/tools/browser/tab_manager.py +344 -0
  134. aipt_v2/tools/cloud/__init__.py +70 -0
  135. aipt_v2/tools/cloud/cloud_config.py +273 -0
  136. aipt_v2/tools/cloud/cloud_scanner.py +639 -0
  137. aipt_v2/tools/cloud/prowler_tool.py +571 -0
  138. aipt_v2/tools/cloud/scoutsuite_tool.py +359 -0
  139. aipt_v2/tools/executor.py +307 -0
  140. aipt_v2/tools/parser.py +408 -0
  141. aipt_v2/tools/proxy/__init__.py +5 -0
  142. aipt_v2/tools/proxy/proxy_actions.py +103 -0
  143. aipt_v2/tools/proxy/proxy_manager.py +789 -0
  144. aipt_v2/tools/registry.py +196 -0
  145. aipt_v2/tools/scanners/__init__.py +343 -0
  146. aipt_v2/tools/scanners/acunetix_tool.py +712 -0
  147. aipt_v2/tools/scanners/burp_tool.py +631 -0
  148. aipt_v2/tools/scanners/config.py +156 -0
  149. aipt_v2/tools/scanners/nessus_tool.py +588 -0
  150. aipt_v2/tools/scanners/zap_tool.py +612 -0
  151. aipt_v2/tools/terminal/__init__.py +5 -0
  152. aipt_v2/tools/terminal/terminal_actions.py +37 -0
  153. aipt_v2/tools/terminal/terminal_manager.py +153 -0
  154. aipt_v2/tools/terminal/terminal_session.py +449 -0
  155. aipt_v2/tools/tool_processing.py +108 -0
  156. aipt_v2/utils/__init__.py +17 -0
  157. aipt_v2/utils/logging.py +201 -0
  158. aipt_v2/utils/model_manager.py +187 -0
  159. aipt_v2/utils/searchers/__init__.py +269 -0
  160. aiptx-2.0.2.dist-info/METADATA +324 -0
  161. aiptx-2.0.2.dist-info/RECORD +165 -0
  162. aiptx-2.0.2.dist-info/WHEEL +5 -0
  163. aiptx-2.0.2.dist-info/entry_points.txt +7 -0
  164. aiptx-2.0.2.dist-info/licenses/LICENSE +21 -0
  165. aiptx-2.0.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,424 @@
1
+ """
2
+ Compliance Framework Mapper
3
+
4
+ Central mapping engine that converts security findings to compliance frameworks.
5
+ Maps CWE IDs to OWASP, PCI-DSS, NIST, and SANS categories.
6
+
7
+ Usage:
8
+ from aipt_v2.compliance import ComplianceMapper
9
+
10
+ mapper = ComplianceMapper()
11
+ mappings = mapper.map_finding(finding)
12
+ """
13
+
14
+ from dataclasses import dataclass, field
15
+ from typing import List, Dict, Any, Optional
16
+ from enum import Enum
17
+
18
+
19
+ class Framework(Enum):
20
+ """Supported compliance frameworks."""
21
+ OWASP = "owasp"
22
+ PCI_DSS = "pci_dss"
23
+ NIST = "nist_800_53"
24
+ SANS = "sans_top_25"
25
+ CIS = "cis_controls"
26
+
27
+
28
+ @dataclass
29
+ class FrameworkCategory:
30
+ """A category within a compliance framework."""
31
+ framework: str
32
+ category_id: str
33
+ category_name: str
34
+ description: str
35
+ requirements: List[str] = field(default_factory=list)
36
+
37
+
38
+ @dataclass
39
+ class ComplianceMapping:
40
+ """Mapping of a finding to compliance frameworks."""
41
+ finding_id: str
42
+ cwe_id: str
43
+ cwe_name: str
44
+ severity: str
45
+ frameworks: Dict[str, FrameworkCategory]
46
+ risk_score: float = 0.0
47
+ remediation_priority: str = ""
48
+
49
+
50
+ # CWE to Framework mapping tables
51
+ CWE_TO_OWASP = {
52
+ # A01:2021 - Broken Access Control
53
+ "CWE-22": "A01", "CWE-23": "A01", "CWE-35": "A01", "CWE-59": "A01",
54
+ "CWE-200": "A01", "CWE-201": "A01", "CWE-219": "A01", "CWE-264": "A01",
55
+ "CWE-275": "A01", "CWE-276": "A01", "CWE-284": "A01", "CWE-285": "A01",
56
+ "CWE-352": "A01", "CWE-359": "A01", "CWE-377": "A01", "CWE-402": "A01",
57
+ "CWE-425": "A01", "CWE-441": "A01", "CWE-497": "A01", "CWE-538": "A01",
58
+ "CWE-540": "A01", "CWE-548": "A01", "CWE-552": "A01", "CWE-566": "A01",
59
+ "CWE-601": "A01", "CWE-639": "A01", "CWE-651": "A01", "CWE-668": "A01",
60
+ "CWE-706": "A01", "CWE-862": "A01", "CWE-863": "A01", "CWE-913": "A01",
61
+ "CWE-922": "A01", "CWE-1275": "A01",
62
+
63
+ # A02:2021 - Cryptographic Failures
64
+ "CWE-261": "A02", "CWE-296": "A02", "CWE-310": "A02", "CWE-319": "A02",
65
+ "CWE-320": "A02", "CWE-321": "A02", "CWE-322": "A02", "CWE-323": "A02",
66
+ "CWE-324": "A02", "CWE-325": "A02", "CWE-326": "A02", "CWE-327": "A02",
67
+ "CWE-328": "A02", "CWE-329": "A02", "CWE-330": "A02", "CWE-331": "A02",
68
+ "CWE-335": "A02", "CWE-336": "A02", "CWE-337": "A02", "CWE-338": "A02",
69
+ "CWE-340": "A02", "CWE-347": "A02", "CWE-523": "A02", "CWE-720": "A02",
70
+ "CWE-757": "A02", "CWE-759": "A02", "CWE-760": "A02", "CWE-780": "A02",
71
+ "CWE-818": "A02", "CWE-916": "A02",
72
+
73
+ # A03:2021 - Injection
74
+ "CWE-20": "A03", "CWE-74": "A03", "CWE-75": "A03", "CWE-77": "A03",
75
+ "CWE-78": "A03", "CWE-79": "A03", "CWE-80": "A03", "CWE-83": "A03",
76
+ "CWE-87": "A03", "CWE-88": "A03", "CWE-89": "A03", "CWE-90": "A03",
77
+ "CWE-91": "A03", "CWE-93": "A03", "CWE-94": "A03", "CWE-95": "A03",
78
+ "CWE-96": "A03", "CWE-97": "A03", "CWE-98": "A03", "CWE-99": "A03",
79
+ "CWE-113": "A03", "CWE-116": "A03", "CWE-138": "A03", "CWE-184": "A03",
80
+ "CWE-470": "A03", "CWE-471": "A03", "CWE-564": "A03", "CWE-610": "A03",
81
+ "CWE-643": "A03", "CWE-644": "A03", "CWE-652": "A03", "CWE-917": "A03",
82
+
83
+ # A04:2021 - Insecure Design
84
+ "CWE-73": "A04", "CWE-183": "A04", "CWE-209": "A04", "CWE-213": "A04",
85
+ "CWE-235": "A04", "CWE-256": "A04", "CWE-257": "A04", "CWE-266": "A04",
86
+ "CWE-269": "A04", "CWE-280": "A04", "CWE-311": "A04", "CWE-312": "A04",
87
+ "CWE-313": "A04", "CWE-316": "A04", "CWE-419": "A04", "CWE-430": "A04",
88
+ "CWE-434": "A04", "CWE-444": "A04", "CWE-451": "A04", "CWE-472": "A04",
89
+ "CWE-501": "A04", "CWE-522": "A04", "CWE-525": "A04", "CWE-539": "A04",
90
+ "CWE-579": "A04", "CWE-598": "A04", "CWE-602": "A04", "CWE-642": "A04",
91
+ "CWE-646": "A04", "CWE-650": "A04", "CWE-653": "A04", "CWE-656": "A04",
92
+ "CWE-657": "A04", "CWE-799": "A04", "CWE-807": "A04", "CWE-840": "A04",
93
+ "CWE-841": "A04", "CWE-927": "A04", "CWE-1021": "A04", "CWE-1173": "A04",
94
+
95
+ # A05:2021 - Security Misconfiguration
96
+ "CWE-2": "A05", "CWE-11": "A05", "CWE-13": "A05", "CWE-15": "A05",
97
+ "CWE-16": "A05", "CWE-260": "A05", "CWE-315": "A05", "CWE-520": "A05",
98
+ "CWE-526": "A05", "CWE-537": "A05", "CWE-541": "A05", "CWE-547": "A05",
99
+ "CWE-611": "A05", "CWE-614": "A05", "CWE-756": "A05", "CWE-776": "A05",
100
+ "CWE-942": "A05", "CWE-1004": "A05", "CWE-1032": "A05", "CWE-1174": "A05",
101
+
102
+ # A06:2021 - Vulnerable and Outdated Components
103
+ "CWE-937": "A06", "CWE-1035": "A06", "CWE-1104": "A06",
104
+
105
+ # A07:2021 - Identification and Authentication Failures
106
+ "CWE-255": "A07", "CWE-259": "A07", "CWE-287": "A07", "CWE-288": "A07",
107
+ "CWE-290": "A07", "CWE-294": "A07", "CWE-295": "A07", "CWE-297": "A07",
108
+ "CWE-300": "A07", "CWE-302": "A07", "CWE-304": "A07", "CWE-306": "A07",
109
+ "CWE-307": "A07", "CWE-346": "A07", "CWE-384": "A07", "CWE-521": "A07",
110
+ "CWE-613": "A07", "CWE-620": "A07", "CWE-640": "A07", "CWE-798": "A07",
111
+ "CWE-940": "A07", "CWE-1216": "A07",
112
+
113
+ # A08:2021 - Software and Data Integrity Failures
114
+ "CWE-345": "A08", "CWE-353": "A08", "CWE-426": "A08", "CWE-494": "A08",
115
+ "CWE-502": "A08", "CWE-565": "A08", "CWE-784": "A08", "CWE-829": "A08",
116
+ "CWE-830": "A08", "CWE-915": "A08",
117
+
118
+ # A09:2021 - Security Logging and Monitoring Failures
119
+ "CWE-117": "A09", "CWE-223": "A09", "CWE-532": "A09", "CWE-778": "A09",
120
+
121
+ # A10:2021 - Server-Side Request Forgery (SSRF)
122
+ "CWE-918": "A10"
123
+ }
124
+
125
+ # CWE to PCI-DSS 4.0 mapping
126
+ CWE_TO_PCI = {
127
+ # Req 6: Develop and maintain secure systems
128
+ "CWE-79": "6.2", "CWE-89": "6.2", "CWE-78": "6.2", "CWE-94": "6.2",
129
+ "CWE-502": "6.2", "CWE-918": "6.2", "CWE-22": "6.2", "CWE-434": "6.2",
130
+
131
+ # Req 2: Apply secure configurations
132
+ "CWE-16": "2.2", "CWE-260": "2.2", "CWE-611": "2.2",
133
+
134
+ # Req 3: Protect stored account data
135
+ "CWE-312": "3.4", "CWE-311": "3.4", "CWE-327": "3.5",
136
+
137
+ # Req 4: Protect cardholder data with strong cryptography
138
+ "CWE-319": "4.1", "CWE-326": "4.1", "CWE-327": "4.1",
139
+
140
+ # Req 7: Restrict access by need to know
141
+ "CWE-284": "7.1", "CWE-285": "7.1", "CWE-862": "7.1", "CWE-863": "7.1",
142
+
143
+ # Req 8: Identify users and authenticate access
144
+ "CWE-287": "8.3", "CWE-521": "8.3", "CWE-798": "8.3", "CWE-307": "8.3",
145
+
146
+ # Req 10: Log and monitor all access
147
+ "CWE-778": "10.2", "CWE-223": "10.2", "CWE-117": "10.2",
148
+
149
+ # Req 11: Test security regularly
150
+ "CWE-937": "11.3", "CWE-1104": "11.3"
151
+ }
152
+
153
+ # CWE to NIST 800-53 mapping
154
+ CWE_TO_NIST = {
155
+ # Access Control (AC)
156
+ "CWE-284": "AC-3", "CWE-285": "AC-6", "CWE-862": "AC-3", "CWE-863": "AC-6",
157
+ "CWE-639": "AC-3",
158
+
159
+ # Audit and Accountability (AU)
160
+ "CWE-778": "AU-2", "CWE-223": "AU-3", "CWE-117": "AU-9",
161
+
162
+ # Identification and Authentication (IA)
163
+ "CWE-287": "IA-2", "CWE-521": "IA-5", "CWE-798": "IA-5", "CWE-307": "IA-5",
164
+ "CWE-384": "IA-8",
165
+
166
+ # System and Communications Protection (SC)
167
+ "CWE-319": "SC-8", "CWE-327": "SC-13", "CWE-326": "SC-12",
168
+ "CWE-311": "SC-28",
169
+
170
+ # System and Information Integrity (SI)
171
+ "CWE-79": "SI-10", "CWE-89": "SI-10", "CWE-78": "SI-10",
172
+ "CWE-502": "SI-10", "CWE-94": "SI-10", "CWE-20": "SI-10",
173
+
174
+ # Configuration Management (CM)
175
+ "CWE-16": "CM-6", "CWE-260": "CM-6", "CWE-611": "CM-6",
176
+
177
+ # Risk Assessment (RA)
178
+ "CWE-937": "RA-5", "CWE-1104": "RA-5"
179
+ }
180
+
181
+
182
+ class ComplianceMapper:
183
+ """
184
+ Maps security findings to compliance frameworks.
185
+
186
+ Supports OWASP Top 10, PCI-DSS, NIST 800-53, and SANS Top 25.
187
+ """
188
+
189
+ def __init__(self):
190
+ """Initialize mapper with CWE mappings."""
191
+ self.cwe_to_owasp = CWE_TO_OWASP
192
+ self.cwe_to_pci = CWE_TO_PCI
193
+ self.cwe_to_nist = CWE_TO_NIST
194
+
195
+ def map_finding(
196
+ self,
197
+ cwe_id: str,
198
+ finding_id: str = "",
199
+ severity: str = "medium",
200
+ frameworks: List[str] = None
201
+ ) -> ComplianceMapping:
202
+ """
203
+ Map a single finding to compliance frameworks.
204
+
205
+ Args:
206
+ cwe_id: CWE identifier (e.g., "CWE-79" or "79")
207
+ finding_id: Unique finding identifier
208
+ severity: Finding severity
209
+ frameworks: List of frameworks to map to
210
+
211
+ Returns:
212
+ ComplianceMapping
213
+ """
214
+ # Normalize CWE ID
215
+ if not cwe_id.upper().startswith("CWE-"):
216
+ cwe_id = f"CWE-{cwe_id}"
217
+ cwe_id = cwe_id.upper()
218
+
219
+ frameworks = frameworks or ["owasp", "pci", "nist"]
220
+ framework_mappings = {}
221
+
222
+ # Map to OWASP
223
+ if "owasp" in frameworks and cwe_id in self.cwe_to_owasp:
224
+ owasp_cat = self.cwe_to_owasp[cwe_id]
225
+ framework_mappings["owasp"] = FrameworkCategory(
226
+ framework="OWASP Top 10 2021",
227
+ category_id=owasp_cat,
228
+ category_name=self._get_owasp_name(owasp_cat),
229
+ description=self._get_owasp_description(owasp_cat)
230
+ )
231
+
232
+ # Map to PCI-DSS
233
+ if "pci" in frameworks and cwe_id in self.cwe_to_pci:
234
+ pci_req = self.cwe_to_pci[cwe_id]
235
+ framework_mappings["pci_dss"] = FrameworkCategory(
236
+ framework="PCI-DSS 4.0",
237
+ category_id=pci_req,
238
+ category_name=f"Requirement {pci_req}",
239
+ description=self._get_pci_description(pci_req)
240
+ )
241
+
242
+ # Map to NIST
243
+ if "nist" in frameworks and cwe_id in self.cwe_to_nist:
244
+ nist_control = self.cwe_to_nist[cwe_id]
245
+ framework_mappings["nist"] = FrameworkCategory(
246
+ framework="NIST 800-53",
247
+ category_id=nist_control,
248
+ category_name=nist_control,
249
+ description=self._get_nist_description(nist_control)
250
+ )
251
+
252
+ # Calculate risk score
253
+ risk_score = self._calculate_risk_score(severity, len(framework_mappings))
254
+
255
+ # Determine remediation priority
256
+ priority = "critical" if risk_score >= 8 else \
257
+ "high" if risk_score >= 6 else \
258
+ "medium" if risk_score >= 4 else "low"
259
+
260
+ return ComplianceMapping(
261
+ finding_id=finding_id,
262
+ cwe_id=cwe_id,
263
+ cwe_name=self._get_cwe_name(cwe_id),
264
+ severity=severity,
265
+ frameworks=framework_mappings,
266
+ risk_score=risk_score,
267
+ remediation_priority=priority
268
+ )
269
+
270
+ def map_findings(
271
+ self,
272
+ findings: List[Dict],
273
+ frameworks: List[str] = None
274
+ ) -> List[ComplianceMapping]:
275
+ """
276
+ Map multiple findings to compliance frameworks.
277
+
278
+ Args:
279
+ findings: List of finding dicts with 'cwe' and 'severity' keys
280
+ frameworks: Frameworks to map to
281
+
282
+ Returns:
283
+ List of ComplianceMapping
284
+ """
285
+ mappings = []
286
+
287
+ for finding in findings:
288
+ cwe = finding.get("cwe", finding.get("cwe_id", ""))
289
+ if cwe:
290
+ mapping = self.map_finding(
291
+ cwe_id=cwe,
292
+ finding_id=finding.get("id", ""),
293
+ severity=finding.get("severity", "medium"),
294
+ frameworks=frameworks
295
+ )
296
+ mappings.append(mapping)
297
+
298
+ return mappings
299
+
300
+ def _calculate_risk_score(self, severity: str, framework_count: int) -> float:
301
+ """Calculate risk score based on severity and compliance impact."""
302
+ severity_scores = {
303
+ "critical": 10,
304
+ "high": 8,
305
+ "medium": 5,
306
+ "low": 3,
307
+ "info": 1
308
+ }
309
+
310
+ base_score = severity_scores.get(severity.lower(), 5)
311
+
312
+ # Increase score based on compliance framework impact
313
+ compliance_multiplier = 1 + (framework_count * 0.1)
314
+
315
+ return min(10, base_score * compliance_multiplier)
316
+
317
+ def _get_owasp_name(self, category: str) -> str:
318
+ """Get OWASP category name."""
319
+ names = {
320
+ "A01": "Broken Access Control",
321
+ "A02": "Cryptographic Failures",
322
+ "A03": "Injection",
323
+ "A04": "Insecure Design",
324
+ "A05": "Security Misconfiguration",
325
+ "A06": "Vulnerable and Outdated Components",
326
+ "A07": "Identification and Authentication Failures",
327
+ "A08": "Software and Data Integrity Failures",
328
+ "A09": "Security Logging and Monitoring Failures",
329
+ "A10": "Server-Side Request Forgery"
330
+ }
331
+ return names.get(category, "Unknown")
332
+
333
+ def _get_owasp_description(self, category: str) -> str:
334
+ """Get OWASP category description."""
335
+ descriptions = {
336
+ "A01": "Access control enforces policy such that users cannot act outside their intended permissions.",
337
+ "A02": "Failures related to cryptography which often leads to sensitive data exposure.",
338
+ "A03": "User-supplied data is not validated, filtered, or sanitized by the application.",
339
+ "A04": "Missing or ineffective control design.",
340
+ "A05": "Missing appropriate security hardening or improperly configured permissions.",
341
+ "A06": "Using components with known vulnerabilities.",
342
+ "A07": "Confirmation of the user's identity, authentication, and session management.",
343
+ "A08": "Code and infrastructure that does not protect against integrity violations.",
344
+ "A09": "Insufficient logging, detection, monitoring, and active response.",
345
+ "A10": "Fetching a remote resource without validating the user-supplied URL."
346
+ }
347
+ return descriptions.get(category, "")
348
+
349
+ def _get_pci_description(self, requirement: str) -> str:
350
+ """Get PCI-DSS requirement description."""
351
+ descriptions = {
352
+ "2.2": "Apply secure configurations to all system components",
353
+ "3.4": "Protect stored cardholder data",
354
+ "3.5": "Protect cryptographic keys",
355
+ "4.1": "Protect cardholder data with strong cryptography during transmission",
356
+ "6.2": "Develop secure software",
357
+ "7.1": "Restrict access to system components",
358
+ "8.3": "Strong authentication for users and administrators",
359
+ "10.2": "Implement automated audit trails",
360
+ "11.3": "External and internal vulnerabilities are identified"
361
+ }
362
+ return descriptions.get(requirement, "")
363
+
364
+ def _get_nist_description(self, control: str) -> str:
365
+ """Get NIST control description."""
366
+ descriptions = {
367
+ "AC-3": "Access Enforcement",
368
+ "AC-6": "Least Privilege",
369
+ "AU-2": "Audit Events",
370
+ "AU-3": "Content of Audit Records",
371
+ "AU-9": "Protection of Audit Information",
372
+ "IA-2": "Identification and Authentication",
373
+ "IA-5": "Authenticator Management",
374
+ "IA-8": "Identification and Authentication (Non-Organizational Users)",
375
+ "SC-8": "Transmission Confidentiality and Integrity",
376
+ "SC-12": "Cryptographic Key Establishment and Management",
377
+ "SC-13": "Cryptographic Protection",
378
+ "SC-28": "Protection of Information at Rest",
379
+ "SI-10": "Information Input Validation",
380
+ "CM-6": "Configuration Settings",
381
+ "RA-5": "Vulnerability Scanning"
382
+ }
383
+ return descriptions.get(control, "")
384
+
385
+ def _get_cwe_name(self, cwe_id: str) -> str:
386
+ """Get CWE name."""
387
+ # Common CWE names
388
+ names = {
389
+ "CWE-79": "Cross-site Scripting (XSS)",
390
+ "CWE-89": "SQL Injection",
391
+ "CWE-78": "OS Command Injection",
392
+ "CWE-94": "Code Injection",
393
+ "CWE-22": "Path Traversal",
394
+ "CWE-287": "Improper Authentication",
395
+ "CWE-284": "Improper Access Control",
396
+ "CWE-327": "Use of Broken Crypto Algorithm",
397
+ "CWE-502": "Deserialization of Untrusted Data",
398
+ "CWE-918": "Server-Side Request Forgery",
399
+ "CWE-434": "Unrestricted File Upload",
400
+ "CWE-798": "Use of Hardcoded Credentials",
401
+ "CWE-862": "Missing Authorization",
402
+ "CWE-863": "Incorrect Authorization",
403
+ "CWE-307": "Improper Restriction of Auth Attempts"
404
+ }
405
+ return names.get(cwe_id, cwe_id)
406
+
407
+
408
+ # Convenience function
409
+ def map_to_frameworks(
410
+ findings: List[Dict],
411
+ frameworks: List[str] = None
412
+ ) -> List[ComplianceMapping]:
413
+ """
414
+ Quick mapping of findings to frameworks.
415
+
416
+ Args:
417
+ findings: List of findings
418
+ frameworks: Target frameworks
419
+
420
+ Returns:
421
+ List of mappings
422
+ """
423
+ mapper = ComplianceMapper()
424
+ return mapper.map_findings(findings, frameworks)