python 下zip压缩包爆破

虽然对于传统zip压缩包加密已经有了比较完备的工具AZPR,但还是想写个脚本,可能这样更真实一点,下课回来写的比较仓促,代码也比较烂,凑合着看,有什么bug记得跟我说,在部分参考python绝技的情况下完成的。

注:

zip压缩包放在与脚本同一目录下

目前只有生成字典爆破。

如果自己有字典的话可以把字典命名为pass.txt放在脚本同目录下

如果有时间会加入掩码和明文爆破等

语法是python zipattack.py -f<zipname> -d<dictionary>


#!/usr/bin/env python
# -*- coding: utf-8 -*-
import time
import string
import zipfile
import optparse
import itertools as its
from threading import Thread



def welcome():
    print ('welcome to zipfile attack py')
    time.sleep(1)


def attack (zFile, password):
    try:
        zFile.extractall(pwd=password)
        print '[+] found password'+password+'\n'
    except:
        pass

def dicProduce():
    choose=raw_input('input y/n to produce a new dictionary or not')
    try:
        if choose=='y':
            print('please make sure that high>low and both >0')
            low=int(raw_input('please input the digit(low)'))
            high=int(raw_input('please input the digit(high)'))
            high=high+1
            words1=string.lowercase
            words2=string.uppercase
            words3=string.letters
            words4=string.printable
            with open('pass.txt','w')as dic:
                print ('dictionary mode\n')
                print('1 pure digital\n')
                print('2 pure lowercase letters\n')
                print('3 pure uppercase letters\n')
                print('4 pure letters\n')
                print('5 printable\n')
                print('6 custom\n')

                choose1=raw_input('please choose a dictionary mode')
                if choose1=='1':
                    for temp in range(high):
                        d=-1
                        if temp>=low:
                            for i in range(pow(10,temp)):
                                d=int(d)
                                d=d+1
                                d=str(d)
                                s=d.zfill(temp)
                                dic.write(s+'\n')
                       
                elif choose1=='2':
                    for temp in range(high):
                        if(temp>=low):
                            prl = its.product(words1, repeat=temp)
                            for i in prl:
                                dic.write("".join(i))
                                dic.write("".join("\n"))
                elif choose1=='3':
                    for temp in range(high):
                        if(temp>=low):
                            pul = its.product(words2, repeat=temp)
                            for i in pul:
                                dic.write("".join(i))
                                dic.write("".join("\n"))
                elif choose1=='4':
                    for temp in range(high):
                        if (temp >= low):
                            prl = its.product(words3, repeat=temp)
                            for i in pl:
                                dic.write("".join(i))
                                dic.write("".join("\n"))
                elif choose1 == '5':
                    for temp in range(high):
                        if(temp>=low):
                            pa = its.product(words4, repeat=temp)
                            for i in pa:
                                dic.write("".join(i))
                                dic.write("".join("\n"))
                elif choose1 == '6':
                    words5=raw_input("please input your character\n")
                    for temp in range(high):
                        if(temp>=low):
                            ct = its.product(words5, repeat=temp)
                            for i in ct:
                                dic.write("".join(i))
                                dic.write("".join("\n"))
            dic.close()
        else:
            pass
    except:
        pass



def main():
    welcome()

    parser=optparse.OptionParser("usage%prog "+\
    "-f <zipfile> -d <dictionary>")
    parser.add_option('-f', dest='zname', type='string', \
    help='specify zip file')
    parser.add_option('-d', dest='dname', type='string', \
    help='specify dictionary file')
    (options, args)=parser.parse_args()

    dicProduce()

    if(options.zname==None) | (options.dname==None):
        print parser.usage
        exit(0)
    else:
        zname = options.zname
        dname = options.dname
    zFile = zipfile.ZipFile(zname)
    print zname
    print dname
    passfile = open(dname)
    for line in passfile.readlines():
        password = line.strip('\n')
        # attack(zFile, password)
        t = Thread(target=attack, args=(zFile, password))
        t.start()


if __name__ == '__main__':
    main()

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值