利用unrarlib库实现对加密rar文件的密码爆力破解

import ctypes
import io
import os
import sys
import itertools

from unrar import constants
from unrar import unrarlib

nums = [str(i) for i in range(10)]
chrs = [chr(i) for i in range(65, 91)]
charsaz = [chr(i) for i in range(97,122)]

if sys.version < '3':
    def b(x):
        return x
else:
    def b(x):
        if x is not None:
            # encode using DOS OEM standard
            return x.encode('cp437')     


nums = [str(i) for i in range(10)]
chrs = [chr(i) for i in range(65, 91)]
charsaz = [chr(i) for i in range(97,122)]

for i in range(2,16,1):
    pwddict = itertools.permutations(nums + chrs + charsaz, i)
    
    for testword in pwddict:
        print(testword)
        inword=''.join(testword)
        
        try:
            # 创建一个RAROpenArchiveData数据
            archive_data = unrarlib.RAROpenArchiveDataEx('f:\\py\\hash.rar', mode=constants.RAR_OM_EXTRACT)
        except unrarlib.UnrarException:
            print("RAROpenArchiveDataEx Error!")
            
        try:
            handle = unrarlib.RAROpenArchiveEx(ctypes.byref(archive_data))
        except unrarlib.UnrarException:
            print("RAROpenArchiveEx Error!")
            
        try:    
            unrarlib.RARSetPassword(handle, b(inword))
        except unrarlib.UnrarException:
            print("RAROpenArchiveEx Error!")

        try:    
            header_data = unrarlib.RARHeaderDataEx()
        except unrarlib.UnrarException:
            print("RARHeaderDataEx Error!")
        
        try:
            res = unrarlib.RARReadHeaderEx(handle, ctypes.byref(header_data))
            #print('FileCRC:%d' % header_data.FileCRC)
        except unrarlib.UnrarException:
            print("RARReadHeaderEx Error!")

        try:    
            unrarlib.RARProcessFileW(handle, constants.RAR_EXTRACT, 'f:\\py', 'hash.exe')
            print('sucess:%s' % testword)
        except unrarlib.UnrarException:
            #print("RARProcessFileW error!")
            pass
            
        try:
            unrarlib.RARCloseArchive(handle)
        except unrarlib.UnrarException:
            print("RARCloseArchive error!")
            
        

代码中实现了从2位组合到16位组合的穷举破解过程

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值