/
vader.py
2806 lines (2004 loc) · 98.3 KB
/
vader.py
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
# Vader.py - Tkinter Frontend for Empire Project
# v1.0.3.2018
# @badhackjob
import Tkinter
from Tkinter import *
import ttk
import tkFont
from ScrolledText import ScrolledText
from empire_api_core import empire_api_core
from Queue import Queue
from threading import Thread
import tkMessageBox
import time
import ast
from ast import *
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
import os
# task all shell command class POPUP
class api_task_all_agents_run_shell_popup:
def __init__(self,parent):
top = self.top = Tkinter.Toplevel(parent)
self.task_all_agents_shell_popup_label = Tkinter.Label(self.top, text = "Shell Command: ")
self.task_all_agents_shell_popup_label.grid(row=0,column=0,sticky=W,padx=10,pady=10)
self.task_all_agents_shell_entry = Tkinter.Entry(self.top,width=40)
self.task_all_agents_shell_entry.grid(row=0,column=1,sticky=NW,padx=5,pady=5,columnspan=15)
self.task_all_agents_shell_action_button = Tkinter.Button(self.top,text = "Send Command",command=self.send)
self.task_all_agents_shell_action_button.grid(row=1,column=1,sticky=NW,padx=10,pady=10)
self.task_all_agents_shell_cancel_button = Tkinter.Button(self.top,text = "Cancel", command = self.top.destroy)
self.task_all_agents_shell_cancel_button.grid(row=1,column=2,sticky=NW,padx=10,pady=10)
def send(self):
self.command = self.task_all_agents_shell_entry.get()
self.top.destroy()
# rename agent class POPUP
class api_rename_agent_popup:
def __init__(self,parent):
top = self.top = Tkinter.Toplevel(parent)
self.rename_agent_label = Tkinter.Label(self.top, text = "New Agent Name: ")
self.rename_agent_label.grid(row=0,column=0,sticky=W,padx=10,pady=10)
self.rename_agent_entry = Tkinter.Entry(self.top,width=40)
self.rename_agent_entry.grid(row=0,column=1,sticky=NW,padx=5,pady=5,columnspan=15)
self.rename_agent_action_button = Tkinter.Button(self.top,text = "Rename Agent",command=self.send)
self.rename_agent_action_button.grid(row=1,column=1,sticky=NW,padx=10,pady=10)
self.rename_agent_cancel_button = Tkinter.Button(self.top,text = "Cancel", command = self.top.destroy)
self.rename_agent_cancel_button.grid(row=1,column=2,sticky=NW,padx=10,pady=10)
def send(self):
self.new_name = self.rename_agent_entry.get()
self.top.destroy()
# stagers results window
class stagers_results_window:
def __init__(self,parent,response,launcher,outfile):
# define the window
top = self.top = Tkinter.Toplevel(parent)
top.grid_columnconfigure(0,weight=1)
top.grid_rowconfigure(1,weight=1)
title = Tkinter.Label(self.top,text=launcher + " Output: ")
title.grid(row=0,column=0,sticky=W)
# track row position in table
row_count = 2
# for key,value in response:
# we have to do some digging here
for key,value in response[launcher].iteritems():
# check if Output, display accordingly
if key == "Output":
if outfile != "":
try:
f = open(outfile,"w")
f.write(str(value))
f.close()
scrolltext = ScrolledText(self.top,height=12,width=100)
scrolltext.config(state="normal")
scrolltext.grid(row=1,column=0,sticky='NEWS',columnspan=3)
scrolltext.insert(Tkinter.END,"[*] Stager Output File created at " + outfile)
except Exception as e:
scrolltext = ScrolledText(self.top,height=12,width=100)
scrolltext.config(state="normal")
scrolltext.grid(row=1,column=0,sticky='NEWS',columnspan=3)
scrolltext.insert(Tkinter.END,"[!!] Exception on Outfile create: " + str(e))
else:
scrolltext = ScrolledText(self.top,height=12,width=100)
scrolltext.config(state="normal")
scrolltext.grid(row=1,column=0,sticky='NEWS',columnspan=3)
scrolltext.insert(Tkinter.END,str(value))
# increment row count
row_count += 1
# option to save results to file
def savefile(self):
file_name = tkFileDialog.asksaveasfile(mode='w',defaultextension=".txt")
agent_results = self.results
try:
file_name.write(agent_results)
file_name.close()
except: pass;
# reporting event details window
class reporting_event_details_window:
def __init__(self,parent,data):
# define the window
top = self.top = Tkinter.Toplevel(parent)
top.grid_columnconfigure(0,weight=1)
top.grid_rowconfigure(1,weight=1)
top.wm_title("Reporting Event Details")
scrolltext = ScrolledText(self.top,height=10,width=60)
scrolltext.config(state="normal")
scrolltext.grid(row=0,column=0,sticky='NEWS')
keys = [ "EventType","TimeStamp","TaskID","AgentName","Message","ID" ]
for i in range(0,len(keys)):
scrolltext.insert(Tkinter.END,keys[i] + ": " + str(data[i]) + "\n")
scrolltext.config(state="disabled")
# credentials event details window
class credentials_event_details_window:
def __init__(self,parent,data):
# define the window
top = self.top = Tkinter.Toplevel(parent)
top.grid_columnconfigure(0,weight=1)
top.grid_rowconfigure(1,weight=1)
top.wm_title("Credential Details")
scrolltext = ScrolledText(self.top,height=10,width=60)
scrolltext.config(state="normal")
scrolltext.grid(row=0,column=0,sticky='NEWS')
keys = [ "ID", "UserName", "Domain", "CredType", "Notes", "Host", "SID", "Password", "OS" ]
for i in range(0,len(keys)):
scrolltext.insert(Tkinter.END,keys[i] + ": " + str(data[i]) + "\n")
scrolltext.config(state="disabled")
# main application classs
class vader:
###### CONSTRUCTOR #####
def __init__(self):
# empire api core object
self.eac_object = empire_api_core()
# stager outfile path
self.stager_outfile_path = ""
# module outfile path
self.module_outfile_path = ""
# empire version string
self.empire_version = ""
# reporting by agent name choice dict
self.reporting_agent_choices = []
self.reporting_agent_choices.append("")
# selected agent name for option execution
self.selected_agent_name = ""
# selected module name for option execution
self.selected_module_name = ""
# define the API Logging Queue
self.api_log_queue = Queue(maxsize=0)
# define the main form - super parent
self.form = Tkinter.Tk()
self.form.wm_title(' Vader.py ')
self.form.resizable(0,0)
###### ACTION TABS FRAME #######
# application tabs notebook, child to the form, parent to the tabs
self.nb = ttk.Notebook(self.form,height=600,width=1300)
self.nb.pack(fill=BOTH, expand=True)
self.nb.pressed_index = None
# define the API frames
self.admin_api = Tkinter.Frame(self.nb)
self.listeners_api = Tkinter.Frame(self.nb)
self.agents_api = Tkinter.Frame(self.nb)
self.modules_api = Tkinter.Frame(self.nb)
self.stagers_api = Tkinter.Frame(self.nb)
self.creds_api = Tkinter.Frame(self.nb)
self.report_api = Tkinter.Frame(self.nb)
# pack frames into notebook
self.admin_api.pack(fill=BOTH, expand=True)
self.listeners_api.pack(fill=BOTH, expand=True)
self.agents_api.pack(fill=BOTH, expand=True)
self.modules_api.pack(fill=BOTH, expand=True)
self.stagers_api.pack(fill=BOTH, expand=True)
self.creds_api.pack(fill=BOTH, expand=True)
self.report_api.pack(fill=BOTH, expand=True)
# add application frames to notebook
# defines the tab ordering
self.nb.add(self.admin_api,text=' Admin / API ')
self.nb.add(self.listeners_api,text=' Listeners ',state="disabled")
self.nb.add(self.stagers_api,text=' Stagers ',state="disabled")
self.nb.add(self.agents_api,text=' Agents ',state="disabled")
self.nb.add(self.modules_api,text=' Modules ',state="disabled")
self.nb.add(self.creds_api,text=' Credentials ',state="disabled")
self.nb.add(self.report_api,text=' Reporting ',state="disabled")
######### API LOG FRAME #################
self.api_log_textbox = ScrolledText(self.form,height=12)
self.api_log_textbox.config(bg='black',fg='white',state="disabled")
self.api_log_textbox.pack(fill=BOTH,expand=YES,padx=5)
######### BUILD APPLICATION ###########
self.build_api_admin_tab()
self.build_listeners_tab()
self.build_stagers_tab()
self.build_agents_tab()
self.build_modules_tab()
self.build_reporting_tab()
self.build_credentials_tab()
# start the application
self.start_application()
# API / ADMIN Tab
def build_api_admin_tab(self):
# notebook tab - admin/api
##### AUTHENTICATION INFO FRAME ##############
# authentication input fields
self.api_connection_lframe = Tkinter.LabelFrame(self.admin_api)
self.api_connection_lframe.grid(row=0,column=0,padx=10,pady=5,sticky=NW)
# ------- Username Entry Field ------------ #
# Define the Username label text
self.api_username_label = Tkinter.StringVar()
self.api_username_label.set("Username: ")
# Display the Username label - reference label text var
self.api_username_dlabel = Tkinter.Label(self.api_connection_lframe,textvariable=self.api_username_label)
self.api_username_dlabel.grid(row=0,column=0,sticky=E)
# Define the Username text entry field
self.api_username_str = Tkinter.StringVar()
self.api_username_str.set("empire")
self.api_username_field = Tkinter.Entry(self.api_connection_lframe,textvariable=self.api_username_str,width=30)
self.api_username_field.grid(row=0,column=1,sticky=W,padx=5,pady=5,columnspan=2)
# ------- Username Entry Field ------------ #
# ------- Password Entry Field ------------ #
# Define the Password label text
self.api_password_label = Tkinter.StringVar()
self.api_password_label.set("Password: ")
# Display the Password label - reference label text var
self.api_password_dlabel = Tkinter.Label(self.api_connection_lframe,textvariable=self.api_password_label)
self.api_password_dlabel.grid(row=1,column=0,sticky=E)
# Define the Password text entry field
self.api_password_str = Tkinter.StringVar()
self.api_password_str.set("empire")
self.api_password_field = Tkinter.Entry(self.api_connection_lframe,textvariable=self.api_password_str,width=30,show="*")
self.api_password_field.grid(row=1,column=1,sticky=W,padx=5,pady=5,columnspan=2)
# ------- Password Entry Field ------------ #
# ------- Host Entry Field ------------ #
# Define the Host label text
self.api_host_label = Tkinter.StringVar()
self.api_host_label.set("Host / IP: ")
# Display the Host label - reference label text var
self.api_host_dlabel = Tkinter.Label(self.api_connection_lframe,textvariable=self.api_host_label)
self.api_host_dlabel.grid(row=2,column=0,sticky=E)
# Define the Host text entry field
self.api_host_str = Tkinter.StringVar()
self.api_host_str.set("127.0.0.1")
self.api_host_field = Tkinter.Entry(self.api_connection_lframe,textvariable=self.api_host_str,width=30)
self.api_host_field.grid(row=2,column=1,sticky=W,padx=5,pady=5,columnspan=2)
# ------- Host Entry Field ------------ #
# ------- Port Entry Field ------------ #
# Define the Port label text
self.api_port_label = Tkinter.StringVar()
self.api_port_label.set("Port: ")
# Display the Port label - reference label text var
self.api_port_dlabel = Tkinter.Label(self.api_connection_lframe,textvariable=self.api_port_label)
self.api_port_dlabel.grid(row=3,column=0,sticky=E)
# Define the Port text entry field
self.api_port_str = Tkinter.StringVar()
self.api_port_str.set("1337")
self.api_port_field = Tkinter.Entry(self.api_connection_lframe,textvariable=self.api_port_str,width=10)
self.api_port_field = Tkinter.Entry(self.api_connection_lframe,textvariable=self.api_port_str,width=10)
self.api_port_field.grid(row=3,column=1,sticky=W,padx=5,pady=5)
# ------- Port Entry Field ------------ #
##### CONNECTION INFO FRAME ##############
##### API BUTTON FRAME ##############
self.api_action_lframe = Tkinter.LabelFrame(self.admin_api)
self.api_action_lframe.grid(row=0,column=1,padx=10,pady=5,sticky=NW)
# Get Session Token
self.api_action_get_session_button = Tkinter.Button(self.api_action_lframe,text="Access the Empire",command=self.api_get_session)
self.api_action_get_session_button.config(fg='white',bg='blue',font=('arial','10','bold'))
self.api_action_get_session_button.grid(row=0,column=0,sticky=W,padx=5,pady=5)
# Get Permanent Session Token
self.api_action_get_perm_session_button = Tkinter.Button(self.api_action_lframe,text="Get Permanent Token",command=self.api_get_perm_session)
self.api_action_get_perm_session_button.config(state="disabled",fg='white',bg='slate gray',font=('arial','10','bold'))
self.api_action_get_perm_session_button.grid(row=1,column=0,sticky=W,padx=5,pady=5)
# Restart RESTful API Server
self.api_action_restart_api_button = Tkinter.Button(self.api_action_lframe,text="Restart API Server",command=self.api_restart_api_server)
self.api_action_restart_api_button.config(state="disabled",fg='white',bg='slate gray',font=('arial','10','bold'))
self.api_action_restart_api_button.grid(row=2,column=0,sticky=W,padx=5,pady=5)
# Shutdown RESTful API Server
self.api_action_shutdown_api_button = Tkinter.Button(self.api_action_lframe,text="Shutdown API Server",command=self.api_shutdown_api_server)
self.api_action_shutdown_api_button.config(state="disabled",fg='white',bg='slate gray',font=('arial','10','bold'))
self.api_action_shutdown_api_button.grid(row=3,column=0,sticky=W,padx=5,pady=5)
##### API ACTION FRAME ##############
######## API CONFIG INFO FRAME #############
self.api_config_lframe = Tkinter.LabelFrame(self.admin_api)
self.api_config_lframe.grid(row=1,column=0,columnspan=2,padx=10,pady=5,sticky=NW)
self.api_config_textbox = ScrolledText(self.api_config_lframe,width=64,height=12)
self.api_config_textbox.config(bg='ghost white',state="disabled")
self.api_config_textbox.grid(row=0,column=0,sticky='W',columnspan=2)
# ------- Request Session Tokem ------------ #
# Define the Request Session Token label text
self.api_request_session_token_label = Tkinter.StringVar()
self.api_request_session_token_label.set("Request Token: ")
# Display the Request Session Token label - reference label text var
self.api_request_session_token_dlabel = Tkinter.Label(self.api_config_lframe,textvariable=self.api_request_session_token_label)
self.api_request_session_token_dlabel.grid(row=1,column=0,sticky=E,pady=5)
# Define the Request Session Token field
self.api_request_token_str = Tkinter.StringVar()
self.api_request_token_str.set("")
self.api_request_token_field = Tkinter.Entry(self.api_config_lframe,textvariable=self.api_request_token_str,width=45)
self.api_request_token_field.grid(row=1,column=1,sticky=W)
self.api_request_token_field.config(state="readonly")
##### XTERM WINDOW #########
self.api_xterm_lframe = Tkinter.LabelFrame(self.admin_api)
self.api_xterm_lframe.grid(row=0,column=2,padx=10,pady=5,sticky=NW,rowspan=15)
termf = Frame(self.api_xterm_lframe, height=550, width=700)
termf.grid(row=0,column=0,sticky=NSEW)
wid = termf.winfo_id()
os.system('xterm -into %d -geometry 80x30 -sb -fa "Monospace" -fs 11 -fg black -bg gray &' % wid)
# LISTENERS Tab
def build_listeners_tab(self):
# notebook tab - listeners
##### LISTENER TYPE SELECTION FRAME ##############
self.listener_options_lframe = Tkinter.LabelFrame(self.listeners_api)
self.listener_options_lframe.grid(row=0,column=0,padx=5,pady=5,sticky=NW)
# LISTENER TYPES LISTBOX
self.listener_type_treeview = ttk.Treeview(self.listener_options_lframe,height=8,selectmode="extended")
self.listener_type_treeview.column("#0",minwidth="0",width="250")
self.listener_type_treeview.heading("#0",text=" Listener Types: ")
# Add Listener Types
self.listener_type_treeview.insert("","end", text="dbx")
self.listener_type_treeview.insert("","end", text="http")
self.listener_type_treeview.insert("","end", text="http_com")
self.listener_type_treeview.insert("","end", text="http_foreign")
self.listener_type_treeview.insert("","end", text="http_hop")
self.listener_type_treeview.insert("","end", text="meterpreter")
self.listener_type_treeview.insert("","end", text="redirector")
# Bind to Action
self.listener_type_treeview.bind("<Double-1>", self.api_get_listener_type_options)
self.listener_type_treeview.grid(row=0,column=0,sticky=NW,padx=5,pady=5)
###### List ALL LISTENERS ############
self.listener_all_treeview = ttk.Treeview(self.listener_options_lframe,height=12)
self.listener_all_treeview.heading("#0",text=" Current Listeners: ")
self.listener_all_treeview.column("#0",minwidth="0",width="250")
# Bind to Action
self.listener_all_treeview.bind("<Double-1>", self.api_get_listener_by_name)
self.listener_all_treeview.grid(row=2,column=0,sticky=NW,padx=5,pady=5)
# ---------- Refresh Button----------#
self.listener_refresh_button = Tkinter.Button(self.listener_options_lframe,text=" Refresh List ",command=self.api_get_current_listeners)
self.listener_refresh_button.config(state="normal",fg='white',bg='slate gray',font=('arial','10','bold'))
self.listener_refresh_button.grid(row=3,column=0,sticky=N,padx=5,pady=5)
###### LISTENER OPTIONS ENTRY FRAME - DYNAMIC ############
self.listener_type_dynamic_lframe = Tkinter.Frame(self.listeners_api)
self.listener_type_dynamic_lframe.grid(row=0,column=1,sticky=NE,rowspan=3)
# Build the listeners API Canvas and Scroll
self.listeners_api_canvas = Canvas(self.listener_type_dynamic_lframe,width=1010, height=600)
self.listeners_api_scroll = Scrollbar(self.listener_type_dynamic_lframe, command=self.listeners_api_canvas.yview)
self.listeners_api_canvas.config(yscrollcommand=self.listeners_api_scroll.set, scrollregion=(0,0,100,2000))
self.listeners_api_canvas.pack(side=LEFT, fill=BOTH, expand=True)
self.listeners_api_scroll.pack(side=RIGHT, fill=Y)
# STAGERS Tab
def build_stagers_tab(self):
##### STAGERS TYPE SELECTION FRAME ##############
self.stagers_options_lframe = Tkinter.LabelFrame(self.stagers_api)
self.stagers_options_lframe.grid(row=0,column=0,padx=5,pady=5,sticky=NW)
###### List ALL STAGERS ############
self.stagers_all_treeview = ttk.Treeview(self.stagers_options_lframe,height=25)
self.stagers_all_treeview.heading("#0",text=" Stagers: ")
self.stagers_all_treeview.column("#0",minwidth="0",width="250")
# Bind to Action
self.stagers_all_treeview.bind("<Double-1>", self.api_get_stager_by_name)
self.stagers_all_treeview.grid(row=0,column=0,sticky=NW,padx=5,pady=5)
###### STAGERS OPTIONS ENTRY FRAME - DYNAMIC ############
self.stager_type_dynamic_lframe = Tkinter.Frame(self.stagers_api)
self.stager_type_dynamic_lframe.grid(row=0,column=1,sticky=NE)
# Build the stagers API Canvas and Scroll
self.stagers_api_canvas = Canvas(self.stager_type_dynamic_lframe,width=1010, height=600)
self.stagers_api_scroll = Scrollbar(self.stager_type_dynamic_lframe, command=self.stagers_api_canvas.yview)
self.stagers_api_canvas.config(yscrollcommand=self.stagers_api_scroll.set, scrollregion=(0,0,100,2000))
self.stagers_api_canvas.pack(side=LEFT, fill=BOTH, expand=True)
self.stagers_api_scroll.pack(side=RIGHT, fill=Y)
# AGENTS Tab
def build_agents_tab(self):
##### agents TYPE SELECTION FRAME ##############
self.agents_current_options_lframe = Tkinter.LabelFrame(self.agents_api)
self.agents_current_options_lframe.grid(row=0,column=0,padx=5,pady=5,sticky=NW)
###### List CURRENT AGENTS ############
self.agents_current_treeview = ttk.Treeview(self.agents_current_options_lframe,height=12)
self.agents_current_treeview.heading("#0",text=" Current Agents: ")
# Bind to Action and Grid
self.agents_current_treeview.bind("<Double-1>", self.api_get_agent_by_name)
self.agents_current_treeview.grid(row=0,column=0,sticky=NW,padx=5,pady=5)
# ---------- Refresh Current Agents----------#
self.agents_current_refresh_button = Tkinter.Button(self.agents_current_options_lframe,text=" Refresh List ",command=self.api_get_current_agents)
self.agents_current_refresh_button.config(fg='white',bg='slate gray',font=('arial','10','bold'))
self.agents_current_refresh_button.grid(row=1,column=0,sticky=N,padx=5,pady=5)
###### List STALE AGENTS ############
self.agents_stale_treeview = ttk.Treeview(self.agents_current_options_lframe,height=10)
self.agents_stale_treeview.heading("#0",text=" Stale Agents: ")
self.agents_stale_treeview.grid(row=3,column=0,sticky=NW,padx=5,pady=5)
# ---------- Remove Stale Agents----------#
self.agents_stale_remove_button = Tkinter.Button(self.agents_current_options_lframe,text=" Remove Stale Agents ",command=self.api_get_remove_stale_agents)
self.agents_stale_remove_button.config(fg='white',bg='slate gray',font=('arial','10','bold'))
self.agents_stale_remove_button.grid(row=4,column=0,sticky=N,padx=5,pady=5)
###### AGENTS INFO / ACTION FRAME - DYNAMIC ############
self.agent_info_action_lframe = Tkinter.Frame(self.agents_api)
self.agent_info_action_lframe.grid(row=0,column=1,padx=15,pady=5,sticky=NW)
# MODULES Tab
def build_modules_tab(self):
##### modules TYPE SELECTION FRAME ##############
self.modules_options_lframe = Tkinter.LabelFrame(self.modules_api)
self.modules_options_lframe.grid(row=0,column=0,padx=5,pady=5,sticky=NW,rowspan=2)
###### List ALL modules ############
self.modules_all_treeview = ttk.Treeview(self.modules_options_lframe,height=25)
self.modules_all_treeview.heading("#0",text=" Modules: ")
self.modules_all_treeview.column("#0",minwidth="0",width="540")
# Bind to Action
self.modules_all_treeview.bind("<Double-1>", self.api_get_module_by_name)
self.modules_all_treeview.grid(row=0,column=0,sticky=NW,padx=5,pady=5,rowspan=2,columnspan=10)
# search entry and search button
self.modules_search_str = Tkinter.StringVar()
self.modules_search_field = Tkinter.Entry(self.modules_options_lframe,textvariable=self.modules_search_str,width=25)
self.modules_search_field.grid(row=2,column=0,sticky=W,padx=5,pady=5)
self.modules_search_button = Tkinter.Button(self.modules_options_lframe,text="Search Modules",command=self.api_search_for_module)
self.modules_search_button.config(fg='white',bg='slate gray',font=('arial','10','bold'))
self.modules_search_button.grid(row=2,column=1,sticky=W,padx=5,pady=5)
# view all modules button
self.modules_view_all_button = Tkinter.Button(self.modules_options_lframe,text="View All",command=self.api_get_current_modules)
self.modules_view_all_button.config(fg='white',bg='slate gray',font=('arial','10','bold'))
self.modules_view_all_button.grid(row=2,column=2,sticky=W,padx=5,pady=5)
###### modules OPTIONS ENTRY FRAME - DYNAMIC ############
# options frame for entry
self.modules_type_dynamic_frame = Tkinter.Frame(self.modules_api)
self.modules_type_dynamic_frame.grid(row=0,column=1,sticky=NE)
# Build the modules API Canvas and Scroll
self.modules_api_canvas = Canvas(self.modules_type_dynamic_frame,width=720, height=600)
self.modules_api_scroll = Scrollbar(self.modules_type_dynamic_frame, command=self.modules_api_canvas.yview)
self.modules_api_canvas.config(yscrollcommand=self.modules_api_scroll.set, scrollregion=(0,0,100,2000))
self.modules_api_canvas.pack(side=LEFT, fill=BOTH, expand=True)
self.modules_api_scroll.pack(side=RIGHT, fill=Y)
# REPORTING tab
def build_reporting_tab(self):
# delete all childitems on reload
# clear the frame
try:
for child in self.report_api.winfo_children():
child.destroy()
except:
pass
##### REPORTING OUTPUT ##############
self.reporting_output_lframe = Tkinter.LabelFrame(self.report_api)
self.reporting_output_lframe.grid(row=0,column=0,padx=5,pady=5,sticky='nw')
# ---------- Request Events----------#
reporting_request_button = Tkinter.Button(self.reporting_output_lframe,text=" Request Events ",command=self.reporting_display_output)
reporting_request_button.config(fg='white',bg='blue',font=('arial','10','bold'))
reporting_request_button.grid(row=0,column=0,sticky=NW,padx=5,pady=5)
cols = [ "EventType", "TimeStamp", "TaskID", "AgentName", "Message", "ID" ]
self.reporting_tree = ttk.Treeview(self.reporting_output_lframe, columns=cols, show="headings",height="23")
self.reporting_tree.bind("<Double-1>", self.misc_reporting_display_event_details)
for c in cols:
self.reporting_tree.heading(c, text=str(c), command=lambda x=c: self.misc_col_sort(self.reporting_tree, x, 0) )
self.reporting_tree.column(c, width=tkFont.Font().measure(c.title() + " " * 28))
self.reporting_tree.grid(row=1,column=0,padx=5,pady=5)
# CREDENTIALS tab
def build_credentials_tab(self):
# creds main frame
self.creds_output_lframe = Tkinter.LabelFrame(self.creds_api)
self.creds_output_lframe.grid(row=0,column=0,padx=10,pady=10,sticky=NW)
# refresh button
self.creds_refresh_button = Button(self.creds_output_lframe,text="Refresh Credentials",command=self.api_get_stored_credentials)
self.creds_refresh_button.config(fg='white',bg='slate gray',font=('arial','10','bold'))
self.creds_refresh_button.grid(row=0,column=0,padx=5,pady=5,sticky=NW)
# label info
self.creds_label_info = Label(self.creds_output_lframe,text="* Double-click Credential row to view details in separate window.")
self.creds_label_info.grid(row=0,column=1,padx=5,pady=5,sticky=W)
# build creds treeview
cols = [ "username", "domain", "credtype", "notes", "host", "sid", "password", "os", "id" ]
self.creds_tree = ttk.Treeview(self.creds_output_lframe, columns=cols, show="headings",height="23")
self.creds_tree.bind("<Double-1>", self.misc_creds_display_event_details)
for c in cols:
self.creds_tree.heading(c, text=str(c), command=lambda x=c: self.misc_col_sort(self.creds_tree, x, 0))
self.creds_tree.column(c, width=tkFont.Font().measure(c.title() + " " * 18))
self.creds_tree.grid(row=1,column=0,padx=2,pady=2,columnspan=20)
####### ADMIN FUNCTIONS ###########
# get session token
def api_get_session(self):
# validate and set authentication form fields
if self.error_check_api_auth_fields():
# get session token request successful (True)
response = self.eac_object.admin_get_session_token()
# authentication successful
if response == True:
# set the request token field
self.api_request_token_str.set(self.eac_object.api_request_token)
# get the api server configuration
try:
response = self.eac_object.api_config_info()
self.misc_api_log_write(self.eac_object.api_url_holder + "\n")
# clear the config textarea
self.api_config_textbox.config(state="normal")
self.api_config_textbox.delete(1.0,Tkinter.END)
self.api_config_textbox.config(state="disabled")
# write to the config scrolledtext window root
for item in response['config']:
for key,value in item.iteritems():
self.api_config_textbox.config(state="normal")
# mask password value
if str(key).upper() == "API_PASSWORD":
self.api_config_textbox.insert(Tkinter.END,str(key).upper() + " : " + "**************" + "\n")
else:
self.api_config_textbox.insert(Tkinter.END,str(key).upper() + " : " + str(value) + "\n")
self.api_config_textbox.see(Tkinter.END)
self.api_config_textbox.config(state="disabled")
except Exception as e:
tkMessageBox.showerror("ERROR","API Configuration Request Failed - " + str(e))
# enable additional Admin / API Actions
# ------------------------------------- #
self.api_action_get_perm_session_button.config(state="normal")
self.api_action_restart_api_button.config(state="normal")
self.api_action_shutdown_api_button.config(state="normal")
# enable additional application tabs
# ------------------------------------- #
try:
self.nb.tab(self.listeners_api,state="normal")
self.nb.tab(self.agents_api,state="normal")
self.nb.tab(self.modules_api,state="normal")
self.nb.tab(self.stagers_api,state="normal")
self.nb.tab(self.creds_api,state="normal")
self.nb.tab(self.report_api,state="normal")
# build application selection lists
# -----------------------------#
self.api_get_current_listeners()
self.api_get_current_stagers()
self.api_get_current_agents()
self.api_get_current_modules()
self.api_get_stored_credentials()
except Exception as e:
tkMessageBox.showerror("ERROR","Error enabling additional application tabs and function calls: " + str(e))
# start the API Logging Threads
self.api_log_update_thread = Thread(target=self.api_thread_update_queue,args=(self.api_log_queue,))
self.api_log_update_thread.setDaemon(True)
self.api_log_update_thread.start()
self.api_log_display_thread = Thread(target=self.api_thread_display_queue)
self.api_log_display_thread.setDaemon(True)
self.api_log_display_thread.start()
else:
tkMessageBox.showerror("ERROR","Unable to retrieve Session Token with provided authentication info:" + response)
# get permanent token
def api_get_perm_session(self):
# get the permanent token
if self.eac_object.admin_get_perm_token():
# set the request token field
self.api_request_token_str.set(self.eac_object.api_request_token)
# log the request
self.misc_api_log_write(self.eac_object.api_url_holder + "\n")
# restart the api server
def api_restart_api_server(self):
if tkMessageBox.askyesno("Restart API","Are you sure you want to restart the API?"):
# restart api server call
response = self.eac_object.admin_restart_restful_api_server()
self.misc_api_log_write(self.eac_object.api_url_holder + "\n")
# restart success
if response['success']:
pass
else:
tkMessageBox.showerror("ERROR","Empire RESTful API Server restart FAILED.")
# shutdown the api server
def api_shutdown_api_server(self):
if tkMessageBox.askyesno("Shutdown API","Are you sure you want to shutdown the API?"):
# shutdown api server call
response = self.eac_object.admin_shutdown_restful_api_server()
self.misc_api_log_write(self.eac_object.api_url_holder + "\n")
try:
# shutdown success
if response['success']:
# disable additional Admin / API Actions
# ------------------------------------- #
self.api_action_get_perm_session_button.config(state="disabled")
self.api_action_restart_api_button.config(state="disabled")
self.api_action_shutdown_api_button.config(state="disabled")
# clear the config textarea
self.api_config_textbox.config(state="normal")
self.api_config_textbox.delete(1.0,Tkinter.END)
self.api_config_textbox.config(state="disabled")
# disable additional application tabs
# ------------------------------------- #
self.nb.tab(self.listeners_api,state="disabled")
self.nb.tab(self.agents_api,state="disabled")
self.nb.tab(self.modules_api,state="disabled")
self.nb.tab(self.stagers_api,state="disabled")
self.nb.tab(self.creds_api,state="disabled")
self.nb.tab(self.report_api,state="disabled")
# set the request token field
self.api_request_token_str.set("")
return
# shutdown failed
else:
tkMessageBox.showerror("ERROR","Empire RESTful API Server shutdown FAILED.")
return
except Exception as e:
tkMessageBox.showerror("ERROR","Error occurred processing shutdown: " + str(e))
##### LISTENER FUNCTIONS ########
# get listener by name
def api_get_listener_by_name(self,event):
# get the selected item
try:
self.selected_listener = self.listener_all_treeview.selection()[0]
listener_name = str(self.listener_all_treeview.item(self.selected_listener,"text"))
except Exception as e:
tkMessageBox.showerror("ERROR","An error has occurred defining selected listener - " + str(e))
return
# call to the api with listener name
response = self.eac_object.listeners_get_listener_by_name(listener_name)
self.misc_api_log_write(self.eac_object.api_url_holder + "\n")
# parsing was successful
try:
# clear the canvas
try:
for child in self.listeners_api_canvas.winfo_children():
child.destroy()
except:
pass
# build temporary frame
# define the temp labelframe
self.temp_labelframe = Tkinter.LabelFrame(self.listeners_api_canvas)
self.listeners_api_canvas.create_window(0,10,window=self.temp_labelframe,anchor=NW)
# display the kill listener and kill all listeners buttons
# ---------- Kill Listener Button----------#
listener_kill_button = Tkinter.Button(self.temp_labelframe,text="Kill Listener",command=self.api_delete_kill_listener)
listener_kill_button.config(fg='white',bg='slate gray',font=('arial','10','bold'))
listener_kill_button.grid(row=0,column=1,sticky=NW,padx=2,pady=2)
# ---------- Kill All Listener Button----------#
listener_kill_all_button = Tkinter.Button(self.temp_labelframe,text="Kill All Listeners",command=self.api_delete_kill_all_listeners)
listener_kill_all_button.config(fg='white',bg='slate gray',font=('arial','10','bold'))
listener_kill_all_button.grid(row=0,column=2,sticky=NW,padx=2,pady=2)
# track the row count for placement
row_count = 1
# create the dynamic form - readonly state
for item in response['listeners']:
for key,value in item.iteritems():
# regular key value print
if (key == "listener_type") or \
(key == "name") or \
(key == "listener_category") or \
(key == "module") or \
(key == "ID"):
# Option Name
self.option_name_str = Tkinter.StringVar()
self.option_name_str.set(key)
self.option_name_dlabel = Tkinter.Label(self.temp_labelframe,textvariable=self.option_name_str,justify=LEFT)
self.option_name_dlabel.grid(row=row_count,column=0,sticky=E,padx=2,pady=2)
# Option Field Value
self.option_field_str = Tkinter.StringVar()
self.option_field_str.set(value)
self.option_entry_field = Tkinter.Entry(self.temp_labelframe,textvariable=self.option_field_str,width=40)
self.option_entry_field.config(state="disabled",disabledbackground='ghost white',disabledforeground='black')
self.option_entry_field.grid(row=row_count,column=1,columnspan=2,sticky=W,padx=2,pady=2)
# increment the row count
row_count += 1
# check if options key
# iterate thru dictionaries in options value
# style fields based on requirements
elif (key == "options"):
# we need to do some digging
for key2,val2 in value.iteritems():
for key3,val3 in val2.iteritems():
if key3 == "Description":
description_str = val3
elif key3 == "Value":
value_str = val3
# Option Name
self.option_name_str = Tkinter.StringVar()
self.option_name_str.set(key2)
self.option_name_dlabel = Tkinter.Label(self.temp_labelframe,textvariable=self.option_name_str,justify=LEFT)
self.option_name_dlabel.grid(row=row_count,column=0,sticky=E,padx=2,pady=2)
# Option Field
self.option_field_str = Tkinter.StringVar()
self.option_field_str.set(str(value_str))
self.option_entry_field = Tkinter.Entry(self.temp_labelframe,textvariable=self.option_field_str,width=40)
self.option_entry_field.config(state="disabled",disabledbackground='ghost white',disabledforeground='black')
self.option_entry_field.grid(row=row_count,column=1,columnspan=2,sticky=W,padx=2,pady=2)
# Option Description
self.option_description_str = Tkinter.StringVar()
self.option_description_str.set(str(description_str))
self.option_description_dlabel = Tkinter.Label(self.temp_labelframe,textvariable=self.option_description_str,wraplength=500,justify=LEFT)
self.option_description_dlabel.grid(row=row_count,column=3,sticky=W,padx=2,pady=2)
# increment the row count
row_count += 1
# parsing json failed
except Exception as e:
tkMessageBox.showerror("ERROR","Error parsing Get Listener by Name - " + str(e))
# get current listeners
def api_get_current_listeners(self):
# Get All current Listeners
response = self.eac_object.listeners_get_current_listeners()
self.misc_api_log_write(self.eac_object.api_url_holder + "\n")
# temp list of listener names
holder = []
try:
for item in response['listeners']:
holder.append(item['name'])
holder.sort()
# clear the treeview
self.listener_all_treeview.delete(*self.listener_all_treeview.get_children())
# populate treeview
for l in holder:
self.listener_all_treeview.insert("","end", text=str(l))
except Exception as e:
tkMessageBox.showerror("ERROR","Unable to parse response from Current Listeners: " + str(e))
# get listener options and display
def api_get_listener_type_options(self,event):
try:
# get the selected item
self.selected_item = self.listener_type_treeview.selection()[0]
except:
return
# call to api function with selected listener type, return json
response = self.eac_object.listeners_get_current_listener_options(str(self.listener_type_treeview.item(self.selected_item,"text")))
self.misc_api_log_write(self.eac_object.api_url_holder + "\n")
# parsing was successful
try:
# try to destory previous temp_labelframe if it exists
try:
for child in self.listeners_api_canvas.winfo_children():
child.destroy()
except:
pass
# define the temp labelframe
self.temp_labelframe = Tkinter.LabelFrame(self.listeners_api_canvas)
self.listeners_api_canvas.create_window(0,10,window=self.temp_labelframe,anchor=NW)
# ---------- Create Button----------#
listener_create_action_button = Tkinter.Button(self.temp_labelframe,text="Create Listener",command=self.api_post_create_listener)
listener_create_action_button.config(fg='white',bg='blue',font=('arial','10','bold'))
listener_create_action_button.grid(row=0,column=1,sticky=NW,padx=2,pady=2)
# track the row count for placement (account for button, row =1)
row_count = 1
column_count = 0
# create the dynamic form
# track all key name values
self.temp_keys_list = []
# track all required key name values
self.temp_reqd_keys_list = []
for key,value in response['listeneroptions'].iteritems():
# append to temp keys list
self.temp_keys_list.append(key)
# grab dictionary values
for key2,value2 in value.iteritems():
if key2 == "Description":
description_str = value2
elif key2 == "Required":
required_bool = value2
elif key2 == "Value":
val = value2
# Option Name
name_label = Tkinter.Label(self.temp_labelframe,text=str(key),justify=LEFT)
name_label.grid(row=row_count,column=0,sticky=E,padx=2,pady=2)
# check if field required
# if so, append to reqd keys name list and change entry bgcolor