【问题标题】:RarFile Python ModuleRarFile Python 模块
【发布时间】:2016-12-08 06:27:27
【问题描述】:

我正在尝试为 rar 文件制作一个简单的暴力破解器。我的代码是...

import rarfile

file = input("Password List Directory: ")
rarFile = input("Rar File: ")

passwordList = open(file,"r")


for i in passwordList:

    try :
        rarfile.read(rarFile, psw=i)
        print('[+] Password Found: '+i)

    except Exception as e:
        print('[-] '+i+' is not a password ')

passwordList.close()

我认为这与我对模块的使用有关,因为当我输入一个我 10000% 确定包含 rarFile 的密码的密码列表时,它会打印异常。

【问题讨论】:

    标签: python python-3.x zipfile rar


    【解决方案1】:

    这里真正的问题是您要捕获所有异常,而不仅仅是您想要的异常。所以使用except rarfile.PasswordRequired: 那会告诉你错误不是密码丢失。相反,rarfile 模块中没有函数read

    看看一些Documentation。 Rar 加密是每个文件,而不是每个存档。

    您需要从 RarFile 类创建一个对象,并在存档中的每个文件上尝试密码。 (或者如果你知道它是加密的,那就是第一个)

    import rarfile
    
    file = input("Password List Directory: ")
    rarFilename = input("Rar File: ")
    
    rf = rarfile.RarFile(rarFilename)
    passwordList = open(file,"r")
    first_file =  next(rf.infolist)
    
    for i in passwordList:
        password = i.rstrip()        
        try:
            rf.open(first_file, psw=password)
            print(password, "found")
        except rarfile.PasswordRequired:
            print(password,"is not a password")
    

    当您打开文件并从文件中读取行时,会保留“换行”字符 在行尾。这需要从每一行中去掉。

    for i in passwordList:
        password = i.rstrip()
        try :
            rarfile.read(rarFile, psw=password)
            print('[+] Password Found: '+password)  
    

    【讨论】:

    • 我相应地更改了代码,但仍然收到与以前相同的输出。
    • 包罗万象的异常处理程序隐藏了真正的问题。没有rarfile.read函数。
    • 更改后,我收到关于对象不可下标的错误
    • 可能是信息列表[0]。尝试使用 next()。
    猜你喜欢
    • 2020-03-04
    • 1970-01-01
    • 1970-01-01
    • 2016-10-10
    • 2021-07-24
    • 2013-09-10
    • 2017-11-24
    • 1970-01-01
    • 2017-06-19
    相关资源
    最近更新 更多