21
21
)
22
22
from common .agent_plugins import AgentPluginManifest , AgentPluginType
23
23
from common .network .network_range import NetworkRange
24
- from common .network .network_utils import get_my_ip_addresses_legacy , get_network_interfaces
25
24
from common .network .segmentation_utils import get_ip_if_in_subnet
26
25
from common .types import PortStatus
27
26
from monkey_island .cc .models import CommunicationType , Machine
37
36
get_monkey_exploited ,
38
37
)
39
38
40
- from .issue_processing .exploit_processing .exploiter_descriptor_enum import ExploiterDescriptorEnum
41
39
from .issue_processing .exploit_processing .exploiter_report_info import ExploiterReportInfo
42
40
43
41
logger = logging .getLogger (__name__ )
@@ -73,9 +71,6 @@ class ReportService:
73
71
_report : Dict [str , Dict ] = {}
74
72
_report_generation_lock : Lock = Lock ()
75
73
76
- class DerivedIssueEnum :
77
- ZEROLOGON_PASS_RESTORE_FAILED = "zerologon_pass_restore_failed"
78
-
79
74
@classmethod
80
75
def initialize (
81
76
cls ,
@@ -229,35 +224,6 @@ def get_exploits(cls) -> List[dict]:
229
224
# Convert the ExploitationEvent into an ExploiterReportInfo
230
225
return [asdict (cls .process_exploit_event (e , password_restored )) for e in filtered_exploits ]
231
226
232
- @classmethod
233
- def get_island_cross_segment_issues (cls ):
234
- issues = []
235
- island_ips = get_my_ip_addresses_legacy ()
236
- island_machines = [m for m in cls ._machine_repository .get_machines () if m .island ]
237
- for island_machine in island_machines :
238
- found_good_ip = False
239
- island_subnets = island_machine .network_interfaces
240
- for subnet in island_subnets :
241
- if str (subnet .ip ) in island_ips :
242
- found_good_ip = True
243
- break
244
- if found_good_ip :
245
- break
246
- if not found_good_ip :
247
- issues .append (
248
- {
249
- "machine_id" : island_machine .id ,
250
- "type" : "island_cross_segment" ,
251
- "machine" : island_machine .hostname ,
252
- "networks" : [str (subnet ) for subnet in island_subnets ],
253
- "server_networks" : [
254
- str (interface .network ) for interface in get_network_interfaces ()
255
- ],
256
- }
257
- )
258
-
259
- return issues
260
-
261
227
@classmethod
262
228
def get_cross_segment_issues_of_single_machine (
263
229
cls , source_subnet_range : NetworkRange , target_subnet_range : NetworkRange
@@ -466,26 +432,6 @@ def get_config_scan(cls):
466
432
agent_configuration = cls ._agent_configuration_repository .get_configuration ()
467
433
return agent_configuration .propagation .network_scan .targets .scan_my_networks
468
434
469
- @staticmethod
470
- def get_issue_set (issues ):
471
- issue_set = set ()
472
-
473
- for machine in issues :
474
- for issue in issues [machine ]:
475
- if ReportService ._is_zerologon_pass_restore_failed (issue ):
476
- issue_set .add (ReportService .DerivedIssueEnum .ZEROLOGON_PASS_RESTORE_FAILED )
477
-
478
- issue_set .add (issue ["type" ])
479
-
480
- return issue_set
481
-
482
- @staticmethod
483
- def _is_zerologon_pass_restore_failed (issue : dict ):
484
- return (
485
- issue ["type" ] == ExploiterDescriptorEnum .ZEROLOGON .value .class_name
486
- and not issue ["password_restored" ]
487
- )
488
-
489
435
@classmethod
490
436
def is_report_generated (cls ) -> bool :
491
437
return bool (cls ._report )
@@ -498,7 +444,6 @@ def generate_report(cls):
498
444
return RuntimeError ("Machine repository does not exist" )
499
445
500
446
issues = ReportService .get_issues ()
501
- issue_set = ReportService .get_issue_set (issues )
502
447
cross_segment_issues = ReportService .get_cross_segment_issues ()
503
448
latest_event_timestamp = ReportService .get_latest_event_timestamp ()
504
449
@@ -517,9 +462,8 @@ def generate_report(cls):
517
462
"%d/%m/%Y %H:%M:%S"
518
463
),
519
464
"monkey_duration" : ReportService .get_monkey_duration (),
520
- "issues" : issue_set ,
521
- "cross_segment_issues" : cross_segment_issues ,
522
465
},
466
+ "cross_segment_issues" : cross_segment_issues ,
523
467
"glance" : {
524
468
"scanned" : scanned_nodes ,
525
469
"exploited_cnt" : exploited_cnt ,
@@ -534,14 +478,15 @@ def generate_report(cls):
534
478
def get_issues (cls ):
535
479
ISSUE_GENERATORS = [
536
480
ReportService .get_exploits ,
537
- ReportService .get_island_cross_segment_issues ,
538
481
]
539
482
540
483
issues = functools .reduce (lambda acc , issue_gen : acc + issue_gen (), ISSUE_GENERATORS , [])
541
484
542
485
issues_dict = {}
543
486
for issue in issues :
544
- issue = cls .add_remediation_to_issue (issue )
487
+ manifest = cls ._get_exploiter_manifests ().get (issue ["type" ])
488
+ issue = cls .add_remediation_to_issue (issue , manifest )
489
+ issue = cls .add_description_to_issue (issue , manifest )
545
490
if issue .get ("is_local" , True ):
546
491
machine_id = issue .get ("machine_id" )
547
492
if machine_id not in issues_dict :
@@ -551,12 +496,21 @@ def get_issues(cls):
551
496
return issues_dict
552
497
553
498
@classmethod
554
- def add_remediation_to_issue (cls , issue : Dict [str , Any ]) -> Dict [str , Any ]:
555
- manifest = cls ._get_exploiter_manifests ().get (issue ["type" ])
499
+ def add_remediation_to_issue (
500
+ cls , issue : Dict [str , Any ], manifest : Optional [AgentPluginManifest ]
501
+ ) -> Dict [str , Any ]:
556
502
if manifest :
557
503
issue ["remediation_suggestion" ] = manifest .remediation_suggestion
558
504
return issue
559
505
506
+ @classmethod
507
+ def add_description_to_issue (
508
+ cls , issue : Dict [str , Any ], manifest : Optional [AgentPluginManifest ]
509
+ ) -> Dict [str , Any ]:
510
+ if manifest :
511
+ issue ["description" ] = manifest .description
512
+ return issue
513
+
560
514
@classmethod
561
515
def get_latest_event_timestamp (cls ) -> Optional [float ]:
562
516
if not cls ._agent_event_repository :
0 commit comments