forked from jfoote/burp-git-bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathburp_git_bridge.py
executable file
·1616 lines (1312 loc) · 54.9 KB
/
burp_git_bridge.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
'''
Git Bridge extension for Burp Suite Pro
The Git Bridge plugin lets Burp users store and share findings and other Burp
items via git. Users can right-click supported items in Burp to send them to
a git repo and use the Git Bridge tab to send items back to their respective
Burp tools.
For more information see https://github.com/mateodurante/burp-git-bridge.
This extension is a PoC. Right now only Repeater and Scanner are supported,
and the code could use refactoring. If you're interested in a more polished
version or more features let me know, or better yet consider sending me a pull request.
Thanks for checking it out.
Writer: Jonathan Foote 2015-04-21
Editor: Mateo Durante 2020-10-15
This project needs:
- git
- xdotools
- ssh
'''
from burp import IBurpExtender, ITab, IHttpListener, IMessageEditorController, IContextMenuFactory, IScanIssue, IHttpService, IHttpRequestResponse, IBurpExtenderCallbacks
from java.awt import Component
from java.awt.event import ActionListener
from java.io import PrintWriter
from java.util import ArrayList, List
from java.net import URL
from javax.swing import JScrollPane, JSplitPane, JTabbedPane, JTable, SwingUtilities, JPanel, JButton, JLabel, JMenuItem, BoxLayout, Box, JTextField
from javax.swing.table import AbstractTableModel
from threading import Lock
import datetime, os, hashlib
import sys
'''
Entry point for Burp Git Bridge extension.
'''
class BurpExtender(IBurpExtender):
'''
Entry point for plugin; creates UI and Log
'''
def registerExtenderCallbacks(self, callbacks):
# Assign stdout/stderr for debugging and set extension name
sys.stdout = callbacks.getStdout()
sys.stderr = callbacks.getStderr()
callbacks.setExtensionName("Git Bridge")
# import time
# print(dir(callbacks))
# print(callbacks.loadConfigFromJson())
# for fn in dir(callbacks):
# if fn not in ['unloadExtension'] and not 'out' in fn:
# try:
# # print(fn, getattr(callbacks, fn)())
# print(fn, getattr(callbacks, fn))
# time.sleep(2)
# except:
# pass
# Create major objects and load user data
self.log = Log(callbacks)
self.ui = BurpUi(callbacks, self.log)
self.log.setUi(self.ui)
self.log.reload()
'''
Classes that support logging of data to in-Burp extension UI as well
as the underlying git repo
'''
class LogEntry(object):
'''
Hacky dictionary used to store Burp tool data. Objects of this class
are stored in the Java-style table represented in the Burp UI table.
They are created by the BurpUi when a user sends Burp tool data to Git
Bridge, or by Git Bridge when a user's git repo is reloaded into Burp.
'''
def __init__(self, *args, **kwargs):
self.__dict__ = kwargs
# Hash most of the tool data to uniquely identify this entry.
# Note: Could be more pythonic.
md5 = hashlib.md5()
for k, v in self.__dict__.iteritems():
if v and k != "messages":
if not getattr(v, "__getitem__", False):
v = str(v)
md5.update(k)
md5.update(v[:2048])
self.md5 = md5.hexdigest()
class Log():
'''
Log of burp activity: this class encapsulates both the Burp UI log and the git
repo log. A single object of this class is created when the extension is
loaded. It is used by BurpExtender when it logs input events or the
in-Burp Git Bridge log is reloaded from the underlying git repo.
'''
def __init__(self, callbacks):
'''
Creates GUI log and git log objects
'''
self.ui = None
self._callbacks = callbacks
self._helpers = callbacks.getHelpers()
self.gui_log = GuiLog(callbacks)
self.git_log = GitLog(callbacks)
def setUi(self, ui):
'''
There is a circular dependency between the Log and Burp GUI objects:
the GUI needs a handle to the Log to add new Burp tool data, and the
Log needs a handle to the GUI to update in the in-GUI table.
The GUI takes the Log in its constructor, and this function gives the
Log a handle to the GUI.
'''
self.ui = ui
self.gui_log.ui = ui
def reload(self):
'''
Reloads the Log from on the on-disk git repo.
'''
self.gui_log.clear()
for entry in self.git_log.entries():
self.gui_log.add_entry(entry)
def add_repeater_entry(self, messageInfo):
'''
Loads salient info from the Burp-supplied messageInfo object and
stores it to the GUI and Git logs
'''
timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
service = messageInfo.getHttpService()
entry = LogEntry(tool="repeater",
host=service.getHost(),
port=service.getPort(),
protocol=service.getProtocol(),
url=str(self._helpers.analyzeRequest(messageInfo).getUrl()),
timestamp=timestamp,
who=self.git_log.whoami(),
description='',
request=messageInfo.getRequest(),
response=messageInfo.getResponse())
self.gui_log.add_entry(entry)
self.git_log.add_repeater_entry(entry)
def add_scanner_entry(self, scanIssue):
'''
Loads salient info from the Burp-supplied scanInfo object and
stores it to the GUI and Git logs
'''
timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# Gather info from messages. Oi, ugly.
messages = []
for message in scanIssue.getHttpMessages():
service = message.getHttpService()
msg_entry = LogEntry(tool="scanner_message",
host=service.getHost(),
port=service.getPort(),
protocol=service.getProtocol(),
comment=message.getComment(),
highlight=message.getHighlight(),
request=message.getRequest(),
response=message.getResponse(),
timestamp=timestamp)
messages.append(msg_entry)
# Gather info for scan issue
service = scanIssue.getHttpService()
entry = LogEntry(tool="scanner",
timestamp=timestamp,
who=self.git_log.whoami(),
description='',
messages=messages,
host=service.getHost(),
port=service.getPort(),
protocol=service.getProtocol(),
confidence=scanIssue.getConfidence(),
issue_background=scanIssue.getIssueBackground(),
issue_detail=scanIssue.getIssueDetail(),
issue_name=scanIssue.getIssueName(),
issue_type=scanIssue.getIssueType(),
remediation_background=scanIssue.getRemediationBackground(),
remediation_detail=scanIssue.getRemediationDetail(),
severity=scanIssue.getSeverity(),
url=str(scanIssue.getUrl()))
self.gui_log.add_entry(entry)
self.git_log.add_scanner_entry(entry)
def remove(self, entry):
'''
Removes the supplied entry from the Log
'''
self.git_log.remove(entry)
self.gui_log.remove_entry(entry)
def pull(self):
'''
pulls the supplied entry from the Log
'''
self.git_log.pull()
def push(self):
'''
Pushs the supplied entry from the Log
'''
self.git_log.push()
def set_config(self, user, mail, repo):
'''
Set the supplied data to git config
'''
self.gui_log.clear()
self.git_log.set_config(user, mail, repo)
def delete_repo_local(self, repo):
'''
Set the supplied data to git config
'''
self.gui_log.clear()
self.git_log.delete_repo_local(repo)
def set_description(self, entry_hash, description):
'''
Set the supplied data to git config
'''
self.git_log.set_description(entry_hash, description)
def get_actual_repo_uri(self):
'''
Get actual repo uri
'''
return self.git_log.get_actual_repo_uri()
def get_key_pub(self):
'''
Get actual repo uri
'''
return self.git_log.get_key_pub()
def reload_project(self):
'''
Reload config of burp project
'''
self.gui_log.clear()
self.git_log.reload_project()
class GuiLog(AbstractTableModel):
'''
Acts as an AbstractTableModel for the table that is shown in the UI tab:
when this data structure changes, the in-UI table is updated.
'''
def __init__(self, callbacks):
'''
Creates a Java-style ArrayList to hold LogEntries that appear in the table
'''
self.ui = None
self._log = ArrayList()
self._lock = Lock()
self._callbacks = callbacks
self._helpers = callbacks.getHelpers()
self.cols = ["Time added",
"Tool",
"URL",
"Issue",
"Who",
"Description"]
def clear(self):
'''
Clears all entries from the table
'''
self._lock.acquire()
last = self._log.size()
if last > 0:
self._log.clear()
self.fireTableRowsDeleted(0, last-1)
# Note: if callees modify table this could deadlock
self._lock.release()
def add_entry(self, entry):
'''
Adds entry to the table
'''
self._lock.acquire()
row = self._log.size()
self._log.add(entry)
# Note: if callees modify table this could deadlock
self.fireTableRowsInserted(row, row)
self._lock.release()
def remove_entry(self, entry):
'''
Removes entry from the table
'''
self._lock.acquire()
for i in range(0, len(self._log)):
ei = self._log[i]
if ei.md5 == entry.md5:
self._log.remove(i)
break
self.fireTableRowsDeleted(i, i)
self._lock.release()
def getRowCount(self):
'''
Used by the Java Swing UI
'''
try:
return self._log.size()
except:
return 0
def getColumnCount(self):
'''
Used by the Java Swing UI
'''
return len(self.cols)
def getColumnName(self, columnIndex):
'''
Used by the Java Swing UI
'''
try:
return self.cols[columnIndex]
except KeyError:
return ""
def get(self, rowIndex):
'''
Gets the LogEntry at rowIndex
'''
l = self._log.get(rowIndex)
return self._log.get(rowIndex)
def getValueAt(self, rowIndex, columnIndex):
'''
Used by the Java Swing UI
'''
logEntry = self._log.get(rowIndex)
if columnIndex == 0:
return logEntry.timestamp
elif columnIndex == 1:
return logEntry.tool.capitalize()
elif columnIndex == 2:
return logEntry.url
elif columnIndex == 3:
if logEntry.tool == "scanner":
return logEntry.issue_name
else:
return "N/A"
elif columnIndex == 4:
return logEntry.who
elif columnIndex == 5:
return logEntry.description
return ""
import os, subprocess
class GitLog(object):
'''
Represents the underlying Git Repo that stores user information. Used
by the Log object. As it stands, uses only a single git repo at a fixed
path.
'''
def __init__(self, callbacks):
'''
Initializes git repo config
'''
self.callbacks = callbacks
self.repo_path = None
self.home = os.path.expanduser("~")
self.base_path = os.path.join(self.home, ".burp-git-bridge/")
if not os.path.exists(self.base_path):
os.makedirs(self.base_path)
self.burp_config_path = os.path.join(self.home, ".java/.userPrefs/burp/prefs.xml")
self.project_repo_path = os.path.join(self.base_path, "repo_path_relations.txt")
# if not os.path.exists(self.repo_path):
# self._run_subprocess_command(["git", "init", self.repo_path], cwd=home)
self.user = None
self.email = None
self.key_pub = self._get_key_pub()
self.reload_project()
def reload_project(self):
# Load project-repo relations
self.project_repo_rels = {}
if os.path.exists(self.project_repo_path):
with open(self.project_repo_path, "r") as f:
for line in f.read().split('\n'):
try:
proj_name, repo = line.split(',')
self.project_repo_rels[proj_name] = repo
except Exception as e:
print("Cannot be unpacked file project_repo_path in line {}".format(line))
# Load actual project name. If it is temporary project loads lastone. can it be hacked better?
self.project_name = self.get_current_project_name()
self.project_path = None
if self.project_name == 'Temporary Project':
self.project_name = None
self.project_path = None
else:
try:
# TODO: This can be better, right?
with open(self.burp_config_path, "r") as f:
config = f.read().split('\n')
for line in config:
if 'suite.recentProjectNames' in line and self.project_name in line:
temp_project_id = line.split('suite.recentProjectNames')[1].split('" value="')[0]
search = 'suite.recentProjectNames'+temp_project_id
for line in config:
if search in line:
self.project_path = line.split('value="')[1].split('"/>')[0]
except:
self.project_name = None
self.project_path = None
# try:
# # TODO: This can be better, right?
# with open(self.burp_config_path, "r") as f:
# config = f.read().split('\n')
# for line in config:
# if 'suite.recentProjectFiles0' in line:
# self.project_path = line.split('value="')[1].split('"/>')[0]
# if 'suite.recentProjectNames0' in line:
# self.project_name = line.split('value="')[1].split('"/>')[0]
# except:
# self.project_name = None
# self.project_path = None
if self.project_name in self.project_repo_rels.keys():
self.repo_uri = self.project_repo_rels[self.project_name]
self.repo_path = self._generate_path_repo_name(self._extract_repo_name(self.repo_uri))
else:
self.repo_uri = None
print("Loaded project {}\nProject path {}\nRepo uri {}".format(self.project_name, self.project_path, self.repo_uri))
def save_current_project_repo(self):
print("saving project_repo_rels file project {} with repo {}".format(self.project_name, self.repo_uri))
self.project_repo_rels[self.project_name] = self.repo_uri
lines = '\n'.join(['{},{}'.format(k,v) for k, v in self.project_repo_rels.items()])
with open(self.project_repo_path, "w") as f:
f.write(lines)
def _run_subprocess_command(self, cmd_list, cwd=None, quiet=False):
process = subprocess.Popen(cmd_list, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = process.communicate()
print("Subprocess: {}".format(cmd_list))
if not quiet:
print(out)
print(err)
if process.returncode != 0:
if not quiet:
print("########### Error on call: {}".format(cmd_list))
print(out)
print(err)
print("########### End Error on call")
raise Exception("Error on call: {}".format(cmd_list))
return out
def get_current_project_name(self):
"""
Extracts project name from window, uglyy right?
"""
w = None
wids = self._run_subprocess_command(['xdotool', 'search', 'Burp'], quiet=True).decode()
for wid in wids.split('\n'):
try:
wname = self._run_subprocess_command(['xdotool', 'getwindowname', wid], quiet=True).decode()
if wname.startswith("Burp Suite Professional v"):
w = wname
except:
pass
print(w)
if w:
return w.split(' - ')[1].strip()
def _generate_path_repo_name(self, repo_name):
return os.path.join(self.base_path, repo_name)
def _extract_repo_name(self, repo_uri):
return repo_uri.split('/')[-1].split('.git')[0]
def add_repeater_entry(self, entry):
'''
Adds a LogEntry containing Burp Repeater data to the git repo
'''
# Make directory for this entry
entry_dir = os.path.join(self.repo_path, entry.md5)
if not os.path.exists(entry_dir):
os.mkdir(entry_dir)
# Add and commit repeater data to git repo
self.write_entry(entry, entry_dir)
self._run_subprocess_command(["git", "commit", "-m", "Added Repeater entry"],
cwd=self.repo_path)
def add_scanner_entry(self, entry):
'''
Adds a LogEntry containing Burp Scanner data to the git repo
'''
# Create dir hierarchy for this issue
entry_dir = os.path.join(self.repo_path, entry.md5)
# Log this entry; log 'messages' to its own subdir
messages = entry.messages
del entry.__dict__["messages"]
self.write_entry(entry, entry_dir)
messages_dir = os.path.join(entry_dir, "messages")
if not os.path.exists(messages_dir):
os.mkdir(messages_dir)
lpath = os.path.join(messages_dir, ".burp-list")
open(lpath, "wt")
self._run_subprocess_command(["git", "add", lpath], cwd=self.repo_path)
i = 0
for message in messages:
message_dir = os.path.join(messages_dir, str(i))
if not os.path.exists(message_dir):
os.mkdir(message_dir)
self.write_entry(message, message_dir)
i += 1
self._run_subprocess_command(["git", "commit", "-m", "Added scanner entry"],
cwd=self.repo_path)
def write_entry(self, entry, entry_dir):
'''
Stores a LogEntry to entry_dir and adds it to git repo.
'''
if not os.path.exists(entry_dir):
os.mkdir(entry_dir)
for filename, data in entry.__dict__.iteritems():
if not data:
data = ""
if not getattr(data, "__getitem__", False):
data = str(data)
path = os.path.join(entry_dir, filename)
with open(path, "wb") as fp:
fp.write(data)
fp.flush()
self._run_subprocess_command(["git", "add", path],
cwd=self.repo_path)
def entries(self):
'''
Generator; yields a LogEntry for each entry in the on-disk git repo
'''
def load_entry(entry_path):
'''
Loads a single entry from the path. Could be a "list" entry (see
below)
'''
entry = LogEntry()
for filename in os.listdir(entry_path):
file_path = os.path.join(entry_path, filename)
if os.path.isdir(file_path):
if ".burp-list" in os.listdir(file_path):
list_entry = load_list(file_path)
entry.__dict__[filename] = list_entry
else:
sub_entry = load_entry(file_path)
entry.__dict__[filename] = sub_entry
else:
entry.__dict__[filename] = open(file_path, "rb").read()
return entry
def load_list(entry_path):
'''
Loads a "list" entry (corresponds to a python list, or a Java
ArrayList, such as the "messages" member of a Burp Scanner Issue).
'''
entries = []
for filename in os.listdir(entry_path):
file_path = os.path.join(entry_path, filename)
if filename == ".burp-list":
continue
entries.append(load_entry(file_path))
return entries
# Process each of the directories in the underlying git repo
if self.repo_path:
for entry_dir in os.listdir(self.repo_path):
if entry_dir == ".git":
continue
entry_path = os.path.join(self.repo_path, entry_dir)
if not os.path.isdir(entry_path):
continue
entry = load_entry(entry_path)
yield entry
def _whoami(self):
'''
Returns user.name from the underlying git repo. Used to note who
created or modified an entry.
'''
self.user = self._run_subprocess_command(["git", "config", "user.name"],
cwd=self.repo_path)
return self.user
def whoami(self):
'''
wrapper of _whoami
'''
return self.user
def remove(self, entry):
'''
Removes the given LogEntry from the underlying git repo.
'''
self.pull()
entry_path = os.path.join(self.repo_path, entry.md5)
self._run_subprocess_command(["git", "rm", "-rf", entry_path],
cwd=self.repo_path)
self._run_subprocess_command(["git", "commit", "-m", "Removed entry at %s" %
entry_path], cwd=self.repo_path)
def pull(self):
'''
pulles the actual state from the underlying git repo.
'''
self.add_key_to_know_hosts(self.repo_uri)
self._run_subprocess_command(["git", "pull"], cwd=self.repo_path)
def push(self):
'''
Pushes the actual state from the underlying git repo.
'''
self.pull()
print(self._run_subprocess_command(["git", "push"], cwd=self.repo_path))
def add_key_to_know_hosts(self, repo_uri):
server = repo_uri.split('@')[1].split(':')[0]
keys = self._run_subprocess_command(["ssh-keyscan", server]).decode()
hosts_file = os.path.join(self.home, ".ssh", "known_hosts")
lines = []
if os.path.exists(hosts_file):
with open(hosts_file, "r") as f:
lines = f.read().split('\n')
for k in keys.split('\n'):
if not k in lines:
lines.append(k)
with open(hosts_file, "w") as f:
f.write('\n'.join(lines)+'\n')
def set_config(self, user, email, repo_uri):
'''
Set the supplied data to git config
'''
self.repo_name = self._extract_repo_name(repo_uri)
self.repo_path = self._generate_path_repo_name(self.repo_name)
self.repo_uri = repo_uri
self.user = user
self.email = email
self.add_key_to_know_hosts(repo_uri)
self._run_subprocess_command(["git", "config", "--global", "user.name", user], cwd=self.base_path)
self._run_subprocess_command(["git", "config", "--global", "user.email", email], cwd=self.base_path)
if not os.path.exists(self.repo_path):
self._run_subprocess_command(["git", "clone", repo_uri, self.repo_name], cwd=self.base_path)
self.save_current_project_repo()
def delete_repo_local(self, repo_uri):
'''
Deletes local repo_uri folder.
'''
repo_name = self._extract_repo_name(repo_uri)
self._run_subprocess_command(["rm", "-rf", repo_name], cwd=self.base_path)
def set_description(self, entry_hash, description):
'''
Set description data in local repo folder, commit and push.
'''
entry_path = os.path.join(self.repo_path, entry_hash)
who_file = os.path.join(entry_path, 'who')
description_file = os.path.join(entry_path, 'description')
with open(who_file, "r") as f:
who = f.read()
if who != self.whoami():
print("You cannot edit description entry that you not created (check 'who' field)")
return False
self.pull()
with open(description_file, 'w') as f:
f.write(description)
self._run_subprocess_command(["git", "add", description_file],
cwd=self.repo_path)
self._run_subprocess_command(["git", "commit", "-m", "Edited description entry"],
cwd=self.repo_path)
self.push()
def get_actual_repo_uri(self):
return self.repo_uri
def get_key_pub(self):
return self.key_pub
def _get_key_pub(self):
self.ssh_pub_key_path = os.path.join(self.home, ".ssh/id_rsa.pub")
with open(self.ssh_pub_key_path, 'r') as f:
self.key_pub = f.read()
return self.key_pub
'''
Implementation of extension's UI.
'''
class BurpUi(ITab):
'''
The collection of objects that make up this extension's Burp UI. Created
by BurpExtender.
'''
def __init__(self, callbacks, log):
'''
Creates GUI objects, registers right-click handlers, and adds the
extension's tab to the Burp UI.
'''
# Create split pane with top and bottom panes
self._splitpane = JSplitPane(JSplitPane.VERTICAL_SPLIT)
self._splitpane2 = JSplitPane(JSplitPane.HORIZONTAL_SPLIT)
# self.bottom_pane = UiBottomPane(callbacks, log)
self.bottom_pane1 = UiBottomPane1(callbacks, log)
self.bottom_pane2 = UiBottomPane2(callbacks, log)
self.top_pane = UiTopPane(callbacks, self.bottom_pane2, log)
self.bottom_pane1.setLogTable(self.top_pane.logTable)
self.bottom_pane2.setLogTable(self.top_pane.logTable)
self._splitpane.setLeftComponent(self.top_pane)
self._splitpane.setRightComponent(self._splitpane2)
self._splitpane2.setLeftComponent(self.bottom_pane1)
self._splitpane2.setRightComponent(self.bottom_pane2)
# Create right-click handler
self.log = log
rc_handler = RightClickHandler(callbacks, log)
callbacks.registerContextMenuFactory(rc_handler)
# Add the plugin's custom tab to Burp's UI
callbacks.customizeUiComponent(self._splitpane)
callbacks.addSuiteTab(self)
def getTabCaption(self):
return "Git"
def getUiComponent(self):
return self._splitpane
class RightClickHandler(IContextMenuFactory):
'''
Creates menu items for Burp UI right-click menus.
'''
def __init__(self, callbacks, log):
self.callbacks = callbacks
self.log = log
def createMenuItems(self, invocation):
'''
Invoked by Burp when a right-click menu is created; adds Git Bridge's
options to the menu.
'''
context = invocation.getInvocationContext()
tool = invocation.getToolFlag()
if tool == self.callbacks.TOOL_REPEATER:
if context in [invocation.CONTEXT_MESSAGE_EDITOR_REQUEST, invocation.CONTEXT_MESSAGE_VIEWER_RESPONSE]:
item = JMenuItem("Send to Git Bridge")
item.addActionListener(self.RepeaterHandler(self.callbacks, invocation, self.log))
items = ArrayList()
items.add(item)
return items
elif tool == self.callbacks.TOOL_SCANNER:
if context in [invocation.CONTEXT_SCANNER_RESULTS]:
item = JMenuItem("Send to Git Bridge")
item.addActionListener(self.ScannerHandler(self.callbacks, invocation, self.log))
items = ArrayList()
items.add(item)
return items
else:
# TODO: add support for other tools
pass
class ScannerHandler(ActionListener):
'''
Handles selection of the 'Send to Git Bridge' menu item when shown
on a Scanner right click menu.
'''
def __init__(self, callbacks, invocation, log):
self.callbacks = callbacks
self.invocation = invocation
self.log = log
def actionPerformed(self, actionEvent):
for issue in self.invocation.getSelectedIssues():
self.log.add_scanner_entry(issue)
class RepeaterHandler(ActionListener):
'''
Handles selection of the 'Send to Git Bridge' menu item when shown
on a Repeater right click menu.
'''
def __init__(self, callbacks, invocation, log):
self.callbacks = callbacks
self.invocation = invocation
self.log = log
def actionPerformed(self, actionEvent):
for message in self.invocation.getSelectedMessages():
self.log.add_repeater_entry(message)
class UiBottomPane1(JTabbedPane, IMessageEditorController):
'''
The bottom pane in the this extension's UI tab. It shows detail of
whatever is selected in the top pane.
'''
def __init__(self, callbacks, log):
self.configPanel = ConfigPanel(callbacks, log)
self.addTab("Config & Commands", self.configPanel)
# self.commandPanel = CommandPanel(callbacks, log)
# self.addTab("Git Commands", self.commandPanel)
# self.editPanel = EntryEditPanel(callbacks, log)
# self.addTab("Entry edit", self.editPanel)
self._requestViewer = callbacks.createMessageEditor(self, False)
self._responseViewer = callbacks.createMessageEditor(self, False)
self._issueViewer = callbacks.createMessageEditor(self, False)
callbacks.customizeUiComponent(self)
def setLogTable(self, log_table):
'''
Passes the Log table to the "Send to Tools" component so it can grab
the selected rows
'''
# self.commandPanel.log_table = log_table
# self.editPanel.log_table = log_table
self.configPanel.log_table = log_table
def show_log_entry(self, log_entry):
'''
Shows the log entry in the bottom pane of the UI
'''
self.removeAll()
self.addTab("Commands & Config", self.configPanel)
self._currentlyDisplayedItem = log_entry
def getScanIssueSummary(self, log_entry):
'''
A quick hack to generate a plaintext summary of a Scanner issue.
This is shown in the bottom pane of the Git Bridge tab when a Scanner
item is selected.
'''
out = []
for key, val in sorted(log_entry.__dict__.items()):
if key in ["messages", "tool", "md5"]:
continue
out.append("%s: %s" % (key, val))
return "\n\n".join(out)
'''
The three methods below implement IMessageEditorController st. requests
and responses are shown in the UI pane
'''
def getHttpService(self):
return self._currentlyDisplayedItem.requestResponse.getHttpService()
def getRequest(self):
return self._currentlyDisplayedItem.requestResponse.getRequest()
def getResponse(self):
return self._currentlyDisplayedItem.getResponse()
class UiBottomPane2(JTabbedPane, IMessageEditorController):
'''
The bottom pane in the this extension's UI tab. It shows detail of
whatever is selected in the top pane.
'''
def __init__(self, callbacks, log):
self.commandPanel = CommandPanel(callbacks, log)
self.editPanel = EntryEditPanel(callbacks, log)
self.addTab("Entry edit", self.editPanel)
self._requestViewer = callbacks.createMessageEditor(self, False)
self._responseViewer = callbacks.createMessageEditor(self, False)
self._issueViewer = callbacks.createMessageEditor(self, False)
callbacks.customizeUiComponent(self)
def setLogTable(self, log_table):
'''
Passes the Log table to the "Send to Tools" component so it can grab
the selected rows
'''
self.commandPanel.log_table = log_table
self.editPanel.log_table = log_table
def show_log_entry(self, log_entry):
'''
Shows the log entry in the bottom pane of the UI
'''
self.removeAll()
if getattr(log_entry, "request", False):
self.addTab("Request", self._requestViewer.getComponent())
self._requestViewer.setMessage(log_entry.request, True)
if getattr(log_entry, "response", False):
self.addTab("Response", self._responseViewer.getComponent())
self._responseViewer.setMessage(log_entry.response, False)
if log_entry.tool == "scanner":
self.addTab("Issue Summary", self._issueViewer.getComponent())
self._issueViewer.setMessage(self.getScanIssueSummary(log_entry),
False)
self.addTab("Entry Edit", self.editPanel)
self._currentlyDisplayedItem = log_entry