-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.html
More file actions
4402 lines (4019 loc) · 245 KB
/
Copy pathindex.html
File metadata and controls
4402 lines (4019 loc) · 245 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Z-Hound - Reforged</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/cytoscape/3.28.1/cytoscape.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dagre@0.8.5/dist/dagre.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/cytoscape-dagre@2.5.0/cytoscape-dagre.min.js"></script>
<link rel="stylesheet" href="defender-module.css">
<script>
tailwind.config = {
theme: { extend: { colors: { dark: '#1e1e26', panel: '#252530', accent: '#7289da' } } }
}
</script>
<style>
body { overflow: hidden; }
#cy { width: 100%; height: 100%; }
.tab-btn { flex: 1; padding: 6px 8px; font-size: 11px; transition: all .15s; color: #9ca3af; cursor: pointer; border-bottom: 2px solid transparent; }
.tab-btn:hover { background: #374151; color: #fff; }
.tab-btn.active { color: #fff; border-bottom-color: #7289da; }
.risk-critical { color: #e74c3c; }
.risk-high { color: #e67e22; }
.risk-medium { color: #f1c40f; }
.risk-low { color: #2ecc71; }
.node-link { cursor: pointer; font-size: 11px; padding: 2px 4px; border-radius: 3px; }
.node-link:hover { background: #374151; color: #fff; }
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: #1e1e26; }
::-webkit-scrollbar-thumb { background: #4b5563; border-radius: 3px; }
</style>
</head>
<body class="bg-dark text-white h-screen flex flex-col font-sans">
<!-- ===== HEADER ===== -->
<header class="bg-panel border-b border-gray-700 px-4 py-2.5 flex items-center justify-between shrink-0">
<div class="flex items-center gap-3">
<h1 class="text-lg font-bold text-accent">Z-Hound <span class="text-gray-500 text-xs font-normal">Reforged</span></h1>
<label class="bg-blue-600 hover:bg-blue-500 text-white px-3 py-1.5 rounded cursor-pointer text-xs font-semibold transition">
📁 Upload ZIP / JSON
<input type="file" id="zipInput" accept=".zip,.json" class="hidden" multiple>
</label>
<button onclick="clearGraph()" class="bg-gray-700 hover:bg-gray-600 px-3 py-1.5 rounded text-xs transition">Clear</button>
<button onclick="saveSession()" class="bg-gray-700 hover:bg-gray-600 px-3 py-1.5 rounded text-xs transition" title="Save graph + owned nodes to browser storage">💾 Save</button>
<button onclick="loadSession()" class="bg-gray-700 hover:bg-gray-600 px-3 py-1.5 rounded text-xs transition" title="Restore last saved session">📄 Load</button>
<button onclick="exportPNG()" class="bg-gray-700 hover:bg-gray-600 px-3 py-1.5 rounded text-xs transition">Export PNG</button>
<button onclick="exportCSV()" class="bg-gray-700 hover:bg-gray-600 px-3 py-1.5 rounded text-xs transition">Export CSV</button>
<button onclick="exportHTML()" class="bg-gray-700 hover:bg-gray-600 px-3 py-1.5 rounded text-xs transition">Export HTML</button>
</div>
<div class="flex items-center gap-2">
<!-- Search mode toggle -->
<div class="flex rounded overflow-hidden border border-gray-600 shrink-0 text-xs">
<button id="modeNameBtn" onclick="setSearchMode('name')"
class="px-2.5 py-1.5 bg-accent text-white font-semibold transition">Name</button>
<button id="modeSidBtn" onclick="setSearchMode('sid')"
class="px-2.5 py-1.5 bg-gray-800 text-gray-400 hover:text-white transition">SID</button>
</div>
<select id="searchTypeFilter" onchange="handleSearchInput()"
class="bg-gray-800 text-white px-2 py-1.5 rounded text-xs border border-gray-600 focus:outline-none focus:border-accent shrink-0">
<option value="all">All Types</option>
<optgroup label="On-Prem AD">
<option value="User">Users</option>
<option value="Computer">Computers</option>
<option value="Group">Groups</option>
<option value=&qu
CF16
ot;Domain">Domains</option>
<option value="OU">OUs</option>
<option value="GPO">GPOs</option>
<option value="CertTemplate">Certs</option>
<option value="Container">Containers</option>
</optgroup>
<optgroup label="Azure AD">
<option value="AZUser">AZ Users</option>
<option value="AZGroup">AZ Groups</option>
<option value="AZApp">AZ Apps</option>
<option value="AZServicePrincipal">AZ Service Principals</option>
<option value="AZTenant">AZ Tenant</option>
<option value="AZVM">AZ VMs</option>
<option value="AZRole">AZ Roles</option>
<option value="AZSubscription">AZ Subscriptions</option>
<option value="AZResourceGroup">AZ Resource Groups</option>
<option value="AZDevice">AZ Devices</option>
</optgroup>
</select>
<div class="relative w-56">
<input type="text" id="searchInput" placeholder="Search objects..."
class="bg-gray-800 text-white px-3 py-1.5 rounded text-xs w-full border border-gray-600 focus:outline-none focus:border-accent"
oninput="handleSearchInput()" onfocus="handleSearchInput()" onkeydown="handleSearchKeyDown(event)">
<ul id="searchSuggestions" class="absolute z-50 w-80 right-0 bg-gray-800 border border-gray-600 rounded mt-1 hidden max-h-72 overflow-y-auto shadow-xl"></ul>
</div>
<button onclick="findPathToDA()" class="bg-red-700 hover:bg-red-600 px-3 py-1.5 rounded text-xs font-bold transition">🔥 Find DA Path</button>
<button onclick="findAllPaths()" class="bg-orange-700 hover:bg-orange-600 px-3 py-1.5 rounded text-xs font-bold transition">All Paths</button>
</div>
</header>
<!-- ===== STATS BAR ===== -->
<div id="statsBar" class="hidden bg-gray-900 border-b border-gray-700 px-5 py-1.5 flex items-center gap-5 text-xs shrink-0 flex-wrap">
<span class="text-gray-400">Objects: <span id="statObjects" class="text-white font-bold">0</span></span>
<span class="text-gray-400">Edges: <span id="statEdges" class="text-white font-bold">0</span></span>
<span class="text-yellow-400">Kerberoastable: <span id="statKerb" class="font-bold">0</span></span>
<span class="text-orange-400">AS-REP Roastable: <span id="statAsrep" class="font-bold">0</span></span>
<span class="text-red-400">DCSync Risk: <span id="statDcsync" class="font-bold">0</span></span>
<span class="text-red-300">Critical ACLs: <span id="statAcls" class="font-bold">0</span></span>
<span class="text-purple-400">Unconstrained Deleg: <span id="statUnconstrained" class="font-bold">0</span></span>
<span class="text-orange-300">Cert Templates: <span id="statCerts" class="font-bold">0</span></span>
<span class="text-cyan-400">Relay Targets: <span id="statRelayTargets" class="font-bold">0</span></span>
<span class="text-cyan-300">WebClient: <span id="statWebClient" class="font-bold">0</span></span>
<span class="text-indigo-400">High-Risk ACLs: <span id="statExposureEdges" class="font-bold">0</span></span>
<span class="text-pink-400">Paths to DA: <span id="statPaths" class="font-bold">-</span></span>
<button onclick="findAllPaths(); switchTab('paths')" class="ml-auto text-xs text-gray-400 hover:text-white underline">Enumerate all paths</button>
</div>
<!-- ===== CONTROLS BAR ===== -->
<div class="bg-gray-800 border-b border-gray-700 py-1.5 px-4 flex flex-wrap items-center gap-3 shrink-0 text-xs">
<span class="text-gray-500 font-semibold">Filters:</span>
<label class="flex items-center gap-1 cursor-pointer hover:text-white text-gray-300">
<input type="checkbox" id="hideOrphans" checked class="accent-blue-600" onchange="renderGraph()"> Hide Orphans
</label>
<label class="flex items-center gap-1 cursor-pointer hover:text-white text-gray-300">
<input type="checkbox" id="showMemberOf" checked class="accent-blue-600" onchange="renderGraph()"> Structure
</label>
<label class="flex items-center gap-1 cursor-pointer hover:text-white text-gray-300">
<input type="checkbox" id="showAcls" checked class="accent-blue-600" onchange="renderGraph()"> ACLs
</label>
<label class="flex items-center gap-1 cursor-pointer hover:text-white text-gray-300">
<input type="checkbox" id="showExec" checked class="accent-blue-600" onchange="renderGraph()"> Exec/Admin
</label>
<div class="w-px h-4 bg-gray-600"></div>
<span class="text-accent font-semibold">Quick View:</span>
<select id="quickView" class="bg-gray-700 text-white rounded px-2 py-1 outline-none text-xs border border-gray-600 focus:border-accent" onchange="renderGraph()">
<option value="none">-- Show All --</option>
</select>
<div class="w-px h-4 bg-gray-600"></div>
<span class="text-gray-500">Layout:</span>
<select id="layoutSel" class="bg-gray-700 text-white rounded px-2 py-1 outline-none text-xs border border-gray-600 focus:border-accent" onchange="applyLayout()">
<option value="dagre">Hierarchical</option>
<option value="breadthfirst">Breadth-First</option>
<option value="cose">Force-Directed</option>
<option value="concentric" selected>Concentric</option>
<option value="grid">Grid</option>
</select>
<span class="text-gray-500">Labels:</span>
<select id="labelMode" class="bg-gray-700 text-white rounded px-2 py-1 outline-none text-xs border border-gray-600 focus:border-accent" onchange="updateLabels()">
<option value="short">Short</option>
<option value="full">Full</option>
<option value="type">Type Only</option>
</select>
<label class="flex items-center gap-1 cursor-pointer hover:text-white text-gray-300" title="Toggle node labels between display name and SID">
<input type="checkbox" id="showSidLabels" class="accent-blue-600" onchange="updateLabels()"> SID
</label>
<button onclick="resetView()" class="ml-auto bg-accent hover:bg-blue-500 text-white px-3 py-1 rounded text-xs transition">Fit View</button>
<button onclick="resetHighlight()" class="bg-gray-700 hover:bg-gray-600 text-white px-3 py-1 rounded text-xs transition">Clear Highlight</button>
<button id="exitFocusBtn" onclick="exitEgoNetwork()" class="hidden bg-yellow-600 hover:bg-yellow-500 text-white px-3 py-1 rounded text-xs font-bold transition">✖ Exit Focus</button>
</div>
<!-- ===== MAIN ===== -->
<main class="flex-1 flex overflow-hidden">
<!-- Left Panel -->
<div id="leftPanel" class="bg-panel flex flex-col border-r border-gray-700 shrink-0" style="width:310px; min-width:180px; max-width:550px;">
<!-- Tabs -->
<div class="flex border-b border-gray-700 shrink-0">
<button class="tab-btn active" id="tab-details" onclick="switchTab('details')">Details</button>
<button class="tab-btn" id="tab-paths" onclick="switchTab('paths')">Paths</button>
<button class="tab-btn" id="tab-stats" onclick="switchTab('stats')">Report</button>
<button class="tab-btn" id="tab-filter" onclick="switchTab('filter')">
Filter <span id="filterBadge" class="hidden ml-1 bg-accent text-white rounded-full px-1.5 text-xs font-bold"></span>
</button>
</div>
<!-- Details Pane -->
<div id="pane-details" class="flex-1 overflow-y-auto p-3">
<div class="text-gray-500 text-center text-xs mt-12">Click any node to inspect it</div>
</div>
<!-- Paths Pane -->
<div id="pane-paths" class="hidden flex-1 overflow-y-auto p-3">
<div class="text-gray-500 text-center text-xs mt-12">Use "Find DA Path" or "All Paths" above</div>
</div>
<!-- Stats Pane -->
<div id="pane-stats" class="hidden flex-1 overflow-y-auto p-3">
<div class="text-gray-500 text-center text-xs mt-12">Upload data to see risk report</div>
</div>
<!-- Filter Pane -->
<div id="pane-filter" class="hidden flex-1 overflow-y-auto p-3">
<div class="text-gray-500 text-center text-xs mt-12">Upload data to build filters</div>
</div>
</div>
<!-- Resizer -->
<div id="resizer" class="w-1 bg-gray-700 hover:bg-accent cursor-col-resize transition-colors shrink-0 z-20"></div>
<!-- Graph Panel -->
<div class="flex-1 relative overflow-hidden bg-dark">
<div id="cy"></div>
<div id="statusMessage" class="absolute inset-0 flex items-center justify-center text-gray-600 pointer-events-none font-semibold text-center px-10 text-sm">
Upload a SharpHound ZIP or JSON file to begin
</div>
<!-- Right-click context menu -->
<div id="ctxMenu" class="hidden absolute z-50 bg-gray-800 border border-gray-600 rounded shadow-xl text-xs w-48 py-1" style="min-width:170px">
<div id="ctxNodeName" class="px-3 py-1 text-gray-400 font-semibold truncate border-b border-gray-700 mb-1"></div>
<button class="ctx-item w-full text-left px-3 py-1.5 hover:bg-gray-700 text-gray-200" onclick="ctxCopyName()">📋 Copy Name</button>
<button class="ctx-item w-full text-left px-3 py-1.5 hover:bg-gray-700 text-gray-200" onclick="ctxToggleOwned()">☠ Toggle Owned</button>
<div class="border-t border-gray-700 my-1"></div>
<button class="ctx-item w-full text-left px-3 py-1.5 hover:bg-gray-700 text-gray-200" onclick="ctxFindPath()">🔥 Find DA Path from here</button>
<button class="ctx-item w-full text-left px-3 py-1.5 hover:bg-gray-700 text-gray-200" onclick="ctxShowDetails()">🔎 Inspect Node</button>
<div class="border-t border-gray-700 my-1"></div>
<button class="ctx-item w-full text-left px-3 py-1.5 hover:bg-gray-700 text-gray-200" onclick="ctxExpandNeighbors()">🌐 Expand Neighbors</button>
</div>
<!-- Developer credit -->
<a href="https://www.github.com/zrnge" target="_blank" rel="noopener"
class="absolute bottom-4 right-4 z-10 flex items-center gap-1.5 text-xs text-gray-600 hover:text-gray-300 transition select-none"
title="Built by zrnge">
<svg class="w-3.5 h-3.5 shrink-0" fill="currentColor" viewBox="0 0 24 24">
<path d="M12 0C5.37 0 0 5.37 0 12c0 5.303 3.438 9.8 8.205 11.387.6.113.82-.258.82-.577
0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61-.546-1.387-1.333-1.757-1.333-1.757
-1.089-.745.083-.729.083-.729 1.205.084 1.84 1.237 1.84 1.237 1.07 1.834 2.807 1.304
3.492.997.108-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931
0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322
3.301 1.23A11.509 11.509 0 0112 5.803c1.02.005 2.047.138 3.006.404
2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84
1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.922.43.372.823 1.102.823
2.222 0 1.606-.015 2.898-.015 3.293 0 .322.216.694.825.576C20.565 21.796
24 17.303 24 12 24 5.37 18.627 0 12 0z"/>
</svg>
<span>zrnge</span>
</a>
<!-- Legend -->
<div class="absolute bottom-4 left-4 bg-panel border border-gray-700 rounded p-2.5 text-xs text-gray-300 z-10 shadow-lg">
<div class="font-semibold text-gray-400 mb-1.5 border-b border-gray-700 pb-1">Legend</div>
<div class="flex items-center gap-1.5 mb-1"><span class="w-3 h-3 rounded-full inline-block bg-[#3498db]"></span>User</div>
<div class="flex items-center gap-1.5 mb-1"><span class="w-3 h-3 rounded-full inline-block bg-[#2ecc71]"></span>Group</div>
<div class="flex items-center gap-1.5 mb-1"><span class="w-3 h-3 rounded-sm inline-block bg-[#e67e22]"></span>Computer</div>
<div class="flex items-center gap-1.5 mb-1"><span class="w-3 h-3 rotate-45 inline-block bg-[#8e44ad]" style="display:inline-block;width:10px;height:10px;background:#8e44ad;transform:rotate(45deg)"></span> Domain</div>
<div class="flex items-center gap-1.5 mb-1"><span class="w-3 h-3 rounded-full inline-block bg-[#95a5a6]"></span>GPO/OU</div>
<div class="flex items-center gap-1.5 mb-1"><span class="w-3 h-3 rounded-full inline-block bg-[#d35400]"></span>Cert</div>
<div class="flex items-center gap-1.5 mb-1"><span class="w-3 h-3 rounded-sm inline-block bg-[#f1c40f] border border-[#e67e22]"></span>High Value</div>
<div class="flex items-center gap-1.5"><span class="w-3 h-3 rounded-full inline-block bg-[#c0392b]"></span>DCSync</div>
<div class="flex items-center gap-1.5 mt-1 border-t border-gray-700/50 pt-1"><span class="text-gray-500 text-xs">Azure:</span></div>
<div class="flex items-center gap-1.5"><span class="w-3 h-3 rounded-full inline-block bg-[#0078d4]"></span>AZ User</div>
<div class="flex items-center gap-1.5"><span class="w-3 h-3 rounded-full inline-block bg-[#00b4de]"></span>AZ Group</div>
<div class="flex items-center gap-1.5"><span class="w-3 h-3 rounded-full inline-block bg-[#9b59b6]"></span>AZ App</div>
<div class="flex items-center gap-1.5"><span class="w-3 h-3 rounded-full inline-block bg-[#8e44ad]"></span>AZ SP</div>
<div class="flex items-center gap-1.5"><span class="w-3 h-3 rounded-sm inline-block bg-[#e74c3c]"></span>AZ VM</div>
<div class="flex items-center gap-1.5"><span class="w-3 h-3 rounded-full inline-block bg-[#f39c12]"></span>AZ Role</div>
<div class="flex items-center gap-1.5"><span class="w-3 h-3 rounded-full inline-block bg-[#c0392b]"></span>AZ Tenant</div>
</div>
<!-- Zoom Controls -->
<div class="absolute bottom-4 right-4 flex gap-1 bg-panel border border-gray-700 rounded p-1 z-10 shadow-lg">
<button onclick="cy && cy.zoom(cy.zoom()*1.3); cy && cy.center()" class="bg-gray-700 hover:bg-gray-600 px-2.5 py-1 rounded font-bold text-sm transition">+</button>
<button onclick="cy && cy.zoom(cy.zoom()*0.77); cy && cy.center()" class="bg-gray-700 hover:bg-gray-600 px-2.5 py-1 rounded font-bold text-sm transition">−</button>
<button onclick="resetView()" class="bg-gray-700 hover:bg-gray-600 px-2 py-1 rounded text-xs transition">Fit</button>
</div>
</div>
</main>
<script>
// ================================================================
// DATA STORE
// ================================================================
let adNodes = {}; // id (uppercase) -> node object
let adEdges = []; // { from, to, label, isAcl, riskWeight }
let cy = null;
let foundPaths = [];
let ownedNodes = new Set(); // nodeIds marked as compromised
let loadErrors = []; // { filename, error, reason }
let unknownEdgeTypes = {}; // edgeType -> count
let sidIndex = {}; // SID (uppercase) -> node display-name key
let nameToSid = {}; // node display-name key -> SID (uppercase)
let gpoNames = {}; // GUID (upper, with braces) -> friendly name
// ── Pagination state ─────────────────────────────────────────────
let _pathsPage = 0;
const PATHS_PER_PAGE = 25;
const _riskExpanded = new Set(); // section titles that are fully expanded
function goPathsPage(p) {
_pathsPage = p;
renderPathsPanel();
document.getElementById('pane-paths')?.scrollTo({ top: 0, behavior: 'smooth' });
}
function toggleRiskSection(title) {
if (_riskExpanded.has(title)) _riskExpanded.delete(title);
else _riskExpanded.add(title);
renderRiskReport();
}
const _edgeSecPages = {}; // keyed "nodeId||title" → page index
const EDGE_SEC_PER_PAGE = 15;
function goEdgePage(nodeId, title, page) {
_edgeSecPages[nodeId + '||' + title] = page;
showNodeDetails(nodeId);
}
let activeFilters = {
excludeTypes: new Set(), // unchecked types → hidden
excludeDomains: new Set(), // unchecked domain names → hidden
includeOUs: new Set(), // selected OUs → show only their direct members (empty = all)
includeGroups: new Set(), // selected groups → show only their members (empty = all)
};
// ================================================================
// RISK ENGINE
// ================================================================
const EDGE_RISK = {
GenericAll:100, WriteDacl:90, WriteOwner:90, Owns:85,
ForceChangePassword:80, AddMember:75, AddKeyCredentialLink:90,
ReadLAPSPassword:70, AllExtendedRights:80, GenericWrite:80,
WriteProperty:65, AdminTo:85, CanRDP:50, ExecuteDCOM:55,
CanPSRemote:50, GetChangesAll:95, GetChanges:45,
AllowedToDelegate:70, AllowedToAct:75, ManageCA:90,
ManageCertificates:85, Enroll:50, TrustedBy:40,
GPLink:30, MemberOf:10, Contains:15, SQLAdmin:60, HasSession:35,
CanAbuseGPO:65, AddSelf:70, WriteAccountRestrictions:65,
WriteSPN:75, ReadGMSAPassword:85, AddAllowedToAct:80, AddMembers:75, DCSync:95,
// ADCS ESC edges
ADCSESC1:90, ADCSESC3:85, ADCSESC4:90, ADCSESC5:85, ADCSESC6:90,
ADCSESC7:85, ADCSESC8:90, ADCSESC9:80, ADCSESC10:80,
ADCSESC13:75, SyncLAPSPassword:80, WriteGPLink:70, CoerceToTGT:85,
// Azure edges
AZAddMembers:75, AZAddOwner:80, AZAddSecret:85, AZAvereContributor:70,
AZContributor:70, AZExecuteCommand:85, AZGetCertificates:75,
AZGetKeys:80, AZGetSecrets:80, AZGlobalAdmin:95, AZGrantAppRoles:85,
AZHasRole:60, AZMGAddMember:80, AZMGAddOwner:80, AZMGAddSecret:85,
AZMGGrantAppRoles:85, AZMGGrantRole:85, AZOwns:85,
AZPrivilegedRoleAdmin:90, AZResetPassword:80, AZUserAccessAdmin:85,
AZVMAdminLogin:80, AZVMContributor:70,
// Misc CE edges
SyncedToEntraUser:40, HostsCAService:60,
// Targeted Kerberoasting
SPNTarget:55,
// NTLM Relay
NTLMRelay:85
};
const HIGH_RISK_ACLS = new Set([
'GenericAll','WriteDacl','WriteOwner','Owns',
'ForceChangePassword','AddMember','AddKeyCredentialLink',
'ReadLAPSPassword','AllExtendedRights','GenericWrite',
'WriteProperty','AddSelf','WriteAccountRestrictions',
'WriteSPN','AddMembers','ReadGMSAPassword','AddAllowedToAct',
'ADCSESC1','ADCSESC3','ADCSESC4','ADCSESC6','ADCSESC8',
'AZGlobalAdmin','AZPrivilegedRoleAdmin','AZResetPassword',
'AZAddSecret','AZGetSecrets','AZGetKeys','WriteGPLink','CoerceToTGT','SyncLAPSPassword',
'NTLMRelay'
]);
const EDGE_DESCRIPTIONS = {
GenericAll: 'Full control over the object. Equivalent to all rights combined.',
WriteDacl: 'Can modify the DACL (permissions) of the object, granting any right.',
WriteOwner: 'Can take ownership of the object, then modify its DACL.',
Owns: 'Owns the object. Owner can modify the DACL unconditionally.',
ForceChangePassword: 'Can reset the account password without knowing the current one.',
AddMember: 'Can add members to the group.',
AddMembers: 'Can add members to the group.',
AddSelf: 'Can add yourself to the group.',
AddKeyCredentialLink: 'Can add a certificate credential (shadow credential) — leads to PKINIT auth without password.',
ReadLAPSPassword: 'Can read the local administrator LAPS password for this computer.',
ReadGMSAPassword: 'Can read the Group Managed Service Account password.',
AllExtendedRights: 'Has all extended rights — includes DCSync on domains, ForceChangePassword on users.',
GenericWrite: 'Can write to non-protected attributes, including servicePrincipalName (Kerberoast), scriptPath.',
WriteSPN: 'Can set/modify servicePrincipalName — enables targeted Kerberoasting.',
WriteProperty: 'Can write to a specific property of the object.',
WriteAccountRestrictions: 'Can modify the msDS-AllowedToActOnBehalfOfOtherIdentity attribute — enables RBCD.',
AddAllowedToAct: 'Can write to msDS-AllowedToActOnBehalfOfOtherIdentity — Resource-Based Constrained Delegation.',
AdminTo: 'Has local administrator access to the computer.',
CanRDP: 'Can initiate Remote Desktop (RDP) sessions to the computer.',
ExecuteDCOM: 'Can execute DCOM objects on the computer (lateral movement).',
CanPSRemote: 'Can open remote PowerShell sessions (WinRM) to the computer.',
SQLAdmin: 'Has sysadmin role on a SQL Server instance on this computer.',
GetChangesAll: 'Combined with GetChanges: enables DCSync — can replicate all domain secrets.',
GetChanges: 'Part of DCSync rights. Alone insufficient; combined with GetChangesAll enables full DCSync.',
DCSync: 'Can perform DCSync and retrieve all domain credentials (BloodHound CE edge).',
AllowedToDelegate: 'Constrained Kerberos delegation configured — can impersonate users to this service.',
AllowedToAct: 'Resource-Based Constrained Delegation (RBCD) — target trusts this principal to act on behalf of users.',
ManageCA: 'Has Manage CA right on the Certificate Authority — can approve requests, enable templates.',
ManageCertificates: 'Has Manage Certificates right — can approve pending certificate requests.',
Enroll: 'Can enroll in this certificate template.',
CanAbuseGPO: 'Can modify the GPO — will affect all objects in the linked OU/domain.',
TrustedBy: 'This domain is trusted by the target domain.',
GPLink: 'This GPO is linked to the domain/OU and affects all objects within it.',
MemberOf: 'Is a member of this group.',
Contains: 'This OU/Container contains this object.',
HasSession: 'A user session was observed on this computer.',
ADCSESC1: 'ESC1: User-supplied SAN in certificate request → impersonate any AD principal including Domain Admins.',
ADCSESC3: 'ESC3: Certificate template allows enrollment agent requests → enroll certs on behalf of other users.',
ADCSESC4: 'ESC4: Write access to a certificate template → modify to enable ESC1-style attack.',
ADCSESC5: 'ESC5: Weak PKI object ACLs (CA server, enrollment service) → can configure malicious templates.',
ADCSESC6: 'ESC6: CA has EDITF_ATTRIBUTESUBJECTALTNAME2 flag → attacker-supplied SAN in any request.',
ADCSESC7: 'ESC7: ManageCA right → can approve failed requests or set arbitrary flags.',
ADCSESC8: 'ESC8: NTLM relay to AD CS HTTP enrollment → obtain cert for any machine account.',
ADCSESC9: 'ESC9: No-security-extension on template + GenericWrite → shadow credential attack variant.',
ADCSESC10: 'ESC10: Weak certificate mapping on DC → use any UPN cert to authenticate.',
ADCSESC13: 'ESC13: Issuance policy linked to a group → enroll cert to gain group membership.',
SyncLAPSPassword:'Can synchronize LAPS password — allows reading the local administrator password.',
WriteGPLink: 'Can link a GPO to this OU/domain — allows applying malicious policy to all contained objects.',
CoerceToTGT: 'Can coerce Kerberos TGT delegation (e.g. via printer bug/PetitPotam) — enables credential theft.',
AZGlobalAdmin: 'Azure Global Administrator — highest Azure AD privilege, full tenant control.',
AZPrivilegedRoleAdmin: 'Can assign any Azure AD role including Global Admin.',
AZResetPassword:'Can reset the target Azure AD user password.',
AZAddSecret: 'Can add a client secret to an Azure AD application — enables authentication as the app.',
AZGetSecrets: 'Can read Key Vault secrets.',
AZGetKeys: 'Can read Key Vault cryptographic keys.',
AZGetCertificates: 'Can read Key Vault certificates.',
AZExecuteCommand: 'Can execute commands on an Azure VM (Run Command).',
AZVMAdminLogin: 'Can log into Azure VM as administrator via AAD-joined VM login.',
AZOwns: 'Owns an Azure AD object — can modify it unconditionally.',
AZAddMembers: 'Can add members to an Azure AD group.',
AZAddOwner: 'Can add an owner to an Azure AD application or group.',
AZMGAddMember: 'Microsoft Graph app role: can add members to groups.',
AZMGGrantRole: 'Microsoft Graph app role: can grant directory roles.',
AZContributor: 'Azure Contributor role on a resource — broad write/exec access.',
AZHasRole: 'Holds an Azure RBAC role on a resource.',
SyncedToEntraUser: 'On-premises AD account synced to Entra ID (Azure AD).',
HostsCAService: 'Computer hosts the Active Directory Certificate Services CA role.',
SPNTarget: 'This service account has an SPN targeting this computer — Kerberoastable against this specific service.',
NTLMRelay: 'NTLM credential relayed to this host — SMB signing not required, allowing an attacker to authenticate as the coerced machine account and execute commands or write ACLs.',
};
const EDGE_MITRE = {
AdminTo: 'T1021.001 – Remote Services: RDP / T1078 – Valid Accounts',
CanRDP: 'T1021.001 – Remote Services: Remote Desktop Protocol',
ExecuteDCOM: 'T1021.003 – Remote Services: DCOM',
CanPSRemote: 'T1021.006 – Remote Services: Windows Remote Management',
ForceChangePassword:'T1098 – Account Manipulation',
AddMember: 'T1098.007 – Account Manipulation: Additional Group Membership',
AddMembers: 'T1098.007 – Account Manipulation: Additional Group Membership',
AddSelf: 'T1098.007 – Account Manipulation: Additional Group Membership',
AddKeyCredentialLink:'T1556.006 – Modify Authentication Process: Multi-Factor Authentication',
GenericAll: 'T1078 – Valid Accounts / T1484 – Domain Policy Modification',
GenericWrite: 'T1098 – Account Manipulation / T1547 – Boot or Logon Autostart',
WriteSPN: 'T1558.003 – Steal or Forge Kerberos Tickets: Kerberoasting',
WriteOwner: 'T1222 – File and Directory Permissions Modification',
WriteDacl: 'T1222 – File and Directory Permissions Modification',
Owns: 'T1222 – File and Directory Permissions Modification',
GetChanges: 'T1003.006 – OS Credential Dumping: DCSync',
GetChangesAll: 'T1003.006 – OS Credential Dumping: DCSync',
DCSync: 'T1003.006 – OS Credential Dumping: DCSync',
ReadLAPSPassword: 'T1552.001 – Unsecured Credentials: Credentials in Files',
ReadGMSAPassword: 'T1552 – Unsecured Credentials',
SyncLAPSPassword: 'T1552.001 – Unsecured Credentials: Credentials in Files',
AllowedToDelegate: 'T1558.001 – Steal or Forge Kerberos Tickets: Golden Ticket',
AllowedToAct: 'T1558 – Steal or Forge Kerberos Tickets: RBCD',
AddAllowedToAct: 'T1558 – Steal or Forge Kerberos Tickets: RBCD',
WriteAccountRestrictions: 'T1558 – Steal or Forge Kerberos Tickets: RBCD',
ManageCA: 'T1649 – Steal or Forge Authentication Certificates',
ManageCertificates: 'T1649 – Steal or Forge Authentication Certificates',
Enroll: 'T1649 – Steal or Forge Authentication Certificates',
ADCSESC1: 'T1649 – Steal or Forge Authentication Certificates',
ADCSESC3: 'T1649 – Steal or Forge Authentication Certificates',
ADCSESC4: 'T1649 – Steal or Forge Authentication Certificates',
ADCSESC6: 'T1649 – Steal or Forge Authentication Certificates',
ADCSESC8: 'T1557 – Adversary-in-the-Middle / T1649',
CoerceToTGT: 'T1187 – Forced Authentication',
CanAbuseGPO: 'T1484.001 – Domain Policy Modification: Group Policy Modification',
WriteGPLink: 'T1484.001 – Domain Policy Modification: Group Policy Modification',
HasSession: 'T1563 – Remote Service Session Hijacking',
SQLAdmin: 'T1505.001 – Server Software Component: SQL Stored Procedures',
AZResetPassword: 'T1098 – Account Manipulation',
AZAddSecret: 'T1098.001 – Account Manipulation: Additional Cloud Credentials',
AZExecuteCommand: 'T1651 – Cloud Administration Command',
AZVMAdminLogin: 'T1078.004 – Valid Accounts: Cloud Accounts',
AZGetSecrets: 'T1552.001 – Unsecured Credentials',
SPNTarget: 'T1558.003 – Steal or Forge Kerberos Tickets: Kerberoasting',
NTLMRelay: 'T1557.001 – Adversary-in-the-Middle: LLMNR/NBT-NS Poisoning and SMB Relay',
3CAA
};
const EXEC_EDGES = new Set([
'AdminTo','CanRDP','ExecuteDCOM','CanPSRemote',
'AllowedToDelegate','AllowedToAct','SQLAdmin','HasSession','CanAbuseGPO'
]);
const ACL_EDGES = new Set([
...HIGH_RISK_ACLS,
'GetChanges','GetChangesAll','Enroll','ManageCA','ManageCertificates'
]);
function calcNodeRisk(node) {
let score = 0;
const flags = [];
const p = node.props || {};
if (p.hasspn && p.enabled !== false) { score += 40; flags.push('Kerberoastable'); }
if (p.dontreqpreauth && p.enabled !== false) { score += 45; flags.push('AS-REP Roastable'); }
if (p.unconstraineddelegation) { score += 60; flags.push('Unconstrained Delegation'); }
if (p.constraineddelegation) { score += 30; flags.push('Constrained Delegation'); }
if (p.pwdneverexpires && p.enabled !== false){ score += 20; flags.push('Password Never Expires'); }
if (p.admincount) { score += 15; flags.push('AdminCount=1'); }
if (p.sidhistory && p.sidhistory.length > 0) { score += 35; flags.push('SID History'); }
if (p.dontexpirepassword) { score += 10; }
if (p.enabled === false) { score -= 40; flags.push('Disabled'); }
if (p.isdeleted) { score -= 50; flags.push('Deleted');
8020
span> }
if (node.isAdmin) { score += 50; }
if (node.canDCSync) { score += 95; }
// Computer-specific: NTLM relay surface
if (node.type === 'Computer') {
if (p.signing === false || p.signingrequired === false) { score += 30; flags.push('SMB Relay Target'); }
if (p.smb1enabled === true) { score += 20; flags.push('SMBv1 Enabled'); }
if (p.webclient === true) { score += 25; flags.push('WebClient Running'); }
}
return { score: Math.max(0, Math.min(100, score)), flags };
}
function getRiskColor(score) {
if (score >= 70) return '#e74c3c';
if (score >= 40) return '#e67e22';
if (score >= 20) return '#f1c40f';
return '#2ecc71';
}
function getRiskLabel(score) {
if (score >= 70) return 'Critical';
if (score >= 40) return 'High';
if (score >= 20) return 'Medium';
return 'Low';
}
// ================================================================
// PARSING
// ================================================================
function parseFile(json, filename) {
// Detect schema version and type from meta block (SharpHound v3/v4/v5)
const meta = json.meta || {};
// schemaVersion available for future version-specific handling
// const schemaVersion = meta.version || 3;
// BloodHound v4/v5: graph object with nodes/edges
if (json.graph && (json.graph.nodes || json.graph.edges || json.graph.relationships)) {
parseV4Graph(json.graph);
return;
}
// BloodHound v4 alternate: top-level nodes/relationships
if (json.nodes && json.relationships) {
parseV4Graph(json);
return;
}
let items = json.data || (Array.isArray(json) ? json : []);
if (items.length === 0) return;
// AzureHound v2 format: each item has { kind, data } — route to dedicated parser
if (items[0] && items[0].kind !== undefined && items[0].data !== undefined) {
parseAzureHound(items);
return;
}
const fn = filename.toLowerCase();
// Prefer meta.type for accurate file type detection (v5: "users", "computers", etc.)
const metaType = (meta.type || '').toLowerCase();
let fileType = 'Unknown';
if (metaType === 'users' || (!metaType && fn.includes('user'))) fileType = 'User';
else if (metaType === 'groups' || (!metaType && fn.includes('group'))) fileType = 'Group';
else if (metaType === 'computers' || (!metaType && fn.includes('computer'))) fileType = 'Computer';
else if (metaType === 'domains' || (!metaType && fn.includes('domain'))) fileType = 'Domain';
else if (metaType === 'gpos' || (!metaType && fn.includes('gpo'))) fileType = 'GPO';
else if (metaType === 'ous' || (!metaType && fn.includes('ou'))) fileType = 'OU';
else if (metaType === 'certtemplates'|| (!metaType &&
4EF6
fn.includes('cert'))) fileType = 'CertTemplate';
else if (metaType === 'containers' || (!metaType && fn.includes('container'))) fileType = 'Container';
else if (metaType === 'azddevices' || metaType === 'azdevices' || fn.includes('azdevice')) fileType = 'AZDevice';
else if (metaType === 'azusers' || fn.includes('azuser')) fileType = 'AZUser';
else if (metaType === 'azgroups' || fn.includes('azgroup')) fileType = 'AZGroup';
else if (metaType === 'azapps' || fn.includes('azapp')) fileType = 'AZApp';
else if (metaType === 'azserviceprincipals' || fn.includes('azserviceprincipal')) fileType = 'AZServicePrincipal';
else if (metaType === 'aztenants' || fn.includes('aztenant')) fileType = 'AZTenant';
else if (metaType === 'azsubscriptions' || fn.includes('azsubscription')) fileType = 'AZSubscription';
else if (metaType === 'azresourcegroups' || fn.includes('azresourcegroup')) fileType = 'AZResourceGroup';
else if (metaType === 'azvms' || fn.includes('azvm') || fn.includes('az_vm')) fileType = 'AZVM';
else if (metaType === 'azkeyvaults' || fn.includes('azkeyvault')) fileType = 'AZKeyVault';
else if (metaType === 'azmanagementgroups' || fn.includes('azmanagementgroup')) fileType = 'AZMgmtGroup';
else if (metaType) fileType = metaType.charAt(0).toUpperCase() + metaType.slice(1);
items.forEach(item => {
const props = item.Properties || {};
const rawName = props.name || item.ObjectIdentifier || item.Name || '';
const name = rawName.toUpperCase();
if (!name) return;
// Detect type from item.ObjectType if available
let detectedType = fileType;
if (item.ObjectType) {
const ot = item.ObjectType.toLowerCase();
if (ot === 'user') detectedType = 'User';
else if (ot === 'group') detectedType = 'Group';
else if (ot === 'computer') detectedType = 'Computer';
else if (ot === 'domain') detectedType = 'Domain';
else if (ot === 'gpo') detectedType = 'GPO';
else if (ot === 'ou') detectedType = 'OU';
else if (ot === 'certtemplate') detectedType = 'CertTemplate';
else if (ot === 'container') detectedType = 'Container';
}
const isAdmin = name.includes('DOMAIN ADMINS') ||
name.includes('ENTERPRISE ADMINS') ||
name.includes('ADMINISTRATORS') ||
props.highvalue === true;
if (!adNodes[name]) {
adNodes[name] = { name, type: detectedType, isAdmin, props: { ...props } };
} else {
Object.assign(adNodes[name].props, props);
if (!adNodes[name].isAdmin) adNodes[name].isAdmin = isAdmin;
if (adNodes[name].type === 'Unknown') adNodes[name].type = detectedType;
}
// Store ObjectIdentifier as secondary resolution key (_oid).
// SharpHound uses item.ObjectIdentifier (SID or GUID) as the canonical ID
// in all relationship arrays, but Properties.objectsid may be absent or differ.
const oid = (item.ObjectIdentifier || '').toUpperCase();
if (oid && oid !== name) {
adNodes[name].props._oid = oid;
}
// Top-level flags not present in Properties block
if (item.IsACLProtected != null) adNodes[name].props.isaclprotected = item.IsACLProtected;
if (item.IsDeleted != null) adNodes[name].props.isdeleted = item.IsDeleted;
const addEdge = (from, to, label, isAcl = false) => {
from = from.toUpperCase();
to = to.toUpperCase();
if (!from || !to || from === to) return;
if (!adNodes[from]) adNodes[from] = { name: from, type: 'Unknown', isAdmin: false, props: {} };
if (!adNodes[to]) adNodes[to] = { name: to, type: 'Unknown', isAdmin: false, props: {} };
if (label && !(label in EDGE_RISK)) {
unknownEdgeTypes[label] = (unknownEdgeTypes[label] || 0) + 1;
}
if (!adEdges.some(e => e.from === from && e.to === to && e.label === label)) {
adEdges.push({ from, to, label, isAcl, riskWeight: EDGE_RISK[label] || 10 });
}
};
const parseArr = (arr, label, reverse = false) => {
const list = Array.isArray(arr) ? arr : (arr?.Results || []);
list.forEach(t => {
const tid = (t.ObjectIdentifier || t.TargetId || t.GUID || '').toUpperCase();
if (!tid) return;
reverse ? addEdge(tid, name, label) : addEdge(name, tid, label);
});
};
parseArr(item.Members, 'MemberOf', false);
parseArr(item.LocalAdmins, 'AdminTo', true);
parseArr(item.RemoteDesktopUsers,'CanRDP', true);
parseArr(item.DcomUsers, 'ExecuteDCOM', true);
parseArr(item.PSRemoteUsers, 'CanPSRemote', true);
parseArr(item.AllowedToDelegate,'AllowedToDelegate', false);
parseArr(item.AllowedToAct, 'AllowedToAct', true);
parseArr(item.Links, 'GPLink', false);
parseArr(item.AllowedToEnroll, 'Enroll', true);
parseArr(item.SQLAdmins, 'SQLAdmin', true);
parseArr(item.ChildObjects, 'Contains', false);
// ── AzureHound-specific relationship arrays ──────────────
// These keys are only present in AzureHound output; absent keys are silently ignored.
parseArr(item.Owners, 'AZOwns', true);
parseArr(item.Contributors, 'AZContributor', true);
parseArr(item.UserAccessAdmins, 'AZUserAccessAdmin', true);
parseArr(item.AddMembers, 'AZAddMembers', true);
parseArr(item.AddOwners, 'AZAddOwner', true);
parseArr(item.GlobalAdmins, 'AZGlobalAdmin', true);
parseArr(item.PrivilegedRoleAdmins,'AZPrivilegedRoleAdmin', true);
parseArr(item.ResetPasswords, 'AZResetPassword', true);
parseArr(item.AddSecrets, 'AZAddSecret', true);
parseArr(item.GetSecretUsers, 'AZGetSecrets', true);
parseArr(item.GetKeyUsers, 'AZGetKeys', true);
parseArr(item.GetCertificateUsers, 'AZGetCertificates', true);
parseArr(item.VMAdmins, 'AZVMAdminLogin', true);
parseArr(item.RunCommandAdmins, 'AZExecuteCommand', true);
parseArr(item.GrantAppRoles, 'AZGrantAppRoles', true);
parseArr(item.AppRoleAssignments, 'AZGrantAppRoles', false);
parseArr(item.InboundTransitiveRoles, 'AZHasRole', false);
// AZTenant is the Azure root — treat as high value (DA equivalent)
if (detectedType === 'AZTenant') {
adNodes[name].isAdmin = true;
adNodes[name].props.highvalue = true;
}
// GPOChanges: GPO-applied rights present on OU/Domain nodes
if (item.GPOChanges) {
const gc = item.GPOChanges;
const affected = (gc.AffectedComputers || [])
.map(c => (c.ObjectIdentifier || '').toUpperCase()).filter(Boolean);
if (affected.length) {
const _gcArr = (arr) => Array.isArray(arr) ? arr : (arr?.Results || []);
const _gcEdges = (arr, label) => _gcArr(arr).forEach(p => {
const pid = (p.ObjectIdentifier || '').toUpperCase();
if (pid) affected.forEach(cid => addEdge(pid, cid, label, false));
});
_gcEdges(gc.LocalAdmins, 'AdminTo');
_gcEdges(gc.RemoteDesktopUsers, 'CanRDP');
_gcEdges(gc.DcomUsers, 'ExecuteDCOM');
_gcEdges(gc.PSRemoteUsers, 'CanPSRemote');
}
}
// PrimaryGroupSID: implicit group membership not expressed as an explicit MemberOf edge
if (item.PrimaryGroupSID) {
const pgSid = item.PrimaryGroupSID.toUpperCase();
if (pgSid) addEdge(name, pgSid, 'MemberOf', false);
}
// SPNTargets: targeted Kerberoasting — service account can impersonate these targets
if (Array.isArray(item.SPNTargets)) {
item.SPNTargets.forEach(t => {
const tid = (t.ComputerSID || t.ObjectIdentifier || '').toUpperCase();
if (tid) addEdge(name, tid, 'SPNTarget', false);
});
}
// Capture GPO friendly name for GUID resolution
if (detectedType === 'GPO' && props.name) {
const guid = (item.ObjectIdentifier || '').toUpperCase();
if (guid) gpoNames[guid] = props.name;
}
// ACEs
(item.Aces || []).forEach(ace => {
const pId = (ace.PrincipalSID || ace.PrincipalName || '').toUpperCase();
const right = ace.RightName || ace.AceType || '';
if (pId && right) {
if (!adNodes[pId]) adNodes[pId] = {
name: pId, type: ace.PrincipalType || 'Unknown', isAdmin: false, props: {}
};
addEdge(pId, name, right, HIGH_RISK_ACLS.has(right));
}
});
// Sessions — handle both {Results:[...]} and direct array formats across SH versions
const _sessList = (src) => Array.isArray(src) ? src : (src?.Results || []);
const _sesUser = (s) => (s.UserSID || s.UserId || s.User || s.ObjectIdentifier || '').toUpperCase();
_sessList(item.Sessions).forEach(s => {
const user = _sesUser(s); if (user) addEdge(name, user, 'HasSession', false);
});
_sessList(item.PrivilegedSessions).forEach(s => {
const user = _sesUser(s); if (user) addEdge(name, user, 'HasSession', false);
});
_sessList(item.RegistrySessions).forEach(s => {
const user = _sesUser(s); if (user) addEdge(name, user, 'HasSession', false);
});
// Domain trusts
(item.Trusts || []).forEach(trust => {
const target = (trust.TargetDomainName || '').toUpperCase();
if (!target) return;
const dir = trust.TrustDirection;
if (dir === 1 || dir === 3 || dir === 'Inbound' || dir === 'Bidirectional')
addEdge(target, name, 'TrustedBy');
if (dir === 2 || dir === 3 || dir === 'Outbound' || dir === 'Bidirectional')
addEdge(name, target, 'TrustedBy');
});
});
}
function parseV4Graph(graph) {
(graph.nodes || []).forEach(node => {
const id = (node.id || '').toUpperCase();
const props = node.properties || {};
const name = (props.name || id).toUpperCase();
const type = (node.label || node.type || 'Unknown');
const isAdmin = props.highvalue ||
name.includes('DOMAIN ADMINS') ||
name.includes('ENTERPRISE ADMINS');
if (id) adNodes[id] = { name, type, isAdmin, props };
});
const rels = graph.edges || graph.relationships || [];
rels.forEach(edge => {
const from = (edge.startNode || edge.source || edge.start || '').toUpperCase();
const to = (edge.endNode || edge.target || edge.end || '').toUpperCase();
const label = edge.type || edge.label || '';
if (from && to && label) {
if (!adEdges.some(e => e.from === from && e.to === to && e.label === label)) {
adEdges.push({
from, to, label,
isAcl: HIGH_RISK_ACLS.has(label),
riskWeight: EDGE_RISK[label] || 10
});
}
}
});
}
// ================================================================
// AZUREHOUND PARSER
// Handles AzureHound v2 output: flat data[] array of {kind, data} objects
// ================================================================
function parseAzureHound(items) {
const ROLE_EDGE_MAP = {
'62e90394-69f5-4237-9190-012177145e10': 'AZGlobalAdmin',
'e8611ab8-c189-46e8-94e1-60213ab1f814': 'AZPrivilegedRoleAdmin',
};
const HIGH_VALUE_ROLE_IDS = new Set([
'62e90394-69f5-4237-9190-012177145e10',
'e8611ab8-c189-46e8-94e1-60213ab1f814',
'9b895d92-2cd3-44c7-9d02-a6ac2d5ea5c3',
'7be44c8a-adaf-4e2a-84d6-ab2649e08a13',
'194ae4cb-b126-40b2-bd5b-6091b380977d',
'158c047a-c907-4556-b7ef-446551a6b5f7',
]);
const NODE_KINDS = new Set([
'AZTenant','AZUser','AZGroup','AZApp','AZServicePrincipal',
'AZSubscription','AZResourceGroup','AZVM','AZRole','AZDevice',
'AZKeyVault','AZManagedIdentity','AZFunctionApp','AZLogicApp',
'AZContainerRegistry','AZWebApp','AZAutomationAccount',
]);
const addAZEdge = (from, to, label, isAcl = false) => {
from = (from || '').toUpperCase();
to = (to || '').toUpperCase();
if (!from || !to || from === to) return;
if (!adNodes[from]) adNodes[from] = { name: from, displayName: from, type: 'Unknown', isAdmin: f
4EF6
alse, props: {} };
if (!adNodes[to]) adNodes[to] = { name: to, displayName: to, type: 'Unknown', isAdmin: false, props: {} };
if (label && !(label in EDGE_RISK)) unknownEdgeTypes[label] = (unknownEdgeTypes[label] || 0) + 1;
if (!adEdges.some(e => e.from === from && e.to === to && e.label === label))
adEdges.push({ from, to, label, isAcl, riskWeight: EDGE_RISK[label] || 10 });
};
// First pass: create node objects.
// AzureHound uses data.id for most kinds; AZTenant uses data.tenantId; AZSubscription uses data.subscriptionId.
items.forEach(item => {
if (!NODE_KINDS.has(item.kind)) return;
const d = item.data || {};
let rawId;
if (item.kind === 'AZTenant') rawId = d.tenantId;
else if (item.kind === 'AZSubscription') rawId = d.subscriptionId;
else rawId = d.id;
const id = (rawId || '').toUpperCase();
if (!id) return;
// displayName field is lowercase in AzureHound; VMs and ResourceGroups use .name
const displayName = d.displayName || d.name || id;
const roleIdLower = item.kind === 'AZRole' ? id.toLowerCase() : '';
const isHighValue = item.kind === 'AZTenant' || HIGH_VALUE_ROLE_IDS.has(roleIdLower);
if (!adNodes[id]) {
adNodes[id] = {
name: id,
displayName,
type: item.kind,
isAdmin: isHighValue,
props: { name: displayName }
};
} else {
if (!adNodes[id].displayName || adNodes[id].displayName === id) adNodes[id].displayName = displayName;
adNodes[id].props.name = adNodes[id].displayName;
adNodes[id].type = item.kind;
if (isHighValue) adNodes[id].isAdmin = true;
}
if (isHighValue) adNodes[id].props.highvalue = true;
});
// Second pass: edges. All relationship kinds use nested arrays in AzureHound output.
items.forEach(item => {
const d = item.data || {};
switch (item.kind) {
case 'AZGroupMember':
// d.members is an array of {id, ...} or null
(d.members || []).forEach(m => addAZEdge(m.id, d.groupId, 'MemberOf'));
break;
case 'AZGroupOwner':
// d.owners is an array of {id, ...} or null
(d.owners || []).forEach(o => addAZEdge(o.id, d.groupId, 'AZOwns', true));
break;
case 'AZAppOwner':
// d.owners[i].owner.id = owner object ID; d.owners[i].appId = target app object ID
(d.owners || []).forEach(o => addAZEdge(o.owner && o.owner.id, o.appId, 'AZOwns', true));
break;
case 'AZServicePrincipalOwner':
// same nested pattern as AZAppOwner
(d.owners || []).forEach(o => {
const ownerId = (o.owner && (o.owner.id || (o.owner.properties && o.owner.properties.principalId)));
addAZEdge(ownerId, o.servicePrincipalId || d.servicePrincipalId, 'AZOwns', true);
});
break;
case 'AZVMOwner':
// d.owners[i].owner.properties.principalId → d.owners[i].virtualMachineId
(d.owners || []).forEach(o => {
const principalId = o.owner && o.owner.properties && o.owner.properties.principalId;
addAZEdge(principalId, o.virtualMachineId || d.virtualMachineId, 'AZOwns', true);
});
break;
case 'AZVMUserAccessAdmin':
(d.userAccessAdmins || []).forEach(ua => {
const principalId = ua.userAccessAdmin && ua.userAccessAdmin.properties && ua.userAccessAdmin.properties.principalId;
addAZEdge(principalId, ua.virtualMachineId || d.virtualMachineId, 'AZUserAccessAdmin', true);
});
break;
case 'AZSubscriptionOwner':
// subscriptionId in relationships is the ARM path (/subscriptions/<guid>)
// but the AZSubscription node was keyed by just the bare GUID — strip the prefix.
(d.owners || []).forEach(o => {
const principalId = o.owner && o.owner.properties && o.owner.properties.principalId;
const rawSubId = o.subscriptionId || d.subscriptionId || '';
const subId = rawSubId.replace(/^\/subscriptions\//i, '');
addAZEdge(principalId, subId, 'AZOwns', true);
});
break;
case 'AZResourceGroupOwner':
(d.owners || []).forEach(o => {
const principalId = o.owner && o.owner.properties && o.owner.properties.principalId;
addAZEdge(principalId, o.resourceGroupId || d.resourceGroupId, 'AZOwns', true);
});
break;
case 'AZResourceGroupUserAccessAdmin':
(d.userAccessAdmins || []).forEach(ua => {
const principalId = ua.userAccessAdmin && ua.userAccessAdmin.properties && ua.userAccessAdmin.properties.principalId;
addAZEdge(principalId, ua.resourceGroupId || d.resourceGroupId, 'AZUserAccessAdmin', true);
});
break;
case 'AZRoleAssignment':
// d.roleAssignments[i].principalId → d.roleAssignments[i].roleDefinitionId
(d.roleAssignments || []).forEach(ra => {
if (!ra.principalId || !ra.roleDefinitionId) return;
const edgeLabel = ROLE_EDGE_MAP[ra.roleDefinitionId.toLowerCase()] || 'AZHasRole';
addAZEdge(ra.principalId, ra.roleDefinitionId, edgeLabel, edgeLabel !== 'AZHasRole');
});
break;
case 'AZMGGrantAppRoles':
addAZEdge(d.appId, d.targetAppId, 'AZMGGrantAppRoles', true);
break;
case 'AZMGGrantRole':
addAZEdge(d.appId, d.roleId, 'AZMGGrantRole', true);
break;
case 'AZMGAddOwner':
addAZEdge(d.appId, d.targetId, 'AZMGAddOwner', true);
break;
case 'AZMGAddMember':
addAZEdge(d.appId, d.targetId, 'AZMGAddMember', true);
break;
case 'AZMGAddSecret':
addAZEdge(d.appId, d.targetId, 'AZMGAddSecret', true);
break;
}
});
}
// ================================================================
// SID RESOLUTION
// ================================================================
function resolveEdges() {
// SharpHound stores relationships using SIDs/GUIDs but names nodes by display-name.
// Build a unified lookup: SID/GUID → display-name key.
// Priority order: props.objectsid → props._oid (item.ObjectIdentifier stored during parse)
const sidMap = {};
for (const [key, node] of Object.entries(adNodes)) {
const sid = (node.props?.objectsid || node.props?.domainsid || '').toUpperCase();
if (sid && sid !== key && !sidMap[sid]) sidMap[sid] = key;
// ObjectIdentifier (canonical SID or GUID) stored during parsing
const oid = (node.props?._oid || '').toUpperCase();
if (oid && oid !== key && !sidMap[oid]) sidMap[oid] = key;
}
for (const edge of adEdges) {
for (const side of ['from', 'to']) {
const resolved = sidMap[edge[side]];
if (!resolved) continue;
// Merge any ghost SID-keyed node into the real named node
const ghost = adNodes[edge[side]];
if (ghost && ghost.name === edge[side]) {
const real = adNodes[resolved];
if (real) {
if (ghost.isAdmin) real.isAdmin = true;
if (ghost.canDCSync) real.canDCSync = true;
if (ghost.riskFlags?.length)
real.riskFlags = [...new Set([...(real.riskFlags||[]), ...ghost.riskFlags])];
delete adNodes[edge[side]];
}
}
edge[side] = resolved;