Skip to content

Instantly share code, notes, and snippets.

@taco-shellcode
Created July 31, 2021 23:33
Show Gist options
  • Save taco-shellcode/9653d7132c04a7ec9167d48c6e6293af to your computer and use it in GitHub Desktop.
Save taco-shellcode/9653d7132c04a7ec9167d48c6e6293af to your computer and use it in GitHub Desktop.
#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