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 .exe
s, for reference)
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.
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.