Skip to content

Commit

Permalink
[ssh] Add instructions for removing host key from known_hosts (#1770)
Browse files Browse the repository at this point in the history
* [ssh] Add instructions for removing host key from known_hosts

* Fix hostname
  • Loading branch information
heapcrash committed Mar 1, 2021
1 parent d98d82d commit 19cf23b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pwnlib/tubes/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,9 +656,16 @@ def __init__(self, user=None, host=None, port=22, password=None, key=None,

if proxy_command:
proxy_sock = paramiko.ProxyCommand(proxy_command)
self.client.connect(host, port, user, password, key, keyfiles, self.timeout, compress = True, sock = proxy_sock)
else:
self.client.connect(host, port, user, password, key, keyfiles, self.timeout, compress = True)
proxy_sock = None

try:
self.client.connect(host, port, user, password, key, keyfiles, self.timeout, compress = True, sock = proxy_sock)
except paramiko.BadHostKeyException as e:
self.error("Remote host %(host)s is using a different key than stated in known_hosts\n"
" To remove the existing entry from your known_hosts and trust the new key, run the following commands:\n"
" $ ssh-keygen -R %(host)s\n"
" $ ssh-keygen -R [%(host)s]:%(port)s" % locals())

self.transport = self.client.get_transport()
self.transport.use_compression(True)
Expand Down

0 comments on commit 19cf23b

Please sign in to comment.