Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,199,314 members, 7,971,150 topics. Date: Thursday, 10 October 2024 at 12:22 AM |
Nairaland Forum / Science/Technology / Programming / Please Someone Should Read This Code... (474 Views)
I Am Bored, I Just Tried This Code / Eyeopener: Aspiring Nigerian Game/App Developers Should Read This / Java Programmers ,I Need Help Fixing This Code. (2) (3) (4)
Please Someone Should Read This Code... by Nick08130(m): 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 |
(1) (Reply)
Import This Googlemap Route Data Into Googlesheet / Blender Tricks You Need Before You Secure Your First Gig on up work / Build Your Enterprise Applications And Services
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 9 |