def run(dict): try: dir = [] output = [] with FTP() as ftp: ftp.connect(host=dict['host'], port=dict['port'], timeout=int(dict['timeout'])) ftp.login() ftp.dir(dir.append) if dir: output.append('ftp://' + dict['host'] + ' anon') for line in dir: line = re.sub(r'[\x00-\x1f\x7f-\x9f]', '?', line) output.append(line) output.append('') print('\n'.join(output)) print() dict['output'] = '\n'.join(output) dict['username'] = '******' dict['password'] = '******' tef.write_database(dict) tef.write_creds(dict) except Exception as error: if dict['verbose'].lower() in ['true']: print("{} {} : {}".format(tef.minus(), dict['host'], error))
def run(dict): try: temp = io.BytesIO() with FTP() as ftp: ftp.connect(host=dict['host'], port=dict['port'], timeout=int(dict['timeout'])) with temp as file: ftp.login() ftp.retrbinary('RETR ' + dict['file'], file.write) if file: p = Path.home() / '.tef' / 'loot' / dict['host'] f = False if Path.is_file(p / Path(dict['file']).name): count = 1 while not f: if Path.is_file(Path(str(p / Path(dict['file']).name) + '.' + str(count))): f = False count += 1 else: f = str(p / Path(dict['file']).name) + '.' + str(count) else: f = p / Path(dict['file']).name if not p.is_dir(): p.mkdir(parents=True) download = open(f, 'wb') download.write(file.getvalue()) download.close() print('File {} successfully downloaded to {}'.format(dict['file'], p / f)) else: print('File {} empty or does not exist'.format(dict['file'])) except Exception as error: if dict['verbose'].lower() in ['true']: print('{} {} : {}'.format(tef.minus(),dict['host'],error))
def run(dict): # Required function. Main code block that will be executed. See 'How to use tef' in README.md for more info output = [] try: print('Hello World!') print('The host for the module is {}'.format(dict['host'])) print('{} Oh no!'.format(tef.minus())) print('{} Hurray!'.format(tef.plus())) print('Someone put {} for the test option, saving it to module output'.format(dict['test_option'])) output.append(dict['test_option']) print('Writing test_option string to database...') dict['output'] = '\n'.join(output) tef.write_database(dict) ''' If you want to write the returned information to the database: tef.write_database(dict) tef.write_creds(dict) ''' except Exception as error: if dict['verbose'].lower() in ['true']: print("{} {} : {}".format(tef.minus(),dict['host'], error))
def run(dict): sock_type = '' ports = dict['ports'] try: if dict['protocol'].lower() in ['tcp']: sock_type = socket.SOCK_STREAM elif dict['protocol'].lower() in ['udp']: sock_type = socket.SOCK_DGRAM if ',' in ports: comma_split = ports.split(',') a = [] for numbers in comma_split: if '-' in numbers: t = numbers.split('-') if 0 <= int(t[0]) < int(t[1]) <= 65535: pass else: raise ValueError('invalid port value') a += range(int(t[0]), int(t[1]) +1) else: a.append(int(numbers)) ports = set(a) elif '-' in ports: a = [] t = ports.split('-') if 0 <= int(t[0]) < int(t[1]) <= 65535: pass else: raise ValueError('invalid port value') a += range(int(t[0]), int(t[1]) +1) ports = set(a) else: ports = set([int(dict['ports'])]) # Typing lul print(ports) for port in ports: print(port) time.sleep(.5) with socket.socket(socket.AF_INET, sock_type) as s: result = s.connect_ex((dict['host'], port)) if result == 0: print('{} {} : {} OPEN'.format(tef.plus(), dict['host'], port)) except KeyboardInterrupt: return except Exception as error: if dict['verbose'].lower() in ['true']: print("{} {} : {}".format(tef.minus(),dict['host'], error))
def run(dict): try: with FTP(host=dict['host'], port=dict['port'], user=dict['username'], passwd=dict['password']) as ftp: ftp.connect(host=dict['host'], port=int(dict['port']), timeout=int(dict['timeout'])) ftp.login() print("{} Login valid - {} : {}".format(tef.plus(), dict['username'], dict['password'])) print() tef.write_database(dict) tef.write_creds(dict) except Exception as error: if dict['verbose'].lower() in ['true']: print("{} {} : {}".format(tef.minus(), dict['host'], error))
def run(dict): try: print(dict) ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(hostname=dict['host'], port=dict['port'], username=dict['username'], password=dict['password'], timeout=dict['timeout']) ssh.close() print(tef.plus() + " Login valid - {} : {}".format( dict['username'], dict['password'])) print() tef.write_database(dict) tef.write_creds(dict) except Exception as error: if dict['verbose'].lower() in ['true']: print("{} {} : {}".format(tef.minus(), dict['host'], error)) ssh.close()