Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ryanbekabe
Created April 16, 2019 00:21
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 ryanbekabe/0472911830bf5a139bcc7ed1be8f25c4 to your computer and use it in GitHub Desktop.
Save ryanbekabe/0472911830bf5a139bcc7ed1be8f25c4 to your computer and use it in GitHub Desktop.
#Python PE Analyst - DLLs of .exe
#16/04/2019 - bekabeipa@gmail.com
#DB MySQL structure: id;filename;md5;sha256;filesize;dump
import datetime
import time
import pefile
import mmap
import pymysql
pymysql.install_as_MySQLdb()
import MySQLdb
db = MySQLdb.connect(user="root",passwd="",host="localhost",db="test")
cursor = db.cursor()
now = datetime.datetime.now()
global exe_path
exe_path = "cmd4.exe"
fd = open(exe_path, 'rb')
pe_data = mmap.mmap(fd.fileno(), 0, access=mmap.ACCESS_READ)
pe = pefile.PE(exe_path)
#pe = pefile.PE(data=pe_data)
#pe = pefile.PE(data=pe_data, fast_load=True)
#print(pe)
def foo(dll):
cursor.execute("INSERT INTO pedump VALUES (NULL, 'cmd4.exe', 7, %s, 6,%s)", (now,dll))
data=cursor.fetchall()
print("[*] Listing imported DLLs...")
for entry in pe.DIRECTORY_ENTRY_IMPORT:
global dll
dll = '\t' + entry.dll.decode('utf-8')
foo(dll)
print(dll)
db.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment