-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
JSRouteInspector.bambda
112 lines (94 loc) · 3.68 KB
/
JSRouteInspector.bambda
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
/**
* JavaScript Route Explorer designed to discover and analyze JavaScript routes and endpoints.
* It intelligently scans JavaScript files to detect hidden or non-standard endpoints, aiding in thorough exploration of web assets.
* Features include duplicate removal, customizable scan types ('High', 'Deep', 'Custom'), and highlighting of key terms within JavaScript files.
* Users can define their own regex patterns for more targeted scanning and annotate results with custom words for enhanced visibility.
* @author Tur24Tur / BugBountyzip (https://github.com/BugBountyzip)
**/
boolean manualColorHighlightEnabled = true;
String scanType = "High"; // Can be 'High', 'Deep', 'Custom'
String customRegex = "[Your custom regex here]"; // User-defined custom regex
Set<String> uniqueEndpoints = new HashSet<>();
if (!requestResponse.hasResponse()) {
return false;
}
MimeType responseType = requestResponse.response().mimeType();
boolean isJavaScript = responseType == MimeType.SCRIPT;
if (!isJavaScript) {
return false;
}
Pattern regexPattern;
switch (scanType) {
case "High":
regexPattern = Pattern.compile("(?<=(\"|'|`))\\/[a-zA-Z0-9_:?&=/\\-#.]*(?=(\"|'|`))", Pattern.DOTALL);
break;
case "Deep":
regexPattern = Pattern.compile("(?<=(\"|'|`))[^\"'`]*\\/[a-zA-Z0-9_:?&=/\\-#.]*(?=(\"|'|`))", Pattern.DOTALL);
break;
case "Custom":
regexPattern = Pattern.compile(customRegex, Pattern.DOTALL);
break;
default:
return false;
}
String responseBody = requestResponse.response().bodyToString();
Matcher matcher = regexPattern.matcher(responseBody);
while (matcher.find()) {
String item = matcher.group();
if (!item.equals("/") && !item.equals("//") && !item.matches(".*\\.(css|png|gif|svg|woff2|jpeg|jpg|ico|bmp|woff)$")) {
uniqueEndpoints.add(item);
}
}
String dataFilePath = "C:\\Users\\Your\\Path\\File.txt";
// Write endpoints to the file
try (BufferedWriter writer = new BufferedWriter(new FileWriter(dataFilePath, true))) {
for (String endpoint : uniqueEndpoints) {
if (!endpoint.trim().isEmpty()) {
writer.write(endpoint + "\n");
}
}
} catch (IOException e) {
e.printStackTrace();
}
// Read the file, remove duplicates and empty lines, and rewrite
try {
Set<String> lines = new LinkedHashSet<>();
try (BufferedReader reader = new BufferedReader(new FileReader(dataFilePath))) {
String line;
while ((line = reader.readLine()) != null) {
if (!line.trim().isEmpty()) {
lines.add(line);
}
}
}
try (BufferedWriter writer = new BufferedWriter(new FileWriter(dataFilePath))) {
for (String uniqueLine : lines) {
writer.write(uniqueLine + "\n");
}
}
} catch (IOException e) {
e.printStackTrace();
}
boolean foundItems = !uniqueEndpoints.isEmpty();
boolean highValueWordFound = false;
StringBuilder notesBuilder = new StringBuilder();
String[] highValueWords = {"debug", "admin", "test", "config"};
// Check for high-value words and append notes
for (String item : uniqueEndpoints) {
for (String word : highValueWords) {
if (item.contains(word)) {
highValueWordFound = true;
notesBuilder.append(item).append("\n");
break;
}
}
}
// Set the appropriate highlight color
if (foundItems && manualColorHighlightEnabled) {
HighlightColor highlightColor = highValueWordFound ? HighlightColor.RED : HighlightColor.YELLOW;
requestResponse.annotations().setHighlightColor(highlightColor);
if (notesBuilder.length() > 0) {
requestResponse.annotations().setNotes(notesBuilder.toString().trim());
}
}
return foundItems;