From 33f4ca923cf7f43494d6089d4ef4f7d49f842320 Mon Sep 17 00:00:00 2001 From: carlospolop Date: Mon, 7 Feb 2022 08:50:24 -0500 Subject: [PATCH] html and pdf --- README.md | 3 + {parser => parsers}/README.md | 13 +- parsers/json2html.py | 347 ++++++++++++++++++ {parser => parsers}/json2pdf.py | 2 +- .../peass-parser.py => parsers/peas2json.py | 4 +- 5 files changed, 360 insertions(+), 9 deletions(-) rename {parser => parsers}/README.md (79%) create mode 100644 parsers/json2html.py rename {parser => parsers}/json2pdf.py (99%) rename parser/peass-parser.py => parsers/peas2json.py (96%) diff --git a/README.md b/README.md index afeee10..b05d08e 100755 --- a/README.md +++ b/README.md @@ -21,6 +21,9 @@ These tools search for possible **local privilege escalation paths** that you co ## Quick Start Find the **latest versions of all the scripts and binaries in [the releases page](https://github.com/carlospolop/PEASS-ng/releases/latest)**. +## JSON, HTML & PDF output +Check the **[parsers](./parsers/)** directory to **transform PEASS outputs to JSON, HTML and PDF** + ## Let's improve PEASS together If you want to **add something** and have **any cool idea** related to this project, please let me know it in the **telegram group https://t.me/peass** or contribute reading the **[CONTRIBUTING.md](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite/blob/master/CONTRIBUTING.md)** file. diff --git a/parser/README.md b/parsers/README.md similarity index 79% rename from parser/README.md rename to parsers/README.md index 10546d6..7ade240 100644 --- a/parser/README.md +++ b/parsers/README.md @@ -1,14 +1,15 @@ -# Privilege Escalation Awesome Scripts JSON exporter +# Privilege Escalation Awesome Scripts Parsers -This script allows you to transform the output of linpeas/macpeas/winpeas to JSON. +These scripts allows you to transform the output of linpeas/macpeas/winpeas to JSON and then to PDF and HTML. ```python3 -python3 peass-parser.py +python3 peass2json.py +python3 json2pdf.py +python3 json2html.py ``` -This script is still in beta version and has been tested only with linpeas output. -## Format +## JSON Format Basically, **each section has**: - Infos (URLs or info about the section) - Text lines (the real text info found in the section, colors included) @@ -75,4 +76,4 @@ There can also be a `` # TODO: -I'm looking for **someone that could create HTML and PDF reports** from this JSON. \ No newline at end of file +- **PRs improving the code and the aspect of the final PDFs and HTMLs are always welcome!** \ No newline at end of file diff --git a/parsers/json2html.py b/parsers/json2html.py new file mode 100644 index 0000000..b250a05 --- /dev/null +++ b/parsers/json2html.py @@ -0,0 +1,347 @@ +import json +import sys +import random + + +def parse_json(json_data : object) -> str: + """Parse the given json adding it to the HTML file""" + + body = "" + i=1 + for key, value in json_data.items(): + body += """\t\t
\n +
\n""" + i=i+1 + for key1, value1 in value.items(): + + if(type(value1)==list): + body+=parse_list(value1) + + if((type(value1)==dict)): + body+=parse_dict(value1) + body+="\t\t\t
\n" + + return body + + +def parse_dict(json_dict: dict) -> str: + """Parse the given dict from the given json adding it to the HTML file""" + + dict_text="" + for key, value in json_dict.items(): + n=random.randint(0,999999) + infos = [] + for info in value["infos"]: + if info.startswith("http"): + infos.append(f"{info}
\n") + else: + infos.append(str(info) + "
\n") + + dict_text += f'\t\t
\n' + dict_text += '' + "".join(infos) + '' + dict_text += f'
\n' + + if value["lines"]: + dict_text+="\n" + parse_list(value["lines"]) + "\n" + + if value["sections"]: + dict_text+=parse_dict(value["sections"]) + + return dict_text + + +def parse_list(json_list: list) -> str: + """Parse the given list from the given json adding it to the HTML file""" + color_text="" + color_class="" + + for i in json_list: + if "═══" not in i['clean_text']: + if(i['clean_text']): + color_text+= "
"+ replacement + "") + #class=\""+ color_class + "\" "+ " + if "═╣" in text: + text=text.replace("═╣","
  • ") + text+="
  • " + color_text+= "" + color_class + " " + color_text +="no_color\" >"+ text + "
    \n" + return color_text + "\t\t\t
    \n" + + +def main(): + with open(JSON_PATH) as JSON_file: + json_data = json.load(JSON_file) + html = HTML_HEADER + html += HTML_INIT_BODY + html += parse_json(json_data) + html += HTML_END + + with open(HTML_PATH, 'w') as f: + f.write(html) + + + +HTML_HEADER = """ + + + + + + + + + +""" + +HTML_END = """ + + +""" + +HTML_INIT_BODY = body = """ + +
    +
    + +
    + + + +
    """ + + +# Start execution +if __name__ == "__main__": + try: + JSON_PATH = sys.argv[1] + HTML_PATH = sys.argv[2] + except IndexError as err: + print("Error: Please pass the peas.json file and the path to save the html\npeas2html.py ") + sys.exit(1) + + main() \ No newline at end of file diff --git a/parser/json2pdf.py b/parsers/json2pdf.py similarity index 99% rename from parser/json2pdf.py rename to parsers/json2pdf.py index 8d6f5ab..6d1c710 100755 --- a/parser/json2pdf.py +++ b/parsers/json2pdf.py @@ -156,7 +156,7 @@ if __name__ == "__main__": JSON_PATH = sys.argv[1] PDF_PATH = sys.argv[2] except IndexError as err: - print("Error: Please pass the peas.json file and the path to save the pdf\n./json2pdf.py ") + print("Error: Please pass the peas.json file and the path to save the pdf\njson2pdf.py ") sys.exit(1) main() diff --git a/parser/peass-parser.py b/parsers/peas2json.py similarity index 96% rename from parser/peass-parser.py rename to parsers/peas2json.py index 77919c3..a6b5eb2 100755 --- a/parser/peass-parser.py +++ b/parsers/peas2json.py @@ -90,7 +90,7 @@ def clean_colors(line: str) -> str: for reg in re.findall(r'\x1b\[[^a-zA-Z]+\dm', line): line = line.replace(reg,"") - line = line.replace('\x1b',"").replace("[0m", "") #Sometimes that byte stays + line = line.replace('\x1b',"").replace("[0m", "").replace("[3m", "") #Sometimes that byte stays line = line.strip() return line @@ -162,7 +162,7 @@ if __name__ == "__main__": OUTPUT_PATH = sys.argv[1] JSON_PATH = sys.argv[2] except IndexError as err: - print("Error: Please pass the peas.out file and the path to save the json\n./peas-parser.py ") + print("Error: Please pass the peas.out file and the path to save the json\npeas2json.py ") sys.exit(1) main()