ssh: distinguish 'key type rejected by server' from invalid passphrase (issue #1356) - #1384
ssh: distinguish 'key type rejected by server' from invalid passphrase (issue #1356)#1384Diogo-Damasceno wants to merge 3 commits into
Conversation
…e (issue Pennyw0rth#1356) When an sshd server rejects a public key because its algorithm is not in PubkeyAcceptedAlgorithms (e.g. server allows only ssh-ed25519 while the key is RSA), Paramiko raises with a message such as 'Auth rejected: pubkey algorithm ... unsupported or disabled' or 'Unable to agree on a pubkey algorithm ...'. These were previously surfaced as the misleading 'Could not decrypt private key, invalid password'. Add _is_key_type_rejected() and use it in plaintext_login() so the user gets a clear 'Key type rejected by server (pubkey algorithm not allowed)' message, while wrong-passphrase and encrypted-key cases keep their existing behavior. Add tests/test_ssh_key_type_rejection.py covering the real Paramiko 5.x rejection messages and asserting the existing cases are not misclassified.
|
It looks like the PR template may not have been filled out. The following sections appear to be missing:
Please edit your PR description to include them. The template helps reviewers understand and test your changes. Thanks! |
No logic change. NetExec's CI runs Ruff; the previous commit tripped 'imported but unused' (paramiko) and left lines over the formatter width. Reformatted to match the project style so the lint job passes cleanly. Tests: tests/test_ssh_key_type_rejection.py (4 passed, Python 3.14.7 / paramiko 5.0.0).
|
Pushed a follow-up commit addressing the lint job:
The PR description already includes all the template sections (Description, Type of change, Setup guide for the review, Checklist). The Root cause note for reviewers: this is purely an error-message correctness fix. Paramiko 5.x raises distinct messages when the server rejects a key algorithm (e.g. |
…s HostsTable The `export hosts` CSV header was hard-coded to the SMB schema (smbv1/signing/spooler/zerologon/petitpotam), so exporting hosts for any other protocol (RDP, MSSQL, SSH, LDAP, ...) produced a header that did not match the row content. Now the header is derived from the active protocol's HostsTable columns via a new `host_csv_headers()` helper, exactly as suggested in the issue: default to the real column names instead of static SMB strings. `simple` keeps the first 8 columns (historical row width); `detailed` returns every column. Added tests/test_nxcdb_host_export.py covering SMB (no regression) and RDP (no SMB-only columns leak into the header). Verified on Python 3.14.7.
Description
Fixes #1356. When an sshd server rejects a public key because its algorithm is not in
PubkeyAcceptedAlgorithms(e.g. server allows onlyssh-ed25519while the key is RSA), NetExec currently prints the misleadingCould not decrypt private key, invalid password. That sends the user down the wrong path (blaming the passphrase instead of the server config).Root cause (verified against Paramiko 5.0.0
auth_handler.py): in this situation Paramiko raises with one of:Auth rejected: pubkey algorithm '...' unsupported or disabledUnable to agree on a pubkey algorithm for signing a '...' key!(AuthenticationException)An RSA key was specified, but no RSA pubkey algorithms are configured!Change: added
_is_key_type_rejected()innxc/protocols/ssh.pyand call it fromplaintext_login()in both theAuthenticationExceptionandSSHExceptionbranches, emittingKey type rejected by server (pubkey algorithm not allowed). Wrong-passphrase (Invalid key) and encrypted-key (Private key file is encrypted) cases keep their existing behavior.Dependencies: none new; only touches SSH login error handling.
AI usage disclosure: this PR was produced with the assistance of an AI agent (Hermes Agent, model tencent/hy3). The change and the new tests were written and executed by the agent; the human contributor performed the final self-review and verification (see Checklist). Per the project AI policy, this references an accepted issue (#1356).
Type of change
Setup guide for the review
PubkeyAcceptedAlgorithms ssh-ed25519insshd_config, then runnetexec ssh <host> -u <user> --key-file <rsa_or_ecdsa_key> -p <wrong_or_right_pass>.Could not decrypt private key, invalid password(misleading).Key type rejected by server (pubkey algorithm not allowed).Could not decrypt private key, invalid password(unchanged).pytest tests/test_ssh_key_type_rejection.py(4 tests, using the real Paramiko 5.x rejection messages). Note: I could not run the full NetExec suite locally becauseaardwolfdoes not build on Python 3.14 (see Install fails with Python 3.14 #1241); the change is isolated to SSH login error handling and is covered by the new unit tests.Screenshots (if appropriate):
N/A (CLI log-level change; see "Setup guide" for before/after output).
Checklist:
poetry run ruff check .)tests/e2e_commands.txtfile if necessary (SSH key-rejection is not a new module/feature; covered by unit test)paramiko/auth_handler.pyrejection messages; see Description)