Created
July 31, 2021 23:33
-
-
Save taco-shellcode/9653d7132c04a7ec9167d48c6e6293af to your computer and use it in GitHub Desktop.
This file contains 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
#Privacy Enhanced Mail (PEM) Extraction Script for Ghidra | |
#PEM is a common format for storing cryptographic material as ASCII | |
#@category BeginnerGhidraClass | |
from re import findall | |
counter = 0 | |
filename = currentProgram.getExecutablePath(); | |
for data in currentProgram.getListing().getDefinedData(True): | |
if monitor.isCancelled(): break | |
datatype = data.getDataType().getName().lower() | |
if "string" in datatype or "unicode" in datatype: | |
results = re.findall("(-----BEGIN .+?-----(?s).+?-----END .+?-----)", data.getDefaultValueRepresentation()) | |
if results: | |
for result in results: | |
open("%s.py.%d.pem" % (filename, counter), "w").write(result.replace("\\n", "\n")) | |
counter += 1 | |
print("Exported %d PEM files." % (counter)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment