Python 实现专属字典生成器

简介: 编写一个密码生成工具,这里我们使用弱密码与个性化数组组合形成一个定制字典,例如收集用户的姓名,昵称,QQ号手机号等资源,然后通过Python对搜集到的数据与弱密码进行结合,从而定制出属于某个人的专属密码集,从而提高破解的成功率,一般而言使用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
目录
相关文章
|
3天前
|
存储 JSON 索引
一文让你彻底搞懂 Python 字典是怎么实现的
一文让你彻底搞懂 Python 字典是怎么实现的
27 13
|
4天前
|
机器学习/深度学习 设计模式 大数据
30天拿下Python之迭代器和生成器
30天拿下Python之迭代器和生成器
|
5天前
|
存储 数据安全/隐私保护 Python
Python常用数据结构——字典的应用
Python常用数据结构——字典的应用
|
9天前
|
关系型数据库 MySQL 数据库
Python MySQL查询返回字典类型数据的方法
通过使用 `mysql-connector-python`库并选择 `MySQLCursorDict`作为游标类型,您可以轻松地将MySQL查询结果以字典类型返回。这种方式提高了代码的可读性,使得数据操作更加直观和方便。上述步骤和示例代码展示了如何实现这一功能,希望对您的项目开发有所帮助。
28 4
|
7天前
|
Python
Python 字典删除下标前两个
Python 字典删除下标前两个
11 1
|
16天前
|
并行计算 开发者 Python
高效利用Python中的生成器提高内存管理
在处理大量数据或执行复杂计算时,内存管理成为关键问题。Python中的生成器(Generators)提供了一种优雅的解决方案,通过惰性计算和节省内存的方式显著提高程序的效率。本文将探讨生成器的基本概念,实际应用场景,以及如何利用生成器优化内存使用和提高程序性能。
|
4天前
|
存储 数据安全/隐私保护 Python
Python常用数据结构—字典
Python常用数据结构—字典
WK
|
7天前
|
存储 安全 索引
如何在Python中访问字典中的值
在Python中,访问字典(Dictionary)中的值非常简单。字典是一种无序的集合,它存储了键值对(key-value pairs),其中每个键都是唯一的,并映射到一个值上。要访问字典中的值,你需要使用键作为索引。
WK
8 0
WK
|
7天前
|
存储 Python 容器
如何在Python中创建字典
在Python中,创建字典(Dictionary)是非常直观的。字典是一种可变容器模型,且可存储任意类型对象,如字符串、数字、元组等其他容器模型。在字典中,每个元素都是一个键值对(key-value pair),其中键(key)必须是唯一的,而值(value)则可以是任何数据类型。
WK
8 0
|
7天前
|
Python
python推导式-列表,元组,字典,集合推导式
这篇文章介绍了Python中的推导式,包括列表推导式、元组推导式、字典推导式和集合推导式,提供了它们的基本格式和示例代码,并解释了推导式如何简化循环和条件判断的代码编写。
下一篇
无影云桌面