44import logging
55import time
66
7- from io import StringIO
87from nxc .config import process_secret
98from nxc .connection import connection , highlight
109from nxc .logger import NXCAdapter
@@ -182,26 +181,20 @@ def check_if_admin_sudo(self):
182181 self .logger .error ("Command: 'mkfifo' unavailable, running command with 'sudo' failed" )
183182 return
184183
185- def plaintext_login (self , username , password , private_key = None ):
184+ def plaintext_login (self , username , password , private_key = "" ):
186185 self .username = username
187186 self .password = password
188- private_key = ""
189187 stdout = None
190188 try :
191189 if self .args .key_file or private_key :
192- self .logger .debug ("Logging in with key " )
190+ self .logger .debug (f "Logging { self . host } with username: { username } , keyfile: { self . args . key_file } " )
193191
194- if self .args .key_file :
195- with open (self .args .key_file ) as f :
196- private_key = f .read ()
197-
198- pkey = paramiko .RSAKey .from_private_key (StringIO (private_key ))
199192 self .conn .connect (
200193 self .host ,
201194 port = self .port ,
202195 username = username ,
203196 passphrase = password if password != "" else None ,
204- pkey = pkey ,
197+ key_filename = private_key if private_key else self . args . key_file ,
205198 look_for_keys = False ,
206199 allow_agent = False ,
207200 )
@@ -228,13 +221,10 @@ def plaintext_login(self, username, password, private_key=None):
228221 # Some IOT devices will not raise exception in self.conn._transport.auth_password / self.conn._transport.auth_publickey
229222 _ , stdout , _ = self .conn .exec_command ("id" )
230223 stdout = stdout .read ().decode (self .args .codec , errors = "ignore" )
224+ except SSHException as e :
225+ self .logger .fail (f"{ username } :{ process_secret (password )} Could not decrypt private key, error: { e } " )
231226 except Exception as e :
232- if self .args .key_file :
233- password = f"{ process_secret (password )} (keyfile: { self .args .key_file } )"
234- if "OpenSSH private key file checkints do not match" in str (e ):
235- self .logger .fail (f"{ username } :{ password } - Could not decrypt key file, wrong password" )
236- else :
237- self .logger .fail (f"{ username } :{ password } { e } " )
227+ self .logger .fail (f"{ username } :{ process_secret (password )} { e } " )
238228 self .conn .close ()
239229 return False
240230 else :
@@ -287,7 +277,7 @@ def plaintext_login(self, username, password, private_key=None):
287277 self .server_os_platform ,
288278 "- Shell access!" if shell_access else ""
289279 )
290- self .logger .success (f"{ username } :{ password } { self .mark_pwned ()} { highlight (display_shell_access )} " )
280+ self .logger .success (f"{ username } :{ process_secret ( password ) } { self .mark_pwned ()} { highlight (display_shell_access )} " )
291281
292282 return True
293283
0 commit comments