def cleaner(*args): _ = "".join(args) if _ and os.path.isdir(_): shreder_dir(_) elif _ and os.path.isfile(_): shreder_file(_) elif _ and _.upper() in prefix_range: for filename in os.listdir(get_result_store_path()): if _.upper() in str(filename[0:8]).upper(): shreder_file(os.path.join(get_result_store_path(), filename)) else: exit(CRLF + cool.red("[-] invalid shredder path_or_dir arguments"))
def do_run(self, args): results = [] storepath = os.path.join(get_result_store_path(), '%s_%s%s' % (SEDB_prefix, get_buildtime(), filextension)) with open(storepath, 'w') as f: # SingleRule for single in SingleRule(settings_dict['cname'], settings_dict['ename'], settings_dict['sname'], settings_dict['birth'], settings_dict['usedpwd'], settings_dict['phone'], settings_dict['uphone'], settings_dict['hphone'], settings_dict['email'], settings_dict['postcode'], settings_dict['nickname'], settings_dict['idcard'], settings_dict['jobnum'], settings_dict['otherdate'], settings_dict['usedchar']): results.append(single) # CBrule for cb in CBrule(settings_dict['cname'], settings_dict['birth']): results.append(cb) # EBrule for eb in EBrule(settings_dict['ename'], settings_dict['birth']): results.append(eb) # SBrule for sb in SBrule(settings_dict['sname'], settings_dict['birth']): results.append(sb) # WeakPass for weakpwd in weak_pass_set: results.append(weakpwd) # de-duplication for _ in reduce(lambda x, y: x if y in x else x + [y], [[], ] + results): f.write(_ + CRLF) finishprinter(finishcounter(storepath), storepath)
def do_run(self, args): results = [] storepath = os.path.join(get_result_store_path(), '%s_%s%s' % (SEDB_prefix, get_buildtime(), filextension)) with open(storepath, "a") as f: # SingleRule for single in SingleRule(settings_dict[sedb_range[0]], settings_dict[sedb_range[1]], settings_dict[sedb_range[2]], settings_dict[sedb_range[3]], settings_dict[sedb_range[4]], settings_dict[sedb_range[5]], settings_dict[sedb_range[6]], settings_dict[sedb_range[7]], settings_dict[sedb_range[8]], settings_dict[sedb_range[9]], settings_dict[sedb_range[10]], settings_dict[sedb_range[11]], settings_dict[sedb_range[12]], settings_dict[sedb_range[13]], settings_dict[sedb_range[14]]): results.append(single) # CBrule for cb in CBrule(settings_dict[sedb_range[0]], settings_dict[sedb_range[3]]): results.append(cb) # EBrule for eb in EBrule(settings_dict[sedb_range[1]], settings_dict[sedb_range[3]]): results.append(eb) # SBrule for sb in SBrule(settings_dict[sedb_range[2]], settings_dict[sedb_range[3]]): results.append(sb) # WeakPass for weakpwd in weak_pass_set: results.append(weakpwd) # Using extend_enter plug for extendstr in extend_enter(settings_dict[sedb_range[0]], settings_dict[sedb_range[1]], settings_dict[sedb_range[2]], settings_dict[sedb_range[4]], settings_dict[sedb_range[10]], settings_dict[sedb_range[14]]): results.append(extendstr) # de-duplication for _ in reduce(lambda x, y: x if y in x else x + [y], [[], ] + results): f.write(_ + CRLF) finishprinter(finishcounter(storepath), storepath)
def shredder_enter(*args): fnum = 0 _ = "".join(args) if _ and os.path.isdir(_): shreder_dir(_) elif _ and os.path.isfile(_): shreder_file(_) elif _ and _.upper() in prefix_range: for filename in os.listdir(get_result_store_path()): if _.upper() in str(filename[0:10]).upper(): fnum += 1 shreder_file(os.path.join(get_result_store_path(), filename)) if fnum == 0: exit(CRLF + cool.orange("[+] prefix %s files has been clean" % _.upper())) else: exit(CRLF + cool.red("[-] invalid shredder path_or_dir arguments"))
def get_chunk_dic(objflag, encodeflag, head, tail): countchecker(len(objflag)) storepath = os.path.join(get_result_store_path(), "%s_%s_%s%s" % (CHUNK_prefix, get_buildtime(), encodeflag, filextension)) with open(storepath, "a") as f: for item in itertools.permutations(objflag, len(objflag)): f.write(operator.get(encodeflag)(head + "".join(item) + tail) + CRLF) finishprinter(finishcounter(storepath), storepath)
def getIDCardPost(posflag, encodeflag, head, tail, sex): storepath = os.path.join( get_result_store_path(), "%s_%s_%s_%s%s" % (IDCARD_prefix, str(posflag)[-1:], get_buildtime(), encodeflag, filextension)) posrule = lambda _: str(_) if _ >= 10 else "0" + str(_) # month value1112 = " ".join(posrule(x) for x in range_compatible(1, 13)) # day value1314 = " ".join(posrule(x) for x in range_compatible(1, 32)) value1516 = " ".join(posrule(x) for x in range_compatible(1, 100)) post18 = "0 1 2 3 4 5 6 7 8 9 X" value1718 = "" if sex == 'm': rand = "1 3 5 7 9" for _ in rand.split(' '): for _p in post18.split(' '): value1718 += _ + _p + " " elif sex == 'f': rand = "0 2 4 6 8" for _ in rand.split(' '): for _p in post18.split(' '): value1718 += _ + _p + " " else: rand = " ".join(str(_) for _ in range_compatible(0, 10)) for _ in rand.split(' '): for _p in post18.split(' '): value1718 += _ + _p + " " with open(storepath, "w") as f: if posflag == 'pid8': for v1112 in value1112.split(' '): for v1314 in value1314.split(' '): for v1516 in value1516.split(' '): for v1718 in value1718.split(' '): if v1718 != "": if encodeflag == "": f.write(head + v1112 + v1314 + v1516 + v1718 + tail + CRLF) else: f.write( operator.get(encodeflag) (head + v1112 + v1314 + v1516 + v1718 + tail) + CRLF) elif posflag == 'pid6': for v1314 in value1314.split(' '): for v1516 in value1516.split(' '): for v1718 in value1718.split(' '): if v1718 != "": if encodeflag == "": f.write(head + v1314 + v1516 + v1718 + tail + CRLF) else: f.write( operator.get(encodeflag) (head + v1314 + v1516 + v1718 + tail) + CRLF) finishprinter(finishcounter(storepath), storepath)
def uniqify_enter(original_file_path): storepath = os.path.join( get_result_store_path(), "%s_%s%s" % (tool_fun_str[1].upper(), get_buildtime(), filextension)) with open(original_file_path) as o_f: with open(storepath, 'a') as s_f: for _ in fast_uniqify(o_f.readlines()): s_f.write(_) print("[+] Start : {0:10} lines".format( cool.orange(finishcounter(original_file_path)))) print("[+] Current : {0:10} lines".format( cool.orange(finishcounter(storepath)))) print("[+] Cost : {0:} seconds".format( cool.orange(str(time.time() - start)[:6]))) print("[+] Store in: {0}".format(cool.orange(storepath)))
def get_base_dic(minlength, maxlength, objflag, encodeflag, head, tail): countchecker(len(objflag), minlength, maxlength) global description storepath = os.path.join( get_result_store_path(), "%s_%s_%s_%s_%s_%s%s" % (BASE_prefix, minlength, maxlength, description, get_buildtime(), encodeflag, filextension)) with open(storepath, "w") as f: for i in range_compatible(minlength, maxlength + 1): for item in itertools.product(objflag, repeat=i): if encodeflag == "": f.write(head + "".join(item) + tail + CRLF) else: f.write( operator.get(encodeflag)(head + "".join(item) + tail) + CRLF) finishprinter(finishcounter(storepath), storepath)
def get_extend_dic(rawlist, encodeflag='none', need_passcratch=False): prefix = EXTEND_prefix if rawlist == []: exit(CRLF + cool.red("[-] raw extend_enter file cannot be empty")) if need_passcratch: prefix = PASSCRAPER_prefix storepath = os.path.join( get_result_store_path(), "%s_%s_%s%s" % (prefix, get_buildtime(), encodeflag, filextension)) with open(storepath, "a") as f: try: for _ in extend_enter(rawlist): f.write(operator.get(encodeflag)(str(_) + CRLF)) except: traceback.print_exc() exit(CRLF + cool.red("[-] Some error")) finishprinter(finishcounter(storepath), storepath)
def getExtendDic(rawlist, encodeflag=""): if rawlist == []: exit(CRLF + cool.red("[-] raw extend file cannot be empty")) storepath = os.path.join( get_result_store_path(), "%s_%s_%s%s" % (EXTEND_prefix, get_buildtime(), encodeflag, filextension)) with open(storepath, 'w') as f: try: for _ in extend(rawlist): _ = str(_) if encodeflag == "": f.write(_ + CRLF) else: f.write(operator.get(encodeflag)(_ + CRLF)) except: exit(CRLF + cool.red("[-] File's character encoding maybe error")) finishprinter(finishcounter(storepath), storepath)
def counter_operator(original_file_path, justsave, justview, encodeflag, head, tail, view_count=default_view_items): items = Counter( open(original_file_path, 'r').read().replace( string.punctuation, "").split(counter_split)).most_common(view_count) items_length = len(items) storepath = os.path.join( get_result_store_path(), "%s_%s%s" % (COUNTER_prefix, get_buildtime(), filextension)) if view_count > view_counter_switcher: exit(CRLF + cool.fuchsia("[!] view items should Leq {0}".format( view_counter_switcher))) elif items_length < view_count: exit(CRLF + cool.fuchsia("[!] max items is {0}".format(items_length))) print("{0}Welcome to the COUNTER tool".format(" " * 8)) if justsave: with open(storepath, "a") as f: for _ in items: f.write(operator.get(encodeflag)(head + _[0] + tail) + CRLF) finishprinter(finishcounter(storepath), storepath) elif justview: print(CRLF * 2) for item in items: print("{0}Word:{2:20} -> {1:10} times".format( " " * 5, cool.orange(item[1]), cool.orange(item[0]))) print("[+] Cost:{} seconds".format( cool.orange(str(time.time() - startime)[:6]))) else: print(CRLF * 2) for item in items: print("{0}Word:{2:20} -> {1:10} times".format( " " * 5, cool.orange(item[1]), cool.orange(item[0]))) print(CRLF) with open(storepath, 'a') as f: for _ in items: f.write(operator.get(encodeflag)(head + _[0] + tail) + CRLF) finishprinter(finishcounter(storepath), storepath)
def get_idcard_post(posflag, encodeflag, head, tail, sex): storepath = os.path.join(get_result_store_path(), "%s_%s_%s_%s%s" % (IDCARD_prefix, str(posflag)[-1:], get_buildtime(), encodeflag, filextension)) posrule = lambda _: str(_) if _ >= 10 else "0" + str(_) # month value1112 = " ".join(posrule(x) for x in range_compatible(1, 13)) # day value1314 = " ".join(posrule(x) for x in range_compatible(1, 32)) value1516 = " ".join(posrule(x) for x in range_compatible(1, 100)) post18 = ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "X") value1718 = "" if sex == sex_range[0]: rand = ("1", "3", "5", "7", "9") for _ in rand: for _p in post18: value1718 += _ + _p + " " elif sex == sex_range[1]: rand = ("0", "2", "4", "6", "8") for _ in rand: for _p in post18: value1718 += _ + _p + " " elif sex == sex_range[2]: rand = " ".join(str(_) for _ in range_compatible(0, 10)) for _ in rand.split(" "): for _p in post18: value1718 += _ + _p + " " with open(storepath, "a") as f: if posflag == plug_range[1]: for v1112 in value1112.split(" "): for v1314 in value1314.split(" "): for v1516 in value1516.split(" "): for v1718 in value1718.split(" "): if v1718 != "": f.write(operator.get(encodeflag)(head + v1112 + v1314 + v1516 + v1718 + tail) + CRLF) elif posflag == plug_range[0]: for v1314 in value1314.split(" "): for v1516 in value1516.split(" "): for v1718 in value1718.split(" "): if v1718 != "": f.write(operator.get(encodeflag)(head + v1314 + v1516 + v1718 + tail) + CRLF) finishprinter(finishcounter(storepath), storepath)
def combiner_enter(directory=os.path.abspath(sys.argv[0]), need_uniqifer=False): if not os.path.isdir(os.path.abspath(directory)): exit(CRLF + cool.red("[-] path: {} don't exists".format(directory))) filepaths = [] combine_list = [] storepath = os.path.join(get_result_store_path(), "%s_%s%s" % (COMBINER_prefix, get_buildtime(), filextension)) for rootpath, subdirsname, filenames in os.walk(directory): filepaths.extend([os.path.abspath(os.path.join(rootpath, _)) for _ in filenames]) if len(filepaths) > 0: for _ in filepaths: if mimetypes.guess_type(_)[0] == 'text/plain': combine_list.append(_) try: with open(storepath, "a") as f: for onefile in combine_list: with open(onefile, 'r') as tf: f.write(tf.read()) if not need_uniqifer: finishprinter(finishcounter(storepath), storepath) else: uniqifer_enter(storepath, from_combiner=True) except Exception as ex: print(CRLF + cool.red("[-] Combine file failed, Looking: ")) exit(CRLF + traceback.print_exc())
def get_base_dic(minlength, maxlength, objflag, encodeflag, head, tail, need_char_dic=False): objflag = getchars(objflag, need_char=need_char_dic) countchecker(len(objflag), minlength, maxlength) global description dict_prefix = BASE_prefix if need_char_dic: dict_prefix = CHAR_prefix storepath = os.path.join( get_result_store_path(), "%s_%s_%s_%s_%s_%s%s" % (dict_prefix, minlength, maxlength, description, get_buildtime(), encodeflag, filextension)) with open(storepath, "a") as f: for i in range_compatible(minlength, maxlength + 1): for item in itertools.product(objflag, repeat=i): f.write( operator.get(encodeflag)(head + "".join(item) + tail) + CRLF) finishprinter(finishcounter(storepath), storepath)
def parse_args(): parser = argparse.ArgumentParser( prog='pydictor', formatter_class=argparse.RawTextHelpFormatter, description=cool.green( '*[+] A Useful Hacker Dictionary Builder. [+]*') + CRLF + cool.green(' [+] Build by LandGrey email:[email protected]') + CRLF, usage=cool.blue(''' pydictor.py [options] -base type -char customchar -chunk <chunk1> <chunk2> ... -plug <pid6, pid8, extend> -o output_path -tool [tool_name] <arguments ...> --sex <m, f, all> --len minlen maxlen --head prefix_string --tail suffix_string --encode <b64,md5,md516,sha1,url,sha256,sha512> --conf configuration_file_path --sedb''')) parser.add_argument('-base', dest='type', choices=['d', 'L', 'c', 'dL', 'dc', 'Lc', 'dLc'], metavar='Type', default='', help=cool.yellow(''' Choose from (d, L, c, dL, dc, Lc, dLc) d digital [0 - 9] L lowercase letters [a - z] c capital letters [A - Z] dL Mix d and L [0-9 a-z] dc Mix d and c [0-9 A-Z] Lc Mix L and c [a-z A-Z] dLc Mix d, L and c [0-9 a-z A-Z]''')) parser.add_argument( '-char', dest='customchar', metavar='Character', default='', help=cool.yellow('Use [Custom Character] build the dictionary')) parser.add_argument( '-chunk', dest='chunk', metavar='Chunk', nargs='+', type=str, default='', help=cool.yellow( 'Use the string [Chunk Multiplication] build the dictionary')) parser.add_argument('-plug', dest='plugins', metavar='Plug', nargs='+', type=str, default='', help=cool.yellow(''' Choose from (pid6, pid8, extend) pid6 [Id Card post 6 number] default sex:%s pid8 [Id Card post 8 number] default sex:%s extend [file_path]''' % (default_sex, default_sex))) parser.add_argument('-o', dest='output', metavar='Output', type=str, default='', help=cool.yellow(''' Set the directory output path default: %s''' % get_result_store_path())) parser.add_argument('-tool', dest='tool', metavar='Tool', nargs='+', type=str, default='', help=cool.yellow(''' Choose from ({0}, {1}) {0:4} [file_path_or_dir] {1:4} [file_path]'''.format(tool_fun_str[0], tool_fun_str[1]))) parser.add_argument('--sex', dest='sex', choices=['m', 'f', 'all'], metavar='Sex', type=str, default=default_sex, help=cool.yellow(''' Choose from (m, f, all) m: Male f: Female all: Male and Female Provided for [pid6 | pid8]''')) parser.add_argument('--len', dest='len', metavar=('Minlen', 'Maxlen'), nargs=2, type=int, default=(minimum_length, maximum_length), help=cool.yellow(''' [Minimun_Length] [Maximun_Length] Default: min=%s max=%s''' % (minimum_length, maximum_length))) parser.add_argument('--head', dest='head', metavar='Prefix', type=str, default='', help=cool.yellow('Add string head for the items')) parser.add_argument('--tail', dest='tail', metavar='Suffix', type=str, default='', help=cool.yellow('Add string tail for the items')) parser.add_argument( '--encode', dest='encode', metavar='Encode', default='', choices=['b64', 'md5', 'md516', 'sha1', 'url', 'sha256', 'sha512'], help=cool.yellow(''' b64 base64 encode md5 md5 encryption (32) md516 md5 encryption (16) sha1 sha1 encryption url urlencode sha256 sha256 encrytion sha512 sha512 encrytion''')) parser.add_argument('--conf', dest='conf', nargs='?', metavar='Conf_file_path', default='default', const='const', help=cool.yellow(''' Use the configuration file build the dictionary Default: %s''' % get_conf_path())) parser.add_argument( '--sedb', dest='sedb', default='', action="store_true", help=cool.yellow('Enter the Social Engineering Dictionary Builder')) if len(sys.argv) == 1: sys.argv.append('-h') args = parser.parse_args() check_args(args) return args
def build_conf_dic(): confdicts = confparser(confmatcher(get_conf_path())) finalen = len(confdicts[head]) alllist = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] storepath = os.path.join( get_result_store_path(), "%s_%s%s" % (CONF_prefix, get_buildtime(), filextension)) for x in range(0, finalen): lengthchecker(confdicts[minlen][x], confdicts[maxlen][x]) alllist[x] = get_conf_dic(int(confdicts[minlen][x]), int(confdicts[maxlen][x]), confdicts[char][x], confdicts[encode][x], confdicts[head][x], confdicts[tail][x]) if finalen == 1: countchecker(-1, len(alllist[0])) with open(storepath, "a") as f: for item in itertools.product(alllist[0]): f.write("".join(item) + CRLF) elif finalen == 2: countchecker(-1, len(alllist[0]), len(alllist[1])) with open(storepath, "a") as f: for item in itertools.product(alllist[0], alllist[1]): f.write("".join(item) + CRLF) elif finalen == 3: countchecker(-1, len(alllist[0]), len(alllist[1]), len(alllist[2])) with open(storepath, "a") as f: for item in itertools.product(alllist[0], alllist[1], alllist[2]): f.write("".join(item) + CRLF) elif finalen == 4: countchecker(-1, len(alllist[0]), len(alllist[1]), len(alllist[2]), len(alllist[3])) with open(storepath, "a") as f: for item in itertools.product(alllist[0], alllist[1], alllist[2], alllist[3]): f.write("".join(item) + CRLF) elif finalen == 5: countchecker(-1, len(alllist[0]), len(alllist[1]), len(alllist[2]), len(alllist[3]), len(alllist[4])) with open(storepath, "a") as f: for item in itertools.product(alllist[0], alllist[1], alllist[2], alllist[3], alllist[4]): f.write("".join(item) + CRLF) elif finalen == 6: countchecker(-1, len(alllist[0]), len(alllist[1]), len(alllist[2]), len(alllist[3]), len(alllist[4]), len(alllist[5])) with open(storepath, "a") as f: for item in itertools.product(alllist[0], alllist[1], alllist[2], alllist[3], alllist[4], alllist[5]): f.write("".join(item) + CRLF) elif finalen == 7: countchecker(-1, len(alllist[0]), len(alllist[1]), len(alllist[2]), len(alllist[3]), len(alllist[4]), len(alllist[5]), len(alllist[6])) with open(storepath, "a") as f: for item in itertools.product(alllist[0], alllist[1], alllist[2], alllist[3], alllist[4], alllist[5], alllist[6]): f.write("".join(item) + CRLF) elif finalen == 8: countchecker(-1, len(alllist[0]), len(alllist[1]), len(alllist[2]), len(alllist[3]), len(alllist[4]), len(alllist[5]), len(alllist[6]), len(alllist[7])) with open(storepath, "a") as f: for item in itertools.product(alllist[0], alllist[1], alllist[2], alllist[3], alllist[4], alllist[5], alllist[6], alllist[7]): f.write("".join(item) + CRLF) elif finalen == 9: countchecker(-1, len(alllist[0]), len(alllist[1]), len(alllist[2]), len(alllist[3]), len(alllist[4]), len(alllist[5]), len(alllist[6]), len(alllist[7]), len(alllist[8])) with open(storepath, "a") as f: for item in itertools.product(alllist[0], alllist[1], alllist[2], alllist[3], alllist[4], alllist[5], alllist[6], alllist[7], alllist[8]): f.write("".join(item) + CRLF) elif finalen == 10: countchecker(-1, len(alllist[0]), len(alllist[1]), len(alllist[2]), len(alllist[3]), len(alllist[4]), len(alllist[5]), len(alllist[6]), len(alllist[7]), len(alllist[8]), len(alllist[9])) with open(storepath, "a") as f: for item in itertools.product(alllist[0], alllist[1], alllist[2], alllist[3], alllist[4], alllist[5], alllist[6], alllist[7], alllist[8], alllist[9]): f.write("".join(item) + CRLF) finishprinter(finishcounter(storepath), storepath)
from tools.uniqifer import uniqifer_enter from tools.counter import counter_enter from tools.combiner import combiner_enter from tools.uniqbiner import uniqbiner_enter from plugins.idcard import get_idcard_post from plugins.extend import get_extend_dic from plugins.passcraper import get_passcratch_dic from lib.text import pydictor_ascii_text as pydictor_art_text from lib.data import set_result_store_path, get_result_store_path, set_conf_path, get_conf_path, tool_range, plug_range,\ CRLF, scrabble_site_path, startime if __name__ == '__main__': print("{}".format(cool.green(pydictor_art_text))) args = parse_args() try: if not os.path.exists(get_result_store_path()): os.mkdir(get_result_store_path()) except IOError: exit(CRLF + cool.red("[-] Cannot create %s " % get_result_store_path())) if args.output: if os.path.exists(args.output): tmppath = os.path.abspath(args.output) else: try: os.mkdir(args.output) tmppath = os.path.abspath(args.output) except IOError: tmppath = "" print(CRLF + cool.red("[-] Cannot create %s, default %s" % (args.output, get_result_store_path())))