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

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])

相关文章

Python处理时间日期坐标轴过程详解

Python处理时间日期坐标轴过程详解

1. 前言 当日期数据作为图表的坐标轴时通常需要特殊处理,应为日期字符串比较长,容易产生重叠现象 2. 设定主/次刻度 2.1 引用库 from matplotlib.date...

python中pip的安装与使用教程

python中pip的安装与使用教程

在安装pip前,请确认win系统中已经安装好了python,和easy_install工具,如果系统安装成功,easy_install在目录python的安装盘(如C盘):\Python...

详谈Python 窗体(tkinter)表格数据(Treeview)

如下所示: import tkinter from tkinter import ttk #导入内部包 win=tkinter.Tk() tree=ttk.Treeview(wi...

Python使用正则表达式分割字符串的实现方法

如下: re.split(pattern, string, [maxsplit], [flags]) pattern:表示模式字符串,由要匹配的正则表达式转换而来。 string...

Python(Django)项目与Apache的管理交互的方法

Python(Django)项目与Apache的管理交互的方法

准备:Django的环境(Python)、Apache、Wsgi(必须文件) 首先需要电脑有Python基础下并且安装好Django的环境,下载Apache文件和Wsgi文件。 Apac...