Skip to content

Commit

Permalink
[ssh] fix Pennyw0rth#112
Browse files Browse the repository at this point in the history
Signed-off-by: XiaoliChan <[email protected]>
  • Loading branch information
XiaoliChan committed Nov 10, 2023
1 parent 49d4441 commit 82b2f1e
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions nxc/protocols/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,16 @@ def plaintext_login(self, username, password, private_key=None):
with open(self.args.key_file) as f:
private_key = f.read()

pkey = paramiko.RSAKey.from_private_key(StringIO(private_key), password)

self.conn._transport.auth_publickey(username, pkey)
pkey = paramiko.RSAKey.from_private_key(StringIO(private_key))
self.conn.connect(
self.host,
port=self.port,
username=username,
passphrase=password if password != "" else None,
pkey=pkey,
look_for_keys=False,
allow_agent=False,
)

cred_id = self.db.add_credential(
"key",
Expand All @@ -208,7 +215,14 @@ def plaintext_login(self, username, password, private_key=None):

else:
self.logger.debug(f"Logging {self.host} with username: {self.username}, password: {self.password}")
self.conn._transport.auth_password(username, password, fallback=True)
self.conn.connect(
self.host,
port=self.port,
username=username,
password=password,
look_for_keys=False,
allow_agent=False,
)
cred_id = self.db.add_credential("plaintext", username, password)

# Some IOT devices will not raise exception in self.conn._transport.auth_password / self.conn._transport.auth_publickey
Expand Down

0 comments on commit 82b2f1e

Please sign in to comment.