網站首頁 編程語言 正文
Python 通過pywin32模塊調用WindowsAPI接口,實現(xiàn)對特定進程加載模塊的枚舉輸出并檢測該PE程序模塊所啟用的保護方式,此處枚舉輸出的是當前正在運行進程所加載模塊的DLL模塊信息,需要用戶傳入進程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保護兼容\t強制完整性\tSEH異常保護")
# 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="指定一個正在運行的進程Handle")
parser.add_argument("-P","--pid",dest="pid",help="指定一個正在運行的進程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()
輸出枚舉效果如下:
原文鏈接:https://www.cnblogs.com/LyShark/p/16125498.html
相關推薦
- 2022-04-19 基于HarmonyOS 的ArkUI編寫的社區(qū)類app(一)----隱私服務條款界面
- 2022-10-23 Go語言數(shù)據(jù)結構之希爾排序示例詳解_Golang
- 2022-12-03 C++網絡編程詳細講解_C 語言
- 2023-05-09 Python實現(xiàn)刪除重復文件的示例代碼_python
- 2022-07-03 golang defer,func()閉包,panic ,recover,contex
- 2022-03-22 Linux系統(tǒng)下gcc命令使用詳解_Linux
- 2022-10-10 python?pandas數(shù)據(jù)處理之刪除特定行與列_python
- 2021-12-06 React腳手架搭建的學習_React
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學習環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結構-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支