From f2418593caf1a62a5b00d166b9691739c5bd3024 Mon Sep 17 00:00:00 2001 From: Narbeh Arakil Date: Mon, 11 May 2020 17:03:38 +0400 Subject: [PATCH] Add JSON Output Arg --- README.md | 17 ++++++++++------- ssl_checker.py | 9 +++++++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 636ec81..652ad87 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,15 @@ # SSL Checker -#### Python script that collects SSL information from hosts +#### Python script that collects SSL/TLS information from hosts ## About -It's a simple script running in python that collects SSL information then it returns the group of information in JSON. It can also connects trough your specified SOCKS server. +It's a simple script running in python that collects SSL/TLS information then it returns the group of information in JSON. It can also connects trough your specified SOCKS server. -One of the good thing about this script, is that it will full analyze the SSL certificate for security issue's and will include the report in the output or CSV file. +One of the good thing about this script, is that it will full analyze the SSL certificate for security issue's and will include the report in the output, CSV or JSON file. ## Requirements -You only need to installl pyOpenSSL: +You only need to install pyOpenSSL: `pip install pyopenssl` @@ -21,8 +21,8 @@ or ``` ./ssl_checker.py -h -usage: ssl_checker.py [-H [HOSTS [HOSTS ...]] | -f HOST_FILE] [-s HOST:PORT] - [-c FILENAME.CSV] [-j] [-a] [-p] [-h] +usage: ssl_checker.py (-H [HOSTS [HOSTS ...]] | -f HOST_FILE) [-s HOST:PORT] + [-c FILENAME.CSV] [-j] [-J] [-a] [-h] Collects useful information about given host's SSL certificates. @@ -36,7 +36,8 @@ optional arguments: -c FILENAME.CSV, --csv FILENAME.CSV Enable CSV file export -j, --json Enable JSON in the output - -a, --analyze Enable SSL security analysis on the host. + -J, --json-save Enable JSON export individually per host + -a, --analyze Enable SSL security analysis on the host -h, --help Show this help message and exit ``` @@ -54,6 +55,8 @@ Port is optional here. The script will use 443 if not specified. `-j, --json ` Use this if you want to only have the result in JSON +`-J, --json-save` Use this if you want to save as JSON file per host + `-a, --analyze` This argument will include security analyze on the certificate. Takes more time. No result means failed to analyze. `-h, --help` Shows the help and exit diff --git a/ssl_checker.py b/ssl_checker.py index 6274726..87d8d8d 100755 --- a/ssl_checker.py +++ b/ssl_checker.py @@ -227,10 +227,12 @@ def show_result(user_args): # Enable JSON output if -j/--json argument specified if user_args.json_true: + print(json.dumps(context)) + + if user_args.json_save_true: for host in hosts: - with open(host.split(".")[0] + ".json", "w", encoding="UTF-8") as fp: + with open(host.split('.')[0] + '.json', 'w', encoding='UTF-8') as fp: fp.write(json.dumps(context)) - print(json.dumps(context)) def export_csv(context, filename): @@ -272,6 +274,9 @@ def get_args(): parser.add_argument('-j', '--json', dest='json_true', action='store_true', default=False, help='Enable JSON in the output') + parser.add_argument('-J', '--json-save', dest='json_save_true', + action='store_true', default=False, + help='Enable JSON export individually per host') parser.add_argument('-a', '--analyze', dest='analyze', default=False, action='store_true', help='Enable SSL security analysis on the host')