-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathshow_results.py
More file actions
133 lines (108 loc) · 4.55 KB
/
Copy pathshow_results.py
File metadata and controls
133 lines (108 loc) · 4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env python3
"""
Simple script to show IAM Analyzer results without Unicode issues
"""
import json
import sys
from pathlib import Path
# Add src directory to path
sys.path.insert(0, str(Path(__file__).parent / "src"))
from analyzer import IAMAnalyzer
from iam_parser import IAMParser
def main():
"""Show IAM Analyzer results in a readable format"""
print("=" * 60)
print("RedColors IAM Analyzer - Results Viewer")
print("=" * 60)
print("SAFETY WARNING: This tool processes simulated IAM data only.")
print(" No real cloud resources are accessed or modified.")
print()
# Load sample IAM data
iam_file = Path(__file__).parent / "examples" / "iam.json"
try:
print("Loading IAM data from:", iam_file)
parser = IAMParser.load_from_file(str(iam_file))
print("IAM data loaded successfully")
print()
# Create analyzer
print("Creating IAM Analyzer...")
analyzer = IAMAnalyzer(parser)
print("Analyzer created successfully")
print()
# Build complete trust graph
print("Building complete trust graph...")
trust_graph = analyzer.build_complete_trust_graph()
print(f"Trust graph built: {len(trust_graph['nodes'])} nodes, {len(trust_graph['edges'])} edges")
print()
# Show detailed node information
print("DETAILED NODE ANALYSIS:")
print("-" * 40)
for node in trust_graph['nodes']:
print(f"Entity: {node['label']} ({node['id']})")
print(f" Type: {node['type']}")
print(f" Risk Level: {node['risk_level']}")
print(f" Color: {node['color']}")
print(f" Permissions: {len(node['permissions'])}")
if node['permissions']:
print(f" - {', '.join(node['permissions'][:3])}")
if len(node['permissions']) > 3:
print(f" - ... and {len(node['permissions']) - 3} more")
print()
# Show detailed edge information
print("DETAILED EDGE ANALYSIS:")
print("-" * 40)
for edge in trust_graph['edges']:
print(f"Relationship: {edge['from']} -> {edge['to']}")
print(f" Type: {edge['type']}")
print(f" Label: {edge['label']}")
print(f" Color: {edge['color']}")
print(f" Risk Weight: {edge['weight']:.2f}")
if edge['conditions']:
print(f" Conditions: {edge['conditions']}")
print()
# Find escalation paths
print("ESCALATION PATH ANALYSIS:")
print("-" * 40)
escalation_paths = analyzer.find_all_escalation_paths(max_depth=5)
print(f"Found {len(escalation_paths)} escalation paths")
if escalation_paths:
for i, path in enumerate(escalation_paths[:3], 1):
print(f"Path {i}: {path['start_entity']} -> {path['target_entity']}")
print(f" Type: {path['escalation_type']}")
print(f" Risk Score: {path['risk_score']:.1f}")
print(f" Steps: {len(path['path'])}")
print()
else:
print("No privilege escalation paths found - good security posture!")
print()
# Generate and show report
print("SECURITY RECOMMENDATIONS:")
print("-" * 40)
report = analyzer.generate_analysis_report()
if report['recommendations']:
for i, rec in enumerate(report['recommendations'], 1):
print(f"{i}. {rec}")
else:
print("No specific recommendations - security posture looks good!")
print()
# Show statistics
print("FINAL STATISTICS:")
print("-" * 40)
stats = analyzer.get_statistics()
print(f"Total Entities: {stats['total_entities']}")
print(f"Total Relationships: {stats['total_relationships']}")
print(f"Escalation Paths: {stats['escalation_paths']}")
print(f"High-Risk Entities: {stats['high_risk_entities']}")
print()
print("Analysis completed successfully!")
print()
print("SAFETY REMINDER:")
print(" This analysis was performed on simulated IAM data only.")
print(" No real cloud resources were accessed or modified.")
print(" All findings are for training and educational purposes.")
except Exception as e:
print(f"Error: {e}")
return 1
return 0
if __name__ == "__main__":
exit(main())