


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans
http://www.cs.virginia.edu/cs
UVa CS216 Spring 2006 - Lecture 22: Unconventional Calling 2
UVa CS216 Spring 2006 - Lecture 22: Unconventional Calling 3
UVa CS216 Spring 2006 - Lecture 22: Unconventional Calling 4
void pathological () { char a[4] = "abcd"; char adr; int val; val = 8; / Saved EBP / / return address <- location of a[16] / a[val+4] = 0xe4; a[val+5] = 0xfe; a[val+6] = 0x12; a[val+7] = 0x00; / a[16-17] <- JMP -2 */ a[val+8] = 0xeb; a[val+9] = 0xfe; a[val+10] = 0x00; a[val+11] = 0x00; } int main (int argc, char **argv) { pathological (); printf ("Hello\n"); return EXIT_SUCCESS; }
UVa CS216 Spring 2006 - Lecture 22: Unconventional Calling 5 UVa CS216 Spring 2006 - Lecture 22: Unconventional Calling 6
UVa CS216 Spring 2006 - Lecture 22: Unconventional Calling 7
UVa CS216 Spring 2006 - Lecture 22: Unconventional Calling 8
UVa CS216 Spring 2006 - Lecture 22: Unconventional Calling 9
UVa CS216 Spring 2006 - Lecture 22: Unconventional Calling 10
http://msdn2.microsoft.com/en-US/library/8dbf701c(VS.80).aspx
UVa CS216 Spring 2006 - Lecture 22: Unconventional Calling 11
UVa CS216 Spring 2006 - Lecture 22: Unconventional Calling 12
void pathological () { 00401030 push ebp 00401031 mov ebp,esp 00401033 sub esp,14h 00401036 mov eax,dword ptr [___security_cookie (408060h)] 0040103B mov dword ptr [ebp-8],eax ... 0040109B mov eax,dword ptr [val] 0040109E mov byte ptr [ebp+eax-5], } 004010A3 mov ecx,dword ptr [ebp-8] 004010A6 call __security_check_cookie (40111Eh) 004010AB mov esp,ebp 004010AD pop ebp 004010AE ret
UVa CS216 Spring 2006 - Lecture 22: Unconventional Calling 19
push dword ebp mov ebp, WORM_ADDRESS + WORM_REG_OFFSET pop dword [ebp + WORM_DATA_OFFSET] xor eax, eax ; WormIP = 0 (load from ebp + eax) read_more_worm: ; read NUM_BYTES at a time until worm is done cld xor ecx, ecx mov byte cl, NUM_BYTES mov dword esi, WORM_ADDRESS ; get saved WormIP add dword esi, eax mov edi, begin_worm_exec rep movsb ; copies next Worm block into execution buffer add eax, NUM_BYTES ; change WormIP pushad ; save register vals mov edi, dword [ebp] ; restore worm registers mov esi, dword [ebp + ESI_OFFSET] mov ebx, dword [ebp + EBX_OFFSET] mov edx, dword [ebp + EDX_OFFSET] mov ecx, dword [ebp + ECX_OFFSET] mov eax, dword [ebp + EAX_OFFSET] begin_worm_exec: ; this is the worm execution buffer nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop mov [ebp], edi ; save worm registers mov [ebp + ESI_OFFSET], esi mov [ebp + EBX_OFFSET], ebx mov [ebp + EDX_OFFSET], edx mov [ ebp + ECX_OFFSET], ecx mov [ebp + EAX_OFFSET], eax popad ; restore microVM register vals jmp read_more_worm
Note: this is nasm x assembly code, not masm, so some directives are slightly different
UVa CS216 Spring 2006 - Lecture 22: Unconventional Calling 20