-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBurParser.py
More file actions
1167 lines (950 loc) · 47.9 KB
/
BurParser.py
File metadata and controls
1167 lines (950 loc) · 47.9 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 burp import IBurpExtender, IHttpListener, ITab, IContextMenuFactory, IContextMenuInvocation, IScannerCheck
from javax.swing import JPanel, JTextArea, JScrollPane, BoxLayout, JButton, JLabel, JTextField, JCheckBox, JFileChooser, JSplitPane, JTabbedPane, JTable, JOptionPane, SwingUtilities, JMenuItem, JComboBox, JDialog, BorderFactory
from javax.swing.table import DefaultTableModel
from java.awt import BorderLayout, Dimension, GridLayout, FlowLayout, GridBagLayout, GridBagConstraints
from java.util import ArrayList, HashMap, LinkedHashMap, HashSet
from java.util.concurrent import ConcurrentHashMap, Executors, TimeUnit
from java.io import File, PrintWriter, BufferedWriter, FileWriter
from java.lang import Thread as JThread
from threading import Lock, Thread
from urlparse import urljoin, urlparse
import codecs
import re
import json
import time
import traceback
import os
class BurpExtender(IBurpExtender, IHttpListener, ITab, IContextMenuFactory, IScannerCheck):
def registerExtenderCallbacks(self, callbacks):
self._callbacks = callbacks
self._helpers = callbacks.getHelpers()
# Initialize data structures with thread safety
self.valid_dirs = ConcurrentHashMap()
self.forbidden_dirs = ConcurrentHashMap()
self.redirect_dirs = ConcurrentHashMap()
self.error_pages = ConcurrentHashMap()
self.processed_urls = ConcurrentHashMap() # Track processed URLs to avoid duplicates
self.extracted_paths = HashSet() # For wordlist generation
self.scan_scope = False # Default to processing all requests
self.is_running = True # Extension active state
self.lock = Lock()
# Thread pool for async processing
self.thread_pool = Executors.newFixedThreadPool(10)
# Configure extension
self._callbacks.setExtensionName("Burparser Pro")
self._callbacks.registerHttpListener(self)
self._callbacks.registerContextMenuFactory(self)
self._callbacks.registerScannerCheck(self)
# Error page patterns (customizable)
self.error_patterns = [
r'(?i)not\s+found',
r'(?i)404\s+error',
r'(?i)access\s+denied',
r'(?i)directory\s+listing\s+denied',
r'(?i)page\s+not\s+found',
r'(?i)file\s+not\s+found',
r'(?i)server\s+error',
r'(?i)internal\s+server\s+error',
r'(?i)forbidden'
]
# Content type whitelist
self.valid_content_types = {
'text/html',
'application/json',
'text/xml',
'application/xml',
'text/plain'
}
# Common file extensions to identify in paths
self.common_extensions = [
'.php', '.asp', '.aspx', '.jsp', '.jspx', '.do', '.action',
'.html', '.htm', '.xhtml', '.shtml', '.json', '.xml', '.txt',
'.js', '.css', '.cgi', '.pl', '.py', '.rb'
]
# Initialize UI components
self.setupUI()
print("BurParser Pro Extension loaded successfully")
def processHttpMessage(self, toolFlag, messageIsRequest, messageInfo):
# Respect the running state flag
if not self.is_running:
return
# Process only if it's a response
if not messageIsRequest:
# Check if we should only process in-scope items
if self.scan_scope and not self._callbacks.isInScope(messageInfo.getUrl()):
return
# Submit to thread pool for async processing
self.thread_pool.submit(lambda: self.handle_http_response(messageInfo))
def handle_http_response(self, messageInfo):
try:
# Extract response details
response = messageInfo.getResponse()
analyzed_response = self._helpers.analyzeResponse(response)
# Get URL and remove query parameters
url = str(messageInfo.getUrl())
clean_url = self.clean_url(url)
# Extract path for wordlist
self.extract_path_for_wordlist(url)
# Skip if already processed
if self.processed_urls.putIfAbsent(clean_url, True) is not None:
return
# Extract important information
status_code = analyzed_response.getStatusCode()
headers = analyzed_response.getHeaders()
content_type = self.get_content_type(headers)
# Process according to status code
if status_code == 200:
self.handle_200_response(clean_url, response, analyzed_response, content_type)
elif status_code == 403 or status_code == 401:
self.handle_403_response(clean_url, headers, status_code)
elif status_code >= 300 and status_code < 400:
self.handle_redirect_response(clean_url, headers, content_type, status_code)
elif status_code >= 500:
self.handle_server_error(clean_url, status_code)
# Update UI
SwingUtilities.invokeLater(self.update_results_display)
except Exception as e:
self._callbacks.printError("Error processing message: %s\n%s" % (str(e), traceback.format_exc()))
def extract_path_for_wordlist(self, url):
"""Extract path components and format them for effective wordlist generation."""
try:
parsed = urlparse(url)
if not parsed.path or parsed.path == "/":
return
path_parts = [p for p in parsed.path.split('/') if p]
current_path = ""
for i, part in enumerate(path_parts):
if not part:
continue
# Add raw path segment
self.extracted_paths.add(part)
# Build progressive paths
current_path += "/" + part
self.extracted_paths.add(current_path.lstrip('/'))
# Extract filename without extension if applicable
if i == len(path_parts) - 1:
for ext in self.common_extensions:
if part.endswith(ext):
filename = part[:-len(ext)]
if filename:
self.extracted_paths.add(filename)
break
# Extract numeric IDs separately
if part.isdigit():
self.extracted_paths.add("ID-{}".format(part))
# Extract parameters with potential sensitive data
if parsed.query:
params = parsed.query.split('&')
for param in params:
if '=' in param:
key, value = param.split('=', 1)
self.extracted_paths.add(key)
# Detect sensitive values (UUID, Base64, hashes)
if re.match(r'^[0-9a-fA-F]{32,64}$', value):
self.extracted_paths.add("HASH-{}".format(key))
elif re.match(r'^[0-9]+$', value):
self.extracted_paths.add("NUM-" + str(key))
elif re.match(r'^[A-Za-z0-9+/=]{20,}$', value): # Base64
self.extracted_paths.add("NUM-" + str(key))
except Exception as e:
self._callbacks.printError("Error extracting path: {}\n{}".format(str(e), traceback.format_exc()))
def extract_url_parts(self, url):
"""Extract specific parts of the URL for better categorization"""
parsed = urlparse(url)
path_parts = parsed.path.split('/')
result = {
'domain': parsed.netloc,
'scheme': parsed.scheme,
'path_depth': len([p for p in path_parts if p]),
}
if len(path_parts) >= 2:
result['context'] = path_parts[1]
if len(path_parts) >= 3:
result['servlet'] = path_parts[2]
return result
def handle_200_response(self, url, response, analyzed_response, content_type):
"""Handle successful responses"""
# Only process certain content types
if content_type and any(valid_type in content_type.lower() for valid_type in self.valid_content_types):
body_offset = analyzed_response.getBodyOffset()
body = self._helpers.bytesToString(response[body_offset:])
if not self.is_error_page(body):
info = HashMap()
info.put('status', 200)
info.put('content_type', content_type)
info.put('timestamp', time.time())
info.put('size', len(body))
info.put('url_parts', self.extract_url_parts(url))
# Extract interesting elements from successful responses
if 'html' in content_type.lower():
forms = self.extract_forms(body)
if forms:
info.put('forms', forms)
api_endpoints = self.extract_api_endpoints(body)
if api_endpoints:
info.put('api_endpoints', api_endpoints)
# Extract links and directory paths
self.extract_links_from_html(body, url)
self.valid_dirs.put(url, info)
else:
# It's a 200 OK but looks like an error page
info = HashMap()
info.put('status', 200)
info.put('is_error_page', True)
info.put('content_type', content_type)
info.put('timestamp', time.time())
self.error_pages.put(url, info)
def handle_403_response(self, url, headers, status_code):
"""Handle forbidden responses"""
info = HashMap()
info.put('status', status_code)
info.put('headers', self.extract_security_headers(headers))
info.put('timestamp', time.time())
info.put('url_parts', self.extract_url_parts(url))
self.forbidden_dirs.put(url, info)
def handle_redirect_response(self, url, headers, content_type, status_code):
"""Handle redirect responses"""
location = self.get_header_value(headers, "Location")
if location:
redirect_url = urljoin(url, location)
info = HashMap()
info.put('status', status_code)
info.put('redirect_to', redirect_url)
info.put('content_type', content_type)
info.put('timestamp', time.time())
info.put('url_parts', self.extract_url_parts(url))
self.redirect_dirs.put(url, info)
# Extract the path from redirect location for wordlist
self.extract_path_for_wordlist(redirect_url)
def handle_server_error(self, url, status_code):
"""Handle server error responses"""
info = HashMap()
info.put('status', status_code)
info.put('timestamp', time.time())
info.put('url_parts', self.extract_url_parts(url))
self.error_pages.put(url, info)
def extract_links_from_html(self, body, base_url):
"""Extract links from HTML content for wordlist generation"""
# Extract href links
href_pattern = r'href=["\'](.*?)["\']'
hrefs = re.findall(href_pattern, body)
# Extract src links
src_pattern = r'src=["\'](.*?)["\']'
srcs = re.findall(src_pattern, body)
# Extract action URLs
action_pattern = r'action=["\'](.*?)["\']'
actions = re.findall(action_pattern, body)
# Extract URLs from JavaScript
js_pattern = r'["\'](/[^"\']*?)["\']|["\'](https?://[^"\']*)["\']'
js_urls = re.findall(js_pattern, body)
# Process all found URLs
all_links = hrefs + srcs + actions
for link_pair in js_urls:
if link_pair[0]:
all_links.append(link_pair[0])
if link_pair[1]:
all_links.append(link_pair[1])
for link in all_links:
if link.startswith('/') or link.startswith('http'):
try:
abs_url = urljoin(base_url, link)
self.extract_path_for_wordlist(abs_url)
except:
pass
def extract_forms(self, body):
"""Extract form information from HTML"""
forms = []
form_pattern = r'<form\s+[^>]*>(.*?)</form>'
form_matches = re.finditer(form_pattern, body, re.DOTALL | re.IGNORECASE)
for match in form_matches:
form_html = match.group(0)
# Extract form action
action_match = re.search(r'action=["\'](.*?)["\']', form_html)
action = action_match.group(1) if action_match else ""
# Extract form method
method_match = re.search(r'method=["\'](.*?)["\']', form_html)
method = method_match.group(1) if method_match else "GET"
# Extract form inputs
inputs = []
input_pattern = r'<input\s+[^>]*>'
input_matches = re.finditer(input_pattern, form_html)
for input_match in input_matches:
input_html = input_match.group(0)
# Extract input name
name_match = re.search(r'name=["\'](.*?)["\']', input_html)
name = name_match.group(1) if name_match else ""
# Extract input type
type_match = re.search(r'type=["\'](.*?)["\']', input_html)
input_type = type_match.group(1) if type_match else "text"
if name:
inputs.append({'name': name, 'type': input_type})
# Add input names to wordlist
self.extracted_paths.add(name)
forms.append({
'action': action,
'method': method,
'inputs': inputs
})
return forms
def extract_api_endpoints(self, body):
"""Extract potential API endpoints from JavaScript"""
endpoints = []
# Look for URLs in JS
api_pattern = r'["\'](/api/[^"\']+)["\']|["\'](https?://[^"\']+/api/[^"\']+)["\']'
matches = re.finditer(api_pattern, body)
for match in matches:
endpoint = match.group(1) or match.group(2)
if endpoint and endpoint not in endpoints:
endpoints.append(endpoint)
# Add to wordlist
self.extract_path_for_wordlist(endpoint)
return endpoints
def is_error_page(self, body):
"""Enhanced error page detection"""
if not body:
return True
# Check against error patterns
for pattern in self.error_patterns:
if re.search(pattern, body):
return True
# Check for common error page characteristics
if len(body.strip()) < 100: # Suspicious if too short
return True
return False
def clean_url(self, url):
"""Remove query parameters and fragments from URL"""
parsed = urlparse(url)
cleaned = "%s://%s%s" % (parsed.scheme, parsed.netloc, parsed.path)
# Ensure path ends with / if it's a directory path
if not parsed.path.endswith('/') and '.' not in parsed.path.split('/')[-1]:
cleaned += '/'
return cleaned
def get_content_type(self, headers):
"""Extract content type from headers"""
for header in headers:
if header.lower().startswith("content-type:"):
return header.split(":", 1)[1].strip()
return None
def extract_security_headers(self, headers):
"""Extract security-related headers"""
security_headers = HashMap()
interesting_headers = [
'x-frame-options',
'x-content-type-options',
'x-xss-protection',
'content-security-policy',
'strict-transport-security',
'www-authenticate',
'server',
'x-powered-by'
]
for header in headers:
header_lower = header.lower()
for sec_header in interesting_headers:
if header_lower.startswith("%s:" % sec_header):
security_headers.put(sec_header, header.split(":", 1)[1].strip())
return security_headers
def get_header_value(self, headers, header_name):
"""Get value of specific header"""
for header in headers:
if header.lower().startswith("%s:" % header_name.lower()):
return header.split(":", 1)[1].strip()
return None
def setupUI(self):
"""Setup the extension's UI tab with enhanced interface"""
self.tab = JPanel(BorderLayout())
# Create a tabbed pane for different result categories
tabbed_pane = JTabbedPane()
# Create tables for different result types
self.valid_dirs_table = self.create_table(["URL", "Content Type", "Size", "Timestamp"])
self.forbidden_dirs_table = self.create_table(["URL", "Status", "Security Headers", "Timestamp"])
self.redirect_dirs_table = self.create_table(["URL", "Redirects To", "Status", "Timestamp"])
self.error_pages_table = self.create_table(["URL", "Status", "Timestamp"])
self.wordlist_table = self.create_table(["Path Component", "Source"])
# Add tables to tabbed pane
tabbed_pane.addTab("Valid (200)", JScrollPane(self.valid_dirs_table))
tabbed_pane.addTab("Forbidden", JScrollPane(self.forbidden_dirs_table))
tabbed_pane.addTab("Redirects", JScrollPane(self.redirect_dirs_table))
tabbed_pane.addTab("Errors", JScrollPane(self.error_pages_table))
tabbed_pane.addTab("Wordlist", JScrollPane(self.wordlist_table))
# Control panel
control_panel = JPanel(FlowLayout(FlowLayout.LEFT))
# Create filter field
self.filter_field = JTextField(20)
self.filter_field.setToolTipText("Filter results by domain or path")
# Create scope checkbox
self.scope_checkbox = JCheckBox("In-Scope Only")
self.scope_checkbox.addActionListener(lambda event: self.toggle_scope())
# Create clear button
clear_button = JButton("Clear Results")
clear_button.addActionListener(lambda event: self.clear_results())
# Create export button
export_button = JButton("Export Results")
export_button.addActionListener(lambda event: self.export_results())
# Create filter button
filter_button = JButton("Apply Filter")
filter_button.addActionListener(lambda event: self.apply_filter())
# Create wordlist export button
wordlist_button = JButton("Export Wordlist")
wordlist_button.addActionListener(lambda event: self.export_wordlist())
# Create extract from targets button
extract_targets_button = JButton("Extract from Targets")
extract_targets_button.addActionListener(lambda event: self.extract_from_targets())
# Add components to control panel
control_panel.add(JLabel("Filter:"))
control_panel.add(self.filter_field)
control_panel.add(filter_button)
control_panel.add(self.scope_checkbox)
control_panel.add(clear_button)
control_panel.add(export_button)
control_panel.add(wordlist_button)
control_panel.add(extract_targets_button)
# Add components to main panel
self.tab.add(control_panel, BorderLayout.NORTH)
self.tab.add(tabbed_pane, BorderLayout.CENTER)
# Add custom tab to Burp's UI
self._callbacks.addSuiteTab(self)
def create_table(self, columns):
"""Create a JTable with specified columns"""
model = DefaultTableModel(columns, 0)
table = JTable(model)
table.setAutoCreateRowSorter(True)
return table
def toggle_scope(self):
"""Toggle scope-only processing"""
self.scan_scope = self.scope_checkbox.isSelected()
def clear_results(self):
"""Clear all collected results"""
self.valid_dirs.clear()
self.forbidden_dirs.clear()
self.redirect_dirs.clear()
self.error_pages.clear()
self.processed_urls.clear()
self.extracted_paths.clear()
self.update_results_display()
def apply_filter(self):
"""Apply filter to results"""
self.update_results_display()
def update_results_display(self):
"""Update all result tables"""
try:
filter_text = self.filter_field.getText().lower()
# Update Valid Directories table
self.update_table(self.valid_dirs_table, self.valid_dirs, filter_text,
lambda url, info: [
url,
info.get('content_type', ""),
str(info.get('size', 0)),
time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(info.get('timestamp', 0)))
]
)
# Update Forbidden Directories table
self.update_table(self.forbidden_dirs_table, self.forbidden_dirs, filter_text,
lambda url, info: [
url,
str(info.get('status', 403)),
str(info.get('headers', {})),
time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(info.get('timestamp', 0)))
]
)
# Update Redirect Directories table
self.update_table(self.redirect_dirs_table, self.redirect_dirs, filter_text,
lambda url, info: [
url,
str(info.get('redirect_to', "")),
str(info.get('status', 302)),
time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(info.get('timestamp', 0)))
]
)
# Update Error Pages table
self.update_table(self.error_pages_table, self.error_pages, filter_text,
lambda url, info: [
url,
str(info.get('status', "Unknown")),
time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(info.get('timestamp', 0)))
]
)
# Update Wordlist table
self.update_wordlist_table(filter_text)
except Exception as e:
self._callbacks.printError("Error updating display: %s\n%s" % (str(e), traceback.format_exc()))
def update_table(self, table, data_map, filter_text, row_mapper):
"""Update a table with filtered data"""
model = table.getModel()
model.setRowCount(0)
for url in data_map.keySet():
if filter_text and filter_text not in url.lower():
continue
info = data_map.get(url)
row_data = row_mapper(url, info)
model.addRow(row_data)
def update_wordlist_table(self, filter_text):
"""Update wordlist table"""
model = self.wordlist_table.getModel()
model.setRowCount(0)
for path in sorted(self.extracted_paths):
if filter_text and filter_text not in path.lower():
continue
model.addRow([path, "Extracted"])
def export_results(self):
"""Export results to JSON file"""
try:
# Convert Java HashMaps to Python dicts for JSON serialization
results = self.prepare_export_data()
# Use Java's JFileChooser
file_chooser = JFileChooser()
file_chooser.setSelectedFile(File("burparser_results.json"))
if file_chooser.showSaveDialog(self.tab) == JFileChooser.APPROVE_OPTION:
selected_file = file_chooser.getSelectedFile()
file_path = selected_file.getAbsolutePath()
# Ensure file has .json extension
if not file_path.lower().endswith('.json'):
file_path += '.json'
with open(file_path, 'w') as f:
json.dump(results, f, indent=4)
JOptionPane.showMessageDialog(self.tab,
"Results exported successfully to: %s" % file_path,
"Export Complete",
JOptionPane.INFORMATION_MESSAGE)
except Exception as e:
JOptionPane.showMessageDialog(self.tab,
"Error exporting results: %s" % str(e),
"Export Error",
JOptionPane.ERROR_MESSAGE)
self._callbacks.printError("Error exporting results: %s\n%s" % (str(e), traceback.format_exc()))
def export_wordlist(self):
"""Export discovered paths as a wordlist for tools like dirsearch/dirbuster"""
try:
# Use Java's JFileChooser
file_chooser = JFileChooser()
file_chooser.setSelectedFile(File("burparser_wordlist.txt"))
if file_chooser.showSaveDialog(self.tab) == JFileChooser.APPROVE_OPTION:
selected_file = file_chooser.getSelectedFile()
file_path = selected_file.getAbsolutePath()
# Ensure file has .txt extension
if not file_path.lower().endswith('.txt'):
file_path += '.txt'
# Open the export options dialog
self.show_wordlist_export_options(file_path)
except Exception as e:
JOptionPane.showMessageDialog(self.tab,
"Error exporting wordlist: %s" % str(e),
"Export Error",
JOptionPane.ERROR_MESSAGE)
self._callbacks.printError("Error exporting wordlist: %s\n%s" % (str(e), traceback.format_exc()))
def show_wordlist_export_options(self, file_path):
"""Show dialog with wordlist export options"""
dialog = JDialog(None, "Wordlist Export Options", True)
dialog.setSize(400, 300)
dialog.setLocationRelativeTo(self.tab)
panel = JPanel(GridBagLayout())
panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10))
constraints = GridBagConstraints()
# Set up the constraints
constraints.fill = GridBagConstraints.HORIZONTAL
constraints.weightx = 1.0
constraints.gridx = 0
constraints.gridy = 0
constraints.gridwidth = 2
# Add options
panel.add(JLabel("Export Options:"), constraints)
constraints.gridy = 1
min_length_check = JCheckBox("Filter by minimum length")
panel.add(min_length_check, constraints)
constraints.gridy = 2
constraints.gridwidth = 1
panel.add(JLabel("Minimum length:"), constraints)
constraints.gridx = 1
min_length_field = JTextField("3", 5)
min_length_field.setEnabled(False)
panel.add(min_length_field, constraints)
# Link checkbox to text field
min_length_check.addActionListener(lambda e: min_length_field.setEnabled(min_length_check.isSelected()))
constraints.gridx = 0
constraints.gridy = 3
constraints.gridwidth = 2
common_ext_check = JCheckBox("Add common extensions to paths")
panel.add(common_ext_check, constraints)
constraints.gridy = 4
constraints.gridwidth = 1
panel.add(JLabel("Extension format:"), constraints)
constraints.gridx = 1
format_combo = JComboBox(["DIRECTORY", "DIRECTORY/", "/DIRECTORY/", "DIRECTORY.EXT"])
format_combo.setEnabled(False)
panel.add(format_combo, constraints)
# Link checkbox to combo box
common_ext_check.addActionListener(lambda e: format_combo.setEnabled(common_ext_check.isSelected()))
constraints.gridx = 0
constraints.gridy = 5
constraints.gridwidth = 2
filter_regex_check = JCheckBox("Filter using regex")
panel.add(filter_regex_check, constraints)
constraints.gridy = 6
panel.add(JLabel("Regex pattern:"), constraints)
constraints.gridy = 7
regex_field = JTextField("^[a-zA-Z0-9_-]+$", 20)
regex_field.setEnabled(False)
panel.add(regex_field, constraints)
# Link checkbox to text field
filter_regex_check.addActionListener(lambda e: regex_field.setEnabled(filter_regex_check.isSelected()))
# Add buttons
constraints.gridy = 8
constraints.gridwidth = 1
constraints.fill = GridBagConstraints.NONE
constraints.anchor = GridBagConstraints.CENTER
constraints.weighty = 1.0
export_button = JButton("Export", actionPerformed=lambda e: self.do_export_wordlist(
file_path,
min_length_check.isSelected(),
int(min_length_field.getText()),
common_ext_check.isSelected(),
format_combo.getSelectedItem(),
filter_regex_check.isSelected(),
regex_field.getText(),
dialog
))
panel.add(export_button, constraints)
constraints.gridx = 1
cancel_button = JButton("Cancel", actionPerformed=lambda e: dialog.dispose())
panel.add(cancel_button, constraints)
dialog.add(panel)
dialog.setVisible(True)
def do_export_wordlist(self, file_path, use_min_length, min_length, use_extensions,
format_type, use_regex, regex_pattern, dialog):
"""Export wordlist with selected options"""
try:
# Create a filtered copy of the paths
filtered_paths = set()
# Apply filters
for path in self.extracted_paths:
# Skip empty paths
if not path:
continue
# Apply minimum length filter
if use_min_length and len(path) < min_length:
continue
# Apply regex filter
if use_regex:
try:
if not re.match(regex_pattern, path):
continue
except:
# Invalid regex, skip this filter
pass
filtered_paths.add(path)
# Build final wordlist
final_wordlist = set()
# Add filtered paths in requested format
for path in filtered_paths:
# Add the base path
final_wordlist.add(path)
# Add with extensions if requested
if use_extensions:
if format_type == "DIRECTORY":
final_wordlist.add(path)
elif format_type == "DIRECTORY/":
final_wordlist.add(path + "/")
elif format_type == "/DIRECTORY/":
final_wordlist.add("/" + path + "/")
elif format_type == "DIRECTORY.EXT":
for ext in self.common_extensions:
final_wordlist.add(path + ext)
# Write to file
with codecs.open(file_path, 'w', encoding='utf-8') as f:
for path in sorted(final_wordlist):
f.write(path + "\n")
JOptionPane.showMessageDialog(self.tab,
"Wordlist exported successfully to: %s\nExported %d items." % (file_path, len(final_wordlist)),
"Export Complete",
JOptionPane.INFORMATION_MESSAGE)
# Close the dialog
dialog.dispose()
except Exception as e:
JOptionPane.showMessageDialog(self.tab,
"Error exporting wordlist: %s" % str(e),
"Export Error",
JOptionPane.ERROR_MESSAGE)
self._callbacks.printError("Error exporting wordlist: %s\n%s" % (str(e), traceback.format_exc()))
def extract_from_targets(self):
"""Extract paths from site map/targets"""
try:
# Get all site map entries
sitemap_entries = self._callbacks.getSiteMap(None)
# Process each entry
count = 0
for entry in sitemap_entries:
url = entry.getUrl()
if url and self._callbacks.isInScope(url):
self.extract_path_for_wordlist(str(url))
count += 1
# Update display
self.update_results_display()
JOptionPane.showMessageDialog(self.tab,
"Extracted paths from %d site map entries." % count,
"Extraction Complete",
JOptionPane.INFORMATION_MESSAGE)
except Exception as e:
JOptionPane.showMessageDialog(self.tab,
"Error extracting from targets: %s" % str(e),
"Extraction Error",
JOptionPane.ERROR_MESSAGE)
self._callbacks.printError("Error extracting from targets: %s\n%s" % (str(e), traceback.format_exc()))
def prepare_export_data(self):
"""Prepare results data for export"""
results = {
"valid_directories": [],
"forbidden_directories": [],
"redirect_directories": [],
"error_pages": [],
"wordlist": sorted(list(self.extracted_paths))
}
# Convert Java HashMap to Python dict
for url in self.valid_dirs.keySet():
info = self.valid_dirs.get(url)
entry = {"url": url}
for key in info.keySet():
value = info.get(key)
if key == 'timestamp':
entry[key] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(value))
else:
entry[key] = str(value)
results["valid_directories"].append(entry)
# Convert forbidden dirs
for url in self.forbidden_dirs.keySet():
info = self.forbidden_dirs.get(url)
entry = {"url": url}
for key in info.keySet():
value = info.get(key)
if key == 'timestamp':
entry[key] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(value))
else:
entry[key] = str(value)
results["forbidden_directories"].append(entry)
# Convert redirect dirs
for url in self.redirect_dirs.keySet():
info = self.redirect_dirs.get(url)
entry = {"url": url}
for key in info.keySet():
value = info.get(key)
if key == 'timestamp':
entry[key] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(value))
else:
entry[key] = str(value)
results["redirect_directories"].append(entry)
# Convert error pages
for url in self.error_pages.keySet():
info = self.error_pages.get(url)
entry = {"url": url}
for key in info.keySet():
value = info.get(key)
if key == 'timestamp':
entry[key] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(value))
else:
entry[key] = str(value)
results["error_pages"].append(entry)
return results
def doPassiveScan(self, baseRequestResponse):
"""Perform passive scanning (implements IScannerCheck)"""
# Already handled in processHttpMessage
return None
def doActiveScan(self, baseRequestResponse, insertionPoint):
"""Perform active scanning (implements IScannerCheck)"""
# This extension only does passive scanning
return None
def consolidateDuplicateIssues(self, existingIssue, newIssue):
"""Consolidate duplicate issues (implements IScannerCheck)"""
# This extension only does passive scanning
return 0
def createMenuItems(self, invocation):
"""Create context menu items (implements IContextMenuFactory)"""
context = invocation.getInvocationContext()
if context == IContextMenuInvocation.CONTEXT_TARGET_SITE_MAP_TREE:
menu_items = ArrayList()
menu_item = JMenuItem("Extract Paths for Burparser")
menu_item.addActionListener(lambda event: self.extract_paths_from_selected(invocation))
menu_items.add(menu_item)
return menu_items
return None
def extract_paths_from_selected(self, invocation):
"""Extract paths from selected targets in site map"""
try:
selected_messages = invocation.getSelectedMessages()
if selected_messages and len(selected_messages) > 0:
count = 0
for message in selected_messages:
url = message.getUrl()
if url:
self.extract_path_for_wordlist(str(url))
count += 1
# Update display
SwingUtilities.invokeLater(self.update_results_display)
JOptionPane.showMessageDialog(self.tab,
"Extracted paths from %d selected items." % count,
"Extraction Complete",
JOptionPane.INFORMATION_MESSAGE)
except Exception as e:
self._callbacks.printError("Error extracting from selection: %s\n%s" % (str(e), traceback.format_exc()))
def getTabCaption(self):
"""Return the tab name (implements ITab)"""
return "Burparser Pro"
def getUiComponent(self):
"""Return the UI component (implements ITab)"""
return self.tab
def createMenuItems(self, invocation):
"""Create context menu items (implements IContextMenuFactory)"""
context = invocation.getInvocationContext()
if context == IContextMenuInvocation.CONTEXT_TARGET_SITE_MAP_TREE:
menu_items = ArrayList()
# Extract selected paths only
extract_menu_item = JMenuItem("Extract Selected Paths for Burparser")
extract_menu_item.addActionListener(lambda event: self.extract_paths_from_selected(invocation))
# Extract entire subdirectory tree
extract_tree_menu_item = JMenuItem("Extract Directory Tree for Burparser")
extract_tree_menu_item.addActionListener(lambda event: self.extract_directory_tree(invocation))
menu_items.add(extract_menu_item)
menu_items.add(extract_tree_menu_item)
return menu_items
return None
def extract_directory_tree(self, invocation):
"""Extract entire directory tree from selected nodes in site map"""
try:
selected_messages = invocation.getSelectedMessages()
processed_urls = set() # To avoid duplicates
if selected_messages and len(selected_messages) > 0:
# Get base URLs from selected messages
base_urls = []
for message in selected_messages:
url = message.getUrl().toString().encode('utf-8') # 🔥 Fix here