自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

如何編寫一段內(nèi)存蠕蟲?

安全 應(yīng)用安全
我們怎么寫一段代碼,能夠在程序內(nèi)存里面不停移動(dòng)?就是讓shellcode代碼能在內(nèi)存中不停的復(fù)制自己,并且一直執(zhí)行下去,也就是內(nèi)存蠕蟲。

我們怎么寫一段代碼,能夠在程序內(nèi)存里面不停移動(dòng)?就是讓shellcode代碼能在內(nèi)存中不停的復(fù)制自己,并且一直執(zhí)行下去,也就是內(nèi)存蠕蟲。我們要把shellcode代碼偏移出蠕蟲長度再復(fù)制到蠕蟲后面的內(nèi)存中,然后執(zhí)行。

[[320925]]

我們在實(shí)現(xiàn)過程中同時(shí)把前面同長度代碼變成\x90,那個(gè)就是蟲子走過的路,最終吃掉所有的內(nèi)存。實(shí)現(xiàn)這個(gè)我們要知道shellcode長度,并且計(jì)算好shellcode每次移動(dòng)的位置是多少。我們的shllcode以調(diào)用printf函數(shù)為例。

1. 寫出printf程序

  1. #include "stdio.h" 
  2. int main() 
  3.     printf("begin\n"); 
  4.     char *str="a=%d\n"
  5.      
  6.     __asm{ 
  7.         mov eax,5 
  8.         push eax 
  9.         push str 
  10.         mov eax,0x00401070   
  11.         call eax 
  12.         add esp,8 
  13.         ret 
  14.     } 
  15.         return 0; 

0×00401070 是我機(jī)子上printf的地址,將自己機(jī)子上的printf地址更換一下就行,還要在最后加一個(gè)ret,因?yàn)閳?zhí)行完shellcode還要回到復(fù)制shellcode的代碼執(zhí)行。

上面匯編轉(zhuǎn)成shellcode形式,shellcode為:

  1. char shellcode[]="\xB8\x05\x00\x00\x00\x50\xFF\x75\xFC\xB8\x70\x10\x40\x00\xFF\xD0\x83\x**\x08\xc3"; 

2. 編寫蠕蟲代碼

  1. insect:mov bl,byte ptr ds:[eax+edx] 
  2.        mov byte ptr ds:[eax+edx+20],bl 
  3.        mov byte ptr ds:[eax+edx],0x90 
  4.        inc edx 
  5.        cmp edx,20 
  6.        je ee 
  7.        jmp insect 
  8.         
  9. ee:     add eax,20 
  10.         push eax 
  11.         call eax 
  12.         pop eax 
  13.         xor edx,edx 
  14.         jmp insect 

shellcode長度是20,假設(shè)數(shù)據(jù)的地址是s,我們把數(shù)據(jù)復(fù)制到地址為s+20處,原來的數(shù)據(jù)變?yōu)?×90,表示數(shù)據(jù)曾經(jīng)來過這里,insect段是用來復(fù)制數(shù)據(jù)用到,復(fù)制了20次,剛剛好把shellcode復(fù)制完。

因?yàn)閟hellcode相當(dāng)于向下移動(dòng)20位,所以我們要把eax加上20,還要把edx恢復(fù)成0,方便下次接著復(fù)制,然后去執(zhí)行我們的shellcode,接著跳轉(zhuǎn)到insect段繼續(xù)執(zhí)行,這是ee段干的事。

inscet和ee段加起來是復(fù)制我們的shellcode到其他地方,然后去執(zhí)行shellcode,然后再復(fù)制,循環(huán)下去。

3. 最終程序

  1. #include "stdio.h" 
  2.  
  3. char shellcode[]="\xB8\x05\x00\x00\x00\x50\xFF\x75\xFC\xB8\x70\x10\x40\x00\xFF\xD0\x83\x**\x08\xc3"; 
  4. int main() 
  5.     printf("begin\n"); 
  6.     char *str="a=%d\n"
  7.      
  8.      
  9.     __asm{ 
  10.          
  11.         lea eax,shellcode 
  12.         push eax 
  13.         call eax 
  14.         pop eax 
  15.         xor edx,edx 
  16.              
  17. insect:mov bl,byte ptr ds:[eax+edx] 
  18.        mov byte ptr ds:[eax+edx+20],bl 
  19.        mov byte ptr ds:[eax+edx],0x90 
  20.        inc edx 
  21.        cmp edx,20 
  22.        je ee 
  23.        jmp insect 
  24.         
  25. ee:     add eax,20 
  26.         push eax 
  27.         call eax 
  28.         pop eax 
  29.         xor edx,edx 
  30.         jmp insect 
  31.  
  32.  
  33.          
  34.     } 
  35.      
  36.      
  37.     return 0; 

調(diào)試的時(shí)候找到shellcode位置,一步步調(diào)試能看見shellcode被復(fù)制,原來的轉(zhuǎn)成0×90,并且printf還被執(zhí)行

沒有復(fù)制前:

復(fù)制后:

4. 總結(jié)

我們要先計(jì)算出shellcode的長度,計(jì)算好shellcode每次移動(dòng)的位置是多少,然后寫出復(fù)制程序,并且還要有調(diào)轉(zhuǎn)到復(fù)制后的shellcode首地址程序,執(zhí)行復(fù)制后的shellcode,接著在復(fù)制再執(zhí)行,循環(huán)下去,當(dāng)然在一段內(nèi)存里循環(huán)執(zhí)行也可以,只要找到位置,跳轉(zhuǎn)過去就行

 

責(zé)任編輯:趙寧寧 來源: FreeBuf
相關(guān)推薦

2015-03-27 11:34:59

JavaJava編寫引發(fā)內(nèi)存泄露

2022-06-21 12:27:12

JavaScript前端

2018-11-02 16:16:41

程序硬盤存儲

2009-11-07 11:18:57

2020-10-26 10:11:45

Jupyter Not早起Python開發(fā)

2014-03-21 09:58:08

比特幣

2014-07-08 09:21:10

死代碼創(chuàng)意歌曲

2020-12-31 10:14:42

防注入代碼繞過

2018-06-19 08:02:00

統(tǒng)計(jì)程序微信

2018-06-23 08:02:31

程序員代碼故事

2021-01-04 05:58:57

WindowsXP微軟操作系統(tǒng)

2014-09-09 14:47:20

2021-02-04 07:55:28

代碼離職互聯(lián)網(wǎng)

2020-04-29 10:19:29

Python數(shù)據(jù)函數(shù)

2022-02-08 09:00:00

智能自動(dòng)化人工智能RPA

2017-11-20 16:44:59

云端算力

2021-04-08 09:14:24

js前端函數(shù)

2019-10-14 09:51:08

爬蟲網(wǎng)絡(luò)系統(tǒng)

2019-10-18 09:39:44

爬蟲消息大數(shù)據(jù)

2021-08-10 05:49:10

網(wǎng)絡(luò)協(xié)議C語言Linux操作
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號