From 058daf9f04ad907414b340582dc9ab0037aa62bd Mon Sep 17 00:00:00 2001 From: Dharm Pimsen Date: Sun, 5 May 2024 17:12:26 +0700 Subject: [PATCH 1/4] hot fix for server fix freezing when no banner --- src/PyserSSH/server.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/PyserSSH/server.py b/src/PyserSSH/server.py index 530db1d..078606e 100644 --- a/src/PyserSSH/server.py +++ b/src/PyserSSH/server.py @@ -36,7 +36,7 @@ from .system.SFTP import SSHSFTPServer from .system.interface import Sinterface from .interactive import * from .system.inputsystem import expect -from .system.info import __version__ +from .system.info import __version__, system_banner # paramiko.sftp_file.SFTPFile.MAX_REQUEST_SIZE = pow(2, 22) @@ -67,7 +67,7 @@ class Server: self.__processmode = None self.__serverisrunning = False - self.__server_stopped = threading.Event() # Event to signal server stop + self.__daemon = False if self.enasyscom: print("\033[33m!!Warning!! System commands is enable! \033[0m") @@ -162,7 +162,15 @@ class Server: if self.sysmess or userbanner != None: channel.send(f"\033]0;{self.title}\007".encode()) - channel.sendall(replace_enter_with_crlf(userbanner)) + + if userbanner is None and self.sysmess: + channel.sendall(replace_enter_with_crlf(system_banner)) + elif userbanner != None and self.sysmess: + channel.sendall(replace_enter_with_crlf(system_banner)) + channel.sendall(replace_enter_with_crlf(userbanner)) + elif userbanner != None and not self.sysmess: + channel.sendall(replace_enter_with_crlf(userbanner)) + channel.sendall(replace_enter_with_crlf("\n")) try: @@ -171,6 +179,7 @@ class Server: self._handle_event("error", self.client_handlers[channel.getpeername()], e) client_handler["connecttype"] = "ssh" + if self.enainputsystem: try: if self.accounts.get_user_timeout(self.client_handlers[channel.getpeername()]["current_user"]) != None: @@ -223,11 +232,12 @@ class Server: while self.__serverisrunning: client, addr = self.server.accept() if self.__processmode == "thread": - client_thread = threading.Thread(target=self.handle_client, args=(client, addr)) + client_thread = threading.Thread(target=self.handle_client, args=(client, addr), daemon=self.__daemon) client_thread.start() else: self.handle_client(client, addr) - + except KeyboardInterrupt: + self.stop_server() except Exception as e: logger.error(e) @@ -244,9 +254,9 @@ class Server: self.__processmode = mode.lower() self.__serverisrunning = True + self.__daemon = daemon - client_thread = threading.Thread(target=self._start_listening_thread) - client_thread.daemon = daemon + client_thread = threading.Thread(target=self._start_listening_thread, daemon=self.__daemon) client_thread.start() def kickbyusername(self, username, reason=None): From 98361c33f2c8dc4c55a973fb22b20a1bdd220f67 Mon Sep 17 00:00:00 2001 From: Dharm Pimsen Date: Sat, 20 Jul 2024 20:47:22 +0700 Subject: [PATCH 2/4] Update README.md --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 145269b..31c4654 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,9 @@ PyserSSH is a library for remote control your code with ssh client. The aim is to provide a scriptable SSH server which can be made to behave like any SSH-enabled device. +## Some smail PyserSSH history +PyserSSH version [1.0](https://github.com/DPSoftware-Foundation/PyserSSH/releases/download/Legacy/PyserSSH10.py) was created in 2023/9/15 for experimental purposes only. Because I couldn't find the best ssh server library for python and I started this project only for research. But I have time to develop this research into a real library for use. In software or server. + This project is part from [damp11113-library](https://github.com/damp11113/damp11113-library) This Server use port **2222** for default port @@ -64,4 +67,4 @@ For exit demo you can use `ctrl+c` or use `shutdown now` in PyserSSH shell **(no I intend to leaked private key because that key i generated new. I recommend to generate new key if you want to use on your host because that key is for demo only. why i talk about this? because when i push private key into this repo in next 5 min++ i getting new email from GitGuardian. in that email say " -GitGuardian has detected the following RSA Private Key exposed within your GitHub account" i dont knows what is GitGuardian and i not install this app into my account. \ No newline at end of file +GitGuardian has detected the following RSA Private Key exposed within your GitHub account" i dont knows what is GitGuardian and i not install this app into my account. From c4b5314fdafeee548b4e549ec1c7a3ed5d39cf91 Mon Sep 17 00:00:00 2001 From: Dharm Pimsen Date: Sat, 20 Jul 2024 20:51:41 +0700 Subject: [PATCH 3/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 31c4654..61185ef 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ PyserSSH is a library for remote control your code with ssh client. The aim is to provide a scriptable SSH server which can be made to behave like any SSH-enabled device. ## Some smail PyserSSH history -PyserSSH version [1.0](https://github.com/DPSoftware-Foundation/PyserSSH/releases/download/Legacy/PyserSSH10.py) was created in 2023/9/15 for experimental purposes only. Because I couldn't find the best ssh server library for python and I started this project only for research. But I have time to develop this research into a real library for use. In software or server. +PyserSSH version [1.0](https://github.com/DPSoftware-Foundation/PyserSSH/releases/download/Legacy/PyserSSH10.py) (real filename is "test277.py") was created in 2023/9/3 for experimental purposes only. Because I couldn't find the best ssh server library for python and I started this project only for research. But I have time to develop this research into a real library for use. In software or server. This project is part from [damp11113-library](https://github.com/damp11113/damp11113-library) From f578fc57d5878027897987c7519d29e5aaaf6c33 Mon Sep 17 00:00:00 2001 From: Dharm Pimsen Date: Mon, 29 Jul 2024 16:52:14 +0700 Subject: [PATCH 4/4] Update README.md --- README.md | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/README.md b/README.md index 61185ef..3eebf02 100644 --- a/README.md +++ b/README.md @@ -46,25 +46,6 @@ If you input `hello` the response is `world` # Demo https://github.com/damp11113/PyserSSH/assets/64675096/49bef3e2-3b15-4b64-b88e-3ca84a955de7 -For run this demo you can use this command -``` -$ python -m PyserSSH -``` -then -``` -Do you want to run demo? (y/n): y -``` -But if no [damp11113-library](https://github.com/damp11113/damp11113-library) -``` -No 'damp11113-library' -This demo is require 'damp11113-library' for run -``` -you need to install [damp11113-library](https://github.com/damp11113/damp11113-library) for run this demo by choose `y` or `yes` in lowercase or uppercase -``` -Do you want to install 'damp11113-library'? (y/n): y -``` -For exit demo you can use `ctrl+c` or use `shutdown now` in PyserSSH shell **(not in real terminal)** - I intend to leaked private key because that key i generated new. I recommend to generate new key if you want to use on your host because that key is for demo only. why i talk about this? because when i push private key into this repo in next 5 min++ i getting new email from GitGuardian. in that email say " GitGuardian has detected the following RSA Private Key exposed within your GitHub account" i dont knows what is GitGuardian and i not install this app into my account.