Please Someone Should Read This Code... - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › Please Someone Should Read This Code... (585 Views)
| Please Someone Should Read This Code... by Nick08130(op): 6:47am On Nov 04, 2022 |
```python #!/usr/bin/env python3 # Python SSH Checker # Fix indent =G:wq import argparse import socket import paramiko import sys import os class SystemScanner: def __init__(self, target, port, service): #Globals? self.target = target self.port = port self.service = service def test_ssh(self): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: sock.connect((self.target, self.port)) print("SSH Open" ![]() except Exception as err: #Conn failed print(f"Connection failed on " ![]() finally: sock.close() def ssh_auth(self): test = paramiko.Transport((self.target, self.port)) try: test.connect() except paramiko.ssh_exception.SSHException as err: print(f"SSH Connection failed:", self.host, self.port, "because ", str(err)) test.close() exit(1) try: test.auth_none('') except paramiko.BadAuthenticationType as err: print(err.allowed_types) finally: test.close() def ssh_login(self): print(f"Checking {self.service} logins..." ![]() try: print("Dropping into shell" ![]() command = "journalctl --system --follow | grep -i ssh" '''TODO 1) Parse output and find get the info cleaner 2) Add Services [http, ftp, smb] 3) clean exit 4) Counters for successfull/failed logins ''' os.system(command) except KeyboardInterrupt as kd: exit(1) finally: print("\n\n\r\nEND" ![]() if __name__ == '__main__': parser = argparse.ArgumentParser(prog="sysmon.py" ![]() parser.add_argument('--port', '-p', help="Enter Port Number", type=int, default=22) parser.add_argument('--target', '-t', help='Hostname or IP', default="127.0.0.1" ![]() parser.add_argument('--service', '-s', help="Show Service logins", default="ssh" ![]() args = parser.parse_args() scanner = SystemScanner(args.target, args.port, args.service) if scanner.test_ssh(): scanner.ssh_auth() if args.service: scanner.ssh_login() ``` |
| Re: Please Someone Should Read This Code... by bedfordng(m): 11:38am On Nov 04, 2022 |
The code is self explanatory. Code is simply used for making SSH connection. So when running the script you have to add the arguments such as target, port , service etc along with the script else it won't work. Are you the one that created it. |
| Re: Please Someone Should Read This Code... by Skodrran(m): 3:11pm On Nov 04, 2022 |
Socket programming ![]() |
I Am Bored, I Just Tried This Code • Eyeopener: Aspiring Nigerian Game/App Developers Should Read This • Please,Help Explain This Code In C • 2 • 3 • 4
Why Are Nigerians Accepting Low Pay In Tech? • Happy New Year Software Developer • Free Web Design And Development Training

