Skip to content

Instantly share code, notes, and snippets.

@mgeeky
Created March 22, 2016 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgeeky/7a9930f8f036c889e3f5 to your computer and use it in GitHub Desktop.
Save mgeeky/7a9930f8f036c889e3f5 to your computer and use it in GitHub Desktop.
Lists imported modules from all of the PE EXE/DLL files along the specified path. Helpful when looking for DLL Search-Order Hijacking weak points.
import sys
import os
import pefile
rootPath = sys.argv[1]
modules = set()
def scanFile(f):
try:
pe = pefile.PE(f)
for entry in pe.DIRECTORY_ENTRY_IMPORT:
modules.add(entry.dll)
except:
pass
for root, dirs, files in os.walk(rootPath):
path = root.split('/')
for file in files:
scanFile(root + '\\' + file)
for mod in modules:
print mod
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment