diff --git a/nukesort.py b/nukesort.py index 1d12d7e..7c64791 100644 --- a/nukesort.py +++ b/nukesort.py @@ -1,4 +1,6 @@ # Author: perp +# Description: Sort nuclei json into folders +# Usage: nukesort scan.json results import json import os @@ -25,32 +27,33 @@ elif os.path.isdir(scan_folder): # Open json file with open(scan_json, "r") as f: - # Go through each line - for line in f.readlines(): - # Load json, get domain & vulnerability - line = json.loads(line) - domain = str(line["host"]).replace("http://", "").replace("https://", "").replace("www.", "").split("/")[0] - vulnerability = line["template-id"] + # Load JSON + lines = json.loads(f.read()) - # Path doesn't exist, make + # Go through each line + for line in range(len(lines)): + # Get domain & vulnerability + domain = lines[line]["host"].replace("http://", "").replace("https://", "").replace("www", "") + vulnerability = lines[line]["template-id"] + + # Create domain folder if not os.path.exists(f"{scan_folder}/domains/{domain}"): os.mkdir(f"{scan_folder}/domains/{domain}") - # Domain on current line - if domain in line["host"]: - # Path doesn't exist, make - if not os.path.exists(f"{scan_folder}/domains/{domain}/{vulnerability}"): - os.mkdir(f"{scan_folder}/domains/{domain}/{vulnerability}") + # Create vulnerability folder + if not os.path.exists(f"{scan_folder}/domains/{domain}/{vulnerability}"): + os.mkdir(f"{scan_folder}/domains/{domain}/{vulnerability}") - # Text key to file - if "extracted-results" in line: - # Open text file - with open(f"{scan_folder}/domains/{domain}/{vulnerability}/{vulnerability}.txt", "a") as v: - # Get each result & go through - results = line["extracted-results"] - for extracted in results: - v.write(extracted+"\n") + # Result found + if "extracted-results" in lines[line]: + # Open vulnerability text file + with open(f"{scan_folder}/domains/{domain}/{vulnerability}/{vulnerability}.txt", "a") as vuln: + # Write vulnerability + results = lines[line]["extracted-results"] + for result in results: + vuln.write(result+"\n") - # Open json file - with open(f"{scan_folder}/domains/{domain}/{vulnerability}/{vulnerability}.json", "a") as v: - json.dump(line, v, indent=4) + # Open vulnerability json file + with open(f"{scan_folder}/domains/{domain}/{vulnerability}/{vulnerability}.json", "a") as vulns: + # Write json + json.dump(lines[line], vulns, indent=4)