Python利用LyScript插件实现批量打开关闭进程
作者:lyshark 时间:2021-10-07 04:46:15
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
标签:Python,打开,关闭,进程
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Django实现微信小程序的登录验证功能并维护登录态
2022-03-14 22:56:48
![](https://img.aspxhome.com/file/2023/6/76826_0s.png)
设计之外随谈
2009-06-16 14:38:00
![](https://img.aspxhome.com/file/UploadPic/20096/16/anddy_xiantan-64s.jpg)
Python 实现判断图片格式并转换,将转换的图像存到生成的文件夹中
2023-07-19 04:13:23
sqlserver 触发器实例代码
2012-01-29 18:30:45
Mysql的最大连接数怎样用java程序测试
2009-01-14 12:05:00
MySQL数据库与表的最基本命令大盘点
2010-08-31 14:29:00
python保留小数位的三种实现方法
2021-09-05 22:36:09
利用python实现逐步回归
2023-10-05 19:24:27
![](https://img.aspxhome.com/file/2023/4/80584_0s.jpg)
二十八法优化SQL Server数据库查询
2010-07-02 20:56:00
使用Python的Flask框架实现视频的流媒体传输
2023-05-07 02:46:53
![](https://img.aspxhome.com/file/2023/2/69512_0s.jpg)
如何将计数器的值赋给一个变量?
2009-12-03 20:02:00
Python 数字转化成列表详情
2023-09-24 06:53:25
![](https://img.aspxhome.com/file/2023/3/67373_0s.png)
Python安装及Pycharm安装使用教程图解
2023-08-01 05:38:06
![](https://img.aspxhome.com/file/2023/0/61460_0s.jpg)
Golang中字符串(string)与字节数组([]byte)一行代码互转实例
2023-09-17 14:37:07
![](https://img.aspxhome.com/file/2023/8/101038_0s.png)
使用Python实现一个栈判断括号是否平衡
2022-01-04 02:20:29
使用python搭建Django应用程序步骤及版本冲突问题解决
2023-01-29 07:36:34
![](https://img.aspxhome.com/file/2023/1/63891_0s.jpg)
asp中InstrRev的语法
2008-01-22 18:14:00
SQL Server 2000 占内存居高不下可能的原因及其解决方法
2010-04-25 10:39:00
python 异常捕获详解流程
2022-06-12 15:31:04
![](https://img.aspxhome.com/file/2023/9/71519_0s.jpg)
python静态web服务器实现方法及代码详解
2023-01-13 17:17:12