Python檢測(cè)PE所啟用保護(hù)方式詳解
Python 通過(guò)pywin32模塊調(diào)用WindowsAPI接口,實(shí)現(xiàn)對(duì)特定進(jìn)程加載模塊的枚舉輸出并檢測(cè)該P(yáng)E程序模塊所啟用的保護(hù)方式,此處枚舉輸出的是當(dāng)前正在運(yùn)行進(jìn)程所加載模塊的DLL模塊信息,需要用戶(hù)傳入進(jìn)程PID才可實(shí)現(xiàn)輸出。
- 首先需要安裝兩個(gè)依賴(lài)包:
- pip install pywin32
- pip install pefile
然后再命令行模式下執(zhí)行命令啟動(dòng)枚舉功能。
# By: LyShark
import win32process
import win32api,win32con,win32gui
import os,pefile,argparse
def Banner():
print(" _ ____ _ _ ")
print(" | | _ _/ ___|| |__ __ _ _ __| | __")
print(" | | | | | \___ \| '_ \ / _` | '__| |/ /")
print(" | |__| |_| |___) | | | | (_| | | | < ")
print(" |_____\__, |____/|_| |_|\__,_|_| |_|\_\\")
print(" |___/ \n")
print("E-Mail: me@lyshark.com")
def GetProcessModules(pid):
ModuleList = []
handle = win32api.OpenProcess(win32con.PROCESS_ALL_ACCESS, False, pid )
hModule = win32process.EnumProcessModules(handle)
for item in hModule:
Module_Addr = hex(item)
Module_Path = win32process.GetModuleFileNameEx(handle,item)
Module_Name = os.path.basename(str(Module_Path))
ModuleList.append([Module_Addr,Module_Name,Module_Path])
win32api.CloseHandle(handle)
return ModuleList
def CheckModulesProtect(ClassName):
UNProtoModule = []
if type(ClassName) is str:
handle = win32gui.FindWindow(0,ClassName)
threadpid, procpid = win32process.GetWindowThreadProcessId(handle)
ProcessModule = GetProcessModules(int(procpid))
else:
ProcessModule = GetProcessModules(int(ClassName))
print("-" * 100)
print("映像基址\t\t模塊名稱(chēng)\t基址隨機(jī)化\tDEP保護(hù)兼容\t強(qiáng)制完整性\tSEH異常保護(hù)")
# By: LyShark.com
print("-" * 100)
for item in ProcessModule:
pe = pefile.PE(item[2])
DllFlage = pe.OPTIONAL_HEADER.DllCharacteristics
print("%10s"%(item[0]),end="\t")
print("%21s"%(item[1]),end="\t")
# 隨機(jī)基址 => hex(pe.OPTIONAL_HEADER.DllCharacteristics) & 0x40 == 0x40
if( (DllFlage & 64)==64 ):
print(" True",end="\t\t")
else:
print(" False",end="\t\t")
UNProtoModule.append(item[2])
if( (DllFlage & 256)==256 ):
print("True",end="\t\t")
else:
print("False",end="\t\t")
if ( (DllFlage & 128)==128 ):
print("True",end="\t\t")
else:
print("False",end="\t\t")
if ( (DllFlage & 1024)==1024 ):
print("False",end="\t\t\n")
else:
print("True",end="\t\t\n")
print("-" * 100)
print("\n[+] 總模塊數(shù): {} 可利用模塊: {}".format(len(ProcessModule),len(UNProtoModule)),end="\n\n")
for item in UNProtoModule:
print("[-] {}".format(item))
print("-" * 100)
if __name__ == "__main__":
Banner()
parser = argparse.ArgumentParser()
parser.add_argument("-H","--handle",dest="handle",help="指定一個(gè)正在運(yùn)行的進(jìn)程Handle")
parser.add_argument("-P","--pid",dest="pid",help="指定一個(gè)正在運(yùn)行的進(jìn)程PID")
args = parser.parse_args()
if args.handle or args.pid:
if args.handle:
CheckModulesProtect(str(args.handle))
elif args.pid:
CheckModulesProtect(int(args.pid))
else:
parser.print_help()輸出枚舉效果如下:

到此這篇關(guān)于Python檢測(cè)PE所啟用保護(hù)方式詳解的文章就介紹到這了,更多相關(guān)Python檢測(cè)PE內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python中的xml與dict的轉(zhuǎn)換方法詳解
這篇文章主要介紹了Python中的xml與dict的轉(zhuǎn)換方法詳解,xml 是指可擴(kuò)展標(biāo)記語(yǔ)言,一種標(biāo)記語(yǔ)言類(lèi)似html,作用是傳輸數(shù)據(jù),而且不是顯示數(shù)據(jù)??梢宰远x標(biāo)簽,需要的朋友可以參考下2023-07-07
Python3 MySQL 數(shù)據(jù)庫(kù)連接的使用示例
本文我們?yōu)榇蠹医榻B Python3 使用 PyMySQL 連接數(shù)據(jù)庫(kù),并實(shí)現(xiàn)簡(jiǎn)單的增刪改查,需要的朋友可以參考下2021-06-06
Django切換數(shù)據(jù)庫(kù)和遷移數(shù)據(jù)詳解
這篇文章主要介紹了Django切換數(shù)據(jù)庫(kù)和遷移數(shù)據(jù)詳解的相關(guān)資料,需要的朋友可以參考下2022-11-11
Python 實(shí)現(xiàn) 貪吃蛇大作戰(zhàn) 代碼分享
本文給大家分享的是一個(gè)使用cocos2d-python游戲引擎庫(kù)制作出來(lái)的貪吃蛇大作戰(zhàn)的游戲代碼,基于Python 2.7 和 cocos2d 庫(kù),有需要的小伙伴可以參考下2016-09-09
Python實(shí)現(xiàn)計(jì)算AUC的三種方式總結(jié)
AUC(Area?under?curve)是機(jī)器學(xué)習(xí)常用的二分類(lèi)評(píng)測(cè)手段,直接含義是ROC曲線(xiàn)下的面積。本文總結(jié)了Python語(yǔ)言實(shí)現(xiàn)計(jì)算AUC的三種方式,感興趣的可以學(xué)習(xí)一下2022-07-07
Python實(shí)現(xiàn)的線(xiàn)性回歸算法示例【附csv文件下載】
這篇文章主要介紹了Python實(shí)現(xiàn)的線(xiàn)性回歸算法,涉及Python使用最小二乘法、梯度下降算法實(shí)現(xiàn)線(xiàn)性回歸相關(guān)算法操作與使用技巧,需要的朋友可以參考下2018-12-12

