通過LyScript實現(xiàn)從文本中讀寫ShellCode
LyScript 插件通過配合內(nèi)存讀寫,可實現(xiàn)對特定位置的ShellCode代碼的導(dǎo)出,或者將一段存儲在文本中的ShellCode代碼插入到程序堆中,此功能可用于快速將自己編寫的ShellCode注入到目標(biāo)進(jìn)程中,以用于后續(xù)測試工作。
LyScript項目地址:https://github.com/lyshark/LyScript
將本地ShellCode注入到堆中: 第一種用法是將一個本地文本中的ShellCode代碼導(dǎo)入到堆中。
首先準(zhǔn)備一個文本文件,將生成的shellcode放入文件內(nèi)。

然后可以循環(huán)讀取文本,并逐個將shellcode注入到目標(biāo)堆空間中。
from LyScript32 import MyDebug
# 將shellcode讀入內(nèi)存
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()
# 設(shè)置內(nèi)存可執(zhí)行屬性
dbg.set_local_protect(address,32,1024)
# 從文本中讀取shellcode
shellcode = read_shellcode("d://shellcode.txt")
# 循環(huán)寫入到內(nèi)存
for code_byte in range(0,len(shellcode)):
bytef = int(shellcode[code_byte],16)
dbg.write_memory_byte(code_byte + address, bytef)
# 設(shè)置EIP位置
dbg.set_register("eip",address)
input()
dbg.delete_alloc(address)
dbg.close()
執(zhí)行后,堆空間內(nèi)會自動填充。

如果把這個過程反過來,就是將特定位置的匯編代碼保存到本地。
from LyScript32 import MyDebug
# 將特定內(nèi)存保存到文本中
def write_shellcode(dbg,address,size,path):
with open(path,"a+",encoding="utf-8") as fp:
for index in range(0, size - 1):
# 讀取機(jī)器碼
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()
寫出后的文件如下:

到此這篇關(guān)于通過LyScript實現(xiàn)從文本中讀寫ShellCode的文章就介紹到這了,更多相關(guān)LyScript文本讀寫ShellCode內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
PyQt教程之自定義組件Switch?Button的實現(xiàn)
這篇文章主要為大家詳細(xì)介紹了PyQt中如何實現(xiàn)自定義組件Switch?Button,文中的示例代碼簡潔易懂,具有一定的學(xué)習(xí)價值,感興趣的可以了解一下2023-05-05
Python實現(xiàn)鏈表反轉(zhuǎn)與合并操作詳解
這篇文章主要為大家詳細(xì)介紹了?Python?中反轉(zhuǎn)鏈表和合并鏈表的應(yīng)用場景及實現(xiàn)方法,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解下2025-02-02
Python中 CSV格式清洗與轉(zhuǎn)換的實例代碼
這篇文章主要介紹了Python123 CSV格式清洗與轉(zhuǎn)換的實例代碼,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2019-08-08
python-web根據(jù)元素屬性進(jìn)行定位的方法
這篇文章主要介紹了python-web根據(jù)元素屬性進(jìn)行定位的方法,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下2019-12-12
Python Pandas中合并數(shù)據(jù)的5個函數(shù)使用詳解
數(shù)據(jù)合并是數(shù)據(jù)處理過程中的必經(jīng)環(huán)節(jié),pandas作為數(shù)據(jù)分析的利器,提供了五種常用的數(shù)據(jù)合并方式,讓我們看看如何使用這些方法吧!2022-05-05

