Skip to content

Commit

Permalink
Server kex/host key parsing failures no longer output a stack trace u…
Browse files Browse the repository at this point in the history
…nless in debug mode.
  • Loading branch information
jtesta committed Sep 25, 2024
1 parent 67e11f8 commit 3b8a75e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/ssh_audit/hostkeytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,12 @@ def perform_test(out: 'OutputBuffer', s: 'SSH_Socket', server_kex: 'SSH2_Kex', k
_, payload = s.read_packet()
SSH2_Kex.parse(out, payload)
except Exception:
out.v("Failed to parse server's kex. Stack trace:\n%s" % str(traceback.format_exc()), write_now=True)
msg = "Failed to parse server's kex."
if not out.debug:
msg += " Re-run in debug mode to see stack trace."

out.v(msg, write_now=True)
out.d("Stack trace:\n%s" % str(traceback.format_exc()), write_now=True)
return

# Do the initial DH exchange. The server responds back
Expand All @@ -162,7 +167,12 @@ def perform_test(out: 'OutputBuffer', s: 'SSH_Socket', server_kex: 'SSH2_Kex', k
kex_reply = kex_group.recv_reply(s)
raw_hostkey_bytes = kex_reply if kex_reply is not None else b''
except KexDHException:
out.v("Failed to parse server's host key. Stack trace:\n%s" % str(traceback.format_exc()), write_now=True)
msg = "Failed to parse server's host key."
if not out.debug:
msg += " Re-run in debug mode to see stack trace."

out.v(msg, write_now=True)
out.d("Stack trace:\n%s" % str(traceback.format_exc()), write_now=True)

# Since parsing this host key failed, there's nothing more to do but close the socket and move on to the next host key type.
s.close()
Expand Down

0 comments on commit 3b8a75e

Please sign in to comment.