def pid8_magic(*args):
    """chinese id card last 8 digit"""

    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 pystrs.default_sex == pystrs.sex_range[0]:
        rand = ("1", "3", "5", "7", "9")
        for _ in rand:
            for _p in post18:
                value1718 += _ + _p + " "
    elif pystrs.default_sex == pystrs.sex_range[1]:
        rand = ("0", "2", "4", "6", "8")
        for _ in rand:
            for _p in post18:
                value1718 += _ + _p + " "
    elif pystrs.default_sex == pystrs.sex_range[2]:
        rand = " ".join(str(_) for _ in range_compatible(0, 10))
        for _ in rand.split(" "):
            for _p in post18:
                value1718 += _ + _p + " "

    @magic
    def pid8():
        for v1112 in value1112.split(" "):
            for v1314 in value1314.split(" "):
                for v1516 in value1516.split(" "):
                    for v1718 in value1718.split(" "):
                        if v1718 != "":
                            yield "".join(v1112 + v1314 + v1516 + v1718)
def idcard_magic(posflag):
    storepath = finalsavepath(paths.results_path, pystrs.IDCARD_prefix,
                              mybuildtime(), pyoptions.filextension,
                              paths.results_file_name)

    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 pystrs.default_sex == pystrs.sex_range[0]:
        rand = ("1", "3", "5", "7", "9")
        for _ in rand:
            for _p in post18:
                value1718 += _ + _p + " "
    elif pystrs.default_sex == pystrs.sex_range[1]:
        rand = ("0", "2", "4", "6", "8")
        for _ in rand:
            for _p in post18:
                value1718 += _ + _p + " "
    elif pystrs.default_sex == pystrs.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 == pystrs.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(
                                    pyoptions.operator.get(pyoptions.encode)
                                    (pyoptions.head +
                                     "".join(v1112 + v1314 + v1516 + v1718) +
                                     pyoptions.tail) + pyoptions.CRLF)

        elif posflag == pystrs.plug_range[0]:
            for v1314 in value1314.split(" "):
                for v1516 in value1516.split(" "):
                    for v1718 in value1718.split(" "):
                        if v1718 != "":
                            f.write(
                                pyoptions.operator.get(pyoptions.encode)
                                (pyoptions.head +
                                 "".join(v1314 + v1516 + v1718) +
                                 pyoptions.tail) + pyoptions.CRLF)

    finishprinter(finishcounter(storepath), storepath)
Пример #3
0
def get_char_dic(objflag):
    storepath = finalsavepath(fun_name())

    countchecker(len(objflag), pyoptions.minlen, pyoptions.maxlen)

    # global variable transfer local variable to improved speed
    buffer = []
    buffer_size = pyoptions.buffer_size
    head = pyoptions.head
    tail = pyoptions.tail
    crlf = pyoptions.CRLF
    encode_name = pyoptions.encode
    encode_fun = pyoptions.operator.get(encode_name)

    with open(storepath, "a") as f:
        for i in range_compatible(pyoptions.minlen, pyoptions.maxlen + 1):
            for item in itertools.product(objflag, repeat=i):
                if encode_name == "none":
                    buffer.append(head + "".join(item) + tail)
                else:
                    buffer.append(encode_fun(head + "".join(item) + tail))
                if len(buffer) == buffer_size:
                    f.write(crlf.join(buffer) + crlf)
                    buffer = []
        f.write(crlf.join(buffer))
    finishprinter(storepath)
Пример #4
0
def truncating(filepath):
    # default: 2 times
    for _ in range_compatible(0, 2):
        try:
            with open(filepath, "w"):
                pass
        except:
            pass
Пример #5
0
def rewrite(filepath):
    try:
        filesize = os.path.getsize(filepath)
        with open(filepath, "w+b") as f:
            f.write("".join(
                chr(random.randint(0, 255))
                for _ in range_compatible(0, filesize)))
    except:
        pass
Пример #6
0
def shreder_dir(directory, rewritecounts=pyoptions.dir_rewrite_count):
    filepaths = []
    dirpaths = []
    print(pyoptions.CRLF + "[+] Shredding '%s' ..." % cool.orange(directory))
    try:
        newdirectoryname = os.path.join(
            os.path.dirname(directory), "".join(
                chr(random.randint(97, 122)) for _ in range_compatible(1, 6)))
        os.rename(directory, newdirectoryname)
        directory = newdirectoryname
    except:
        traceback.print_exc()
        exit(pyoptions.CRLF + cool.red(
            "[-] Error: cannot rename root directory name, Please check permissions"
        ))

    subdir_files_path = get_subdir_files_path(directory, only_file_path=False)
    dirpaths.extend(subdir_files_path[0])
    filepaths.extend(subdir_files_path[1])

    for filepath in filepaths:
        try:
            os.chmod(filepath, stat.S_IREAD | stat.S_IWRITE)
        except:
            pass

    for _ in range_compatible(0, rewritecounts):
        print("[+] Rewrite count: %d" % (_ + 1))
        for filepath in filepaths:
            rewrite(filepath)
    for filepath in filepaths:
        truncating(filepath)
    for filepath in filepaths:
        renamefile(filepath)
    renamedir(dirpaths)
    os.chdir(os.path.join(directory, ".."))
    try:
        shutil.rmtree(directory)
    except OSError as ex:
        print(
            cool.fuchsia("[!] Error: Cannot removing directory: '%s' " %
                         directory))
        traceback.print_exc()
    print(cool.orange("[+] Done"))
Пример #7
0
def get_conf_dic(minlength, maxlength, objflag, encodeflag, head, tail):
    diclist = []
    for i in range_compatible(minlength, maxlength+1):
        for item in itertools.product(objflag, repeat=i):
            if encodeflag in pyoptions.operator.keys():
                diclist.append(pyoptions.operator.get(encodeflag)(head + "".join(item) + tail))
            else:
                exit(pyoptions.CRLF + cool.red('[-] wrong encode type'))
    # items count check
    countchecker(-1, len(diclist))
    return diclist
Пример #8
0
def shreder_file(filepath, rewritecounts=pyoptions.file_rewrite_count):
    try:
        os.chmod(filepath, stat.S_IREAD | stat.S_IWRITE)
    except:
        pass
    for _ in range_compatible(0, rewritecounts):
        rewrite(filepath)
    truncating(filepath)
    newname = renamefile(filepath)
    os.remove(newname)
    print("[+] Shredded %s Completely!" % cool.orange(filepath))
def get_base_dic(objflag):
    storepath = finalsavepath(fun_name())

    objflag = getchars(objflag)
    countchecker(len(objflag), pyoptions.minlen, pyoptions.maxlen)
    with open(storepath, "a") as f:
        for i in range_compatible(pyoptions.minlen, pyoptions.maxlen + 1):
            for item in itertools.product(objflag, repeat=i):
                f.write(
                    pyoptions.operator.get(pyoptions.encode)
                    (pyoptions.head + "".join(item) + pyoptions.tail) +
                    pyoptions.CRLF)

    finishprinter(storepath)
Пример #10
0
def get_base_dic(objflag, need_char_dic=False):
    objflag = getchars(objflag, need_char=need_char_dic)
    countchecker(len(objflag), pyoptions.minlen, pyoptions.maxlen)
    dict_prefix = pystrs.BASE_prefix
    if need_char_dic:
        dict_prefix = pystrs.CHAR_prefix
    storepath = finalsavepath(paths.results_path, dict_prefix, mybuildtime(),
                              pyoptions.filextension, paths.results_file_name)
    with open(storepath, "a") as f:
        for i in range_compatible(pyoptions.minlen, pyoptions.maxlen + 1):
            for item in itertools.product(objflag, repeat=i):
                f.write(
                    pyoptions.operator.get(pyoptions.encode)
                    (pyoptions.head + "".join(item) + pyoptions.tail) +
                    pyoptions.CRLF)
    finishprinter(finishcounter(storepath), storepath)