-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathburpaai.py
More file actions
1378 lines (1111 loc) · 53.2 KB
/
burpaai.py
File metadata and controls
1378 lines (1111 loc) · 53.2 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
# -*- coding: utf-8 -*-
from __future__ import print_function
"""
BurpAI NATIVE REPEATER MODE - Burp Suite Extension
Production-grade Jython extension with FIXED imports, clean UI, no crashes
"""
import sys
import traceback
import threading
import json
import time
# ===== BURP IMPORTS =====
from burp import IBurpExtender, ITab, IHttpListener, IContextMenuFactory, IMessageEditorController
# ===== JAVA/SWING IMPORTS (EXPLICIT - NO java. PREFIX) =====
from javax.swing import JPanel
from javax.swing import JScrollPane
from javax.swing import JSplitPane
from javax.swing import JTabbedPane
from javax.swing import JTable
from javax.swing import JTextArea
from javax.swing import JTextField
from javax.swing import JButton
from javax.swing import JLabel
from javax.swing import JComboBox
from javax.swing import JCheckBox
from javax.swing import JMenuItem
from javax.swing import SwingUtilities
from javax.swing import BorderFactory
from javax.swing import BoxLayout
from javax.swing import Box
from javax.swing import ListSelectionModel
from javax.swing.table import DefaultTableModel
from javax.swing.event import ListSelectionListener
# ===== JAVA AWT IMPORTS (EXPLICIT - NO java. PREFIX) =====
from java.awt import BorderLayout
from java.awt import FlowLayout
from java.awt import Dimension
from java.awt import Color
from java.awt import Font
from java.awt import Insets
# ===== JAVA AWT EVENT IMPORTS =====
from java.awt.event import ActionListener
from java.awt.event import KeyListener
from java.awt.event import KeyEvent
# ===== JAVA LANG IMPORTS =====
from java.lang import Runnable
# ===== URLLIB COMPATIBILITY =====
try:
from urllib2 import Request, urlopen, HTTPError
except ImportError:
from urllib.request import Request, urlopen
from urllib.error import HTTPError
# ===== MESSAGE EDITOR CONTROLLER =====
class MessageEditorController(IMessageEditorController):
def __init__(self, extension):
self.ext = extension
def getHttpService(self):
return None
def getRequest(self):
return None
def setRequest(self, message):
pass
def getResponse(self):
return None
def setResponse(self, message):
pass
def getEditorName(self):
return "BurpAI"
# ===== EVENT LISTENERS =====
class SendButtonListener(ActionListener):
def __init__(self, extension):
self.ext = extension
def actionPerformed(self, event):
try:
self.ext.send_chat_message()
except Exception as e:
print("[!] SendButtonListener error: " + str(e))
traceback.print_exc()
class InputKeyListener(KeyListener):
def __init__(self, extension):
self.ext = extension
def keyPressed(self, e):
try:
if e.getKeyCode() == KeyEvent.VK_ENTER:
self.ext.send_chat_message()
except Exception as e:
print("[!] InputKeyListener error: " + str(e))
traceback.print_exc()
def keyReleased(self, e):
pass
def keyTyped(self, e):
pass
class SaveAPIListener(ActionListener):
def __init__(self, extension):
self.ext = extension
def actionPerformed(self, event):
try:
self.ext.save_api_key()
except Exception as e:
print("[!] SaveAPIListener error: " + str(e))
traceback.print_exc()
class UpdateModelListener(ActionListener):
def __init__(self, extension):
self.ext = extension
def actionPerformed(self, event):
try:
self.ext.update_model()
except Exception as e:
print("[!] UpdateModelListener error: " + str(e))
traceback.print_exc()
class RepeatSendListener(ActionListener):
def __init__(self, extension):
self.ext = extension
def actionPerformed(self, event):
try:
self.ext.send_request()
except Exception as e:
print("[!] RepeatSendListener error: " + str(e))
traceback.print_exc()
class HistorySelectionListener(ListSelectionListener):
def __init__(self, extension):
self.ext = extension
def valueChanged(self, event):
try:
if not event.getValueIsAdjusting():
self.ext.load_from_history()
except Exception as e:
print("[!] HistorySelectionListener error: " + str(e))
traceback.print_exc()
class ContextMenuSendToAIListener(ActionListener):
def __init__(self, extension, messages):
self.ext = extension
self.messages = messages
def actionPerformed(self, event):
try:
self.ext.forward_to_ai_from_menu(self.messages)
except Exception as e:
print("[!] ContextMenuSendToAIListener error: " + str(e))
traceback.print_exc()
class ContextMenuFactory(IContextMenuFactory):
def __init__(self, extension):
self.extension = extension
def createMenuItems(self, invocation):
try:
menu_items = []
selected = invocation.getSelectedMessages()
if selected and len(selected) > 0:
item = JMenuItem("Send to BurpAI")
item.addActionListener(ContextMenuSendToAIListener(self.extension, selected))
menu_items.append(item)
return menu_items if menu_items else None
except Exception as e:
print("[!] ContextMenuFactory error: " + str(e))
traceback.print_exc()
return None
class AnalyzeButtonListener(ActionListener):
def __init__(self, extension):
self.ext = extension
def actionPerformed(self, event):
try:
self.ext.analyze_with_ai()
except Exception as e:
print("[!] AnalyzeButtonListener error: " + str(e))
traceback.print_exc()
class AutoAnalyzeListener(ActionListener):
def __init__(self, extension):
self.ext = extension
def actionPerformed(self, event):
try:
self.ext.auto_analyze = self.ext.auto_analyze_checkbox.isSelected()
print("[*] Auto Analyze: " + str(self.ext.auto_analyze))
except Exception as e:
print("[!] AutoAnalyzeListener error: " + str(e))
traceback.print_exc()
# ===== MAIN EXTENSION CLASS =====
class BurpExtender(IBurpExtender, ITab, IHttpListener):
def registerExtenderCallbacks(self, callbacks):
try:
self.callbacks = callbacks
self.helpers = callbacks.getHelpers()
self.api_key = ""
self.model = "kimi-k2.5"
self.traffic_log = []
self.ai_history = []
self.max_history = 1000 # Limit history to 1000 entries for performance
self.current_request = None
self.current_response = None
# Multi-model engine with fallback (Bug Bounty Hunter Mode)
self.primary_models = [
"alibaba-qwen3-32b",
"deepseek-r1-distill-llama-70b",
"glm-5",
"kimi-k2.5",
"llama3-8b-instruct",
"llama3.3-70b-instruct",
"minimax-m2.5",
"mistral-nemo-instruct-2407",
"nvidia-nemotron-3-super-120b",
"openai-gpt-oss-120b",
"openai-gpt-oss-20b"
]
self.fallback_models = []
self.all_models = self.primary_models + self.fallback_models
self.current_model_index = 0
# UI Components
self.chat_display = None
self.chat_input = None
self.api_input = None
self.status_label = None
self.model_combo = None
self.history_table = None
self.history_model = None
# Native Message Editors
self.request_editor = None
self.response_editor = None
self.editor_controller = MessageEditorController(self)
# Repeater controls
self.auto_analyze = False
self.auto_analyze_checkbox = None
self.callbacks.registerHttpListener(self)
self.callbacks.registerContextMenuFactory(ContextMenuFactory(self))
self.callbacks.addSuiteTab(self)
print("[*] BurpAI loaded successfully - ready to capture requests")
except Exception as e:
print("[!] Error in registerExtenderCallbacks: " + str(e))
traceback.print_exc()
def getTabCaption(self):
try:
return "BurpAI"
except Exception as e:
print("[!] Error in getTabCaption: " + str(e))
traceback.print_exc()
return "BurpAI"
def getUiComponent(self):
try:
return self.build_ui()
except Exception as e:
print("[!] Error in getUiComponent: " + str(e))
traceback.print_exc()
return JPanel()
def build_ui(self):
"""Build main UI with clean alignment"""
try:
main_panel = JPanel(BorderLayout())
main_panel.setBackground(Color(30, 30, 30))
# TOP: Compact toolbar
toolbar = self.build_toolbar()
main_panel.add(toolbar, BorderLayout.NORTH)
# CENTER: Main horizontal split
main_split = JSplitPane(JSplitPane.HORIZONTAL_SPLIT)
main_split.setDividerLocation(400)
main_split.setBackground(Color(30, 30, 30))
main_split.setResizeWeight(0.4)
main_split.setBorder(BorderFactory.createLineBorder(Color(60, 60, 60), 1))
left_panel = self.build_chat_panel()
right_panel = self.build_right_panel()
main_split.setLeftComponent(left_panel)
main_split.setRightComponent(right_panel)
main_panel.add(main_split, BorderLayout.CENTER)
return main_panel
except Exception as e:
print("[!] Error in build_ui: " + str(e))
traceback.print_exc()
return JPanel()
def build_toolbar(self):
"""Create compact Burp-style toolbar with proper alignment"""
try:
toolbar = JPanel(FlowLayout(FlowLayout.LEFT, 8, 5))
toolbar.setBackground(Color(40, 40, 40))
toolbar.setBorder(BorderFactory.createLineBorder(Color(60, 60, 60), 1))
toolbar.setPreferredSize(Dimension(100, 38))
# API Key label
api_label = JLabel("API Key:")
api_label.setForeground(Color(180, 180, 180))
api_label.setFont(Font("Arial", Font.PLAIN, 10))
toolbar.add(api_label)
# API Key input field
self.api_input = JTextField()
self.api_input.setBackground(Color(50, 50, 50))
self.api_input.setForeground(Color(200, 200, 200))
self.api_input.setFont(Font("Monospaced", Font.PLAIN, 10))
self.api_input.setPreferredSize(Dimension(200, 26))
self.api_input.setMaximumSize(Dimension(200, 26))
self.api_input.setMargin(Insets(2, 4, 2, 4))
toolbar.add(self.api_input)
# Save button
save_btn = JButton("Save")
save_btn.setBackground(Color(100, 180, 100))
save_btn.setForeground(Color.WHITE)
save_btn.setFont(Font("Arial", Font.BOLD, 9))
save_btn.setPreferredSize(Dimension(65, 26))
save_btn.setMaximumSize(Dimension(65, 26))
save_btn.setMargin(Insets(2, 8, 2, 8))
save_btn.setFocusPainted(False)
save_btn.addActionListener(SaveAPIListener(self))
toolbar.add(save_btn)
# Separator
toolbar.add(JLabel(" | "))
# Model label
model_label = JLabel("Model:")
model_label.setForeground(Color(180, 180, 180))
model_label.setFont(Font("Arial", Font.PLAIN, 10))
toolbar.add(model_label)
# Model dropdown
self.model_combo = JComboBox(self.all_models)
self.model_combo.setBackground(Color(50, 50, 50))
self.model_combo.setForeground(Color(200, 200, 200))
self.model_combo.setFont(Font("Arial", Font.PLAIN, 10))
self.model_combo.setPreferredSize(Dimension(170, 26))
self.model_combo.setMaximumSize(Dimension(170, 26))
self.model_combo.addActionListener(UpdateModelListener(self))
toolbar.add(self.model_combo)
# Separator
toolbar.add(JLabel(" | "))
# Status label
status_label_text = JLabel("Status:")
status_label_text.setForeground(Color(180, 180, 180))
status_label_text.setFont(Font("Arial", Font.PLAIN, 10))
toolbar.add(status_label_text)
self.status_label = JLabel("Ready")
self.status_label.setForeground(Color(255, 200, 100))
self.status_label.setFont(Font("Arial", Font.BOLD, 10))
toolbar.add(self.status_label)
return toolbar
except Exception as e:
print("[!] Error in build_toolbar: " + str(e))
traceback.print_exc()
return JPanel()
def build_chat_panel(self):
"""Build left chat panel"""
try:
panel = JPanel(BorderLayout())
panel.setBackground(Color(30, 30, 30))
panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5))
# Chat display
self.chat_display = JTextArea()
self.chat_display.setEditable(False)
self.chat_display.setBackground(Color(30, 30, 30))
self.chat_display.setForeground(Color(212, 212, 212))
self.chat_display.setFont(Font("Consolas", Font.PLAIN, 11))
self.chat_display.setLineWrap(True)
self.chat_display.setWrapStyleWord(True)
self.chat_display.setMargin(Insets(8, 8, 8, 8))
scroll = JScrollPane(self.chat_display)
scroll.setBackground(Color(30, 30, 30))
scroll.setBorder(BorderFactory.createLineBorder(Color(60, 60, 60), 1))
scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED)
scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER)
panel.add(scroll, BorderLayout.CENTER)
# Input area
input_panel = JPanel(BorderLayout())
input_panel.setBackground(Color(30, 30, 30))
input_panel.setBorder(BorderFactory.createEmptyBorder(8, 0, 0, 0))
self.chat_input = JTextField()
self.chat_input.setBackground(Color(45, 45, 48))
self.chat_input.setForeground(Color(212, 212, 212))
self.chat_input.setFont(Font("Monospaced", Font.PLAIN, 11))
self.chat_input.setCaretColor(Color(212, 212, 212))
self.chat_input.setMargin(Insets(4, 6, 4, 6))
self.chat_input.addKeyListener(InputKeyListener(self))
input_panel.add(self.chat_input, BorderLayout.CENTER)
send_btn = JButton("Send")
send_btn.setBackground(Color(51, 122, 183))
send_btn.setForeground(Color.WHITE)
send_btn.setFont(Font("Arial", Font.PLAIN, 10))
send_btn.setFocusPainted(False)
send_btn.setPreferredSize(Dimension(75, 32))
send_btn.setMargin(Insets(2, 10, 2, 10))
send_btn.addActionListener(SendButtonListener(self))
input_panel.add(send_btn, BorderLayout.EAST)
panel.add(input_panel, BorderLayout.SOUTH)
return panel
except Exception as e:
print("[!] Error in build_chat_panel: " + str(e))
traceback.print_exc()
return JPanel()
def build_right_panel(self):
"""Build right panel with history and repeater"""
try:
right_split = JSplitPane(JSplitPane.VERTICAL_SPLIT)
right_split.setDividerLocation(200)
right_split.setBackground(Color(30, 30, 30))
right_split.setResizeWeight(0.35)
right_split.setBorder(BorderFactory.createLineBorder(Color(60, 60, 60), 1))
history_panel = self.build_history_panel()
repeater_panel = self.build_repeater_panel()
right_split.setTopComponent(history_panel)
right_split.setBottomComponent(repeater_panel)
return right_split
except Exception as e:
print("[!] Error in build_right_panel: " + str(e))
traceback.print_exc()
return JPanel()
def build_history_panel(self):
"""Build history table panel with data binding"""
try:
panel = JPanel(BorderLayout())
panel.setBackground(Color(30, 30, 30))
panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5))
# Title
title_label = JLabel("Request History")
title_label.setForeground(Color(150, 150, 150))
title_label.setFont(Font("Arial", Font.BOLD, 10))
title_panel = JPanel()
title_panel.setBackground(Color(30, 30, 30))
title_panel.add(title_label)
panel.add(title_panel, BorderLayout.NORTH)
# Create history table model with columns
self.history_model = DefaultTableModel(
["#", "Method", "Host", "Path", "Status"],
0
)
# Bind model to table
self.history_table = JTable(self.history_model)
self.history_table.setBackground(Color(45, 45, 48))
self.history_table.setForeground(Color(212, 212, 212))
self.history_table.setFont(Font("Monospaced", Font.PLAIN, 9))
self.history_table.setGridColor(Color(60, 60, 60))
self.history_table.setRowHeight(22)
self.history_table.setSelectionBackground(Color(66, 110, 165))
# Add selection listener to load requests
self.history_table.getSelectionModel().addListSelectionListener(HistorySelectionListener(self))
# Set column widths
self.history_table.getColumnModel().getColumn(0).setPreferredWidth(30)
self.history_table.getColumnModel().getColumn(1).setPreferredWidth(50)
self.history_table.getColumnModel().getColumn(2).setPreferredWidth(80)
self.history_table.getColumnModel().getColumn(3).setPreferredWidth(100)
self.history_table.getColumnModel().getColumn(4).setPreferredWidth(40)
# Add scroll pane
scroll = JScrollPane(self.history_table)
scroll.setBackground(Color(30, 30, 30))
scroll.setBorder(BorderFactory.createLineBorder(Color(60, 60, 60), 1))
scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED)
scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER)
panel.add(scroll, BorderLayout.CENTER)
print("[*] History table initialized: model=" + str(self.history_model) + ", table=" + str(self.history_table))
return panel
except Exception as e:
print("[!] Error in build_history_panel: " + str(e))
traceback.print_exc()
return JPanel()
def build_repeater_panel(self):
"""Build native repeater panel"""
try:
panel = JPanel(BorderLayout())
panel.setBackground(Color(30, 30, 30))
panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5))
# Title
title_label = JLabel("Repeater / Response")
title_label.setForeground(Color(150, 150, 150))
title_label.setFont(Font("Arial", Font.BOLD, 10))
title_panel = JPanel()
title_panel.setBackground(Color(30, 30, 30))
title_panel.add(title_label)
panel.add(title_panel, BorderLayout.NORTH)
# Native Burp Message Editors
try:
self.request_editor = self.callbacks.createMessageEditor(self.editor_controller, True)
self.response_editor = self.callbacks.createMessageEditor(self.editor_controller, False)
except Exception as editor_err:
print("[!] Error creating message editors: " + str(editor_err))
traceback.print_exc()
self.request_editor = None
self.response_editor = None
# Tabs for request/response
tabs = JTabbedPane()
tabs.setBackground(Color(40, 40, 40))
tabs.setForeground(Color(180, 180, 180))
if self.request_editor:
request_component = self.request_editor.getComponent()
tabs.addTab("Request", request_component)
if self.response_editor:
response_component = self.response_editor.getComponent()
tabs.addTab("Response", response_component)
panel.add(tabs, BorderLayout.CENTER)
# Control buttons panel
btn_panel = JPanel()
btn_panel.setLayout(FlowLayout(FlowLayout.LEFT, 8, 5))
btn_panel.setBackground(Color(30, 30, 30))
btn_panel.setBorder(BorderFactory.createEmptyBorder(8, 0, 0, 0))
repeat_send = JButton("Send Request")
repeat_send.setBackground(Color(100, 200, 100))
repeat_send.setForeground(Color.WHITE)
repeat_send.setFont(Font("Arial", Font.BOLD, 10))
repeat_send.setPreferredSize(Dimension(120, 30))
repeat_send.setMargin(Insets(4, 15, 4, 15))
repeat_send.setFocusPainted(False)
repeat_send.addActionListener(RepeatSendListener(self))
btn_panel.add(repeat_send)
# Separator
btn_panel.add(JLabel(" | "))
# Analyze button
analyze_btn = JButton("Analyze with AI")
analyze_btn.setBackground(Color(51, 122, 183))
analyze_btn.setForeground(Color.WHITE)
analyze_btn.setFont(Font("Arial", Font.BOLD, 10))
analyze_btn.setPreferredSize(Dimension(130, 30))
analyze_btn.setMargin(Insets(4, 15, 4, 15))
analyze_btn.setFocusPainted(False)
analyze_btn.addActionListener(AnalyzeButtonListener(self))
btn_panel.add(analyze_btn)
# Auto Analyze checkbox
try:
self.auto_analyze_checkbox = JCheckBox()
self.auto_analyze_checkbox.setText("Auto Analyze")
self.auto_analyze_checkbox.setBackground(Color(30, 30, 30))
self.auto_analyze_checkbox.setForeground(Color(212, 212, 212))
self.auto_analyze_checkbox.setFont(Font("Arial", Font.PLAIN, 10))
self.auto_analyze_checkbox.setFocusPainted(False)
self.auto_analyze_checkbox.addActionListener(AutoAnalyzeListener(self))
btn_panel.add(self.auto_analyze_checkbox)
except Exception as checkbox_err:
print("[!] Error creating auto analyze checkbox: " + str(checkbox_err))
panel.add(btn_panel, BorderLayout.SOUTH)
return panel
except Exception as e:
print("[!] Error in build_repeater_panel: " + str(e))
traceback.print_exc()
return JPanel()
# ===== CORE METHODS =====
def save_api_key(self):
try:
key = self.api_input.getText().strip()
if not key:
self.add_chat_message("System", "Error: API key cannot be empty")
return
self.api_key = key
self.callbacks.saveExtensionSetting("burpaai_api_key", key)
self.add_chat_message("System", "API key saved successfully")
self.status_label.setText("Connected")
self.status_label.setForeground(Color(100, 200, 100))
except Exception as e:
print("[!] Error saving API key: " + str(e))
traceback.print_exc()
self.add_chat_message("System", "Error saving API key: " + str(e))
def update_model(self):
try:
self.model = str(self.model_combo.getSelectedItem())
print("[*] Model updated: " + self.model)
except Exception as e:
print("[!] Error updating model: " + str(e))
traceback.print_exc()
def send_chat_message(self):
try:
text = self.chat_input.getText().strip()
if not text:
return
if not self.api_key:
self.add_chat_message("System", "Error: API key not configured")
return
self.add_chat_message("You", text)
self.chat_input.setText("")
thread = threading.Thread(target=lambda: self._send_chat_async(text))
thread.daemon = True
thread.start()
except Exception as e:
print("[!] Error in send_chat_message: " + str(e))
traceback.print_exc()
def _send_chat_async(self, text):
try:
response = self.call_ai(text)
SwingUtilities.invokeLater(lambda: self.add_chat_message("AI", response))
except Exception as e:
print("[!] Error in _send_chat_async: " + str(e))
traceback.print_exc()
SwingUtilities.invokeLater(lambda: self.add_chat_message("System", "Error: " + str(e)))
def add_chat_message(self, sender, text):
def update_ui():
try:
timestamp = time.strftime("%H:%M:%S")
current = self.chat_display.getText()
# Format message based on sender type
if sender == "BugBounty":
prefix = "[" + timestamp + "] [ANALYSIS]: "
elif sender == "AI":
prefix = "[" + timestamp + "] [AI]: "
elif sender == "You":
prefix = "[" + timestamp + "] [YOU]: "
else:
prefix = "[" + timestamp + "] [" + sender + "]: "
formatted_text = prefix + text
if current:
new_text = current + "\n" + formatted_text
else:
new_text = formatted_text
self.chat_display.setText(new_text)
self.chat_display.setCaretPosition(len(new_text))
except Exception as e:
print("[!] Error in add_chat_message: " + str(e))
traceback.print_exc()
SwingUtilities.invokeLater(update_ui)
def send_request(self):
"""Send request via Burp's native HTTP handler"""
try:
# Get request from native editor
request_bytes = self.request_editor.getMessage()
if not request_bytes or len(request_bytes) == 0:
self.add_chat_message("System", "Error: Request editor is empty")
return
# Parse request to extract host, port, protocol
request_str = self.helpers.bytesToString(request_bytes)
# Use Burp's analyzeRequest to get proper structure
analyzed = self.helpers.analyzeRequest(request_bytes)
# Get HTTP service details
host = analyzed.getUrl().getHost()
port = analyzed.getUrl().getPort()
protocol = analyzed.getUrl().getProtocol()
use_https = (protocol.lower() == "https")
if not host:
self.add_chat_message("System", "Error: Could not parse host from request")
return
# Build HTTP service
http_service = self.helpers.buildHttpService(host, port, use_https)
# Send request and get response
response_bytes = self.callbacks.makeHttpRequest(http_service, request_bytes)
if response_bytes:
# Load response into native editor
self.response_editor.setMessage(response_bytes, False)
self.add_chat_message("System", "[RESPONSE] Received from " + host)
# Store in history
entry = {
"method": analyzed.getMethod(),
"host": host,
"path": analyzed.getUrl().getPath(),
"request": request_bytes,
"response": response_bytes,
"timestamp": time.time()
}
self.ai_history.append(entry)
# Update table thread-safe
def update_table():
try:
status_code = self._extract_status_code(response_bytes)
row_num = len(self.ai_history)
self.history_model.addRow([
str(row_num),
analyzed.getMethod(),
host[:30],
analyzed.getUrl().getPath()[:40],
status_code
])
print("[+] Request added to history: " + analyzed.getMethod() + " " + host)
except Exception as e:
print("[!] Error updating table: " + str(e))
SwingUtilities.invokeLater(update_table)
# Auto Analyze if enabled
if self.auto_analyze:
print("[*] Auto Analyze triggered")
thread = threading.Thread(target=self.analyze_with_ai)
thread.daemon = True
thread.start()
else:
self.add_chat_message("System", "Error: No response from server")
except Exception as e:
print("[!] Error in send_request: " + str(e))
traceback.print_exc()
self.add_chat_message("System", "Error: " + str(e))
def load_from_history(self):
"""Load request/response from history table on row selection"""
try:
if not self.history_table:
print("[!] History table not initialized")
return
row = self.history_table.getSelectedRow()
print("[*] History row selected: " + str(row))
if row < 0:
print("[!] No row selected (row < 0)")
return
if row >= len(self.ai_history):
print("[!] Row index out of bounds: " + str(row) + " >= " + str(len(self.ai_history)))
return
entry = self.ai_history[row]
print("[*] Loading from history - row: " + str(row) + ", method: " + entry.get("method", "?"))
# Load request
if "request" in entry and entry["request"]:
if self.request_editor:
self.request_editor.setMessage(entry["request"], True)
print("[+] Request loaded into editor")
else:
print("[!] Request editor not available")
# Load response
if "response" in entry and entry["response"]:
if self.response_editor:
self.response_editor.setMessage(entry["response"], False)
print("[+] Response loaded into editor")
else:
print("[!] Response editor not available")
except Exception as e:
print("[!] Error loading from history: " + str(e))
traceback.print_exc()
def add_row_to_history(self, row_data):
"""Thread-safe method to add row to history table"""
def add_row_ui():
try:
if self.history_model:
self.history_model.addRow(row_data)
print("[+] Row added to history: " + str(row_data[0]))
except Exception as e:
print("[!] Error adding row to history: " + str(e))
traceback.print_exc()
SwingUtilities.invokeLater(add_row_ui)
def _extract_status_code(self, response_bytes):
"""Extract HTTP status code from response"""
try:
response_str = self.helpers.bytesToString(response_bytes)
first_line = response_str.split('\n')[0]
parts = first_line.split(' ')
if len(parts) >= 2:
return parts[1]
except:
pass
return "?"
def _clean_reasoning_content(self, text):
"""Remove thinking/reasoning text from AI response and extract key payload sections"""
try:
# Remove common reasoning patterns
lines = text.split('\n')
cleaned = []
skip_section = False
for line in lines:
line_lower = line.lower().strip()
# Detect and preserve section headers
if any(header in line_lower for header in ["[vulns]", "[payloads]", "[attack", "[exploit", "[test", "[issues]", "[vectors]"]):
cleaned.append(line)
skip_section = False
continue
# Skip extended thinking patterns
if any(pattern in line_lower for pattern in [
"the user is asking",
"the user is requesting",
"i need to",
"let me think",
"first, let me",
"to summarize",
"in conclusion",
"thinking about",
"considering the request",
"<thinking>",
"</thinking>",
"analyze the request"
]):
continue
# Skip lines that are just thinking markers
if line_lower.startswith("<") and line_lower.endswith(">"):
continue
if line.strip():
cleaned.append(line)
result = '\n'.join(cleaned).strip()
# Limit to 800 chars for comprehensive analysis
if len(result) > 800:
result = result[:797] + "..."
return result if result else "Processing complete"
except:
return text
def _parse_vulnerability_response(self, response_text):
"""Parse AI response to extract and structure vulnerability data"""
try:
lines = response_text.split('\n')
parsed = {
"vulns": [],
"attack_points": [],
"payloads": [],
"exploit_idea": [],
"raw": response_text
}
current_section = None
for line in lines:
line_stripped = line.strip()
if not line_stripped:
continue
# Detect section headers
if "[VULNS]" in line_stripped.upper():
current_section = "vulns"
continue
elif "[ATTACK" in line_stripped.upper():
current_section = "attack_points"
continue
elif "[PAYLOADS]" in line_stripped.upper():
current_section = "payloads"
continue
elif "[EXPLOIT" in line_stripped.upper():
current_section = "exploit_idea"
continue
elif "[" in line_stripped and "]" in line_stripped:
current_section = None
continue
# Add content to current section
if current_section and line_stripped:
if line_stripped.startswith("-"):
line_stripped = line_stripped[1:].strip()
parsed[current_section].append(line_stripped)
return parsed
except:
return {"vulns": [], "attack_points": [], "payloads": [], "exploit_idea": [], "raw": response_text}
def _classify_vulnerability_severity(self, vuln_text):
"""Classify vulnerability severity based on keywords"""
vuln_lower = vuln_text.lower()
severity_map = {
"CRITICAL": ["rce", "code execution", "remote command", "database dump", "full system compromise"],
"HIGH": ["idor", "ssrf", "sqli", "auth bypass", "session hijack", "privilege escalation", "admin access"],
"MEDIUM": ["xss", "csrf", "xxe", "header injection", "cookie manipulation", "weak authentication"],
"LOW": ["information disclosure", "missing headers", "weak configuration", "cors"]
}
for severity, keywords in severity_map.items():
if any(kw in vuln_lower for kw in keywords):
return severity
return "MEDIUM"
def _format_vulnerability_output(self, parsed_vulns):
"""Format parsed vulnerability data for display"""
try:
output = ""
if parsed_vulns["vulns"]: