Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide support for customizable timeout #26

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions ssl_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,21 @@ def get_cert(self, host, port, user_args):
print('{}Connecting to socket{}\n'.format(Clr.YELLOW, Clr.RST))

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
osobj = SSL.Context(PROTOCOL_TLSv1)
sock.connect((host, int(port)))
oscon = SSL.Connection(osobj, sock)
oscon.set_tlsext_host_name(host.encode())
oscon.set_connect_state()
oscon.do_handshake()
cert = oscon.get_peer_certificate()
sock.close()
if user_args.timeout != False:
sock.settimeout(user_args.timeout)
try:
osobj = SSL.Context(PROTOCOL_TLSv1)
sock.connect((host, int(port)))
oscon = SSL.Connection(osobj, sock)
oscon.set_tlsext_host_name(host.encode())
oscon.set_connect_state()
oscon.setblocking(1)
oscon.do_handshake()
cert = oscon.get_peer_certificate()
except socket.timeout as e:
raise e
finally:
sock.close()
if user_args.verbose:
print('{}Closing socket{}\n'.format(Clr.YELLOW, Clr.RST))

Expand Down Expand Up @@ -250,6 +257,10 @@ def show_result(self, user_args):
if not user_args.json_true:
print('\t{}[-]{} {:<20s} Failed: Misconfigured SSL/TLS\n'.format(Clr.RED, Clr.RST, host))
self.total_failed += 1
except socket.timeout as error:
if not user_args.json_true:
print('\t{}[-]{} {:<20s} Timeout: {}\n'.format(Clr.RED, Clr.RST, host, error))
self.total_failed += 1
except Exception as error:
if not user_args.json_true:
print('\t{}[-]{} {:<20s} Failed: {}\n'.format(Clr.RED, Clr.RST, host, error))
Expand Down Expand Up @@ -332,6 +343,7 @@ def get_args(self, json_args={}):
setattr(args, 'socks', False)
setattr(args, 'analyze', False)
setattr(args, 'hosts', json_args['hosts'])
setattr(args, 'timeout', json_args.get('timeout', False))
return args

group = parser.add_mutually_exclusive_group(required=True)
Expand Down Expand Up @@ -360,6 +372,9 @@ def get_args(self, json_args={}):
parser.add_argument('-a', '--analyze', dest='analyze',
default=False, action='store_true',
help='Enable SSL security analysis on the host')
parser.add_argument('-t', '--timeout', dest='timeout',
default=False, type=float,
help='Enable timeout on the SSL connection.')
parser.add_argument('-v', '--verbose', dest='verbose',
default=False, action='store_true',
help='Enable verbose to see what is going on')
Expand Down