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模塊信息,需要用戶傳入進(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)文章
YOLOv8訓(xùn)練自己的數(shù)據(jù)集(詳細(xì)教程)
YOLO是一種基于圖像全局信息進(jìn)行預(yù)測(cè)的目標(biāo)檢測(cè)系統(tǒng),YOLOv8 是ultralytics公司在2023年1月10號(hào)開(kāi)源的YOLOv5的下一個(gè)重大更新版本,這篇文章主要給大家介紹了關(guān)于YOLOv8訓(xùn)練自己的數(shù)據(jù)集的相關(guān)資料,需要的朋友可以參考下2023-01-01Python機(jī)器學(xué)習(xí)之基礎(chǔ)概述
今天帶大家回顧python機(jī)器學(xué)習(xí)的相關(guān)知識(shí),文中非常詳細(xì)的介紹了Python機(jī)器學(xué)習(xí)的基礎(chǔ)概述,算法分類(lèi)及研究?jī)?nèi)容,需要的朋友可以參考下2021-05-05