Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
CoreyD97 committed Oct 26, 2023
2 parents a208679 + 9330879 commit 02373ad
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/main/java/com/nccgroup/loggerplusplus/imports/LoggerImport.java
Expand Up @@ -21,6 +21,8 @@
import burp.api.montoya.http.message.responses.HttpResponse;
import burp.api.montoya.utilities.Base64DecodingOptions;
import burp.api.montoya.utilities.Base64Utils;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.nccgroup.loggerplusplus.LoggerPlusPlus;
import com.nccgroup.loggerplusplus.logview.processor.EntryImportWorker;
import lombok.extern.log4j.Log4j2;
Expand Down Expand Up @@ -80,15 +82,15 @@ public static ArrayList<String> readFile(String filename) {
public static ArrayList<HttpRequestResponse> importWStalker() {
ArrayList<String> lines;
ArrayList<HttpRequestResponse> requests = new ArrayList<>();

String filename = getLoadFile();
if ( filename.length() == 0 ) { // exit if no file selected
return new ArrayList<>();
}

lines = readFile(filename);
Iterator<String> i = lines.iterator();

while (i.hasNext()) {
try {
String line = i.next();
Expand All @@ -115,7 +117,7 @@ public static ArrayList<HttpRequestResponse> importWStalker() {
public static ArrayList<HttpRequestResponse> importZAP() {
ArrayList<String> lines = new ArrayList<String>();
ArrayList<HttpRequestResponse> requests = new ArrayList<HttpRequestResponse>();

String filename = getLoadFile();
if ( filename.length() == 0 ) { // exit if no file selected
return new ArrayList<HttpRequestResponse>();
Expand Down Expand Up @@ -180,7 +182,7 @@ public static ArrayList<HttpRequestResponse> importZAP() {
} catch (Exception e) {
log.error("importZAP: Wrong Path Format");
return new ArrayList<>();
}
}
}

// It's the beginning of a response
Expand All @@ -203,20 +205,22 @@ public static ArrayList<HttpRequestResponse> importZAP() {

public static ArrayList<HttpRequestResponse> importFromExportedJson() {
ArrayList<HttpRequestResponse> requests = new ArrayList<>();

String filename = getLoadFile();
if ( filename.length() == 0 ) { // exit if no file selected
return new ArrayList<>();
}

BufferedReader reader;
try {
BufferedReader reader = new BufferedReader(new FileReader(filename));
reader = new BufferedReader(new FileReader(filename));
} catch (FileNotFoundException e) {
log.error("LoggerImport-readFile: Error Opening File " + filename);
return new ArrayList<>();
}

// declare all required variables for re-use in runtime
Gson gson = LoggerPlusPlus.gsonProvider.getGson();
JsonArray arr = gson.fromJson(reader, JsonElement.class).getAsJsonArray();
Base64Utils b64Decoder = LoggerPlusPlus.montoya.utilities().base64Utils();
JsonObject obj, req, res;
Expand All @@ -233,20 +237,20 @@ public static ArrayList<HttpRequestResponse> importFromExportedJson() {
req = obj.getAsJsonObject("Request");
res = obj.getAsJsonObject("Response");

url = req.getAsString("URL");
v[0] = req.getAsString("AsBase64");
v[1] = res.getAsString("AsBase64");
url = req.get("URL").getAsString();
v[0] = req.get("AsBase64").getAsString();
v[1] = res.get("AsBase64").getAsString();

try {
httpService = HttpService.httpService(url);
httpRequest = HttpRequest.httpRequest(httpService, b64Decoder.decode(v[0], Base64DecodingOptions.URL));
httpResponse = HttpResponse.httpResponse(b64Decoder.decode(v[1], Base64DecodingOptions.URL));
httpRequest = HttpRequest.httpRequest(httpService, b64Decoder.decode(v[0]));
httpResponse = HttpResponse.httpResponse(b64Decoder.decode(v[1]));
requestResponse = HttpRequestResponse.httpRequestResponse(httpRequest, httpResponse);

requests.add(requestResponse);
} catch (Exception e) {
log.error("LoggerImport-importFromExportedJson: Error Parsing Content");
return new ArrayList<>();
log.error("LoggerImport-importFromExportedJson: Error Parsing Content", e);

}
}

Expand All @@ -264,8 +268,8 @@ public static boolean loadImported(ArrayList<HttpRequestResponse> requests, Bool
})
.setCallback(() -> {
//Optional
//Called when all entries have been imported.
}).build();
//Called when all entries have been imported.
}).build();
importWorker.execute();

return true;
Expand Down

0 comments on commit 02373ad

Please sign in to comment.