如何使用已知的密码在Python中解锁PGP自解密存档.exe文件(PGP SDAs)?

huangapple go评论77阅读模式
英文:

How to unlock PGP Self Decrypting Archive .exe files (PGP SDAs) in python with a known passphrase?

问题

I can provide a Chinese translation of your text, excluding the code parts:

我有一组PGP自解密存档.exe文件(https://knowledge.broadcom.com/external/article/153684/creating-a-self-decrypting-archive-with.html)(在Windows系统上),并且知道解锁它们的密码。如何在Python中遍历所有这些PGP自解密存档并使用密码解锁它们?(我相信这只是知道要使用的正确库和参数的简单问题,但我以前没有使用过这些类型的文件)。

(示例图像,用于参考)

如何使用已知的密码在Python中解锁PGP自解密存档.exe文件(PGP SDAs)?

尝试使用gnupg库(https://gnupg.readthedocs.io/en/latest/#decryption)进行一些操作,例如...

import gnupg

PASSWD = mypassword
extracted_files = [PATHS_OF_SDA_FILES]
for extracted_file_path in extracted_files:
    decr_file = gpg.decrypt_file(extracted_file_path, passphrase=PASSWD)
    print(decr_file.ok)
    print(decr_file.status)

...或者像这样...

import gnupg

PASSWD = mypassword
extracted_files = [PATHS_OF_SDA_FILES]
for extracted_file_path in extracted_files:
    with open(extracted_file_path, 'rb') as file_obj:
        decr_file = gpg.decrypt_file(file_obj, passphrase=PASSWD)
        print(decr_file.ok)
        print(decr_file.status)

...显示状态错误
> False
>
> 未提供任何数据

我已安装了gpg4win-4.1.0.exe(https://gnupg.org/download/)以尝试以此方式批量解锁它们,但不太确定如何使用它(并且在运行附带的kleopatra.exe UI时,当尝试导入目标文件夹中的.exe文件时,它无法检测到这些文件。在使用解密选项时,它显示“未找到一个或多个文件中的加密或签名数据”)。我完全不了解情况,因此将不胜感激任何指导。

英文:

I have a set of PGP Self Decrypting Archive .exe files (https://knowledge.broadcom.com/external/article/153684/creating-a-self-decrypting-archive-with.html) (on a Windows system) and have the password that unlocks them all. How can I just iterate through all of these PGP SDAs and use the passphrase to unlock them in python? (I'm sure this is a simple matter of knowing the right libs and args to use, but I've never worked with these kinds of files before).

(Example image of what I see when clicking the .exes, for reference)

如何使用已知的密码在Python中解锁PGP自解密存档.exe文件(PGP SDAs)?

Trying something with the gnupg lib (https://gnupg.readthedocs.io/en/latest/#decryption) like...

import gnupg

PASSWD = mypassword
extracted_files = [PATHS_OF_SDA_FILES]
for extracted_file_path in extracted_files:
    decr_file = gpg.decrypt_file(extracted_file_path, passphrase=PASSWD)
    print(decr_file.ok)
    print(decr_file.status)

...or like...

import gnupg

PASSWD = mypassword
extracted_files = [PATHS_OF_SDA_FILES]
for extracted_file_path in extracted_files:
    with open(extracted_file_path, 'rb') as file_obj:
        decr_file = gpg.decrypt_file(file_obj, passphrase=PASSWD)
        print(decr_file.ok)
        print(decr_file.status)

...shows status error
> False
>
> no data was provided

I've installed gpg4win-4.1.0.exe (https://gnupg.org/download/) to try to bulk unlock them this way, but not really sure how to use it (and when running the kleopatra.exe UI that came with it, it cannot detect the .exe files in the target folder when trying to Import. When using the Decrypt option, it says "Failed to find encrypted or signed data in one or more files"). Totally in the dark here, so any guidance would be appreciated.

答案1

得分: 0

这样做行不通,因为GnuPG无法解析.exe文件。你应该首先使用一些Python库(比如这个:https://pypi.org/project/pereader/)来解析.exe文件并找出OpenPGP消息存储的位置。然后将该消息提取到单独的文件中,并在其上运行GnuPG解密。

英文:

It will not work in this way as GnuPG cannot parse .exe files. You should first use some Python library (like this one: https://pypi.org/project/pereader/ ) to parse .exe file andfind out where OpenPGP message is stored.

Then extract that message to the separate file, and run GnuPG decryption on it.

答案2

得分: 0

以下是您提供的代码的中文翻译:

最终,我在从这里的用户、其他帖子以及其他社区中获得的印象之后,决定使用autohotkey脚本,而不是通过Python来完成这个任务。我认为通过Python来完成会更加繁琐(虽然我接受了这个帖子上的另一个答案,因为它与Python更相关,而我的原始问题也是关于Python的,但下面的`.ahk`脚本是我最终使用的)。我能够使用autohotkey从PGP SDAs中提取文件,将脚本放置在包含SDAs的各个文件夹中,并从那里执行它。我使用的代码是...

```plaintext
SetWorkingDir,%A_ScriptDir% ; 将工作目录设置为脚本所在位置

Loop,Files,%A_ScriptDir%\*.exe ; 用实际的SDA文件路径替换"C:\Path\To\SDA\Files"
{
    currentFile := A_LoopFileFullPath
    
    ; 打开PGP自解密归档可执行文件
    Run,%currentFile%
    Sleep,5000 ; 根据需要调整延迟(以毫秒为单位)
    
    ; 等待"PGP自解密归档 - 输入密码短语"窗口出现
    WinWaitActive,PGP自解密归档 - 输入密码短语
    
    ; 将密码短语发送到窗口
    Send,{Text}YourPassphraseHere ; 用实际的密码短语替换"YourPassphraseHere"
    Send,{Enter}
    
    ; 等待解密过程完成
    WinWaitActive,解码自解密归档...
    WinWaitClose,解码自解密归档...
    
    ; 关闭PGP自解密归档窗口(如果仍然打开)
    ;WinClose,%currentFile%
}

ExitApp ; 退出AutoHotkey脚本

请注意,上述代码是您提供的原始代码的中文翻译部分。

英文:

Ultimately, I ended up using an autohotkey script after getting the impression from users here, in other posts, and in other communities that doing this via python would be more onerous than I had thought (I accepted the other answer on this post since it was more linked to python, which was my original question, but the .ahk script below is what I ultimately used). I was able to extract the files within the PGP SDAs using autohotkey, placing the script in the various folders that contained the SDAs, and executing it from there. The code I used was...

SetWorkingDir, %A_ScriptDir% ; Set the working directory to the script location

Loop, Files, %A_ScriptDir%\*.exe ; Replace "C:\Path\To\SDA\Files" with the actual path to your SDA files
{
    currentFile := A_LoopFileFullPath
   
    ; Open the PGP Self-Decrypting Archive executable
    Run, %currentFile%
    Sleep, 5000 ; Adjust the delay (in milliseconds) as needed
   
    ; Wait for "PGP Self Decrypting Archive - Enter Passphrase" window to appear
    WinWaitActive, PGP Self Decrypting Archive - Enter Passphrase
   
    ; Send the passphrase to the window
    Send, {Text}YourPassphraseHere ; Replace "YourPassphraseHere" with the actual passphrase
    Send, {Enter}
   
    ; Wait for the decryption process to complete
    WinWaitActive, Decoding Self Decrypting Archive...
    WinWaitClose, Decoding Self Decrypting Archive...
   
    ; Close the PGP Self-Decrypting Archive window (if it remains open)
    ;WinClose, %currentFile%
}

ExitApp ; Exit the AutoHotkey script

huangapple
  • 本文由 发表于 2023年5月17日 07:03:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76267598.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定