Python檢測PE所啟用保護(hù)方式詳解
更新時間:2022年10月08日 08:43:42 作者:lyshark
Python通過pywin32模塊調(diào)用WindowsAPI接口,可以實現(xiàn)對特定進(jìn)程加載模塊的枚舉輸出并檢測該PE程序模塊所啟用的保護(hù)方式,感興趣的可以了解一下
Python 通過pywin32模塊調(diào)用WindowsAPI接口,實現(xiàn)對特定進(jìn)程加載模塊的枚舉輸出并檢測該PE程序模塊所啟用的保護(hù)方式,此處枚舉輸出的是當(dāng)前正在運行進(jìn)程所加載模塊的DLL模塊信息,需要用戶傳入進(jìn)程PID才可實現(xiàn)輸出。
- 首先需要安裝兩個依賴包:
- pip install pywin32
- pip install pefile
然后再命令行模式下執(zhí)行命令啟動枚舉功能。
# 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模塊名稱\t基址隨機化\tDEP保護(hù)兼容\t強制完整性\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") # 隨機基址 => 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="指定一個正在運行的進(jìn)程Handle") parser.add_argument("-P","--pid",dest="pid",help="指定一個正在運行的進(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檢測PE所啟用保護(hù)方式詳解的文章就介紹到這了,更多相關(guān)Python檢測PE內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
YOLOv8訓(xùn)練自己的數(shù)據(jù)集(詳細(xì)教程)
YOLO是一種基于圖像全局信息進(jìn)行預(yù)測的目標(biāo)檢測系統(tǒng),YOLOv8 是ultralytics公司在2023年1月10號開源的YOLOv5的下一個重大更新版本,這篇文章主要給大家介紹了關(guān)于YOLOv8訓(xùn)練自己的數(shù)據(jù)集的相關(guān)資料,需要的朋友可以參考下2023-01-01