def get_resource_usages(self): #query each slash2 compenent for resource usage rusages = {} for host, type, ctl_path, pid in self.runtime["daemons"]: print type user = os.getenv("USER") ssh = SSH(user, host, ''); kernel = "".join(ssh.run("uname -s")["out"]).lower() if "linux" in kernel: output = self.check_status(ssh, type, ctl_path, pid) elif "bsd" in kernel: output = self.query_ctl_rusage(ssh, type, ctl_path) else: # do something pass rusages[host] = output return rusages sys.exit(1)
def main(): # Input files and variables start_time = datetime.now() # Devices file and commands source devices_file = "/app/src/devices_commands.csv" # Format commands and devices on dictionary for outputs new_collector = Collector(devices_file) new_collector.get_env() devices_commands = new_collector.format_devices() new_collector.output_json() # Send SSH sessions for outputs # Number of threads number_threads = 10 # Number of retry number_retry = 3 new_ssh = SSH(devices_commands,number_threads,number_retry) new_ssh.run() print("Process Collect Files Done: " + str(datetime.now() - start_time))
def setup_droplet(): # Create a droplet do_key = configparse('DigitalOcean')['digitalocean_api_key'] do = DO(do_key) #do.create_droplet() for droplet in do.get_all_droplets(tag_name="vpn-server"): ip = droplet.ip_address print("Waiting for setup of VPN") #sleep(35) # SSH接続 path = configparse('SSH')['ssh_secretkey_path'] print(path) ssh = SSH(ip,"root",path) ssh.connect ssh.excute_command("wget https://raw.githubusercontent.com/s151003/openvpn-install/master/openvpn-install.sh && chmod 777 openvpn-install.sh && bash openvpn-install.sh") ssh.close()
def main(self, line): args = line.split() ssh = SSH() if len(args) == 0: print '''Usage: addhost save_name hostname user [password] connect save_name connect hostname user password ''' return if args[0] == 'addhost': ssh.addhost(' '.join(args[1:])) elif args[0] == 'connect': ssh.connect(' '.join(args[1:])) elif args[0] == 'listhost': ssh.listhost() elif args[0] == 'delhost': ssh.delhost(' '.join(args[1:])) else: print __file__.__doc__ return
def shodan_search(self, args): shodan = Shodan_Search() if shodan.validateapi(): results = shodan.search(args.shodan) response = raw_input( 'YOU WANT TO TEST SHODAN RESULTS? Y/N: ').upper().strip() if response == "Y": parser = Passlist(args.passlist) for result in results['matches']: passwords = parser.get_list() try: if args.method is None: if result['port'] == 21: method = "ftp" Attack = FTP() if result['port'] == 22: method = "ssh" Attack = SSH() if result['port'] == 443: method = "https" Attack = Basic_Auth() else: args.method = "http" Attack = Basic_Auth() else: if args.method == "http": method = "http" Attack = Basic_Auth() if args.method == "https": method = "https" Attack = Basic_Auth if args.method == "ftp": method = "ftp" Attack = FTP() if args.method == "ssh": method = "ssh" Attack = SSH() Attack.brute_force(result['ip_str'], result['port'], args.username, passwords, method) except: pass else: sys.exit() else: sys.exit()
/_/ \_\__,_|\__\___/|_| |_|\__, |\__,_|_| \__,_| __/ | |___/ _) (_ _) \ /\%/\ /\%/\ /\%/\ /\%/\ / (_ _) \\(0 0) (0 0) (0 0) (0 0)// (_ )_ -- \(oo) (oo) (oo) (oo)/-- _( )_ / / \_,__/ \__,__/ \_,__/ \ \ _( )_ / --;-- --;- --;-- --;-- \ _( *. ( )) () (( () ) .* '...(___)z z(__)z(__)z(__)z z(__)....' """ exploits = { 'ssh': SSH(), 'http': HTTP(), 'postgres': postgresql(), 'ldap': LDAP() } def read_lines(filename): with open(filename, 'r') as f: lines = f.read_lines() return lines def main(): import argparse parser = argparse.ArgumentParser(description="Automate Hydra attacks against a specified network range.") parser.add_argument("-i", "--host_ips", metavar="<i>", type=str, help="IP address range to search", dest='host_ips')
def __init__(self, session_logs, taskconf, sshkey, ipaddress=None, destroy=None, event_stop=None, launchq=None): self.pid = os.getpid() if event_stop: signal.signal(signal.SIGINT, signal.SIG_IGN) self.event_stop = event_stop self.logs = session_logs self.sshkey = sshkey self.strikes = taskconf.strikes self.strike = 0 self.timeout = taskconf.timeout self.cleanup_command = taskconf.post self.user = taskconf.user self.ipaddress = ipaddress self.instanceid = None self.hub = None self.ssh = None if destroy is None: if ipaddress: destroy = False else: destroy = True self.destroy = destroy if not ipaddress: if not taskconf.hub_apikey: raise self.Error( "can't auto launch a worker without a Hub API KEY") self.hub = Hub(taskconf.hub_apikey) if launchq: with sighandle.sigignore(signal.SIGINT, signal.SIGTERM): instance = launchq.get() else: class Bool: value = False stopped = Bool() def handler(s, f): stopped.value = True with sighandle.sighandle(handler, signal.SIGINT, signal.SIGTERM): def callback(): return not stopped.value instance = list( self.hub.launch(1, VerboseLog(session_logs.manager), callback, **taskconf.ec2_opts))[0] if not instance or (event_stop and event_stop.is_set()): raise self.Terminated self.ipaddress, self.instanceid = instance self.status("launched worker %s" % self.instanceid) else: self.status("using existing worker") self.handle_stop = self._stop_handler(event_stop) try: self.ssh = SSH(self.ipaddress, identity_file=self.sshkey.path, login_name=taskconf.user, callback=self.handle_stop) except SSH.Error, e: self.status("unreachable via ssh: " + str(e)) traceback.print_exc(file=self.logs.worker) raise self.Error(e)
def __copy_tarball_to_node(self, tarball, node): logger.console('Copying tarball to {0}'.format(node['host'])) ssh = SSH() ssh.connect(node) ssh.scp(tarball, "/tmp/")
def put_client(self): ssh = SSH(self) self.clients[self._id()] = ssh
def test_services(service): ssh = SSH("localhost") ssh.sudo(f"systemctl restart {service}") is_active = ssh.sudo(f"systemctl is-active {service}") assert is_active["out"].rstrip() == "active" assert requests.get(url).status_code == 200
Session = sessionmaker(bind=engine) session = Session() qry_all_machines = session.query(Machine) for machine in qry_all_machines: data_e_hora_atuais = datetime.now() ref_time = RefTime(time_ref=data_e_hora_atuais, machine_id=machine.id) session.add(ref_time) session.commit() try: con_ssh = SSH(hostname=machine.hostname, username=machine.username) ca = ConnectionActive(connected='YES', ref_time_id=ref_time.id) session.add(ca) session.commit() disk_usage = con_ssh.cmd_disk_usage() for disk in disk_usage: du = DiskUsage(filesystem=disk['filesystem'], type=disk['type'], size=disk['size'], used=disk['used'], mounted_on=disk['mounted_on'], available=disk['available'], use_percent=disk['use_percent'], ref_time_id=ref_time.id)
def _get_ssh(self): return SSH(host=self.ceph_host, user=self.ceph_user, password=self.ceph_password, key_file=self.ceph_key_file)
def _delete_files(self, node, *files): ssh = SSH() ssh.connect(node) files = " ".join([str(x) for x in files]) ssh.exec_command("rm {0}".format(files))
from ssh import SSH from helper import * if __name__ == '__main__': ip = input("Enter ip: ").strip() mask = input("Enter mask: ").strip() row_id = input("Enter row id: ").strip() # Store credentials in 'auth_data' and script won't ask you about them. # login, password = auth_data(ip) login, password = auth_data_alt(ip) with SSH(ip, login, password) as ssh: path = ssh.path_to_logfile(mask) file = ssh.read_logfile(path) rows = find_result(file, row_id) print_log(rows)
def connect(self): try: self.accept() query_string = self.scope['query_string'] connect_argv = QueryDict(query_string=query_string, encoding='utf-8') server_id = connect_argv.get('server_id') user = connect_argv.get('user') width = connect_argv.get('width') height = connect_argv.get('height') width = int(width) height = int(height) connect_info = get_object_or_404(models.Server, id=server_id) host = connect_info.alias port = connect_info.ssh_port # auth = '' # pkey = '' # connect_info.delete() if user == str("root"): # # password = base64.b64decode(pwd).decode('utf-8') password = connect_info.ssh_user_root_password else: password = connect_info.ssh_user_other_password self.ssh = SSH(websocker=self, message=self.message) # self.ssh = SSH(websocker=self) self.ssh.connect(host=host, user=user, password=password, port=port, pty_width=width, pty_height=height) # if auth == 'key': # pkey = pkey # obj = StringIO() # obj.write(pkey) # obj.flush() # obj.seek(0) # self.pkey = obj # # self.ssh.connect( # host=host, # user=user, # password=password, # pkey=self.pkey, # port=port, # pty_width=width, # pty_height=height # ) # else: # self.ssh.connect( # host=host, # user=user, # password=password, # port=port, # pty_width=width, # pty_height=height # ) except Exception as e: self.message['status'] = 1 self.message['message'] = str(e) message = json.dumps(self.message) self.send(message) self.close()