Created
August 5, 2013 06:03
-
-
Save cloudjunky/6153797 to your computer and use it in GitHub Desktop.
Get the txt pkcs7 from the der
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import subprocess | |
from OpenSSL.crypto import PKCS7Type, load_pkcs7_data | |
directory = "/Users/michael/Downloads/Torrents/VirusShare_APT1_281/" | |
size_array = [] | |
write_file = True | |
get_txt = True | |
for files in os.listdir(directory): | |
try: | |
pe = pefile.PE(directory+files) | |
address = pe.OPTIONAL_HEADER.DATA_DIRECTORY[pefile.DIRECTORY_ENTRY['IMAGE_DIRECTORY_ENTRY_SECURITY']].VirtualAddress | |
size = pe.OPTIONAL_HEADER.DATA_DIRECTORY[pefile.DIRECTORY_ENTRY['IMAGE_DIRECTORY_ENTRY_SECURITY']].Size | |
if address!=0: | |
#print "VA:%s, Size %s" % (address,size) | |
signature = pe.write()[address+8:] | |
if write_file: | |
oname = directory+files+".der" | |
tname = directory+files+".txt" | |
outfile = open(oname,'wb') | |
outfile.write(signature) | |
outfile.close() | |
if get_txt: | |
cmd = "openssl pkcs7 -inform DER -print_certs -text -in %s > %s" % (oname,tname) | |
os.system(cmd) | |
'''If you want to return STDOUT to a variable then use subprocess rather than os.system | |
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) | |
out, error = p.communicate() | |
txt_signature = out | |
print txt_signature''' | |
#p7 = load_pkcs7_data(FILETYPE_ASN1,signature) | |
#print type(p7) | |
except pefile.PEFormatError: | |
print "Something wrong with the file" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment