Skip to content

Commit

Permalink
presence detection fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
thewhiteh4t committed Oct 19, 2023
1 parent 381103e commit 10d82c3
Showing 1 changed file with 29 additions and 21 deletions.
50 changes: 29 additions & 21 deletions modules/sslinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,29 @@

def cert(hostname, sslp, output, data):
result = {}
presence = False
print(f'\n{Y}[!] SSL Certificate Information : {W}\n')

port_test = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
port_test.settimeout(5)
try:
port_test.connect((hostname, sslp))
port_test.close()
presence = True
except Exception:
port_test.close()
print(f'{R}[-] {C}SSL is not Present on Target URL...Skipping...{W}')
result.update({'Error': 'SSL is not Present on Target URL'})
log_writer('[sslinfo] SSL is not Present on Target URL...Skipping...')

ctx = ssl.create_default_context()
sock = socket.socket()
sock.settimeout(5)
ssl_conn = ctx.wrap_socket(sock, server_hostname=hostname)

try:
ssl_conn.connect((hostname, sslp))
info = ssl_conn.getpeercert()
except Exception:
def fetch_cert_alt():
info = ssl.get_server_certificate((hostname, sslp))
with open(f'{hostname}.pem', 'w') as outfile:
outfile.write(info)
cert_dict = ssl._ssl._test_decode_cert(f'{hostname}.pem')
info = cert_dict
os.remove(f'{hostname}.pem')
return info

def unpack(nested_tuple, pair):
for item in nested_tuple:
Expand All @@ -54,18 +49,31 @@ def unpack(nested_tuple, pair):
else:
pair[nested_tuple.index(item)] = item

pair = {}
for key, val in info.items():
if isinstance(val, tuple):
print(f'{G}[+] {C}{key}{W}')
unpack(val, pair)
for sub_key, sub_val in pair.items():
print(f'\t{G}└╴{C}{sub_key}: {W}{sub_val}')
result.update({f'{key}-{sub_key}': sub_val})
pair.clear()
else:
print(f'{G}[+] {C}{key} : {W}{val}')
result.update({key: val})
def process_cert(info):
pair = {}
for key, val in info.items():
if isinstance(val, tuple):
print(f'{G}[+] {C}{key}{W}')
unpack(val, pair)
for sub_key, sub_val in pair.items():
print(f'\t{G}└╴{C}{sub_key}: {W}{sub_val}')
result.update({f'{key}-{sub_key}': sub_val})
pair.clear()
else:
print(f'{G}[+] {C}{key} : {W}{val}')
result.update({key: val})

if presence:
ctx = ssl.create_default_context()
sock = socket.socket()
sock.settimeout(5)
ssl_conn = ctx.wrap_socket(sock, server_hostname=hostname)
try:
ssl_conn.connect((hostname, sslp))
info = ssl_conn.getpeercert()
except Exception:
info = fetch_cert_alt()
process_cert(info)

result.update({'exported': False})

Expand Down

0 comments on commit 10d82c3

Please sign in to comment.