added excepts for basic error catching

This commit is contained in:
c0decave
2021-04-24 16:26:46 +02:00
parent afb6906e68
commit 39557540ab

View File

@@ -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):
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):
try:
ssock = ssl.wrap_socket(sock)
except Exception as e:
print(repr(e))
return False
return ssock
def get_pem_cert(ssock):
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():