ersec 21.0.0__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.
- ersec/__init__.py +2 -0
- ersec/ai.py +206 -0
- ersec/cli.py +924 -0
- ersec/mitre.py +116 -0
- ersec/scanner.py +231 -0
- ersec/version.py +2 -0
- ersec-21.0.0.dist-info/METADATA +22 -0
- ersec-21.0.0.dist-info/RECORD +12 -0
- ersec-21.0.0.dist-info/WHEEL +5 -0
- ersec-21.0.0.dist-info/entry_points.txt +2 -0
- ersec-21.0.0.dist-info/licenses/LICENSE +21 -0
- ersec-21.0.0.dist-info/top_level.txt +1 -0
ersec/__init__.py
ADDED
ersec/ai.py
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"""Professional AI Analysis Engine for ERSEC"""
|
|
2
|
+
|
|
3
|
+
from typing import Dict, Any, List
|
|
4
|
+
from .mitre import MITREKnowledgeBase
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class ProfessionalAI:
|
|
8
|
+
"""AI-powered analysis engine using MITRE knowledge base"""
|
|
9
|
+
|
|
10
|
+
def __init__(self):
|
|
11
|
+
self.mitre = MITREKnowledgeBase()
|
|
12
|
+
|
|
13
|
+
def analyze(self, target: str, results: Dict[str, Any]) -> str:
|
|
14
|
+
"""Generate comprehensive analysis"""
|
|
15
|
+
findings = results.get("all_findings", [])
|
|
16
|
+
|
|
17
|
+
sections = []
|
|
18
|
+
sections.append(self._generate_summary(target, findings))
|
|
19
|
+
sections.append(self._generate_vulnerability_details(findings))
|
|
20
|
+
sections.append(self._generate_mitre_mapping(findings))
|
|
21
|
+
sections.append(self._generate_exploitation_guide(findings))
|
|
22
|
+
sections.append(self._generate_defense_strategies(findings))
|
|
23
|
+
sections.append(self._generate_recommendations(findings))
|
|
24
|
+
|
|
25
|
+
return "\n\n".join(sections)
|
|
26
|
+
|
|
27
|
+
def _generate_summary(self, target: str, findings: List[Dict]) -> str:
|
|
28
|
+
"""Generate executive summary"""
|
|
29
|
+
critical = len([f for f in findings if f.get("severity") == "Critical"])
|
|
30
|
+
high = len([f for f in findings if f.get("severity") == "High"])
|
|
31
|
+
medium = len([f for f in findings if f.get("severity") == "Medium"])
|
|
32
|
+
total = len(findings)
|
|
33
|
+
|
|
34
|
+
risk_score = min(100, critical * 30 + high * 15 + medium * 5)
|
|
35
|
+
|
|
36
|
+
if risk_score >= 80:
|
|
37
|
+
risk_level = "CRITICAL"
|
|
38
|
+
elif risk_score >= 60:
|
|
39
|
+
risk_level = "HIGH"
|
|
40
|
+
elif risk_score >= 40:
|
|
41
|
+
risk_level = "MEDIUM"
|
|
42
|
+
else:
|
|
43
|
+
risk_level = "LOW"
|
|
44
|
+
|
|
45
|
+
return f"""
|
|
46
|
+
╔══════════════════════════════════════════════════════════════╗
|
|
47
|
+
║ EXECUTIVE SECURITY REPORT ║
|
|
48
|
+
╚══════════════════════════════════════════════════════════════╝
|
|
49
|
+
|
|
50
|
+
📋 Target: {target}
|
|
51
|
+
📊 Risk Score: {risk_score}/100 - {risk_level}
|
|
52
|
+
|
|
53
|
+
Vulnerability Distribution:
|
|
54
|
+
🔴 Critical: {critical}
|
|
55
|
+
🟠 High: {high}
|
|
56
|
+
🟡 Medium: {medium}
|
|
57
|
+
📊 Total: {total}
|
|
58
|
+
|
|
59
|
+
{"⚠️ CRITICAL VULNERABILITIES - IMMEDIATE ACTION REQUIRED!" if critical > 0 else "⚡ Vulnerabilities found - remediation recommended" if total > 0 else "✅ No critical vulnerabilities detected"}
|
|
60
|
+
"""
|
|
61
|
+
|
|
62
|
+
def _generate_vulnerability_details(self, findings: List[Dict]) -> str:
|
|
63
|
+
"""Generate detailed vulnerability analysis"""
|
|
64
|
+
if not findings:
|
|
65
|
+
return "No vulnerabilities detected."
|
|
66
|
+
|
|
67
|
+
details = "╔══════════════════════════════════════════════════════════════╗\n"
|
|
68
|
+
details += "║ VULNERABILITY DETAILS ║\n"
|
|
69
|
+
details += "╚══════════════════════════════════════════════════════════════╝\n"
|
|
70
|
+
|
|
71
|
+
for i, f in enumerate(findings, 1):
|
|
72
|
+
severity = f.get("severity", "Unknown")
|
|
73
|
+
emoji = "🔴" if severity == "Critical" else "🟠" if severity == "High" else "🟡"
|
|
74
|
+
|
|
75
|
+
details += f"""
|
|
76
|
+
|
|
77
|
+
{emoji} Finding #{i}: {f.get('name', 'Unknown')}
|
|
78
|
+
{'=' * 60}
|
|
79
|
+
Type: {f.get('type', 'Unknown')}
|
|
80
|
+
Severity: {severity}
|
|
81
|
+
CVSS Score: {f.get('cvss', 'N/A')}
|
|
82
|
+
|
|
83
|
+
Description:
|
|
84
|
+
{f.get('description', 'No description available')}
|
|
85
|
+
|
|
86
|
+
Impact:
|
|
87
|
+
{f.get('impact', 'Unknown impact')}
|
|
88
|
+
"""
|
|
89
|
+
|
|
90
|
+
return details
|
|
91
|
+
|
|
92
|
+
def _generate_mitre_mapping(self, findings: List[Dict]) -> str:
|
|
93
|
+
"""Generate MITRE ATT&CK mapping"""
|
|
94
|
+
if not findings:
|
|
95
|
+
return ""
|
|
96
|
+
|
|
97
|
+
mapping = "╔══════════════════════════════════════════════════════════════╗\n"
|
|
98
|
+
mapping += "║ MITRE ATT&CK MAPPING ║\n"
|
|
99
|
+
mapping += "╚══════════════════════════════════════════════════════════════╝\n"
|
|
100
|
+
|
|
101
|
+
seen = set()
|
|
102
|
+
for f in findings:
|
|
103
|
+
for tech_id in f.get("techniques", []):
|
|
104
|
+
if tech_id in seen:
|
|
105
|
+
continue
|
|
106
|
+
seen.add(tech_id)
|
|
107
|
+
|
|
108
|
+
tech = self.mitre.get_technique(tech_id)
|
|
109
|
+
if tech:
|
|
110
|
+
mapping += f"""
|
|
111
|
+
|
|
112
|
+
[{tech_id}] {tech.get('name', 'Unknown')}
|
|
113
|
+
Tactic: {tech.get('tactic', 'Unknown')}
|
|
114
|
+
Description: {tech.get('description', 'N/A')}
|
|
115
|
+
"""
|
|
116
|
+
|
|
117
|
+
return mapping
|
|
118
|
+
|
|
119
|
+
def _generate_exploitation_guide(self, findings: List[Dict]) -> str:
|
|
120
|
+
"""Generate exploitation guide"""
|
|
121
|
+
if not findings:
|
|
122
|
+
return ""
|
|
123
|
+
|
|
124
|
+
guide = "╔══════════════════════════════════════════════════════════════╗\n"
|
|
125
|
+
guide += "║ EXPLOITATION GUIDE ║\n"
|
|
126
|
+
guide += "╚══════════════════════════════════════════════════════════════╝\n"
|
|
127
|
+
|
|
128
|
+
for f in findings:
|
|
129
|
+
tools = f.get("tools", [])
|
|
130
|
+
commands = f.get("commands", [])
|
|
131
|
+
|
|
132
|
+
if tools or commands:
|
|
133
|
+
guide += f"""
|
|
134
|
+
|
|
135
|
+
{'-' * 60}
|
|
136
|
+
Exploiting: {f.get('name', 'Unknown')}
|
|
137
|
+
{'-' * 60}
|
|
138
|
+
|
|
139
|
+
🛠️ Tools:
|
|
140
|
+
{', '.join(tools) if tools else 'Manual exploitation'}
|
|
141
|
+
|
|
142
|
+
💻 Commands:
|
|
143
|
+
"""
|
|
144
|
+
for cmd in commands:
|
|
145
|
+
guide += f" $ {cmd}\n"
|
|
146
|
+
|
|
147
|
+
return guide
|
|
148
|
+
|
|
149
|
+
def _generate_defense_strategies(self, findings: List[Dict]) -> str:
|
|
150
|
+
"""Generate defense strategies"""
|
|
151
|
+
if not findings:
|
|
152
|
+
return ""
|
|
153
|
+
|
|
154
|
+
defense = "╔══════════════════════════════════════════════════════════════╗\n"
|
|
155
|
+
defense += "║ DEFENSE STRATEGIES ║\n"
|
|
156
|
+
defense += "╚══════════════════════════════════════════════════════════════╝\n"
|
|
157
|
+
|
|
158
|
+
for f in findings:
|
|
159
|
+
strategies = f.get("defense", [])
|
|
160
|
+
if strategies:
|
|
161
|
+
defense += f"""
|
|
162
|
+
|
|
163
|
+
{'-' * 60}
|
|
164
|
+
Defending Against: {f.get('name', 'Unknown')}
|
|
165
|
+
{'-' * 60}
|
|
166
|
+
|
|
167
|
+
"""
|
|
168
|
+
for s in strategies:
|
|
169
|
+
defense += f" ✅ {s}\n"
|
|
170
|
+
|
|
171
|
+
defense += """
|
|
172
|
+
|
|
173
|
+
🔒 General Hardening:
|
|
174
|
+
✅ Regular patching
|
|
175
|
+
✅ Network segmentation
|
|
176
|
+
✅ Least privilege
|
|
177
|
+
✅ MFA everywhere
|
|
178
|
+
✅ WAF deployment
|
|
179
|
+
"""
|
|
180
|
+
|
|
181
|
+
return defense
|
|
182
|
+
|
|
183
|
+
def _generate_recommendations(self, findings: List[Dict]) -> str:
|
|
184
|
+
"""Generate prioritized recommendations"""
|
|
185
|
+
recommendations = "╔══════════════════════════════════════════════════════════════╗\n"
|
|
186
|
+
recommendations += "║ PRIORITIZED RECOMMENDATIONS ║\n"
|
|
187
|
+
recommendations += "╚══════════════════════════════════════════════════════════════╝\n"
|
|
188
|
+
|
|
189
|
+
if not findings:
|
|
190
|
+
recommendations += "\n✅ No critical vulnerabilities\n✅ Maintain security posture\n"
|
|
191
|
+
return recommendations
|
|
192
|
+
|
|
193
|
+
critical = [f for f in findings if f.get("severity") == "Critical"]
|
|
194
|
+
high = [f for f in findings if f.get("severity") == "High"]
|
|
195
|
+
|
|
196
|
+
if critical:
|
|
197
|
+
recommendations += "\n🚨 IMMEDIATE (24-48 Hours):\n"
|
|
198
|
+
for f in critical:
|
|
199
|
+
recommendations += f" ⚡ {f.get('name')}: {f.get('description', '')[:80]}\n"
|
|
200
|
+
|
|
201
|
+
if high:
|
|
202
|
+
recommendations += "\n⚠️ URGENT (1 Week):\n"
|
|
203
|
+
for f in high:
|
|
204
|
+
recommendations += f" ⚠️ {f.get('name')}: {f.get('description', '')[:80]}\n"
|
|
205
|
+
|
|
206
|
+
return recommendations
|