python实现:压缩文件爆破,社工字典生成小工具

       其实我学python的本心是用来开发工具的,有一个python实现的whois域名查询工具,过于简单就不写博客了,其实就是一个简单爬虫就能实现的功能。

最近闲来无事发现工作室的招新试卷压缩包是经过加密的,以前爆破都是直接下载工具下载字典爆破的。终于可以自己写一个工具了哈哈。于是就开始写压缩文件爆破工具和社工字典生成工具。下面简单介绍下原理:

压缩文件爆破工具:

其实原理很简单,python导入一个zipfile模块可以调用extractall()函数可以打开压缩文件,传入密码作为参数,然后再写一个逻辑读取字典文件,把从字典文件读到的密码一个一个的试图打开zip文件,失败就直接pass,成功就输出相应密码。

上代码:

import zipfile
import threading
def extractIt(ZIPfile,passwd):
  try:
    ZIPfile.extractall(pwd=passwd.encode())
    print('Successful , this file\'s password is ',passwd)
    return passwd
  except:
    pass
if __name__ == '__main__':
  file = input('请输入文件路径:')
  dic = input('请输入字典路径:')
  zip_file = zipfile.ZipFile(file)
  try:
    file_context = open(dic)
    for i in file_context.readlines():
      passw = i.strip('\n')
      extractIt(zip_file,passw)
  except:
    print('字典打开失败!')

注意:我的python环境是3.5,注意代码第五行的encode(),传入函数的应该是byte类型的数据而不是str之前报错找了好久

社工字典生成工具:

主要是将你输入的所有关键词进行排列组合,增大破解几率,而且极大的缩小了运行时间。核心算法就是一个数组全排列

。全排列完毕后重组为字符串放入TXT文件中。

代码:

num = input('请输入关键词个数:')
list = []
for i in range(1,int(num)+1):
  list.append(input('关键词{}:'.format(i)))
def permutation(result, str, list):
  if len(list) == 1:
    result.append(str + list[0])
  else:
    uniq_dict={}
    for temp_str in list:
      temp_list = list[:]
      temp_list.remove(temp_str)
      if str == '':
        permutation(result, temp_str, temp_list)
      else:
        permutation(result, str + temp_str, temp_list)
def listToStr(list):
  str = ''
  for i in list:
    str = str+i
  return str
def saveDic(str=''):
  loc = input('请输入字典存放路径:')
  with open(loc,'a') as f:
    f.write(str)
  return
def listToTxt(list):
  txt = ''
  for i in list:
    txt = txt + i + '\n'
  return txt
if __name__ == '__main__':
  result = []
  permutation(result,'',list)
  ok = listToTxt(result)
  saveDic(ok)

好下面来试着破解一下工作室的招新试卷压缩包:

根据工作室往年的密码有如下几个关键词:

时间:2018

名称:qmx

管理员:admin

招新后台名词:join

得到上面的信息后首先造一个字典:

[root@iZ9qedw3bo1smhZ pythonCode]# python dictionary.py

导入一下压缩包到服务器:

开始运行暴力破解程序:

可以看到已经解出了zip文件的密码:join2018qmx

如果造的社工字典解不出来也可以从网上下载字典,只不过破解时间可能会长一些。

猜你喜欢

转载自blog.csdn.net/dfgdgfbb/article/details/82831851
今日推荐