def get_ids(self): known = set() for user, identity in homes.users(file=[ os.path.join('.ssh', item) for item in ('id_rsa', 'id_dsa', 'id_ecdsa', 'id_ed25519') ]): if os.path.isfile(identity): try: with open(identity) as fidentity: yield { 'KEY': fidentity.read(), 'User': user, } known.add(identity) except Exception: pass for user, config in self.get_configs(): for pw in self.get_ids_from_config(user, config): if pw['KEY'] in known: continue try: with open(pw['KEY']) as fidentity: pw['KEY'] = fidentity.read() yield pw known.add(identity) except Exception: pass
def get_files(self): known = set() for user, histfile in homes.users( file=['.history', '.sh_history', '.bash_history', '.zhistory' ]): yield user, histfile known.add(histfile) for process in psutil.process_iter(): try: environ = process.environ() user = process.username() except Exception: continue if 'HISTFILE' not in environ: continue histfile = environ['HISTFILE'] if histfile in ('/dev/zero', '/dev/null'): continue if histfile.startswith('~/'): try: home = pwd.getpwuid(process.uids().effective).pw_dir except Exception: continue histfile = os.path.join(home, histfile[2:]) if os.path.isfile(histfile) and not histfile in known: yield user, histfile known.add(histfile)
def get_ids(self): known = set() for user, identity in homes.users(file=[ os.path.join('.ssh', item) for item in ( 'id_rsa', 'id_dsa', 'id_ecdsa', 'id_ed25519' ) ]): if os.path.isfile(identity): try: with open(identity) as fidentity: yield { 'KEY': fidentity.read(), 'User': user, } known.add(identity) except Exception: pass for user, config in self.get_configs(): for pw in self.get_ids_from_config(user, config): if pw['KEY'] in known: continue try: with open(pw['KEY']) as fidentity: pw['KEY'] = fidentity.read() yield pw known.add(identity) except Exception: pass
def get_files(self): known = set() for user, histfile in homes.users(file=['.history', '.sh_history', '.bash_history', '.zhistory']): yield user, histfile known.add(histfile) for process in psutil.process_iter(): try: environ = process.environ() user = process.username() except: continue if not 'HISTFILE' in environ: continue histfile = environ['HISTFILE'] if histfile in ('/dev/zero', '/dev/null'): continue if histfile.startswith('~/'): try: home = pwd.getpwuid(process.uids().effective).pw_dir except: continue histfile = os.path.join(home, histfile[2:]) if os.path.isfile(histfile) and not histfile in known: yield user, histfile known.add(histfile)
def get_lines(self): known = set() for user, plainfile in self.get_files(): try: with open(plainfile) as infile: for line in infile.readlines(): line = line.strip() if line.startswith('#'): continue try: int(line) continue except Exception: pass line = ' '.join(x for x in line.split() if x) if line not in known: yield user, line known.add(line) except Exception: pass for user, histfile in homes.users(file='.local/share/mc/history'): parser = ConfigParser() try: parser.read(histfile) except Exception: continue try: for i in parser.options('cmdline'): line = parser.get('cmdline', i) if line not in known: yield user, line known.add(line) except Exception: pass
def get_configs(self): return homes.users(file=os.path.join('.ssh', 'config'))