added excepts for basic error catching
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
# You have exactly *one* job: Get me the fingerprint of the remote SSL layer.
|
||||
|
||||
#cert_pem = ssl.get_server_certificate(addr)
|
||||
|
||||
import os
|
||||
import sys
|
||||
import ssl
|
||||
@@ -13,25 +11,43 @@ from M2Crypto import X509
|
||||
|
||||
__tool_name__ = 'fingerprint'
|
||||
__tool_author__ = 'dash'
|
||||
__tool_version__ = 'v0.2'
|
||||
__tool_version__ = 'v0.3'
|
||||
__tool_desc__ = 'get fingerprint from remote ssl layer'
|
||||
|
||||
|
||||
def connect(host, port):
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.connect((host, port))
|
||||
|
||||
try:
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.connect((host, port))
|
||||
|
||||
except Exception as e:
|
||||
print(repr(e))
|
||||
return False
|
||||
|
||||
return s
|
||||
|
||||
|
||||
def wrap_it(sock):
|
||||
ssock = ssl.wrap_socket(sock)
|
||||
|
||||
try:
|
||||
ssock = ssl.wrap_socket(sock)
|
||||
except Exception as e:
|
||||
print(repr(e))
|
||||
return False
|
||||
|
||||
return ssock
|
||||
|
||||
|
||||
def get_pem_cert(ssock):
|
||||
|
||||
cert = ssock.getpeercert(binary_form=True)
|
||||
try:
|
||||
|
||||
cert = ssock.getpeercert(binary_form=True)
|
||||
except Exception as e:
|
||||
print(repr(e))
|
||||
return False
|
||||
|
||||
return cert
|
||||
|
||||
|
||||
@@ -42,15 +58,26 @@ def run(args):
|
||||
port = args.port
|
||||
|
||||
sock = connect(host, port)
|
||||
if not sock:
|
||||
sys.exit(1)
|
||||
|
||||
ssock = wrap_it(sock)
|
||||
|
||||
if not ssock:
|
||||
sys.exit(1)
|
||||
|
||||
pem_cert = get_pem_cert(ssock)
|
||||
|
||||
if not pem_cert:
|
||||
sys.exit(1)
|
||||
|
||||
x509 = X509.load_cert_string(pem_cert, X509.FORMAT_DER)
|
||||
|
||||
print('Results')
|
||||
print('-'*7)
|
||||
for entry in myfp:
|
||||
fp = x509.get_fingerprint(entry)
|
||||
print(entry + ':' + fp)
|
||||
print(host+':' + str(port) + ',' + entry + ':' + fp)
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
Reference in New Issue
Block a user