import os.path import os import subprocess import curses #import distutils fld = "./" cnt = 0 found = 0 current = '' stdscr = 0 cnt_total = 1 cnt_total_file = 1; def try_pwd(pwd): global found, current, stdscr, cnt_total try: current = pwd p = subprocess.Popen('./try "%s"' % current, shell=True,stdout = subprocess.PIPE) tmp = os.waitpid(p.pid,0) # 16 bit, low: killing signal num, high: exit code found = ((tmp[1]>>8)==0) except Exception as e: stdscr.addstr(6,5, '(%d) Cannot try \'%s\': %s' % (cnt_total, pwd, e)) fle = open('cannot_try_%d.done' % cnt_total, "w") fle.write(pwd) fle.close def handle_file(file): global found, stdscr, cnt_total, fld, cnt_total_file fle = open(fld + file) try: content = fle.readlines() stdscr.addstr(3,4, 'Handling \'%s%s\': %d pwds (#%d)' % (fld, file, len(content), cnt_total_file)) cnt=1; for pwd in content: stdscr.addstr(4,4,'Trying pwd #%06d (%d)' % (cnt,cnt_total)) try_pwd(pwd[:-1]) stdscr.refresh() cnt+=1 cnt_total+=1 if(found): break if(not found): tmpfrom = '%s%s' % (fld,file) tmpto = '%s%s.done' % (fld, file) subprocess.call(['mv',tmpfrom, tmpto]) except Exception as e : stdscr.addstr(6,4, 'Cannot handle %s%s: %s' % (fld, file, e)) finally: fle.close() stdscr.refresh() def is_not_handled(file): return not('done' in file) and ('pwd' in file) # ____________ Main ___________________ stdscr = curses.initscr() curses.echo() curses.cbreak() try: stdscr.addstr('[TryPass PWD testing]') if(os.path.isdir(fld)): stdscr.addstr(1,4, 'Handling folder: %s' % fld) list = os.listdir(fld) filtered = filter(is_not_handled, list) stdscr.addstr(2,4, 'Found %d unhandled files' % len(filtered)) for file in filtered: cnt+=1 handle_file(file) cnt_total_file += 1 if(found): break if(found): stdsacr.addstr(5,4, 'Password found!: "%s"' % current) else: stdscr.addstr(5,4,'Password NOT found...') else: stdscr.addstr(1,4, '%s is not a folder' % fld) except Exception as e: stdscr.addstr('Error %s' % e) finally: stdscr.refresh() while 1: c = stdscr.getch() if(c== ord('q')): break; curses.nocbreak(); curses.echo() curses.endwin()