修復(fù)一個shellcode

https://www.exploit-db.com/shellcodes/40245

Windows/x86 - MessageBoxA() Shellcode (242 bytes)

shellcode功能是使用MessageBox彈出一個對話框

這個shellcode 在xpsp3 與win10 上是調(diào)不通的,提示內(nèi)存不能讀,經(jīng)過查看shellcode對應(yīng)的匯編,發(fā)現(xiàn)作者在查找GetProcAdress這個函數(shù)式使用了錯誤的方法,代碼片段如下:

xor ecx,ecx

mov eax,[fs:ecx+0x30] ;PEB

mov eax,[eax+0xc] ;PEB->Ldr

mov esi,[eax+0x14] ;PEB->ldr.InMemOrderModuleList

lodsd

xchg esi,eax

lodsd

mov ecx,[eax+0x10] ;kernel32 base address

xor ebx,ebx

mov ebx,[ecx+0x3c] ;DOS->elf_anew

add ebx,ecx

mov ebx,[ebx+0x78] ;DataDirectory->VirtualAddress

add ebx,ecx ;IMAGE_EXPORT_DIRECTORY

mov esi,[ebx+0x20] ;AddressOfNames

add esi,ecx

xor edx,edx

上面是通過PEB一路找到kernel32.dll的函數(shù)導(dǎo)出表,函數(shù)導(dǎo)出表結(jié)構(gòu)中最后三個字段是:

函數(shù)地址表:AddressOfFunctions,存儲的是導(dǎo)出函數(shù)的偏移

函數(shù)名稱表:AddressOfNames,存儲的是導(dǎo)出函數(shù)的名稱

函數(shù)地址索引表:AddressOfNameOrdinals,存儲的是函數(shù)地址表中的序號

g:

inc edx

lodsd

add eax,ecx

cmp dword [eax],'GetP'

jnz g

cmp dword [eax+4],'rocA'

jnz g

cmp dword [eax+8],'ddre'

jnz g

;執(zhí)行到這里edx中存儲的是函數(shù)GetProcAdress的索引,在AdressOfNameOrdinals表中同樣的索引位置存儲著AddressOfFunctions索引值+1。

mov esi,[ebx+0x1c] ;AddressOfFunctions

add esi,ecx

mov edx,[esi+edx*4]

;上面這一段作者直接用前面找到的索引值對AdressOfFunctions進(jìn)行索引,這樣做可能碰巧能獲取到正確的值。修改后的代碼如下:

mov eax,[ebx+24h];找到導(dǎo)出表中的AddressOfNameOrdinals RVA

add eax,ecx;生成VA

mov dx,word ptr[eax+edx*2];因?yàn)锳ddressOfNameOrdinals表示word類型,且與AddressOfNames的索引是對應(yīng)的

;ax 中存放的值為GetProcAdress函數(shù)在AdressOfFunctions表中的位置

dec edx

mov eax,[ebx+1ch];找到導(dǎo)出表中的AddressOfFunctions的RVA

add eax,ecx;生成VA

mov edx,[eax+edx*4];找到GetProcAdress 在AdressOfFunctions 表中具體位置保存的RVA

add edx,ecx;生成VA

到這里edx中保存的就是GetProcAdress函數(shù)地址

完整的匯編代碼如下,分號在匯編中表示注釋:

xor ecx,ecx ; shellcod.00424B90

mov eax,dword ptr fs:[ecx+0x30]

mov eax,dword ptr ds:[eax+0xC]

mov esi,dword ptr ds:[eax+0x14]

lods dword ptr ds:[esi]

xchg eax,esi

lods dword ptr ds:[esi]

mov ecx,dword ptr ds:[eax+0x10]

xor ebx,ebx

mov ebx,dword ptr ds:[ecx+0x3C]

add ebx,ecx

mov ebx,dword ptr ds:[ebx+0x78]

add ebx,ecx

mov esi,dword ptr ds:[ebx+0x20]

add esi,ecx

xor edx,edx

;-------------------

;ecx kernel32.imagebase

;ebx kernel32.export_table.base

;-------------------

;獲取GetProcAdress在導(dǎo)出表中的位置

getadd:

inc edx

lods dword ptr ds:[esi]

add eax,ecx

cmp dword ptr ds:[eax],0x50746547

jnz getadd

cmp dword ptr ds:[eax+0x4],0x41636F72

jnz getadd

cmp dword ptr ds:[eax+0x8],0x65726464

jnz getadd

;edx 為GetProcAdress在導(dǎo)出表的的索引值

;mov esi,dword ptr ds:[ebx+0x1C];這個是找到AddressOfFunctions的RVA

;add esi,ecx;生成VA

;mov edx,dword ptr ds:[esi+edx*4];使用找到的索引值在AdreessOfFuncitons 表中找RVA,但這是錯誤的

;add edx,ecx;生成VA

;edx 為找到的GetProcAdress的地址值,但是上面這個方法是錯誤的

;-------------------

;ecx kernel32.imagebase

;ebx kernel32.export_table.base

;-------------------

mov eax,[ebx+24h];找到導(dǎo)出表中的AddressOfNameOrdinals RVA

add eax,ecx;生成VA

mov dx,word ptr[eax+edx*2];因?yàn)锳ddressOfNameOrdinals表示word類型,且與AddressOfNames的索引是對應(yīng)的

;ax 中存放的值為GetProcAdress函數(shù)在AdressOfFunctions表中的位置

dec edx

mov eax,[ebx+1ch];找到導(dǎo)出表中的AddressOfFunctions的RVA

add eax,ecx;生成VA

mov edx,[eax+edx*4];找到GetProcAdress 在AdressOfFunctions 表中具體位置保存的RVA

add edx,ecx;生成VA

;-------------------

mov esi,edx

mov edi,ecx

xor ebx,ebx

push ebx

push 0x41797261

push 0x7262694C

push 0x64616F4C

push esp

push ecx

call edx

add esp,0x10

xor ecx,ecx

push 0x42426C6C

mov byte ptr ss:[esp+0x2],cl

push 0x642E3233

push 0x72657375

push esp

call eax

add esp,0xC

xor ecx,ecx

push 0x4241786F

mov byte ptr ss:[esp+0x3],cl

push 0x42656761

push 0x7373654D

push esp

push eax

call esi

add esp,0xC

xor edx,edx

xor ecx,ecx

push edx

push 0x21216773

push 0x6D20656C

push 0x706D6153

lea edx,dword ptr ss:[esp]

push ecx

push 0x65726568

push 0x54206968

lea ecx,dword ptr ss:[esp]

xor ebx,ebx

inc ebx

push ebx

push edx

push ecx

xor ebx,ebx

push ebx

call eax

xor ecx,ecx

push 0x41737365

mov byte ptr ss:[esp+0x3],cl

push 0x636F7250

push 0x74697845

lea ecx,dword ptr ss:[esp]

push ecx

push edi

call esi

xor ecx,ecx

push ecx

call eax

nop

生成shellcode 如下:

include<stdio.h>

include<string.h>

char shellcode[]="\x33\xC9\x64\x8B\x41\x30\x3E\x8B\x40\x0C\x3E\x8B\x70\x14\xAD\x96\xAD\x3E\x8B\x48\x10\x33\xDB\x3E\x8B\x59\x3C\x03\xD9\x3E\x8B\x5B\x78\x03\xD9\x3E\x8B\x73\x20\x03\xF1\x33\xD2\x42\xAD\x03\xC1\x3E\x81\x38\x47\x65\x74\x50\x75\xF3\x3E\x81\x78\x04\x72\x6F\x63\x41\x75\xE9\x3E\x81\x78\x08\x64\x64\x72\x65\x75\xDF\x8B\x43\x24\x03\xC1\x66\x8B\x14\x50\x4A\x8B\x43\x1C\x03\xC1\x8B\x14\x90\x8B\xC1\x03\xD0\x8B\xF2\x8B\xF9\x33\xDB\x53\x68\x61\x72\x79\x41\x68\x4C\x69\x62\x72\x68\x4C\x6F\x61\x64\x54\x51\xFF\xD2\x83\xC4\x10\x33\xC9\x68\x6C\x6C\x42\x42\x36\x88\x4C\x24\x02\x68\x33\x32\x2E\x64\x68\x75\x73\x65\x72\x54\xFF\xD0\x83\xC4\x0C\x33\xC9\x68\x6F\x78\x41\x42\x36\x88\x4C\x24\x03\x68\x61\x67\x65\x42\x68\x4D\x65\x73\x73\x54\x50\xFF\xD6\x83\xC4\x0C\x33\xD2\x33\xC9\x52\x68\x73\x67\x21\x21\x68\x6C\x65\x20\x6D\x68\x53\x61\x6D\x70\x36\x8D\x14\x24\x51\x68\x68\x65\x72\x65\x68\x68\x69\x20\x54\x36\x8D\x0C\x24\x33\xDB\x43\x53\x52\x51\x33\xDB\x53\xFF\xD0\x33\xC9\x68\x65\x73\x73\x41\x36\x88\x4C\x24\x03\x68\x50\x72\x6F\x63\x68\x45\x78\x69\x74\x36\x8D\x0C\x24\x51\x57\xFF\xD6\x33\xC9\x51\xFF\xD0";

void main()

{

printf("shellcode lenght %ld\n",(long)strlen(shellcode));

_asm{

lea eax,shellcode

push eax

ret

}

}

運(yùn)行截圖如下:


圖片.png

https://www.exploit-db.com/shellcodes/40246這個shellcode 是同樣的問題

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容