Python 实现专属字典生成器

编写一个密码生成工具,这里我们使用弱密码与个性化数组组合形成一个定制字典,例如收集用户的姓名,昵称,QQ号手机号等资源,然后通过Python对搜集到的数据与弱密码进行结合,从而定制出属于某个人的专属密码集,从而提高破解的成功率,一般而言使用Python可以很容易的生成专属字典。

这段弱密码生成代码如下所示:

import os,sys
from random import randint,sample
import argparse

def Open_File(file):
    with open(file,"r",encoding="utf-8") as fp:
        for item in fp.readlines():
            data = "".join(item.split("\n"))
            yield data

# 调用: OrderDict("template.log","pass.log",world,flag)
def OrderDict(template,outfile,world,flag):
    Count = 0
    fp = open(outfile,"a+",encoding="utf-8")
    if len(flag) <= 0:
        for item in Open_File(template):
            for w in world:
                fp.write(w + item + "\n")
                fp.write(item + w + "\n")
                Count = Count + 2
    else:
        for item in Open_File(template):
            for w in world:
                for f in flag:
                    fp.write(item + w + f + "\n")
                    fp.write(item + f + w + "\n")
                    fp.write(w + item + f + "\n")
                    fp.write(w + f + item + "\n")
                    fp.write(f + item + w + "\n")
                    fp.write(f + w + item + "\n")
                    Count = Count + 6
    fp.close()
    print("[+] 总共生成弱密码条数: {}".format(Count))

# 调用: RandomDict("pass.log",world,flag)
def RandomDict(outfile,world,flag):
    Count = 0
    fp = open(outfile,"a+",encoding="utf-8")
    if len(flag) <= 0:
        for item in range(1,1000):
            random = sample(world, 2)
            fp.write(random[0]+random[1] + "\n")
            Count = Count + 1
    else:
        for item in range(1,1000):
            random = sample(world, 2)
            for f in flag:
                fp.write(random[0] + random[1] + f + "\n")
                fp.write(f + random[0] + random[1] + "\n")
                fp.write(random[0] + f + random[1] + "\n")
                Count = Count + 3
    fp.close()
    print("[+] 总共生成随机密码条数: {}".format(Count))

def Banner():
    print("  _          ____  _                _    ")
    print(" | |   _   _/ ___|| |__   __ _ _ __| | __")
    print(" | |  | | | \___ \| '_ \ / _` | '__| |/ /")
    print(" | |__| |_| |___) | | | | (_| | |  |   < ")
    print(" |_____\__, |____/|_| |_|\__,_|_|  |_|\_\\")
    print("       |___/                             \n")
    print("E-Mail: me@lyshark.com")

if __name__== "__main__":
    #关键字: world = ["wang","lyshark","1997","qew","1104"]
    #标志: flag = ["@","!","#"]
    Banner()
    parser = argparse.ArgumentParser()
    parser.add_argument("-t","--template",dest="template",help="指定一个基础模板字典.")
    parser.add_argument("-k","--keyword",dest="keyword",help="指定一些关键字,用逗号分隔.")
    parser.add_argument("-s","--symbol",dest="symbol",help="指定一些特殊符号,用逗号分隔.")
    parser.add_argument("-o","--outfile",dest="outfile",help="指定输出字典的名字.")
    args = parser.parse_args()

    if args.template and args.keyword and args.outfile:
        world = [item for item in args.keyword.split(",")]
        if args.symbol == None:
        # 使用方式: main.py -t template.log -k lyshark,wang,19981211 -o pass.log
            flag = []
            OrderDict(args.template,args.outfile,world,flag)
        else:
        # 使用方式: main.py -t template.log -k lyshark,wang,19981211 -s !,@,#,$ -o pass.log
            flag = [item for item in args.symbol.split(",")]
            OrderDict(args.template,args.outfile,world,flag)
    else:
        parser.print_help()

使用方法: -t指定模板字典,-k指定关键字序列,以逗号分隔开-s指定一些特殊符号可以不写-o指定输出后的文件名。

  • 不指定特殊字符: main.py -t temp.log -k lyshark,wang,abc,zhangsan -o pass.log
  • 指定特殊字符: main.py -t temp.log -k lyshark,wang,19981211 -s !,@,#,$ -o pass.log
posted @ 2020-03-17 15:52  lyshark  阅读(1443)  评论(0编辑  收藏  举报

loading... | loading...
博客园 - 开发者的网上家园