From 19aefdfc395e65d2a18dc4c5745b043e56cf3491 Mon Sep 17 00:00:00 2001 From: Corey <1339555+CoreyD97@users.noreply.github.com> Date: Thu, 26 Oct 2023 12:05:22 +0100 Subject: [PATCH] Fixes to #PR195 --- .../loggerplusplus/imports/LoggerImport.java | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/nccgroup/loggerplusplus/imports/LoggerImport.java b/src/main/java/com/nccgroup/loggerplusplus/imports/LoggerImport.java index e92e193..674dc62 100644 --- a/src/main/java/com/nccgroup/loggerplusplus/imports/LoggerImport.java +++ b/src/main/java/com/nccgroup/loggerplusplus/imports/LoggerImport.java @@ -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; @@ -80,7 +82,7 @@ public static ArrayList readFile(String filename) { public static ArrayList importWStalker() { ArrayList lines; ArrayList requests = new ArrayList<>(); - + String filename = getLoadFile(); if ( filename.length() == 0 ) { // exit if no file selected return new ArrayList<>(); @@ -88,7 +90,7 @@ public static ArrayList importWStalker() { lines = readFile(filename); Iterator i = lines.iterator(); - + while (i.hasNext()) { try { String line = i.next(); @@ -115,7 +117,7 @@ public static ArrayList importWStalker() { public static ArrayList importZAP() { ArrayList lines = new ArrayList(); ArrayList requests = new ArrayList(); - + String filename = getLoadFile(); if ( filename.length() == 0 ) { // exit if no file selected return new ArrayList(); @@ -180,7 +182,7 @@ public static ArrayList importZAP() { } catch (Exception e) { log.error("importZAP: Wrong Path Format"); return new ArrayList<>(); - } + } } // It's the beginning of a response @@ -203,20 +205,22 @@ public static ArrayList importZAP() { public static ArrayList importFromExportedJson() { ArrayList 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; @@ -233,20 +237,20 @@ public static ArrayList 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); + } } @@ -264,8 +268,8 @@ public static boolean loadImported(ArrayList requests, Bool }) .setCallback(() -> { //Optional - //Called when all entries have been imported. - }).build(); + //Called when all entries have been imported. + }).build(); importWorker.execute(); return true;