压缩包密码破解示例分享(类似典破解)

yipeiwu_com6年前Python基础

昨天翻硬盘,找到一个好东西,可惜自己加了密码自己不记得了。试了几个常用的没试出来,于是写了这么个小脚本来替我尝试。。呵呵,还真给解出来了。
python脚本内容如下,跑跑自己加密的压缩包还不错

复制代码 代码如下:

# -*- coding: utf-8 -*-

import sys,os

def IsElementUniq(list):
    """
          判断list中的元素是否为唯一的
    """
    for word in list:
        if list.count(word)>1:
            return False

    return True

def GenPswList():
    """
          要求用户输入词,并根据单词组合密码,只尝试四个单词来组合,并限制密码长度为20。写的比较挫
    """
    psw=raw_input('input a word>')
    wordlist = []
    while psw:
        wordlist.append(psw)
        psw=raw_input('input a word>')
    print wordlist

    global g_pswlist
    g_pswlist = []
    for word in wordlist:
        g_pswlist.append(word)

    for word1 in wordlist:
        for word2 in wordlist:
            locallist = [word1, word2]
            if IsElementUniq(locallist):
                tmp = word1 + word2
                if len(tmp) < 20:
                    g_pswlist.append(tmp)

    for word1 in wordlist:
        for word2 in wordlist:
            for word3 in wordlist:
                locallist = [word1, word2, word3]
                if IsElementUniq(locallist):
                    tmp = word1 + word2 + word3
                    if len(tmp) < 20:
                        g_pswlist.append(tmp)

    for word1 in wordlist:
        for word2 in wordlist:
            for word3 in wordlist:
                for word4 in wordlist:
                    locallist = [word1, word2, word3, word4]
                    if IsElementUniq(locallist):
                        tmp = word1 + word2 + word3 + word4
                        if len(tmp) < 20:
                            g_pswlist.append(tmp)

    print 'gen psw is:', g_pswlist

def TestUnZipPack(filename):
    """
          尝试用密码来解压压缩包
    """

    command = ""
    for psw in g_pswlist:
        command = "7z e -p%s -y %s" %(psw,filename)
        print command
        ret = os.system(command)
        if ret == 0:
            print 'right psw is ', psw
            break

def main(filename):
    GenPswList()
    TestUnZipPack(filename)

if __name__ == '__main__':
    if len(sys.argv) != 2:
        print 'argv error'
        print 'example:test_7z_psw.py 1.7z'
        sys.exit(1)

    main(sys.argv[1])

相关文章

python下setuptools的安装详解及No module named setuptools的解决方法

前言 python下的setuptools带有一个easy_install的工具,在安装python的每三方模块、工具时很有用,也很方便。 安装setuptools前先安装pip,请参...

Python+Socket实现基于UDP协议的局域网广播功能示例

Python+Socket实现基于UDP协议的局域网广播功能示例

本文实例讲述了Python+Socket实现基于UDP协议的局域网广播功能。分享给大家供大家参考,具体如下: 服务器端: # udp_gb_server.py '''服务端(UDP协...

浅谈python3.6的tkinter运行问题

python3.6在运行tkinter时要选择 run as Python unit-test, 否则报错 ModuleNotFoundError: No module named 't...

图文讲解选择排序算法的原理及在Python中的实现

图文讲解选择排序算法的原理及在Python中的实现

基本思想:从未排序的序列中找到一个最小的元素,放到第一位,再从剩余未排序的序列中找到最小的元素,放到第二位,依此类推,直到所有元素都已排序完毕。假设序列元素总共n+1个,则我们需要找n轮...

小米5s微信跳一跳小程序python源码

本文实例为大家分享了微信跳一跳小程序python源码,供大家参考,具体内容如下 微信跳一跳小程序小米5s源码python,搭建环境后亲测可用。 # coding: utf-8 imp...