From 2791ba564f156dfd8acff8ca56db26a9de7f340b Mon Sep 17 00:00:00 2001 From: tristanlatr Date: Tue, 9 May 2023 10:01:06 -0400 Subject: [PATCH] Fix #60. Add option --show_html and --show_json. --- docs/source/all-options.rst | 14 +++++++++++++- wpwatcher/__version__.py | 2 +- wpwatcher/cli.py | 29 +++++++++++++++++++++++++---- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/docs/source/all-options.rst b/docs/source/all-options.rst index aa21326..067d957 100644 --- a/docs/source/all-options.rst +++ b/docs/source/all-options.rst @@ -237,8 +237,20 @@ All configuration options - File path or None - None - * - Inspect a report in database + * - Print a report in database - NA - ``--show`` - String - None + + * - Print a report in database in HTML format, use with --quiet to print only HTML content + - NA + - ``--show_html`` + - String + - None + + * - Print a report in database in JSON format, use with --quiet to print only JSON content + - NA + - ``--show_json`` + - String + - None \ No newline at end of file diff --git a/wpwatcher/__version__.py b/wpwatcher/__version__.py index 935312a..54a10b4 100644 --- a/wpwatcher/__version__.py +++ b/wpwatcher/__version__.py @@ -5,7 +5,7 @@ Project version and meta informations. """ -__version__ = "3.0.6" +__version__ = "3.0.7" __title__ = "wpwatcher" __description__ = "WPWatcher - Automating WPScan to scan and report vulnerable Wordpress sites" __author__ = "Florian Roth, Tristan Landes" diff --git a/wpwatcher/cli.py b/wpwatcher/cli.py index a85c63e..126a2d5 100644 --- a/wpwatcher/cli.py +++ b/wpwatcher/cli.py @@ -54,6 +54,20 @@ def main(_args: Optional[Sequence[Text]] = None) -> None: filepath=configuration["wp_reports"], daemon=args.daemon, ) + if args.show_html: + show( + urlpart=args.show_html, + filepath=configuration["wp_reports"], + daemon=args.daemon, + format='html', + ) + if args.show_json: + show( + urlpart=args.show_json, + filepath=configuration["wp_reports"], + daemon=args.daemon, + format='json', + ) # Launch syslog test if args.syslog_test: @@ -80,18 +94,18 @@ def wprs(filepath: Optional[str] = None, daemon: bool = False) -> None: exit(0) -def show(urlpart: str, filepath: Optional[str] = None, daemon: bool = False) -> None: +def show(urlpart: str, filepath: Optional[str] = None, daemon: bool = False, format:str='cli') -> None: """Inspect a report in database""" db = DataBase(filepath, daemon=daemon) matching_reports = [r for r in db._data if urlpart in r["site"]] eq_reports = [r for r in db._data if urlpart == r["site"]] if len(eq_reports): print( - format_results(eq_reports[0], format="cli") + format_results(eq_reports[0], format=format) ) elif len(matching_reports) == 1: print( - format_results(matching_reports[0], format="cli") + format_results(matching_reports[0], format=format) ) elif len(matching_reports) > 1: print( @@ -101,6 +115,7 @@ def show(urlpart: str, filepath: Optional[str] = None, daemon: bool = False) -> repr(ReportCollection(matching_reports)) ) print("\nPlease be more specific. \n") + exit(1) else: print("No report found") exit(1) @@ -306,7 +321,13 @@ def get_arg_parser() -> argparse.ArgumentParser: default=False, ) parser.add_argument( - "--show", metavar="Site", help="Inspect a report in the Database" + "--show", metavar="Site", help="Print a report in the Database in text format." + ) + parser.add_argument( + "--show_html", metavar="Site", help="Print a report in the Database in HTML format, use with --quiet to print only HTML content." + ) + parser.add_argument( + "--show_json", metavar="Site", help="Print a report in the Database in JSON format, use with --quiet to print only JSON content." ) return parser