LyScript插件通过配合内存读写,可以实现将ShellCode代码导出到特定位置,或者将一段以文本形式存储的ShellCode代码插入到程序堆中。该功能可用于将自己编写的ShellCode快速注入到目标进程中进行后续测试。插件地址:https://github.com/lyshark/Ly...将本地ShellCode注入堆中:第一种用法是将本地文本中的ShellCode代码导入堆中。首先准备一个文本文件,将生成的shellcode放入文件中。然后可以在循环中读取文本,并将shellcode一个一个地注入目标堆空间。fromLyScript32importMyDebug#将shellcode读入内存defread_shellcode(path):shellcode_list=[]withopen(path,"r",encoding="utf-8")asfp:forindexinfp.readlines():shellcode_line=index.replace('"',"").replace("","").replace("\n","").replace(";","")用于shellcode_line.split("\\x"):ifcode!=""andcode!="\\n":shellcode_list.append("0x"+code)返回shellcode_listif__name__=="__main__":dbg=MyDebug()dbg.connect()#开辟堆空间address=dbg.create_alloc(1024)print("开辟堆空间:{}".format(hex(address)))ifaddress==False:exit()#设置内存可执行属性dbg.set_local_protect(address,32,1024)#从文本中读取shellcodeshellcode=read_shellcode("d://shellcode.txt")#循环写入内存forcode_byteinrange(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()执行后,堆空间会自动被填充。如果反过来,则将特定位置的汇编代码保存在本地。fromLyScript32importMyDebug#将特定内存保存到文本中defwrite_shellcode(dbg,address,size,path):withopen(path,"a+",encoding="utf-8")asfp:forindexinrange(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()写入后的文件如下:
