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
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值