LyScript 从文本中读写ShellCode
LyScript 插件通过配合内存读写,可实现对特定位置的ShellCode代码的导出,或者将一段存储在文本中的ShellCode代码插入到程序堆中,此功能可用于快速将自己编写的ShellCode注入到目标进程中,以用于后续测试工作。
将本地ShellCode注入到堆中: 第一种用法是将一个本地文本中的ShellCode代码导入到堆中。
首先准备一个文本文件,将生成的shellcode放入文件内。
然后可以循环读取文本,并逐个将shellcode注入到目标堆空间中。
from LyScript32 import MyDebug
# 将shellcode读入内存
def read_shellcode(path):
shellcode_list = []
with open(path,"r",encoding="utf-8") as fp:
for index in fp.readlines():
shellcode_line = index.replace('"',"").replace(" ","").replace("\n","").replace(";","")
for code in shellcode_line.split("\\x"):
if code != "" and code != "\\n":
shellcode_list.append("0x" + code)
return shellcode_list
if __name__ == "__main__":
dbg = MyDebug()
dbg.connect()
# 开辟堆空间
address = dbg.create_alloc(1024)
print("开辟堆空间: {}".format(hex(address)))
if address == False:
exit()
# 设置内存可执行属性
dbg.set_local_protect(address,32,1024)
# 从文本中读取shellcode
shellcode = read_shellcode("d://shellcode.txt")
# 循环写入到内存
for code_byte in range(0,len(shellcode)):
bytef = int(shellcode[code_byte],16)
dbg.write_memory_byte(code_byte + address, bytef)
# 设置EIP位置
dbg.set_register("eip",address)
input()
dbg.delete_alloc(address)
dbg.close()
执行后,堆空间内会自动填充。
如果把这个过程反过来,就是将特定位置的汇编代码保存到本地。
from LyScript32 import MyDebug
# 将特定内存保存到文本中
def write_shellcode(dbg,address,size,path):
with open(path,"a+",encoding="utf-8") as fp:
for index in range(0, size - 1):
# 读取机器码
read_code = dbg.read_memory_byte(address + index)
if (index+1) % 16 == 0:
print("\\x" + str(read_code))
fp.write("\\x" + str(read_code) + "\n")
else:
print("\\x" + str(read_code),end="")
fp.write("\\x" + str(read_code))
if __name__ == "__main__":
dbg = MyDebug()
dbg.connect()
eip = dbg.get_register("eip")
write_shellcode(dbg,eip,128,"d://lyshark.txt")
dbg.close()
写出后的文件如下:
文章出处:https://www.cnblogs.com/LyShark/p/16547718.html
本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
合集:
x64dbg 自动化从入门到精通
标签:
x64dbg
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2020-08-03 C/C++ 实现常用的线程注入
2019-08-03 Python 装饰&生成&迭代器
2019-08-03 Python 变量作用域与函数
2019-08-03 Python 流程控制与循环体
2019-08-03 Python 运算符与数据类型
2019-08-03 CentOS7 Python 3.7.0 编译安装
2019-08-03 DVWA漏洞演练平台 - SQL注入