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

yipeiwu_com5年前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])

相关文章

详解Django中的权限和组以及消息

在认证框架中还有其他的一些功能。 我们会在接下来的几个部分中进一步地了解它们。 权限 权限可以很方便地标识用户和用户组可以执行的操作。 它们被Django的admin管理站点所使用,你也...

详解Python中find()方法的使用

 find()方法判断字符串str,如果起始索引beg和结束end索引能找到在字符串或字符串的一个子串中。 语法 以下是find()方法的语法: str.find(str,...

python异步存储数据详解

在Python中,数据存储方式分为同步存储和异步存储。同步写入速度比较慢,而爬虫速度比较快,有可能导致数据保存不完整,一部分数据没有入库。而异步可以将爬虫和写入数据库操作分开执行,互不影...

获取Django项目的全部url方法详解

在为一个项目添加权限时,遇到一个问题,就是为项目所有的url设置权限,但是一个一个手动输入太麻烦了,所以考虑用代码获取到一个项目所有的url 首先,考虑到项目最外层的urlpartte...

利用Python实现kNN算法的代码

邻近算法(k-NearestNeighbor) 是机器学习中的一种分类(classification)算法,也是机器学习中最简单的算法之一了。虽然很简单,但在解决特定问题时却能发挥很好的...