PEP8 Refactor
This commit is contained in:
parent
e27f6ead26
commit
95c176f669
@ -9,7 +9,7 @@ from time import sleep
|
|||||||
from csv import DictWriter
|
from csv import DictWriter
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from OpenSSL import SSL, crypto
|
from OpenSSL import SSL
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print('Required module does not exist. Install: pip install pyopenssl')
|
print('Required module does not exist. Install: pip install pyopenssl')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@ -87,12 +87,12 @@ def analyze_ssl(host, context):
|
|||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
def get_cert_sans(x509cert):
|
def get_cert_sans(x509cert):
|
||||||
'''
|
"""
|
||||||
Get Subject Alt Names from Certificate. Shameless taken from stack overflow:
|
Get Subject Alt Names from Certificate. Shameless taken from stack overflow:
|
||||||
https://stackoverflow.com/users/4547691/anatolii-chmykhalo
|
https://stackoverflow.com/users/4547691/anatolii-chmykhalo
|
||||||
'''
|
"""
|
||||||
|
|
||||||
san = ''
|
san = ''
|
||||||
ext_count = x509cert.get_extension_count()
|
ext_count = x509cert.get_extension_count()
|
||||||
for i in range(0, ext_count):
|
for i in range(0, ext_count):
|
||||||
@ -103,6 +103,7 @@ def get_cert_sans(x509cert):
|
|||||||
san = san.replace(',', ';')
|
san = san.replace(',', ';')
|
||||||
return san
|
return san
|
||||||
|
|
||||||
|
|
||||||
def get_cert_info(host, cert):
|
def get_cert_info(host, cert):
|
||||||
"""Get all the information about cert and create a JSON file."""
|
"""Get all the information about cert and create a JSON file."""
|
||||||
context = {}
|
context = {}
|
||||||
@ -165,8 +166,8 @@ def print_status(host, context, analyze=False):
|
|||||||
|
|
||||||
print('\t\tExpired: {}'.format(context[host]['cert_exp']))
|
print('\t\tExpired: {}'.format(context[host]['cert_exp']))
|
||||||
print('\t\tCertificate SANs: ')
|
print('\t\tCertificate SANs: ')
|
||||||
for san in context[host]['cert_sans'].split(';'): print('\t\t\t{}'.format(san))
|
for san in context[host]['cert_sans'].split(';'):
|
||||||
|
print('\t\t\t{}'.format(san))
|
||||||
|
|
||||||
|
|
||||||
def show_result(user_args):
|
def show_result(user_args):
|
||||||
@ -221,8 +222,9 @@ def show_result(user_args):
|
|||||||
else:
|
else:
|
||||||
print(context)
|
print(context)
|
||||||
|
|
||||||
|
|
||||||
def export_csv(context, filename):
|
def export_csv(context, filename):
|
||||||
""" Export all context results to CSV file."""
|
"""Export all context results to CSV file."""
|
||||||
# prepend dict keys to write column headers
|
# prepend dict keys to write column headers
|
||||||
with open(filename, 'w') as csv_file:
|
with open(filename, 'w') as csv_file:
|
||||||
csv_writer = DictWriter(csv_file, context.items()[0][1].keys())
|
csv_writer = DictWriter(csv_file, context.items()[0][1].keys())
|
||||||
@ -230,6 +232,7 @@ def export_csv(context, filename):
|
|||||||
for host in context.keys():
|
for host in context.keys():
|
||||||
csv_writer.writerow(context[host])
|
csv_writer.writerow(context[host])
|
||||||
|
|
||||||
|
|
||||||
def filter_hostname(host):
|
def filter_hostname(host):
|
||||||
"""Remove unused characters and split by address and port."""
|
"""Remove unused characters and split by address and port."""
|
||||||
host = host.replace('http://', '').replace('https://', '').replace('/', '')
|
host = host.replace('http://', '').replace('https://', '').replace('/', '')
|
||||||
@ -246,11 +249,10 @@ def get_args():
|
|||||||
description="""Collects useful information about given host's SSL certificates.""")
|
description="""Collects useful information about given host's SSL certificates.""")
|
||||||
|
|
||||||
group = parser.add_mutually_exclusive_group()
|
group = parser.add_mutually_exclusive_group()
|
||||||
|
group.add_argument('-H', '--host', dest='hosts', nargs='*',
|
||||||
group.add_argument('-H', '--host', dest='hosts', nargs='*', required=False,
|
required=False, help='Hosts as input separated by space')
|
||||||
help='Hosts as input separated by space')
|
group.add_argument('-f', '--host-file', dest='host_file',
|
||||||
group.add_argument('-f', '--host-file', dest='host_file', required=False,
|
required=False, help='Hosts as input from file')
|
||||||
help='Hosts as input from file')
|
|
||||||
parser.add_argument('-s', '--socks', dest='socks',
|
parser.add_argument('-s', '--socks', dest='socks',
|
||||||
default=False, metavar='HOST:PORT',
|
default=False, metavar='HOST:PORT',
|
||||||
help='Enable SOCKS proxy for connection')
|
help='Enable SOCKS proxy for connection')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user