-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
ChatGPT_API_Predictor.bambda
90 lines (79 loc) · 4.15 KB
/
ChatGPT_API_Predictor.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
/**
* Bambda ChatGPT-Enhanced Endpoint Guesser
* Author: Tur24Tur & CoreyD97 & JaveleyQAQ / BugBountyzip (https://github.com/BugBountyzip)
* This script leverages ChatGPT to intelligently guess endpoints.
*/
// Main logic of the Bambda
if (requestResponse.request().url() != null && requestResponse.hasResponse()) {
if (requestResponse.annotations().hasNotes()) {
String notes = requestResponse.annotations().notes();
if (notes.contains("aaa")) {
// Use pathWithoutQuery() to get the path part of the URL without the query string By CoreyD97
String path = requestResponse.request().pathWithoutQuery();
// Construct the curl command with headers
String command = "curl https://api.openai.com/v1/chat/completions -H \"Content-Type: application/json\" -H \"Authorization: Bearer XYZ\" -d \"{\\\"model\\\": \\\"gpt-3.5-turbo\\\", \\\"messages\\\": [{\\\"role\\\": \\\"user\\\", \\\"content\\\": \\\"Based on the specified path in an HTTP request, please guess 50 potential endpoints. " + path + "\\\"}], \\\"temperature\\\": 0.7}\"";
// Determine the operating system By JaveleyQAQ
String os = System.getProperty("os.name").toLowerCase();
String[] commandArray;
String filePath;
String endpointsPath;
if (os.contains("win")) {
// Windows command and paths
commandArray = new String[]{"cmd", "/c", command};
filePath = "C:\\Users\\User\\Path\\httpRequest.txt"; // Corrected path
endpointsPath = "C:\\Users\\User\\Path\\endpoints.txt"; // Corrected path
} else {
// Unix/Linux/macOS command and paths
commandArray = new String[]{"/bin/bash", "-c", command};
filePath = "/home/kali/Desktop/httpRequest.txt"; // Path for Linux/macOS
endpointsPath = "/home/kali/Desktop/endpoints.txt"; // Path for Linux/macOS
}
// Write the command to a file
try (BufferedWriter commandWriter = new BufferedWriter(new FileWriter(filePath))) {
commandWriter.write(command);
} catch (IOException e) {
e.printStackTrace();
}
// Execute the curl command using the appropriate shell
ProcessBuilder processBuilder = new ProcessBuilder(commandArray);
processBuilder.redirectErrorStream(true);
Process process = null;
try {
process = processBuilder.start();
} catch (IOException e) {
e.printStackTrace();
}
// Read the output from the command
StringBuilder output = new StringBuilder();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
String line;
while ((line = reader.readLine()) != null) {
output.append(line).append("\n");
}
} catch (IOException e) {
e.printStackTrace();
}
// Extract the JSON part of the response
String jsonResponse = output.toString();
String contentMarker = "\"content\": \"";
int contentStart = jsonResponse.indexOf(contentMarker);
if (contentStart != -1) {
contentStart += contentMarker.length();
int contentEnd = jsonResponse.indexOf("\"", contentStart);
if (contentEnd != -1) {
String content = jsonResponse.substring(contentStart, contentEnd).replace("\\n", "\n");
// Write the endpoints to a file
try (BufferedWriter endpointWriter = new BufferedWriter(new FileWriter(endpointsPath))) {
endpointWriter.write(content);
} catch (IOException e) {
e.printStackTrace();
}
}
}
// Highlight the request/response in yellow
requestResponse.annotations().setHighlightColor(HighlightColor.YELLOW);
return true;
}
}
}
return false;