通用ShellCode学习笔记 2003/XP/Win7/Vista/Win8 通用
一、ShellCode的编写[*]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的地址
-> 内存中的下一个dll的地址(00h指向下一个Ldr_Module)
->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, ;
mov esi, ;
next_module:
mov ebp, ;
mov edi, ;
mov esi, ;
cmp ,cl
jne next_module
mov edi,ebp;BaseAddr of Kernel32.dll
[*]GetProcAddress地址的获取
有了kernel32的地址以后,我们就可以方便的通过遍历的方式查询到GetProcAddress的地址
sub esp,100
mov ebp,esp;
mov eax,;pe header
mov edx,
add edx,edi
mov ecx,;number of functions
mov ebx,
add ebx,edi;AddressOfName
search:
dec ecx
mov esi,
add esi,edi;
mov eax,0x50746547;PteG("GetP")
cmp ,eax
jne search
mov eax,0x41636f72;Acor("rocA")
cmp ,eax
jne search
mov ebx,
add ebx,edi;indexaddress
mov cx,
mov ebx,
add ebx,edi
mov eax,
add eax,edi
mov ,eax;将GetProcAddress地址存在ebp+76中
[*]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
mov,eax;将LoadLibraryA地址存在ebp+80中
页:
[1]