日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

Python利用LyScript插件實現批量打開關閉進程_python

作者:lyshark ? 更新時間: 2022-09-16 編程語言

LyScript是一款x64dbg主動化操控插件,經過Python操控X64dbg,完成了遠程動態調試,解決了逆向工作者剖析漏洞,尋覓指令片段,原生腳本不行強壯的問題,經過與Python相結合使用Python語法的靈活性以及豐富的第三方庫,進步剖析功率,完成主動化剖析代碼。

python包請裝置與插件一致的版別,在cmd命令行下履行pip命令即可裝置。

裝置Python包:pipinstallLyScript32或者pipinstallLyScript64

其次你需求手動下載對應x64dbg版別的驅動文件,并放入指定目錄下。

插件下載好以后,請將該插件復制到x64dbg目錄下的plugins目錄下,程序運轉后會主動加載插件文件。

當插件加載成功后,會在日志方位看到具體的綁定信息以及輸出調試,該插件并不會在插件欄顯示。

假如需求遠程調試,則只需求在初始化MyDebug()類是傳入對端IP地址即可,假如不填寫參數則默認使用127.0.0.1地址,請保證對端放行了6589端口,不然無法銜接。

運轉x64dbg程序并手動載入需求剖析的可履行文件,然后我們能夠經過connect()方法銜接到調試器,銜接后會創建一個持久會話直到python腳本完畢則銜接會被強制斷開,在此期間可調用is_connect()查看該鏈接是否還存在,具體代碼如下所示。

fromLyScript32importMyDebugif__name__==”__main__”:#初始化dbg=MyDebug()#銜接到調試器
connect_flag=dbg.connect()print(“銜接狀況:{}”.format(connect_flag))#檢測套接字是否還在
???????ref=dbg.is_connect()print(“是否在銜接:”,ref)dbg.close()

LyScript插件默認沒有批量載入功能,導致用戶只能手動將被調試進程拖入到x64dbg中才可以調試,使用python模擬快捷鍵即可解決這個問題,具體使用代碼如下。

import win32api
import win32gui, win32con
import win32clipboard
import re
import time
from LyScript32 import MyDebug

class cWindow:
    def __init__(self):
        self._hwnd = None

    def SetAsForegroundWindow(self):
        win32gui.SetForegroundWindow(self._hwnd)

    def Maximize(self):
        # 最大化
        win32gui.ShowWindow(self._hwnd, win32con.SW_MAXIMIZE)

    def _window_enum_callback(self, hwnd, regex):
        if self._hwnd is None and re.match(regex, str(win32gui.GetWindowText(hwnd))) is not None:
            self._hwnd = hwnd

    def find_window_regex(self, regex):
        self._hwnd = None
        win32gui.EnumWindows(self._window_enum_callback, regex)

    def hide_always_on_top_windows(self):
        win32gui.EnumWindows(self._window_enum_callback_hide, None)

    def _window_enum_callback_hide(self, hwnd, unused):
        if hwnd != self._hwnd:
            if win32gui.IsWindowVisible(hwnd) and win32gui.GetWindowLong(hwnd, win32con.GWL_EXSTYLE) & win32con.WS_EX_TOPMOST:
                className = win32gui.GetClassName(hwnd)
                if not (className == 'Button' or className == 'Shell_TrayWnd'):
                    win32gui.ShowWindow(hwnd, win32con.SW_FORCEMINIMIZE)

    def OpenFile(self,path):
        # 按下F3
        win32api.keybd_event(0x72, 0, 0, 0)
        win32api.keybd_event(0x72, 0, win32con.KEYEVENTF_KEYUP, 0)

        # 打開剪貼板
        win32clipboard.OpenClipboard()
        # 清空剪貼板
        win32clipboard.EmptyClipboard()
        # 設置剪貼板內容
        win32clipboard.SetClipboardData(win32con.CF_UNICODETEXT, path)
        # 獲取剪貼板內容
        date = win32clipboard.GetClipboardData()
        print("[*] OpenFile = {}".format(date))
        # 關閉剪貼板
        win32clipboard.CloseClipboard()
        time.sleep(0.2)

        # 按下ctrl+v
        win32api.keybd_event(0x11, 0, 0, 0)
        win32api.keybd_event(0x56, 0, 0, 0)
        win32api.keybd_event(0x56, 0, win32con.KEYEVENTF_KEYUP, 0)
        win32api.keybd_event(0x11, 0, win32con.KEYEVENTF_KEYUP, 0)

        # 按下回車
        win32api.keybd_event(0x0D, 0, 0, 0)
        win32api.keybd_event(0x0D, 0, win32con.KEYEVENTF_KEYUP, 0)

    def deatch(self):
        # 按下Ctrl+Alt+F2
        win32api.keybd_event(0x11, 0, 0, 0)
        win32api.keybd_event(0x12, 0, 0, 0)
        win32api.keybd_event(0x71, 0, 0, 0)
        win32api.keybd_event(0x11, 0, win32con.KEYEVENTF_KEYUP, 0)
        win32api.keybd_event(0x12, 0, win32con.KEYEVENTF_KEYUP, 0)
        win32api.keybd_event(0x71, 0, win32con.KEYEVENTF_KEYUP, 0)

# 打開調試程序
def OpenFile(path):
    regex = ".*x32dbg.*"
    cWindows = cWindow()
    cWindows.find_window_regex(regex)
    cWindows.SetAsForegroundWindow()
    cWindows.SetAsForegroundWindow()
    cWindows.OpenFile(path)

# 關閉調試程序
def DeatchFile():
    regex = ".*x32dbg.*"
    cWindows = cWindow()
    cWindows.find_window_regex(regex)
    cWindows.SetAsForegroundWindow()
    cWindows.SetAsForegroundWindow()
    cWindows.deatch()

# 得到腳本返回值
def GetScriptValue(dbg,script):
    try:
        ref = dbg.run_command_exec("push eax")
        if ref != True:
            return None
        ref = dbg.run_command_exec(f"eax={script}")
        if ref != True:
            return None
        reg = dbg.get_register("eax")
        ref = dbg.run_command_exec("pop eax")
        if ref != True:
            return None
        return reg
    except Exception:
        return None
    return None

if __name__ == "__main__":
    dbg = MyDebug()
    dbg.connect()

    # 批量打開一個列表
    for item in ["D:\Win32Project.exe","D:\Windows Tools\C32ASM\c32asm.exe"]:
        OpenFile(item)
        time.sleep(3)

        for i in range(1,100):
            dbg.set_debug("StepIn")
            time.sleep(0.2)

        eip = dbg.get_register("eip")
        print("eip = > {}".format(hex(eip)))

        time.sleep(3)
        DeatchFile()

原文鏈接:https://www.cnblogs.com/LyShark/p/16505096.html

欄目分類
最近更新