SlideShare a Scribd company logo
1 of 45
Download to read offline
MEMORY ALLOCATION
DIVING INTO
TO UNDERSTAND BUFFER OVERFLOW BETTER
DYNAMIC MEMORY ALLOCATION
WHOAMI
Oguzhan Topgul
Application Security Engineer @FORTINET
www.oguzhantopgul.com
@oguzhantopgul
DYNAMIC MEMORY ALLOCATION
CPU REGISTERS
▸ EIP: Instruction Pointer - Next instruction to be executed
▸ ESP: Stack Pointer - Top of the stack
▸ EBP: Base Pointer - Base of the stack
▸ EAX: Accumulator Register - Generally holds the return value
▸ EBX: Base Register - Generally used to address memory
▸ ECX: Counter Register - Generally used in shift, rotate instructions and loops
▸ EDX: Data Register - Generally used in arithmetic and I/O operations
▸ ESI: Source Index Register
▸ EDI: Destination Index Register
DYNAMIC MEMORY ALLOCATION
PROGRAM MEMORY
.TEXT
.DATA
HEAP
STACK
.BSS
LOW MEMORY ADDRESS
HIGH MEMORY ADDRESS
- a.k.a Code Segment
- Executable Instructions
- Read-only
DYNAMIC MEMORY ALLOCATION
PROGRAM MEMORY
.TEXT
.DATA
HEAP
STACK
.BSS
LOW MEMORY ADDRESS
HIGH MEMORY ADDRESS
- a.k.a initialized data
- global variables w/ pre-defined value
- static variables w/ pre-defined value
within the functions
keeps its value between invocations
#include <stdio.h>
void foo()
{
int a = 10;
static int sa = 10;
a += 5;
sa += 5;
printf("a = %d, sa = %dn", a, sa);
}
int main()
{
int i;
for (i = 0; i < 10; ++i)
foo();
}
a = 15, sa = 15
a = 15, sa = 20
a = 15, sa = 25
a = 15, sa = 30
a = 15, sa = 35
a = 15, sa = 40
a = 15, sa = 45
a = 15, sa = 50
a = 15, sa = 55
a = 15, sa = 60
DYNAMIC MEMORY ALLOCATION
PROGRAM MEMORY
.TEXT
.DATA
HEAP
STACK
.BSS
LOW MEMORY ADDRESS
HIGH MEMORY ADDRESS
- a.k.a uninitialized data
- global variables w/o pre-defined value
- static variables w/o predefined value
within the functions
DYNAMIC MEMORY ALLOCATION
PROGRAM MEMORY
.TEXT
.DATA
HEAP
STACK
.BSS
LOW MEMORY ADDRESS
HIGH MEMORY ADDRESS
- grows low->high
- malloc, calloc, realloc, free
- shared by all
- threads,
- shared libraries
- dynamically loaded modules
DYNAMIC MEMORY ALLOCATION
PROGRAM MEMORY
.TEXT
.DATA
HEAP
STACK
.BSS
LOW MEMORY ADDRESS
HIGH MEMORY ADDRESS
- LIFO
- On x86, stack grows Higher->Lower
- What’s stored in Stack:
- Function arguments,
- Local variables
- Function return address
- PUSH adds to the top, POP removes from top
} Stack Frame
#include <stdio.h>
int x = 20;
int y;
int main()
{
char buf[5];
for (i = 0; i < 10; ++i)
foo(15);
}
void foo(int arg)
{
int a = 10;
static int sa = 10;
sa += 5;
char* int = malloc(10 * sizeof(int));
printf("sa = %dn”,sa);
}
DYNAMIC MEMORY ALLOCATION
PROGRAM MEMORY
.TEXT
.DATA
HEAP
STACK
.BSS
LOW MEMORY ADDRESS
HIGH MEMORY ADDRESS
double multiplyByTwo (double input) {
double twice = input * 2.0;
return twice;
}
int main (int argc, char *argv[])
{
int age = 30;
double salary = 12345.67;
double myList[3] = {1.2, 2.3, 3.4};
printf("salary is %.3fn", multiplyByTwo(salary));
return 0;
}
DYNAMIC MEMORY ALLOCATION
double *multiplyByTwo (double *input) {
double *twice = malloc(sizeof(double));
*twice = *input * 2.0;
return twice;
}
int main (int argc, char *argv[])
{
int *age = malloc(sizeof(int));
*age = 30;
double *salary = malloc(sizeof(double));
*salary = 12345.67;
double *myList = malloc(3 * sizeof(double));
myList[0] = 1.2;
myList[1] = 2.3;
myList[2] = 3.4;
double *twiceSalary = multiplyByTwo(salary);
printf(“salary is %.3fn", *twiceSalary);
free(age);
free(salary);
free(myList);
free(twiceSalary);
return 0;
}
DEFINE VARIABLES ON STACK VS HEAP
DYNAMIC MEMORY ALLOCATION
STACK
LOW MEMORY ADDRESS
HIGH MEMORY ADDRESS
- Stack Pointer (SP, ESP) tracks the top of the
stack (last address on the stack)
- Changes during the execution (PUSH&POP)
- Base Pointer (BP, EBP) a.k.a Frame Pointer (FP)
shows the bottom of the stack
- Fixed during the execution
- local variables and arguments are
referenced by their offset from EBP
EBP
ARG 1
ARG 2
LOCAL VAR 2
LOCAL VAR 1
EBP + 8
EBP + 12
EBP - 8
EBP - 4
ESP
RETURN ADDREBP + 4
DYNAMIC MEMORY ALLOCATION
STACK
LOW MEMORY ADDRESS
HIGH MEMORY ADDRESS
int main()
{
function(1,2,3);
}
void function(int a, int b, int c)
{
char buffer1[5];
}
<function>:
push ebp
mov ebp,esp
sub esp,0x10
call 11ba <__x86.get_pc_thunk.ax>
add eax,0x2e6c
nop
leave
ret
<main>:
push ebp
mov ebp,esp
call 11ba <__x86.get_pc_thunk.ax>
add eax,0x2e5c
push 0x3
push 0x2
push 0x1
call 1189 <function>
add esp,0xc
nop
leave
ret
EBP - MAIN ESP
DYNAMIC MEMORY ALLOCATION
STACK
LOW MEMORY ADDRESS
HIGH MEMORY ADDRESS
int main()
{
function(1,2,3);
}
void function(int a, int b, int c)
{
char buffer1[5];
}
ARG 3
EBP - MAIN
<function>:
push ebp
mov ebp,esp
sub esp,0x10
call 11ba <__x86.get_pc_thunk.ax>
add eax,0x2e6c
nop
leave
ret
<main>:
push ebp
mov ebp,esp
call 11ba <__x86.get_pc_thunk.ax>
add eax,0x2e5c
push 0x3
push 0x2
push 0x1
call 1189 <function>
add esp,0xc
nop
leave
ret
ESP
DYNAMIC MEMORY ALLOCATION
STACK
LOW MEMORY ADDRESS
HIGH MEMORY ADDRESS
int main()
{
function(1,2,3);
}
void function(int a, int b, int c)
{
char buffer1[5];
}
ARG 3
EBP - MAIN
<function>:
push ebp
mov ebp,esp
sub esp,0x10
call 11ba <__x86.get_pc_thunk.ax>
add eax,0x2e6c
nop
leave
ret
<main>:
push ebp
mov ebp,esp
call 11ba <__x86.get_pc_thunk.ax>
add eax,0x2e5c
push 0x3
push 0x2
push 0x1
call 1189 <function>
add esp,0xc
nop
leave
ret
ARG 2 ESP
DYNAMIC MEMORY ALLOCATION
STACK
LOW MEMORY ADDRESS
HIGH MEMORY ADDRESS
int main()
{
function(1,2,3);
}
void function(int a, int b, int c)
{
char buffer1[5];
}
ARG 3
EBP - MAIN
<function>:
push ebp
mov ebp,esp
sub esp,0x10
call 11ba <__x86.get_pc_thunk.ax>
add eax,0x2e6c
nop
leave
ret
<main>:
push ebp
mov ebp,esp
call 11ba <__x86.get_pc_thunk.ax>
add eax,0x2e5c
push 0x3
push 0x2
push 0x1
call 1189 <function>
add esp,0xc
nop
leave
ret
ARG 2
ARG 1 ESP
DYNAMIC MEMORY ALLOCATION
STACK
LOW MEMORY ADDRESS
HIGH MEMORY ADDRESS
int main()
{
function(1,2,3);
}
void function(int a, int b, int c)
{
char buffer1[5];
}
ARG 3
EBP - MAIN
<function>:
push ebp
mov ebp,esp
sub esp,0x10
call 11ba <__x86.get_pc_thunk.ax>
add eax,0x2e6c
nop
leave
ret
<main>:
push ebp
mov ebp,esp
call 11ba <__x86.get_pc_thunk.ax>
add eax,0x2e5c
push 0x3
push 0x2
push 0x1
call 1189 <function>
add esp,0xc
nop
leave
ret
ARG 2
ARG 1
RETURN ADDR ESP
EIP
{
PUSH EIP
JMP function
DYNAMIC MEMORY ALLOCATION
STACK
LOW MEMORY ADDRESS
HIGH MEMORY ADDRESS
int main()
{
function(1,2,3);
}
void function(int a, int b, int c)
{
char buffer1[5];
}
ARG 3
EBP - MAIN
<function>:
push ebp
mov ebp,esp
sub esp,0x10
call 11ba <__x86.get_pc_thunk.ax>
add eax,0x2e6c
nop
leave
ret
<main>:
push ebp
mov ebp,esp
call 11ba <__x86.get_pc_thunk.ax>
add eax,0x2e5c
push 0x3
push 0x2
push 0x1
call 1189 <function>
add esp,0xc
nop
leave
ret
ARG 2
ARG 1
RETURN ADDR
EBP - FUNCTION ESP
DYNAMIC MEMORY ALLOCATION
STACK
LOW MEMORY ADDRESS
HIGH MEMORY ADDRESS
EBP - FUNCTION
ARG 1
ARG 2
EBP + 8
EBP + 12
EBP - 8
EBP - 4
RETURN ADDREBP + 4
int main()
{
function(1,2,3);
}
void function(int a, int b, int c)
{
char buffer1[5];
}
ARG 3EBP + 16
EBP - 12
EBP - 16 ESP
EBP - MAIN
<function>:
push ebp
mov ebp,esp
sub esp,0x10
call 11ba <__x86.get_pc_thunk.ax>
add eax,0x2e6c
nop
leave
ret
<main>:
push ebp
mov ebp,esp
call 11ba <__x86.get_pc_thunk.ax>
add eax,0x2e5c
push 0x3
push 0x2
push 0x1
call 1189 <function>
add esp,0xc
nop
leave
ret
DYNAMIC MEMORY ALLOCATIONTEXT
STACK
LOW MEMORY ADDRESS
HIGH MEMORY ADDRESS
ARG 1
ARG 2
RETURN ADDR
int main()
{
function(1,2,3);
}
void function(int a, int b, int c)
{
char buffer1[5];
}
ARG 3
EBP - MAIN
<function>:
push ebp
mov ebp,esp
sub esp,0x10
call 11ba <__x86.get_pc_thunk.ax>
add eax,0x2e6c
nop
leave
ret
<main>:
push ebp
mov ebp,esp
call 11ba <__x86.get_pc_thunk.ax>
add eax,0x2e5c
push 0x3
push 0x2
push 0x1
call 1189 <function>
add esp,0xc
nop
leave
ret
ESP
{
RESTORE ALLOCATED MEMORY
POP EBP
POP RETURN ADDR
JMP RETURN ADDR
DYNAMIC MEMORY ALLOCATION
STACK
LOW MEMORY ADDRESS
HIGH MEMORY ADDRESS
ARG 1
ARG 2
int main()
{
function(1,2,3);
}
void function(int a, int b, int c)
{
char buffer1[5];
}
ARG 3
EBP - MAIN
<function>:
push ebp
mov ebp,esp
sub esp,0x10
call 11ba <__x86.get_pc_thunk.ax>
add eax,0x2e6c
nop
leave
ret
<main>:
push ebp
mov ebp,esp
call 11ba <__x86.get_pc_thunk.ax>
add eax,0x2e5c
push 0x3
push 0x2
push 0x1
call 1189 <function>
add esp,0xc
nop
leave
ret
ESP
DYNAMIC MEMORY ALLOCATION
STACK
LOW MEMORY ADDRESS
HIGH MEMORY ADDRESS
int main()
{
function(1,2,3);
}
void function(int a, int b, int c)
{
char buffer1[5];
}
EBP - MAIN
<function>:
push ebp
mov ebp,esp
sub esp,0x10
call 11ba <__x86.get_pc_thunk.ax>
add eax,0x2e6c
nop
leave
ret
<main>:
push ebp
mov ebp,esp
call 11ba <__x86.get_pc_thunk.ax>
add eax,0x2e5c
push 0x3
push 0x2
push 0x1
call 1189 <function>
add esp,0xc
nop
leave
ret
ESP
TEXT
STACK
LOW MEMORY ADDRESS
HIGH MEMORY ADDRESS
EBP - MAIN
00001199 <function>:
1199:55 push ebp
119a:89 e5 mov ebp,esp
119c:53 push ebx
119d:83 ec 14 sub esp,0x14
…
11aa:83 ec 08 sub esp,0x8
11ad:ff 75 08 push DWORD PTR [ebp+0x8]
11b0:8d 55 e8 lea edx,[ebp-0x18]
11b3:52 push edx
11b4:89 c3 mov ebx,eax
11b6:e8 75 fe ff ff call 1030 <strcpy@plt>
11bb:83 c4 10 add esp,0x10
11be:90 nop
11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4]
11c2:c9 leave
11c3:c3 ret
000011c4 <main>:
…
11ce:55 push ebp
11cf:89 e5 mov ebp,esp
11d1:51 push ecx
11d2:81 ec 14 01 00 00 sub esp,0x114
…
11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0
11e9:eb 12 jmp 11fd <main+0x39>
11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c]
11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc]
11f4:01 d0 add eax,edx
11f6:c6 00 41 mov BYTE PTR [eax],0x41
11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1
11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe
1204:7e e5 jle 11eb <main+0x27>
1206:83 ec 0c sub esp,0xc
1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c]
120f:50 push eax
1210:e8 84 ff ff ff call 1199 <function>
1215:83 c4 10 add esp,0x10
1218:90 nop
1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4]
121c:c9 leave
121d:8d 61 fc lea esp,[ecx-0x4]
1220:c3 ret
ESP
void function(char *str)
{
char buffer[16];
strcpy(buffer,str);
}
int main()
{
char large_string[256];
int i;
for(i = 0; i < 255; i++)
large_string[i] = 'A';
function(large_string);
}
TEXT
STACK
LOW MEMORY ADDRESS
HIGH MEMORY ADDRESS
EBP - MAIN
00001199 <function>:
1199:55 push ebp
119a:89 e5 mov ebp,esp
119c:53 push ebx
119d:83 ec 14 sub esp,0x14
…
11aa:83 ec 08 sub esp,0x8
11ad:ff 75 08 push DWORD PTR [ebp+0x8]
11b0:8d 55 e8 lea edx,[ebp-0x18]
11b3:52 push edx
11b4:89 c3 mov ebx,eax
11b6:e8 75 fe ff ff call 1030 <strcpy@plt>
11bb:83 c4 10 add esp,0x10
11be:90 nop
11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4]
11c2:c9 leave
11c3:c3 ret
000011c4 <main>:
…
11ce:55 push ebp
11cf:89 e5 mov ebp,esp
11d1:51 push ecx
11d2:81 ec 14 01 00 00 sub esp,0x114
…
11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0
11e9:eb 12 jmp 11fd <main+0x39>
11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c]
11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc]
11f4:01 d0 add eax,edx
11f6:c6 00 41 mov BYTE PTR [eax],0x41
11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1
11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe
1204:7e e5 jle 11eb <main+0x27>
1206:83 ec 0c sub esp,0xc
1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c]
120f:50 push eax
1210:e8 84 ff ff ff call 1199 <function>
1215:83 c4 10 add esp,0x10
1218:90 nop
1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4]
121c:c9 leave
121d:8d 61 fc lea esp,[ecx-0x4]
1220:c3 ret
ECX ESP
TEXT
STACK
LOW MEMORY ADDRESS
HIGH MEMORY ADDRESS
EBP - MAIN
00001199 <function>:
1199:55 push ebp
119a:89 e5 mov ebp,esp
119c:53 push ebx
119d:83 ec 14 sub esp,0x14
…
11aa:83 ec 08 sub esp,0x8
11ad:ff 75 08 push DWORD PTR [ebp+0x8]
11b0:8d 55 e8 lea edx,[ebp-0x18]
11b3:52 push edx
11b4:89 c3 mov ebx,eax
11b6:e8 75 fe ff ff call 1030 <strcpy@plt>
11bb:83 c4 10 add esp,0x10
11be:90 nop
11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4]
11c2:c9 leave
11c3:c3 ret
000011c4 <main>:
…
11ce:55 push ebp
11cf:89 e5 mov ebp,esp
11d1:51 push ecx
11d2:81 ec 14 01 00 00 sub esp,0x114
…
11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0
11e9:eb 12 jmp 11fd <main+0x39>
11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c]
11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc]
11f4:01 d0 add eax,edx
11f6:c6 00 41 mov BYTE PTR [eax],0x41
11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1
11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe
1204:7e e5 jle 11eb <main+0x27>
1206:83 ec 0c sub esp,0xc
1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c]
120f:50 push eax
1210:e8 84 ff ff ff call 1199 <function>
1215:83 c4 10 add esp,0x10
1218:90 nop
1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4]
121c:c9 leave
121d:8d 61 fc lea esp,[ecx-0x4]
1220:c3 ret
ECX
EBP - 280 ESP
EBP - 4
TEXT
STACK
LOW MEMORY ADDRESS
HIGH MEMORY ADDRESS
EBP - MAIN
00001199 <function>:
1199:55 push ebp
119a:89 e5 mov ebp,esp
119c:53 push ebx
119d:83 ec 14 sub esp,0x14
…
11aa:83 ec 08 sub esp,0x8
11ad:ff 75 08 push DWORD PTR [ebp+0x8]
11b0:8d 55 e8 lea edx,[ebp-0x18]
11b3:52 push edx
11b4:89 c3 mov ebx,eax
11b6:e8 75 fe ff ff call 1030 <strcpy@plt>
11bb:83 c4 10 add esp,0x10
11be:90 nop
11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4]
11c2:c9 leave
11c3:c3 ret
000011c4 <main>:
…
11ce:55 push ebp
11cf:89 e5 mov ebp,esp
11d1:51 push ecx
11d2:81 ec 14 01 00 00 sub esp,0x114
…
11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0
11e9:eb 12 jmp 11fd <main+0x39>
11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c]
11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc]
11f4:01 d0 add eax,edx
11f6:c6 00 41 mov BYTE PTR [eax],0x41
11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1
11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe
1204:7e e5 jle 11eb <main+0x27>
1206:83 ec 0c sub esp,0xc
1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c]
120f:50 push eax
1210:e8 84 ff ff ff call 1199 <function>
1215:83 c4 10 add esp,0x10
1218:90 nop
1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4]
121c:c9 leave
121d:8d 61 fc lea esp,[ecx-0x4]
1220:c3 ret
ECX
EBP - 280 ESP
EBP - 4
EBP - 8
EBP - 12 0x00 0x00 0x00 0x00
TEXT
STACK
LOW MEMORY ADDRESS
HIGH MEMORY ADDRESS
EBP - MAIN
00001199 <function>:
1199:55 push ebp
119a:89 e5 mov ebp,esp
119c:53 push ebx
119d:83 ec 14 sub esp,0x14
…
11aa:83 ec 08 sub esp,0x8
11ad:ff 75 08 push DWORD PTR [ebp+0x8]
11b0:8d 55 e8 lea edx,[ebp-0x18]
11b3:52 push edx
11b4:89 c3 mov ebx,eax
11b6:e8 75 fe ff ff call 1030 <strcpy@plt>
11bb:83 c4 10 add esp,0x10
11be:90 nop
11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4]
11c2:c9 leave
11c3:c3 ret
000011c4 <main>:
…
11ce:55 push ebp
11cf:89 e5 mov ebp,esp
11d1:51 push ecx
11d2:81 ec 14 01 00 00 sub esp,0x114
…
11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0
11e9:eb 12 jmp 11fd <main+0x39>
11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c]
11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc]
11f4:01 d0 add eax,edx
11f6:c6 00 41 mov BYTE PTR [eax],0x41
11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1
11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe
1204:7e e5 jle 11eb <main+0x27>
1206:83 ec 0c sub esp,0xc
1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c]
120f:50 push eax
1210:e8 84 ff ff ff call 1199 <function>
1215:83 c4 10 add esp,0x10
1218:90 nop
1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4]
121c:c9 leave
121d:8d 61 fc lea esp,[ecx-0x4]
1220:c3 ret
ECX
EBP - 280 ESP
EBP - 4
EBP - 8
EBP - 12 0x00 0x00 0x00 0x00
TEXT
STACK
LOW MEMORY ADDRESS
HIGH MEMORY ADDRESS
EBP - MAIN
00001199 <function>:
1199:55 push ebp
119a:89 e5 mov ebp,esp
119c:53 push ebx
119d:83 ec 14 sub esp,0x14
…
11aa:83 ec 08 sub esp,0x8
11ad:ff 75 08 push DWORD PTR [ebp+0x8]
11b0:8d 55 e8 lea edx,[ebp-0x18]
11b3:52 push edx
11b4:89 c3 mov ebx,eax
11b6:e8 75 fe ff ff call 1030 <strcpy@plt>
11bb:83 c4 10 add esp,0x10
11be:90 nop
11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4]
11c2:c9 leave
11c3:c3 ret
000011c4 <main>:
…
11ce:55 push ebp
11cf:89 e5 mov ebp,esp
11d1:51 push ecx
11d2:81 ec 14 01 00 00 sub esp,0x114
…
11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0
11e9:eb 12 jmp 11fd <main+0x39>
11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c]
11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc]
11f4:01 d0 add eax,edx
11f6:c6 00 41 mov BYTE PTR [eax],0x41
11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1
11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe
1204:7e e5 jle 11eb <main+0x27>
1206:83 ec 0c sub esp,0xc
1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c]
120f:50 push eax
1210:e8 84 ff ff ff call 1199 <function>
1215:83 c4 10 add esp,0x10
1218:90 nop
1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4]
121c:c9 leave
121d:8d 61 fc lea esp,[ecx-0x4]
1220:c3 ret
ECX
EBP - 280 ESP
EBP - 4
EBP - 8
EBP - 12 0x00 0x00 0x00 0x00
TEXT
STACK
LOW MEMORY ADDRESS
HIGH MEMORY ADDRESS
EBP - MAIN
00001199 <function>:
1199:55 push ebp
119a:89 e5 mov ebp,esp
119c:53 push ebx
119d:83 ec 14 sub esp,0x14
…
11aa:83 ec 08 sub esp,0x8
11ad:ff 75 08 push DWORD PTR [ebp+0x8]
11b0:8d 55 e8 lea edx,[ebp-0x18]
11b3:52 push edx
11b4:89 c3 mov ebx,eax
11b6:e8 75 fe ff ff call 1030 <strcpy@plt>
11bb:83 c4 10 add esp,0x10
11be:90 nop
11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4]
11c2:c9 leave
11c3:c3 ret
000011c4 <main>:
…
11ce:55 push ebp
11cf:89 e5 mov ebp,esp
11d1:51 push ecx
11d2:81 ec 14 01 00 00 sub esp,0x114
…
11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0
11e9:eb 12 jmp 11fd <main+0x39>
11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c]
11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc]
11f4:01 d0 add eax,edx
11f6:c6 00 41 mov BYTE PTR [eax],0x41
11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1
11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe
1204:7e e5 jle 11eb <main+0x27>
1206:83 ec 0c sub esp,0xc
1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c]
120f:50 push eax
1210:e8 84 ff ff ff call 1199 <function>
1215:83 c4 10 add esp,0x10
1218:90 nop
1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4]
121c:c9 leave
121d:8d 61 fc lea esp,[ecx-0x4]
1220:c3 ret
ECX
EBP - 280 ESP
EBP - 4
EBP - 8
EBP - 12 0x00 0x00 0x00 0x00
TEXT
STACK
LOW MEMORY ADDRESS
HIGH MEMORY ADDRESS
EBP - MAIN
00001199 <function>:
1199:55 push ebp
119a:89 e5 mov ebp,esp
119c:53 push ebx
119d:83 ec 14 sub esp,0x14
…
11aa:83 ec 08 sub esp,0x8
11ad:ff 75 08 push DWORD PTR [ebp+0x8]
11b0:8d 55 e8 lea edx,[ebp-0x18]
11b3:52 push edx
11b4:89 c3 mov ebx,eax
11b6:e8 75 fe ff ff call 1030 <strcpy@plt>
11bb:83 c4 10 add esp,0x10
11be:90 nop
11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4]
11c2:c9 leave
11c3:c3 ret
000011c4 <main>:
…
11ce:55 push ebp
11cf:89 e5 mov ebp,esp
11d1:51 push ecx
11d2:81 ec 14 01 00 00 sub esp,0x114
…
11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0
11e9:eb 12 jmp 11fd <main+0x39>
11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c]
11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc]
11f4:01 d0 add eax,edx
11f6:c6 00 41 mov BYTE PTR [eax],0x41
11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1
11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe
1204:7e e5 jle 11eb <main+0x27>
1206:83 ec 0c sub esp,0xc
1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c]
120f:50 push eax
1210:e8 84 ff ff ff call 1199 <function>
1215:83 c4 10 add esp,0x10
1218:90 nop
1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4]
121c:c9 leave
121d:8d 61 fc lea esp,[ecx-0x4]
1220:c3 ret
ECX
EBP - 280 ESP
EBP - 4
EBP - 8
EBP - 12 0x00 0x00 0x00 0x00
EBP - 276
EBP - 272
EBP - 268
TEXT
STACK
LOW MEMORY ADDRESS
HIGH MEMORY ADDRESS
EBP - MAIN
00001199 <function>:
1199:55 push ebp
119a:89 e5 mov ebp,esp
119c:53 push ebx
119d:83 ec 14 sub esp,0x14
…
11aa:83 ec 08 sub esp,0x8
11ad:ff 75 08 push DWORD PTR [ebp+0x8]
11b0:8d 55 e8 lea edx,[ebp-0x18]
11b3:52 push edx
11b4:89 c3 mov ebx,eax
11b6:e8 75 fe ff ff call 1030 <strcpy@plt>
11bb:83 c4 10 add esp,0x10
11be:90 nop
11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4]
11c2:c9 leave
11c3:c3 ret
000011c4 <main>:
…
11ce:55 push ebp
11cf:89 e5 mov ebp,esp
11d1:51 push ecx
11d2:81 ec 14 01 00 00 sub esp,0x114
…
11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0
11e9:eb 12 jmp 11fd <main+0x39>
11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c]
11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc]
11f4:01 d0 add eax,edx
11f6:c6 00 41 mov BYTE PTR [eax],0x41
11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1
11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe
1204:7e e5 jle 11eb <main+0x27>
1206:83 ec 0c sub esp,0xc
1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c]
120f:50 push eax
1210:e8 84 ff ff ff call 1199 <function>
1215:83 c4 10 add esp,0x10
1218:90 nop
1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4]
121c:c9 leave
121d:8d 61 fc lea esp,[ecx-0x4]
1220:c3 ret
ECX
EBP - 280 ESP
EBP - 4
EBP - 8
EBP - 12 0x00 0x00 0x00 0x00
EBP - 276
EBP - 272
EBP - 268 0x41
TEXT
STACK
LOW MEMORY ADDRESS
HIGH MEMORY ADDRESS
EBP - MAIN
00001199 <function>:
1199:55 push ebp
119a:89 e5 mov ebp,esp
119c:53 push ebx
119d:83 ec 14 sub esp,0x14
…
11aa:83 ec 08 sub esp,0x8
11ad:ff 75 08 push DWORD PTR [ebp+0x8]
11b0:8d 55 e8 lea edx,[ebp-0x18]
11b3:52 push edx
11b4:89 c3 mov ebx,eax
11b6:e8 75 fe ff ff call 1030 <strcpy@plt>
11bb:83 c4 10 add esp,0x10
11be:90 nop
11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4]
11c2:c9 leave
11c3:c3 ret
000011c4 <main>:
…
11ce:55 push ebp
11cf:89 e5 mov ebp,esp
11d1:51 push ecx
11d2:81 ec 14 01 00 00 sub esp,0x114
…
11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0
11e9:eb 12 jmp 11fd <main+0x39>
11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c]
11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc]
11f4:01 d0 add eax,edx
11f6:c6 00 41 mov BYTE PTR [eax],0x41
11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1
11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe
1204:7e e5 jle 11eb <main+0x27>
1206:83 ec 0c sub esp,0xc
1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c]
120f:50 push eax
1210:e8 84 ff ff ff call 1199 <function>
1215:83 c4 10 add esp,0x10
1218:90 nop
1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4]
121c:c9 leave
121d:8d 61 fc lea esp,[ecx-0x4]
1220:c3 ret
ECX
EBP - 280 ESP
EBP - 4
EBP - 8
EBP - 12 0x00 0x00 0x00 0x01
EBP - 276
EBP - 272
EBP - 268 0x41
TEXT
STACK
LOW MEMORY ADDRESS
HIGH MEMORY ADDRESS
EBP - MAIN
00001199 <function>:
1199:55 push ebp
119a:89 e5 mov ebp,esp
119c:53 push ebx
119d:83 ec 14 sub esp,0x14
…
11aa:83 ec 08 sub esp,0x8
11ad:ff 75 08 push DWORD PTR [ebp+0x8]
11b0:8d 55 e8 lea edx,[ebp-0x18]
11b3:52 push edx
11b4:89 c3 mov ebx,eax
11b6:e8 75 fe ff ff call 1030 <strcpy@plt>
11bb:83 c4 10 add esp,0x10
11be:90 nop
11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4]
11c2:c9 leave
11c3:c3 ret
000011c4 <main>:
…
11ce:55 push ebp
11cf:89 e5 mov ebp,esp
11d1:51 push ecx
11d2:81 ec 14 01 00 00 sub esp,0x114
…
11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0
11e9:eb 12 jmp 11fd <main+0x39>
11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c]
11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc]
11f4:01 d0 add eax,edx
11f6:c6 00 41 mov BYTE PTR [eax],0x41
11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1
11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe
1204:7e e5 jle 11eb <main+0x27>
1206:83 ec 0c sub esp,0xc
1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c]
120f:50 push eax
1210:e8 84 ff ff ff call 1199 <function>
1215:83 c4 10 add esp,0x10
1218:90 nop
1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4]
121c:c9 leave
121d:8d 61 fc lea esp,[ecx-0x4]
1220:c3 ret
ECX
EBP - 280 ESP
EBP - 4
EBP - 8
EBP - 12 0x00 0x00 0x00 0xff
EBP - 276
EBP - 272
EBP - 268 0x41
}for loop
0x410x410x41
0x410x410x410x41
0x410x410x410x41
.
.
.
0x410x410x410x41
TEXT
STACK
LOW MEMORY ADDRESS
HIGH MEMORY ADDRESS
EBP - MAIN
00001199 <function>:
1199:55 push ebp
119a:89 e5 mov ebp,esp
119c:53 push ebx
119d:83 ec 14 sub esp,0x14
…
11aa:83 ec 08 sub esp,0x8
11ad:ff 75 08 push DWORD PTR [ebp+0x8]
11b0:8d 55 e8 lea edx,[ebp-0x18]
11b3:52 push edx
11b4:89 c3 mov ebx,eax
11b6:e8 75 fe ff ff call 1030 <strcpy@plt>
11bb:83 c4 10 add esp,0x10
11be:90 nop
11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4]
11c2:c9 leave
11c3:c3 ret
000011c4 <main>:
…
11ce:55 push ebp
11cf:89 e5 mov ebp,esp
11d1:51 push ecx
11d2:81 ec 14 01 00 00 sub esp,0x114
…
11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0
11e9:eb 12 jmp 11fd <main+0x39>
11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c]
11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc]
11f4:01 d0 add eax,edx
11f6:c6 00 41 mov BYTE PTR [eax],0x41
11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1
11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe
1204:7e e5 jle 11eb <main+0x27>
1206:83 ec 0c sub esp,0xc
1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c]
120f:50 push eax
1210:e8 84 ff ff ff call 1199 <function>
1215:83 c4 10 add esp,0x10
1218:90 nop
1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4]
121c:c9 leave
121d:8d 61 fc lea esp,[ecx-0x4]
1220:c3 ret
ECX
EBP - 280
ESP
EBP - 4
EBP - 8
EBP - 12 0x00 0x00 0x00 0xff
EBP - 276
EBP - 272
EBP - 268 0x410x410x410x41
0x410x410x410x41
0x410x410x410x41
.
.
.
0x410x410x410x41
EBP - 284
EBP - 288
EBP - 292
TEXT
STACK
LOW MEMORY ADDRESS
HIGH MEMORY ADDRESS
EBP - MAIN
00001199 <function>:
1199:55 push ebp
119a:89 e5 mov ebp,esp
119c:53 push ebx
119d:83 ec 14 sub esp,0x14
…
11aa:83 ec 08 sub esp,0x8
11ad:ff 75 08 push DWORD PTR [ebp+0x8]
11b0:8d 55 e8 lea edx,[ebp-0x18]
11b3:52 push edx
11b4:89 c3 mov ebx,eax
11b6:e8 75 fe ff ff call 1030 <strcpy@plt>
11bb:83 c4 10 add esp,0x10
11be:90 nop
11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4]
11c2:c9 leave
11c3:c3 ret
000011c4 <main>:
…
11ce:55 push ebp
11cf:89 e5 mov ebp,esp
11d1:51 push ecx
11d2:81 ec 14 01 00 00 sub esp,0x114
…
11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0
11e9:eb 12 jmp 11fd <main+0x39>
11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c]
11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc]
11f4:01 d0 add eax,edx
11f6:c6 00 41 mov BYTE PTR [eax],0x41
11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1
11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe
1204:7e e5 jle 11eb <main+0x27>
1206:83 ec 0c sub esp,0xc
1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c]
120f:50 push eax
1210:e8 84 ff ff ff call 1199 <function>
1215:83 c4 10 add esp,0x10
1218:90 nop
1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4]
121c:c9 leave
121d:8d 61 fc lea esp,[ecx-0x4]
1220:c3 ret
ECXEBP - 4
EBP - 8
EBP - 12 0x00 0x00 0x00 0xff
EBP - 268 0x410x410x410x41
0x410x410x410x41
0x410x410x410x41
.
.
.
0x410x410x410x41
ADDRESS OF EBP-267 ESPEBP - 296
LOW MEMORY ADDRESS
HIGH MEMORY ADDRESS
EBP - MAIN
00001199 <function>:
1199:55 push ebp
119a:89 e5 mov ebp,esp
119c:53 push ebx
119d:83 ec 14 sub esp,0x14
…
11aa:83 ec 08 sub esp,0x8
11ad:ff 75 08 push DWORD PTR [ebp+0x8]
11b0:8d 55 e8 lea edx,[ebp-0x18]
11b3:52 push edx
11b4:89 c3 mov ebx,eax
11b6:e8 75 fe ff ff call 1030 <strcpy@plt>
11bb:83 c4 10 add esp,0x10
11be:90 nop
11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4]
11c2:c9 leave
11c3:c3 ret
000011c4 <main>:
…
11ce:55 push ebp
11cf:89 e5 mov ebp,esp
11d1:51 push ecx
11d2:81 ec 14 01 00 00 sub esp,0x114
…
11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0
11e9:eb 12 jmp 11fd <main+0x39>
11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c]
11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc]
11f4:01 d0 add eax,edx
11f6:c6 00 41 mov BYTE PTR [eax],0x41
11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1
11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe
1204:7e e5 jle 11eb <main+0x27>
1206:83 ec 0c sub esp,0xc
1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c]
120f:50 push eax
1210:e8 84 ff ff ff call 1199 <function>
1215:83 c4 10 add esp,0x10
1218:90 nop
1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4]
121c:c9 leave
121d:8d 61 fc lea esp,[ecx-0x4]
1220:c3 ret
ECXEBP - 4
EBP - 8
EBP - 12 0x00 0x00 0x00 0xff
EBP - 268 0x410x410x410x41
0x410x410x410x41
0x410x410x410x41
.
.
.
0x410x410x410x41
RETURN ADDR ESP
ADDRESS OF EBP-267EBP - 296
00001199 <function>:
1199:55 push ebp
119a:89 e5 mov ebp,esp
119c:53 push ebx
119d:83 ec 14 sub esp,0x14
…
11aa:83 ec 08 sub esp,0x8
11ad:ff 75 08 push DWORD PTR [ebp+0x8]
11b0:8d 55 e8 lea edx,[ebp-0x18]
11b3:52 push edx
11b4:89 c3 mov ebx,eax
11b6:e8 75 fe ff ff call 1030 <strcpy@plt>
11bb:83 c4 10 add esp,0x10
11be:90 nop
11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4]
11c2:c9 leave
11c3:c3 ret
000011c4 <main>:
…
11ce:55 push ebp
11cf:89 e5 mov ebp,esp
11d1:51 push ecx
11d2:81 ec 14 01 00 00 sub esp,0x114
…
11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0
11e9:eb 12 jmp 11fd <main+0x39>
11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c]
11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc]
11f4:01 d0 add eax,edx
11f6:c6 00 41 mov BYTE PTR [eax],0x41
11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1
11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe
1204:7e e5 jle 11eb <main+0x27>
1206:83 ec 0c sub esp,0xc
1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c]
120f:50 push eax
1210:e8 84 ff ff ff call 1199 <function>
1215:83 c4 10 add esp,0x10
1218:90 nop
1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4]
121c:c9 leave
121d:8d 61 fc lea esp,[ecx-0x4]
1220:c3 ret
HIGH MEMORY ADDRESS
EBP - MAIN
ECX
0x00 0x00 0x00 0xff
0x410x410x410x41
0x410x410x410x41
0x410x410x410x41
.
.
.
0x410x410x410x41
EBX
RETURN ADDR
ADDRESS OF LARGE_STRING
EBP - 4 ESP
EBP - FUNCTION
00001199 <function>:
1199:55 push ebp
119a:89 e5 mov ebp,esp
119c:53 push ebx
119d:83 ec 14 sub esp,0x14
…
11aa:83 ec 08 sub esp,0x8
11ad:ff 75 08 push DWORD PTR [ebp+0x8]
11b0:8d 55 e8 lea edx,[ebp-0x18]
11b3:52 push edx
11b4:89 c3 mov ebx,eax
11b6:e8 75 fe ff ff call 1030 <strcpy@plt>
11bb:83 c4 10 add esp,0x10
11be:90 nop
11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4]
11c2:c9 leave
11c3:c3 ret
000011c4 <main>:
…
11ce:55 push ebp
11cf:89 e5 mov ebp,esp
11d1:51 push ecx
11d2:81 ec 14 01 00 00 sub esp,0x114
…
11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0
11e9:eb 12 jmp 11fd <main+0x39>
11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c]
11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc]
11f4:01 d0 add eax,edx
11f6:c6 00 41 mov BYTE PTR [eax],0x41
11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1
11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe
1204:7e e5 jle 11eb <main+0x27>
1206:83 ec 0c sub esp,0xc
1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c]
120f:50 push eax
1210:e8 84 ff ff ff call 1199 <function>
1215:83 c4 10 add esp,0x10
1218:90 nop
1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4]
121c:c9 leave
121d:8d 61 fc lea esp,[ecx-0x4]
1220:c3 ret
HIGH MEMORY ADDRESS
EBP - MAIN
ECX
0x00 0x00 0x00 0xff
0x410x410x410x41
0x410x410x410x41
0x410x410x410x41
.
.
.
0x410x410x410x41
EBX
RETURN ADDR
ADDRESS OF LARGE_STRING
EBP - 4
.
.
.
EBP - 24
EBP - FUNCTION
ESP
00001199 <function>:
1199:55 push ebp
119a:89 e5 mov ebp,esp
119c:53 push ebx
119d:83 ec 14 sub esp,0x14
…
11aa:83 ec 08 sub esp,0x8
11ad:ff 75 08 push DWORD PTR [ebp+0x8]
11b0:8d 55 e8 lea edx,[ebp-0x18]
11b3:52 push edx
11b4:89 c3 mov ebx,eax
11b6:e8 75 fe ff ff call 1030 <strcpy@plt>
11bb:83 c4 10 add esp,0x10
11be:90 nop
11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4]
11c2:c9 leave
11c3:c3 ret
000011c4 <main>:
…
11ce:55 push ebp
11cf:89 e5 mov ebp,esp
11d1:51 push ecx
11d2:81 ec 14 01 00 00 sub esp,0x114
…
11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0
11e9:eb 12 jmp 11fd <main+0x39>
11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c]
11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc]
11f4:01 d0 add eax,edx
11f6:c6 00 41 mov BYTE PTR [eax],0x41
11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1
11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe
1204:7e e5 jle 11eb <main+0x27>
1206:83 ec 0c sub esp,0xc
1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c]
120f:50 push eax
1210:e8 84 ff ff ff call 1199 <function>
1215:83 c4 10 add esp,0x10
1218:90 nop
1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4]
121c:c9 leave
121d:8d 61 fc lea esp,[ecx-0x4]
1220:c3 ret
HIGH MEMORY ADDRESS
EBP - MAIN
ECX
0x00 0x00 0x00 0xff
0x410x410x410x41
0x410x410x410x41
0x410x410x410x41
.
.
.
0x410x410x410x41
EBP - FUNCTION
EBX
RETURN ADDR
ADDRESS OF LARGE_STRING
EBP - 4
.
.
.
EBP - 24
EBP - 28
EBP - 32 ESP
00001199 <function>:
1199:55 push ebp
119a:89 e5 mov ebp,esp
119c:53 push ebx
119d:83 ec 14 sub esp,0x14
…
11aa:83 ec 08 sub esp,0x8
11ad:ff 75 08 push DWORD PTR [ebp+0x8]
11b0:8d 55 e8 lea edx,[ebp-0x18]
11b3:52 push edx
11b4:89 c3 mov ebx,eax
11b6:e8 75 fe ff ff call 1030 <strcpy@plt>
11bb:83 c4 10 add esp,0x10
11be:90 nop
11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4]
11c2:c9 leave
11c3:c3 ret
000011c4 <main>:
…
11ce:55 push ebp
11cf:89 e5 mov ebp,esp
11d1:51 push ecx
11d2:81 ec 14 01 00 00 sub esp,0x114
…
11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0
11e9:eb 12 jmp 11fd <main+0x39>
11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c]
11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc]
11f4:01 d0 add eax,edx
11f6:c6 00 41 mov BYTE PTR [eax],0x41
11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1
11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe
1204:7e e5 jle 11eb <main+0x27>
1206:83 ec 0c sub esp,0xc
1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c]
120f:50 push eax
1210:e8 84 ff ff ff call 1199 <function>
1215:83 c4 10 add esp,0x10
1218:90 nop
1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4]
121c:c9 leave
121d:8d 61 fc lea esp,[ecx-0x4]
1220:c3 ret
HIGH MEMORY ADDRESS
EBP - MAIN
ECX
0x00 0x00 0x00 0xff
0x410x410x410x41
0x410x410x410x41
0x410x410x410x41
.
.
.
0x410x410x410x41
EBP - FUNCTION
EBX
RETURN ADDR
ADDRESS OF LARGE_STRING
EBP - 4
.
.
.
EBP - 24
EBP - 28
EBP - 32 ESP
EBP + 8
ADDRESS OF LARGE_STRINGEBP - 36
00001199 <function>:
1199:55 push ebp
119a:89 e5 mov ebp,esp
119c:53 push ebx
119d:83 ec 14 sub esp,0x14
…
11aa:83 ec 08 sub esp,0x8
11ad:ff 75 08 push DWORD PTR [ebp+0x8]
11b0:8d 55 e8 lea edx,[ebp-0x18]
11b3:52 push edx
11b4:89 c3 mov ebx,eax
11b6:e8 75 fe ff ff call 1030 <strcpy@plt>
11bb:83 c4 10 add esp,0x10
11be:90 nop
11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4]
11c2:c9 leave
11c3:c3 ret
000011c4 <main>:
…
11ce:55 push ebp
11cf:89 e5 mov ebp,esp
11d1:51 push ecx
11d2:81 ec 14 01 00 00 sub esp,0x114
…
11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0
11e9:eb 12 jmp 11fd <main+0x39>
11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c]
11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc]
11f4:01 d0 add eax,edx
11f6:c6 00 41 mov BYTE PTR [eax],0x41
11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1
11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe
1204:7e e5 jle 11eb <main+0x27>
1206:83 ec 0c sub esp,0xc
1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c]
120f:50 push eax
1210:e8 84 ff ff ff call 1199 <function>
1215:83 c4 10 add esp,0x10
1218:90 nop
1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4]
121c:c9 leave
121d:8d 61 fc lea esp,[ecx-0x4]
1220:c3 ret
HIGH MEMORY ADDRESS
EBP - MAIN
ECX
0x00 0x00 0x00 0xff
0x410x410x410x41
0x410x410x410x41
0x410x410x410x41
.
.
.
0x410x410x410x41
EBP - FUNCTION
EBX
RETURN ADDR
ADDRESS OF LARGE_STRING
EBP - 4
16 BYTE BUFFER.
.
.
EBP - 24
EBP - 28
EBP - 32
EBP + 8
ADDRESS OF LARGE_STRINGEBP - 36
ADDRESS OF BUFFEREBP - 40 ESP
TEXT
STACK JUST BEFORE STRCPY
00001199 <function>:
1199:55 push ebp
119a:89 e5 mov ebp,esp
119c:53 push ebx
119d:83 ec 14 sub esp,0x14
…
11aa:83 ec 08 sub esp,0x8
11ad:ff 75 08 push DWORD PTR [ebp+0x8]
11b0:8d 55 e8 lea edx,[ebp-0x18]
11b3:52 push edx
11b4:89 c3 mov ebx,eax
11b6:e8 75 fe ff ff call 1030 <strcpy@plt>
11bb:83 c4 10 add esp,0x10
11be:90 nop
11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4]
11c2:c9 leave
11c3:c3 ret
000011c4 <main>:
…
11ce:55 push ebp
11cf:89 e5 mov ebp,esp
11d1:51 push ecx
11d2:81 ec 14 01 00 00 sub esp,0x114
…
11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0
11e9:eb 12 jmp 11fd <main+0x39>
11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c]
11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc]
11f4:01 d0 add eax,edx
11f6:c6 00 41 mov BYTE PTR [eax],0x41
11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1
11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe
1204:7e e5 jle 11eb <main+0x27>
1206:83 ec 0c sub esp,0xc
1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c]
120f:50 push eax
1210:e8 84 ff ff ff call 1199 <function>
1215:83 c4 10 add esp,0x10
1218:90 nop
1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4]
121c:c9 leave
121d:8d 61 fc lea esp,[ecx-0x4]
1220:c3 ret
HIGH MEMORY ADDRESS
EBP - MAIN
ECX
0x00 0x00 0x00 0xff
0x410x410x410x41
0x410x410x410x41
0x410x410x410x41
.
.
.
0x410x410x410x41
EBP - FUNCTION
EBX
RETURN ADDR
ADDRESS OF LARGE_STRING
EBP - 4
16 BYTE BUFFER.
.
.
EBP - 24
EBP - 28
EBP - 32
EBP + 8
ADDRESS OF LARGE_STRINGEBP - 36
ADDRESS OF BUFFEREBP - 40 ESP
0x410x410x410x41
0x410x410x410x41
0x410x410x410x41
0x410x410x410x41
0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41
0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41
DYNAMIC MEMORY ALLOCATION
STACK AFTER STRCPY
DYNAMIC MEMORY ALLOCATION
BUFFER OVERFLOW
int main()
{
char large_string[256];
int i;
for(i = 0; i < 255; i++)
large_string[i] = 'A';
char buffer[16];
strcpy(buffer, large_string);
}
int main(int argc, char **argv)
{
char buffer[16];
gets(buffer);
}
▸ What happens if you fill the buffer with a user input?
▸ User can enter an input with the length > 16
HIGH MEMORY ADDRESS
EBP - MAIN
ECX
0x00 0x00 0x00 0xff
0x410x410x410x41
0x410x410x410x41
0x410x410x410x41
.
.
.
0x410x410x410x41
EBP - FUNCTION
EBX
RETURN ADDR
ADDRESS OF LARGE_STRING
16 BYTE BUFFER
0x410x410x410x41
0x410x410x410x41
0x410x410x410x41
user codemyofAddress
0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41
USER CODE
BUFFER OVERFLOW
▸ Overwrite the return address
▸ Change the program flow
DYNAMIC MEMORY ALLOCATION

More Related Content

What's hot

Infrastructure As Code With Terraform
Infrastructure As Code With TerraformInfrastructure As Code With Terraform
Infrastructure As Code With TerraformMystic Coders, LLC
 
Ansible leveraging 2.0
Ansible leveraging 2.0Ansible leveraging 2.0
Ansible leveraging 2.0bcoca
 
Ultimate Unix Meetup Presentation
Ultimate Unix Meetup PresentationUltimate Unix Meetup Presentation
Ultimate Unix Meetup PresentationJacobMenke1
 
Linux-Fu for PHP Developers
Linux-Fu for PHP DevelopersLinux-Fu for PHP Developers
Linux-Fu for PHP DevelopersLorna Mitchell
 
Hacking ansible
Hacking ansibleHacking ansible
Hacking ansiblebcoca
 
PE Packers Used in Malicious Software - Part 2
PE Packers Used in Malicious Software - Part 2PE Packers Used in Malicious Software - Part 2
PE Packers Used in Malicious Software - Part 2amiable_indian
 
Setting up a HADOOP 2.2 cluster on CentOS 6
Setting up a HADOOP 2.2 cluster on CentOS 6Setting up a HADOOP 2.2 cluster on CentOS 6
Setting up a HADOOP 2.2 cluster on CentOS 6Manish Chopra
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐいHisateru Tanaka
 
How to Save, backup and restore IOS on Cisco router
How to Save, backup and restore IOS on Cisco routerHow to Save, backup and restore IOS on Cisco router
How to Save, backup and restore IOS on Cisco routertcpipguru
 
Web Audio API + AngularJS
Web Audio API + AngularJSWeb Audio API + AngularJS
Web Audio API + AngularJSChris Bateman
 
SecZone 2011: Scrubbing SAP clean with SOAP
SecZone 2011: Scrubbing SAP clean with SOAPSecZone 2011: Scrubbing SAP clean with SOAP
SecZone 2011: Scrubbing SAP clean with SOAPChris John Riley
 
Mercurial for Kittens
Mercurial for KittensMercurial for Kittens
Mercurial for Kittensnya3jp
 
Building apache modules
Building apache modulesBuilding apache modules
Building apache modulesMarian Marinov
 
Exploring Async PHP (SF Live Berlin 2019)
Exploring Async PHP (SF Live Berlin 2019)Exploring Async PHP (SF Live Berlin 2019)
Exploring Async PHP (SF Live Berlin 2019)dantleech
 

What's hot (20)

Sahul
SahulSahul
Sahul
 
Sahu
SahuSahu
Sahu
 
Infrastructure As Code With Terraform
Infrastructure As Code With TerraformInfrastructure As Code With Terraform
Infrastructure As Code With Terraform
 
Watch Me Install Alfresco
Watch Me Install AlfrescoWatch Me Install Alfresco
Watch Me Install Alfresco
 
Hadoop installation
Hadoop installationHadoop installation
Hadoop installation
 
Ansible leveraging 2.0
Ansible leveraging 2.0Ansible leveraging 2.0
Ansible leveraging 2.0
 
Ultimate Unix Meetup Presentation
Ultimate Unix Meetup PresentationUltimate Unix Meetup Presentation
Ultimate Unix Meetup Presentation
 
Linux-Fu for PHP Developers
Linux-Fu for PHP DevelopersLinux-Fu for PHP Developers
Linux-Fu for PHP Developers
 
Hacking ansible
Hacking ansibleHacking ansible
Hacking ansible
 
PE Packers Used in Malicious Software - Part 2
PE Packers Used in Malicious Software - Part 2PE Packers Used in Malicious Software - Part 2
PE Packers Used in Malicious Software - Part 2
 
Sah
SahSah
Sah
 
Setting up a HADOOP 2.2 cluster on CentOS 6
Setting up a HADOOP 2.2 cluster on CentOS 6Setting up a HADOOP 2.2 cluster on CentOS 6
Setting up a HADOOP 2.2 cluster on CentOS 6
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
How to Save, backup and restore IOS on Cisco router
How to Save, backup and restore IOS on Cisco routerHow to Save, backup and restore IOS on Cisco router
How to Save, backup and restore IOS on Cisco router
 
Web Audio API + AngularJS
Web Audio API + AngularJSWeb Audio API + AngularJS
Web Audio API + AngularJS
 
SecZone 2011: Scrubbing SAP clean with SOAP
SecZone 2011: Scrubbing SAP clean with SOAPSecZone 2011: Scrubbing SAP clean with SOAP
SecZone 2011: Scrubbing SAP clean with SOAP
 
Mercurial for Kittens
Mercurial for KittensMercurial for Kittens
Mercurial for Kittens
 
Flask SQLAlchemy
Flask SQLAlchemy Flask SQLAlchemy
Flask SQLAlchemy
 
Building apache modules
Building apache modulesBuilding apache modules
Building apache modules
 
Exploring Async PHP (SF Live Berlin 2019)
Exploring Async PHP (SF Live Berlin 2019)Exploring Async PHP (SF Live Berlin 2019)
Exploring Async PHP (SF Live Berlin 2019)
 

Similar to Diving Into Memory Allocation to Understand Buffer Overflow Better

Reversing malware analysis training part4 assembly programming basics
Reversing malware analysis training part4 assembly programming basicsReversing malware analysis training part4 assembly programming basics
Reversing malware analysis training part4 assembly programming basicsCysinfo Cyber Security Community
 
CNIT 127: Ch 2: Stack Overflows in Linux
CNIT 127: Ch 2: Stack Overflows in LinuxCNIT 127: Ch 2: Stack Overflows in Linux
CNIT 127: Ch 2: Stack Overflows in LinuxSam Bowne
 
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)CODE BLUE
 
127 Ch 2: Stack overflows on Linux
127 Ch 2: Stack overflows on Linux127 Ch 2: Stack overflows on Linux
127 Ch 2: Stack overflows on LinuxSam Bowne
 
CNIT 127 Ch 2: Stack overflows on Linux
CNIT 127 Ch 2: Stack overflows on LinuxCNIT 127 Ch 2: Stack overflows on Linux
CNIT 127 Ch 2: Stack overflows on LinuxSam Bowne
 
Basic ASM by @binaryheadache
Basic ASM by @binaryheadacheBasic ASM by @binaryheadache
Basic ASM by @binaryheadachecamsec
 
CNIT 127: Ch 2: Stack overflows on Linux
CNIT 127: Ch 2: Stack overflows on LinuxCNIT 127: Ch 2: Stack overflows on Linux
CNIT 127: Ch 2: Stack overflows on LinuxSam Bowne
 
X86 assembly & GDB
X86 assembly & GDBX86 assembly & GDB
X86 assembly & GDBJian-Yu Li
 
127 Ch 2: Stack overflows on Linux
127 Ch 2: Stack overflows on Linux127 Ch 2: Stack overflows on Linux
127 Ch 2: Stack overflows on LinuxSam Bowne
 
CNIT 127 Ch 2: Stack overflows on Linux
CNIT 127 Ch 2: Stack overflows on LinuxCNIT 127 Ch 2: Stack overflows on Linux
CNIT 127 Ch 2: Stack overflows on LinuxSam Bowne
 
Software to the slaughter
Software to the slaughterSoftware to the slaughter
Software to the slaughterQuinn Wilton
 
Reverse Engineering Dojo: Enhancing Assembly Reading Skills
Reverse Engineering Dojo: Enhancing Assembly Reading SkillsReverse Engineering Dojo: Enhancing Assembly Reading Skills
Reverse Engineering Dojo: Enhancing Assembly Reading SkillsAsuka Nakajima
 
Exploit techniques - a quick review
Exploit techniques - a quick reviewExploit techniques - a quick review
Exploit techniques - a quick reviewCe.Se.N.A. Security
 
Return Oriented Programming (ROP chaining)
Return Oriented Programming (ROP chaining)Return Oriented Programming (ROP chaining)
Return Oriented Programming (ROP chaining)Abhinav Chourasia, GMOB
 
ROP 輕鬆談
ROP 輕鬆談ROP 輕鬆談
ROP 輕鬆談hackstuff
 
Exploiting Memory Overflows
Exploiting Memory OverflowsExploiting Memory Overflows
Exploiting Memory OverflowsAnkur Tyagi
 
rop heap attacks cfi int overflows computer security
rop heap attacks cfi int overflows computer securityrop heap attacks cfi int overflows computer security
rop heap attacks cfi int overflows computer securityFannyBellows
 

Similar to Diving Into Memory Allocation to Understand Buffer Overflow Better (20)

Reversing malware analysis training part4 assembly programming basics
Reversing malware analysis training part4 assembly programming basicsReversing malware analysis training part4 assembly programming basics
Reversing malware analysis training part4 assembly programming basics
 
CNIT 127: Ch 2: Stack Overflows in Linux
CNIT 127: Ch 2: Stack Overflows in LinuxCNIT 127: Ch 2: Stack Overflows in Linux
CNIT 127: Ch 2: Stack Overflows in Linux
 
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)
 
127 Ch 2: Stack overflows on Linux
127 Ch 2: Stack overflows on Linux127 Ch 2: Stack overflows on Linux
127 Ch 2: Stack overflows on Linux
 
CNIT 127 Ch 2: Stack overflows on Linux
CNIT 127 Ch 2: Stack overflows on LinuxCNIT 127 Ch 2: Stack overflows on Linux
CNIT 127 Ch 2: Stack overflows on Linux
 
Basic ASM by @binaryheadache
Basic ASM by @binaryheadacheBasic ASM by @binaryheadache
Basic ASM by @binaryheadache
 
The Stack and Buffer Overflows
The Stack and Buffer OverflowsThe Stack and Buffer Overflows
The Stack and Buffer Overflows
 
CNIT 127: Ch 2: Stack overflows on Linux
CNIT 127: Ch 2: Stack overflows on LinuxCNIT 127: Ch 2: Stack overflows on Linux
CNIT 127: Ch 2: Stack overflows on Linux
 
X86 assembly & GDB
X86 assembly & GDBX86 assembly & GDB
X86 assembly & GDB
 
127 Ch 2: Stack overflows on Linux
127 Ch 2: Stack overflows on Linux127 Ch 2: Stack overflows on Linux
127 Ch 2: Stack overflows on Linux
 
CNIT 127 Ch 2: Stack overflows on Linux
CNIT 127 Ch 2: Stack overflows on LinuxCNIT 127 Ch 2: Stack overflows on Linux
CNIT 127 Ch 2: Stack overflows on Linux
 
ROP
ROPROP
ROP
 
Software to the slaughter
Software to the slaughterSoftware to the slaughter
Software to the slaughter
 
Reverse Engineering Dojo: Enhancing Assembly Reading Skills
Reverse Engineering Dojo: Enhancing Assembly Reading SkillsReverse Engineering Dojo: Enhancing Assembly Reading Skills
Reverse Engineering Dojo: Enhancing Assembly Reading Skills
 
Exploit techniques - a quick review
Exploit techniques - a quick reviewExploit techniques - a quick review
Exploit techniques - a quick review
 
17
1717
17
 
Return Oriented Programming (ROP chaining)
Return Oriented Programming (ROP chaining)Return Oriented Programming (ROP chaining)
Return Oriented Programming (ROP chaining)
 
ROP 輕鬆談
ROP 輕鬆談ROP 輕鬆談
ROP 輕鬆談
 
Exploiting Memory Overflows
Exploiting Memory OverflowsExploiting Memory Overflows
Exploiting Memory Overflows
 
rop heap attacks cfi int overflows computer security
rop heap attacks cfi int overflows computer securityrop heap attacks cfi int overflows computer security
rop heap attacks cfi int overflows computer security
 

More from Oguzhan Topgul

Malicious Word Document Analysis
Malicious Word Document AnalysisMalicious Word Document Analysis
Malicious Word Document AnalysisOguzhan Topgul
 
iOS'da Zararlı Yazılım Yok (mu?)
iOS'da Zararlı Yazılım Yok (mu?)iOS'da Zararlı Yazılım Yok (mu?)
iOS'da Zararlı Yazılım Yok (mu?)Oguzhan Topgul
 
Media Files : Android's New Nightmare
Media Files :  Android's New NightmareMedia Files :  Android's New Nightmare
Media Files : Android's New NightmareOguzhan Topgul
 
Androidin Yeni Kabusu: Medya Dosyalari (Media Files: Android's New Nightmare)
Androidin Yeni Kabusu: Medya Dosyalari (Media Files: Android's New Nightmare)Androidin Yeni Kabusu: Medya Dosyalari (Media Files: Android's New Nightmare)
Androidin Yeni Kabusu: Medya Dosyalari (Media Files: Android's New Nightmare)Oguzhan Topgul
 
Geçmişten Günümüze Mobil Zararlı Yazılımlar
Geçmişten Günümüze Mobil Zararlı YazılımlarGeçmişten Günümüze Mobil Zararlı Yazılımlar
Geçmişten Günümüze Mobil Zararlı YazılımlarOguzhan Topgul
 
iOS Güvenlik Mekanizmaları - UNISIP Siber Güvenlik Sempozyumu 2014
iOS Güvenlik Mekanizmaları - UNISIP Siber Güvenlik Sempozyumu 2014iOS Güvenlik Mekanizmaları - UNISIP Siber Güvenlik Sempozyumu 2014
iOS Güvenlik Mekanizmaları - UNISIP Siber Güvenlik Sempozyumu 2014Oguzhan Topgul
 
Android'de Parmak Kaldırmadan Konusmak - İzinsiz Uygulamda İzin Kullanmak Sib...
Android'de Parmak Kaldırmadan Konusmak - İzinsiz Uygulamda İzin Kullanmak Sib...Android'de Parmak Kaldırmadan Konusmak - İzinsiz Uygulamda İzin Kullanmak Sib...
Android'de Parmak Kaldırmadan Konusmak - İzinsiz Uygulamda İzin Kullanmak Sib...Oguzhan Topgul
 

More from Oguzhan Topgul (7)

Malicious Word Document Analysis
Malicious Word Document AnalysisMalicious Word Document Analysis
Malicious Word Document Analysis
 
iOS'da Zararlı Yazılım Yok (mu?)
iOS'da Zararlı Yazılım Yok (mu?)iOS'da Zararlı Yazılım Yok (mu?)
iOS'da Zararlı Yazılım Yok (mu?)
 
Media Files : Android's New Nightmare
Media Files :  Android's New NightmareMedia Files :  Android's New Nightmare
Media Files : Android's New Nightmare
 
Androidin Yeni Kabusu: Medya Dosyalari (Media Files: Android's New Nightmare)
Androidin Yeni Kabusu: Medya Dosyalari (Media Files: Android's New Nightmare)Androidin Yeni Kabusu: Medya Dosyalari (Media Files: Android's New Nightmare)
Androidin Yeni Kabusu: Medya Dosyalari (Media Files: Android's New Nightmare)
 
Geçmişten Günümüze Mobil Zararlı Yazılımlar
Geçmişten Günümüze Mobil Zararlı YazılımlarGeçmişten Günümüze Mobil Zararlı Yazılımlar
Geçmişten Günümüze Mobil Zararlı Yazılımlar
 
iOS Güvenlik Mekanizmaları - UNISIP Siber Güvenlik Sempozyumu 2014
iOS Güvenlik Mekanizmaları - UNISIP Siber Güvenlik Sempozyumu 2014iOS Güvenlik Mekanizmaları - UNISIP Siber Güvenlik Sempozyumu 2014
iOS Güvenlik Mekanizmaları - UNISIP Siber Güvenlik Sempozyumu 2014
 
Android'de Parmak Kaldırmadan Konusmak - İzinsiz Uygulamda İzin Kullanmak Sib...
Android'de Parmak Kaldırmadan Konusmak - İzinsiz Uygulamda İzin Kullanmak Sib...Android'de Parmak Kaldırmadan Konusmak - İzinsiz Uygulamda İzin Kullanmak Sib...
Android'de Parmak Kaldırmadan Konusmak - İzinsiz Uygulamda İzin Kullanmak Sib...
 

Recently uploaded

Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 

Recently uploaded (20)

Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 

Diving Into Memory Allocation to Understand Buffer Overflow Better

  • 1. MEMORY ALLOCATION DIVING INTO TO UNDERSTAND BUFFER OVERFLOW BETTER
  • 2. DYNAMIC MEMORY ALLOCATION WHOAMI Oguzhan Topgul Application Security Engineer @FORTINET www.oguzhantopgul.com @oguzhantopgul
  • 3. DYNAMIC MEMORY ALLOCATION CPU REGISTERS ▸ EIP: Instruction Pointer - Next instruction to be executed ▸ ESP: Stack Pointer - Top of the stack ▸ EBP: Base Pointer - Base of the stack ▸ EAX: Accumulator Register - Generally holds the return value ▸ EBX: Base Register - Generally used to address memory ▸ ECX: Counter Register - Generally used in shift, rotate instructions and loops ▸ EDX: Data Register - Generally used in arithmetic and I/O operations ▸ ESI: Source Index Register ▸ EDI: Destination Index Register
  • 4. DYNAMIC MEMORY ALLOCATION PROGRAM MEMORY .TEXT .DATA HEAP STACK .BSS LOW MEMORY ADDRESS HIGH MEMORY ADDRESS - a.k.a Code Segment - Executable Instructions - Read-only
  • 5. DYNAMIC MEMORY ALLOCATION PROGRAM MEMORY .TEXT .DATA HEAP STACK .BSS LOW MEMORY ADDRESS HIGH MEMORY ADDRESS - a.k.a initialized data - global variables w/ pre-defined value - static variables w/ pre-defined value within the functions keeps its value between invocations #include <stdio.h> void foo() { int a = 10; static int sa = 10; a += 5; sa += 5; printf("a = %d, sa = %dn", a, sa); } int main() { int i; for (i = 0; i < 10; ++i) foo(); } a = 15, sa = 15 a = 15, sa = 20 a = 15, sa = 25 a = 15, sa = 30 a = 15, sa = 35 a = 15, sa = 40 a = 15, sa = 45 a = 15, sa = 50 a = 15, sa = 55 a = 15, sa = 60
  • 6. DYNAMIC MEMORY ALLOCATION PROGRAM MEMORY .TEXT .DATA HEAP STACK .BSS LOW MEMORY ADDRESS HIGH MEMORY ADDRESS - a.k.a uninitialized data - global variables w/o pre-defined value - static variables w/o predefined value within the functions
  • 7. DYNAMIC MEMORY ALLOCATION PROGRAM MEMORY .TEXT .DATA HEAP STACK .BSS LOW MEMORY ADDRESS HIGH MEMORY ADDRESS - grows low->high - malloc, calloc, realloc, free - shared by all - threads, - shared libraries - dynamically loaded modules
  • 8. DYNAMIC MEMORY ALLOCATION PROGRAM MEMORY .TEXT .DATA HEAP STACK .BSS LOW MEMORY ADDRESS HIGH MEMORY ADDRESS - LIFO - On x86, stack grows Higher->Lower - What’s stored in Stack: - Function arguments, - Local variables - Function return address - PUSH adds to the top, POP removes from top } Stack Frame
  • 9. #include <stdio.h> int x = 20; int y; int main() { char buf[5]; for (i = 0; i < 10; ++i) foo(15); } void foo(int arg) { int a = 10; static int sa = 10; sa += 5; char* int = malloc(10 * sizeof(int)); printf("sa = %dn”,sa); } DYNAMIC MEMORY ALLOCATION PROGRAM MEMORY .TEXT .DATA HEAP STACK .BSS LOW MEMORY ADDRESS HIGH MEMORY ADDRESS
  • 10. double multiplyByTwo (double input) { double twice = input * 2.0; return twice; } int main (int argc, char *argv[]) { int age = 30; double salary = 12345.67; double myList[3] = {1.2, 2.3, 3.4}; printf("salary is %.3fn", multiplyByTwo(salary)); return 0; } DYNAMIC MEMORY ALLOCATION double *multiplyByTwo (double *input) { double *twice = malloc(sizeof(double)); *twice = *input * 2.0; return twice; } int main (int argc, char *argv[]) { int *age = malloc(sizeof(int)); *age = 30; double *salary = malloc(sizeof(double)); *salary = 12345.67; double *myList = malloc(3 * sizeof(double)); myList[0] = 1.2; myList[1] = 2.3; myList[2] = 3.4; double *twiceSalary = multiplyByTwo(salary); printf(“salary is %.3fn", *twiceSalary); free(age); free(salary); free(myList); free(twiceSalary); return 0; } DEFINE VARIABLES ON STACK VS HEAP
  • 11. DYNAMIC MEMORY ALLOCATION STACK LOW MEMORY ADDRESS HIGH MEMORY ADDRESS - Stack Pointer (SP, ESP) tracks the top of the stack (last address on the stack) - Changes during the execution (PUSH&POP) - Base Pointer (BP, EBP) a.k.a Frame Pointer (FP) shows the bottom of the stack - Fixed during the execution - local variables and arguments are referenced by their offset from EBP EBP ARG 1 ARG 2 LOCAL VAR 2 LOCAL VAR 1 EBP + 8 EBP + 12 EBP - 8 EBP - 4 ESP RETURN ADDREBP + 4
  • 12. DYNAMIC MEMORY ALLOCATION STACK LOW MEMORY ADDRESS HIGH MEMORY ADDRESS int main() { function(1,2,3); } void function(int a, int b, int c) { char buffer1[5]; } <function>: push ebp mov ebp,esp sub esp,0x10 call 11ba <__x86.get_pc_thunk.ax> add eax,0x2e6c nop leave ret <main>: push ebp mov ebp,esp call 11ba <__x86.get_pc_thunk.ax> add eax,0x2e5c push 0x3 push 0x2 push 0x1 call 1189 <function> add esp,0xc nop leave ret EBP - MAIN ESP
  • 13. DYNAMIC MEMORY ALLOCATION STACK LOW MEMORY ADDRESS HIGH MEMORY ADDRESS int main() { function(1,2,3); } void function(int a, int b, int c) { char buffer1[5]; } ARG 3 EBP - MAIN <function>: push ebp mov ebp,esp sub esp,0x10 call 11ba <__x86.get_pc_thunk.ax> add eax,0x2e6c nop leave ret <main>: push ebp mov ebp,esp call 11ba <__x86.get_pc_thunk.ax> add eax,0x2e5c push 0x3 push 0x2 push 0x1 call 1189 <function> add esp,0xc nop leave ret ESP
  • 14. DYNAMIC MEMORY ALLOCATION STACK LOW MEMORY ADDRESS HIGH MEMORY ADDRESS int main() { function(1,2,3); } void function(int a, int b, int c) { char buffer1[5]; } ARG 3 EBP - MAIN <function>: push ebp mov ebp,esp sub esp,0x10 call 11ba <__x86.get_pc_thunk.ax> add eax,0x2e6c nop leave ret <main>: push ebp mov ebp,esp call 11ba <__x86.get_pc_thunk.ax> add eax,0x2e5c push 0x3 push 0x2 push 0x1 call 1189 <function> add esp,0xc nop leave ret ARG 2 ESP
  • 15. DYNAMIC MEMORY ALLOCATION STACK LOW MEMORY ADDRESS HIGH MEMORY ADDRESS int main() { function(1,2,3); } void function(int a, int b, int c) { char buffer1[5]; } ARG 3 EBP - MAIN <function>: push ebp mov ebp,esp sub esp,0x10 call 11ba <__x86.get_pc_thunk.ax> add eax,0x2e6c nop leave ret <main>: push ebp mov ebp,esp call 11ba <__x86.get_pc_thunk.ax> add eax,0x2e5c push 0x3 push 0x2 push 0x1 call 1189 <function> add esp,0xc nop leave ret ARG 2 ARG 1 ESP
  • 16. DYNAMIC MEMORY ALLOCATION STACK LOW MEMORY ADDRESS HIGH MEMORY ADDRESS int main() { function(1,2,3); } void function(int a, int b, int c) { char buffer1[5]; } ARG 3 EBP - MAIN <function>: push ebp mov ebp,esp sub esp,0x10 call 11ba <__x86.get_pc_thunk.ax> add eax,0x2e6c nop leave ret <main>: push ebp mov ebp,esp call 11ba <__x86.get_pc_thunk.ax> add eax,0x2e5c push 0x3 push 0x2 push 0x1 call 1189 <function> add esp,0xc nop leave ret ARG 2 ARG 1 RETURN ADDR ESP EIP { PUSH EIP JMP function
  • 17. DYNAMIC MEMORY ALLOCATION STACK LOW MEMORY ADDRESS HIGH MEMORY ADDRESS int main() { function(1,2,3); } void function(int a, int b, int c) { char buffer1[5]; } ARG 3 EBP - MAIN <function>: push ebp mov ebp,esp sub esp,0x10 call 11ba <__x86.get_pc_thunk.ax> add eax,0x2e6c nop leave ret <main>: push ebp mov ebp,esp call 11ba <__x86.get_pc_thunk.ax> add eax,0x2e5c push 0x3 push 0x2 push 0x1 call 1189 <function> add esp,0xc nop leave ret ARG 2 ARG 1 RETURN ADDR EBP - FUNCTION ESP
  • 18. DYNAMIC MEMORY ALLOCATION STACK LOW MEMORY ADDRESS HIGH MEMORY ADDRESS EBP - FUNCTION ARG 1 ARG 2 EBP + 8 EBP + 12 EBP - 8 EBP - 4 RETURN ADDREBP + 4 int main() { function(1,2,3); } void function(int a, int b, int c) { char buffer1[5]; } ARG 3EBP + 16 EBP - 12 EBP - 16 ESP EBP - MAIN <function>: push ebp mov ebp,esp sub esp,0x10 call 11ba <__x86.get_pc_thunk.ax> add eax,0x2e6c nop leave ret <main>: push ebp mov ebp,esp call 11ba <__x86.get_pc_thunk.ax> add eax,0x2e5c push 0x3 push 0x2 push 0x1 call 1189 <function> add esp,0xc nop leave ret
  • 19. DYNAMIC MEMORY ALLOCATIONTEXT STACK LOW MEMORY ADDRESS HIGH MEMORY ADDRESS ARG 1 ARG 2 RETURN ADDR int main() { function(1,2,3); } void function(int a, int b, int c) { char buffer1[5]; } ARG 3 EBP - MAIN <function>: push ebp mov ebp,esp sub esp,0x10 call 11ba <__x86.get_pc_thunk.ax> add eax,0x2e6c nop leave ret <main>: push ebp mov ebp,esp call 11ba <__x86.get_pc_thunk.ax> add eax,0x2e5c push 0x3 push 0x2 push 0x1 call 1189 <function> add esp,0xc nop leave ret ESP { RESTORE ALLOCATED MEMORY POP EBP POP RETURN ADDR JMP RETURN ADDR
  • 20. DYNAMIC MEMORY ALLOCATION STACK LOW MEMORY ADDRESS HIGH MEMORY ADDRESS ARG 1 ARG 2 int main() { function(1,2,3); } void function(int a, int b, int c) { char buffer1[5]; } ARG 3 EBP - MAIN <function>: push ebp mov ebp,esp sub esp,0x10 call 11ba <__x86.get_pc_thunk.ax> add eax,0x2e6c nop leave ret <main>: push ebp mov ebp,esp call 11ba <__x86.get_pc_thunk.ax> add eax,0x2e5c push 0x3 push 0x2 push 0x1 call 1189 <function> add esp,0xc nop leave ret ESP
  • 21. DYNAMIC MEMORY ALLOCATION STACK LOW MEMORY ADDRESS HIGH MEMORY ADDRESS int main() { function(1,2,3); } void function(int a, int b, int c) { char buffer1[5]; } EBP - MAIN <function>: push ebp mov ebp,esp sub esp,0x10 call 11ba <__x86.get_pc_thunk.ax> add eax,0x2e6c nop leave ret <main>: push ebp mov ebp,esp call 11ba <__x86.get_pc_thunk.ax> add eax,0x2e5c push 0x3 push 0x2 push 0x1 call 1189 <function> add esp,0xc nop leave ret ESP
  • 22. TEXT STACK LOW MEMORY ADDRESS HIGH MEMORY ADDRESS EBP - MAIN 00001199 <function>: 1199:55 push ebp 119a:89 e5 mov ebp,esp 119c:53 push ebx 119d:83 ec 14 sub esp,0x14 … 11aa:83 ec 08 sub esp,0x8 11ad:ff 75 08 push DWORD PTR [ebp+0x8] 11b0:8d 55 e8 lea edx,[ebp-0x18] 11b3:52 push edx 11b4:89 c3 mov ebx,eax 11b6:e8 75 fe ff ff call 1030 <strcpy@plt> 11bb:83 c4 10 add esp,0x10 11be:90 nop 11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4] 11c2:c9 leave 11c3:c3 ret 000011c4 <main>: … 11ce:55 push ebp 11cf:89 e5 mov ebp,esp 11d1:51 push ecx 11d2:81 ec 14 01 00 00 sub esp,0x114 … 11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0 11e9:eb 12 jmp 11fd <main+0x39> 11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c] 11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc] 11f4:01 d0 add eax,edx 11f6:c6 00 41 mov BYTE PTR [eax],0x41 11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1 11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe 1204:7e e5 jle 11eb <main+0x27> 1206:83 ec 0c sub esp,0xc 1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c] 120f:50 push eax 1210:e8 84 ff ff ff call 1199 <function> 1215:83 c4 10 add esp,0x10 1218:90 nop 1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4] 121c:c9 leave 121d:8d 61 fc lea esp,[ecx-0x4] 1220:c3 ret ESP void function(char *str) { char buffer[16]; strcpy(buffer,str); } int main() { char large_string[256]; int i; for(i = 0; i < 255; i++) large_string[i] = 'A'; function(large_string); }
  • 23. TEXT STACK LOW MEMORY ADDRESS HIGH MEMORY ADDRESS EBP - MAIN 00001199 <function>: 1199:55 push ebp 119a:89 e5 mov ebp,esp 119c:53 push ebx 119d:83 ec 14 sub esp,0x14 … 11aa:83 ec 08 sub esp,0x8 11ad:ff 75 08 push DWORD PTR [ebp+0x8] 11b0:8d 55 e8 lea edx,[ebp-0x18] 11b3:52 push edx 11b4:89 c3 mov ebx,eax 11b6:e8 75 fe ff ff call 1030 <strcpy@plt> 11bb:83 c4 10 add esp,0x10 11be:90 nop 11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4] 11c2:c9 leave 11c3:c3 ret 000011c4 <main>: … 11ce:55 push ebp 11cf:89 e5 mov ebp,esp 11d1:51 push ecx 11d2:81 ec 14 01 00 00 sub esp,0x114 … 11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0 11e9:eb 12 jmp 11fd <main+0x39> 11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c] 11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc] 11f4:01 d0 add eax,edx 11f6:c6 00 41 mov BYTE PTR [eax],0x41 11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1 11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe 1204:7e e5 jle 11eb <main+0x27> 1206:83 ec 0c sub esp,0xc 1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c] 120f:50 push eax 1210:e8 84 ff ff ff call 1199 <function> 1215:83 c4 10 add esp,0x10 1218:90 nop 1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4] 121c:c9 leave 121d:8d 61 fc lea esp,[ecx-0x4] 1220:c3 ret ECX ESP
  • 24. TEXT STACK LOW MEMORY ADDRESS HIGH MEMORY ADDRESS EBP - MAIN 00001199 <function>: 1199:55 push ebp 119a:89 e5 mov ebp,esp 119c:53 push ebx 119d:83 ec 14 sub esp,0x14 … 11aa:83 ec 08 sub esp,0x8 11ad:ff 75 08 push DWORD PTR [ebp+0x8] 11b0:8d 55 e8 lea edx,[ebp-0x18] 11b3:52 push edx 11b4:89 c3 mov ebx,eax 11b6:e8 75 fe ff ff call 1030 <strcpy@plt> 11bb:83 c4 10 add esp,0x10 11be:90 nop 11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4] 11c2:c9 leave 11c3:c3 ret 000011c4 <main>: … 11ce:55 push ebp 11cf:89 e5 mov ebp,esp 11d1:51 push ecx 11d2:81 ec 14 01 00 00 sub esp,0x114 … 11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0 11e9:eb 12 jmp 11fd <main+0x39> 11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c] 11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc] 11f4:01 d0 add eax,edx 11f6:c6 00 41 mov BYTE PTR [eax],0x41 11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1 11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe 1204:7e e5 jle 11eb <main+0x27> 1206:83 ec 0c sub esp,0xc 1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c] 120f:50 push eax 1210:e8 84 ff ff ff call 1199 <function> 1215:83 c4 10 add esp,0x10 1218:90 nop 1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4] 121c:c9 leave 121d:8d 61 fc lea esp,[ecx-0x4] 1220:c3 ret ECX EBP - 280 ESP EBP - 4
  • 25. TEXT STACK LOW MEMORY ADDRESS HIGH MEMORY ADDRESS EBP - MAIN 00001199 <function>: 1199:55 push ebp 119a:89 e5 mov ebp,esp 119c:53 push ebx 119d:83 ec 14 sub esp,0x14 … 11aa:83 ec 08 sub esp,0x8 11ad:ff 75 08 push DWORD PTR [ebp+0x8] 11b0:8d 55 e8 lea edx,[ebp-0x18] 11b3:52 push edx 11b4:89 c3 mov ebx,eax 11b6:e8 75 fe ff ff call 1030 <strcpy@plt> 11bb:83 c4 10 add esp,0x10 11be:90 nop 11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4] 11c2:c9 leave 11c3:c3 ret 000011c4 <main>: … 11ce:55 push ebp 11cf:89 e5 mov ebp,esp 11d1:51 push ecx 11d2:81 ec 14 01 00 00 sub esp,0x114 … 11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0 11e9:eb 12 jmp 11fd <main+0x39> 11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c] 11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc] 11f4:01 d0 add eax,edx 11f6:c6 00 41 mov BYTE PTR [eax],0x41 11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1 11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe 1204:7e e5 jle 11eb <main+0x27> 1206:83 ec 0c sub esp,0xc 1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c] 120f:50 push eax 1210:e8 84 ff ff ff call 1199 <function> 1215:83 c4 10 add esp,0x10 1218:90 nop 1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4] 121c:c9 leave 121d:8d 61 fc lea esp,[ecx-0x4] 1220:c3 ret ECX EBP - 280 ESP EBP - 4 EBP - 8 EBP - 12 0x00 0x00 0x00 0x00
  • 26. TEXT STACK LOW MEMORY ADDRESS HIGH MEMORY ADDRESS EBP - MAIN 00001199 <function>: 1199:55 push ebp 119a:89 e5 mov ebp,esp 119c:53 push ebx 119d:83 ec 14 sub esp,0x14 … 11aa:83 ec 08 sub esp,0x8 11ad:ff 75 08 push DWORD PTR [ebp+0x8] 11b0:8d 55 e8 lea edx,[ebp-0x18] 11b3:52 push edx 11b4:89 c3 mov ebx,eax 11b6:e8 75 fe ff ff call 1030 <strcpy@plt> 11bb:83 c4 10 add esp,0x10 11be:90 nop 11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4] 11c2:c9 leave 11c3:c3 ret 000011c4 <main>: … 11ce:55 push ebp 11cf:89 e5 mov ebp,esp 11d1:51 push ecx 11d2:81 ec 14 01 00 00 sub esp,0x114 … 11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0 11e9:eb 12 jmp 11fd <main+0x39> 11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c] 11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc] 11f4:01 d0 add eax,edx 11f6:c6 00 41 mov BYTE PTR [eax],0x41 11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1 11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe 1204:7e e5 jle 11eb <main+0x27> 1206:83 ec 0c sub esp,0xc 1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c] 120f:50 push eax 1210:e8 84 ff ff ff call 1199 <function> 1215:83 c4 10 add esp,0x10 1218:90 nop 1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4] 121c:c9 leave 121d:8d 61 fc lea esp,[ecx-0x4] 1220:c3 ret ECX EBP - 280 ESP EBP - 4 EBP - 8 EBP - 12 0x00 0x00 0x00 0x00
  • 27. TEXT STACK LOW MEMORY ADDRESS HIGH MEMORY ADDRESS EBP - MAIN 00001199 <function>: 1199:55 push ebp 119a:89 e5 mov ebp,esp 119c:53 push ebx 119d:83 ec 14 sub esp,0x14 … 11aa:83 ec 08 sub esp,0x8 11ad:ff 75 08 push DWORD PTR [ebp+0x8] 11b0:8d 55 e8 lea edx,[ebp-0x18] 11b3:52 push edx 11b4:89 c3 mov ebx,eax 11b6:e8 75 fe ff ff call 1030 <strcpy@plt> 11bb:83 c4 10 add esp,0x10 11be:90 nop 11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4] 11c2:c9 leave 11c3:c3 ret 000011c4 <main>: … 11ce:55 push ebp 11cf:89 e5 mov ebp,esp 11d1:51 push ecx 11d2:81 ec 14 01 00 00 sub esp,0x114 … 11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0 11e9:eb 12 jmp 11fd <main+0x39> 11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c] 11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc] 11f4:01 d0 add eax,edx 11f6:c6 00 41 mov BYTE PTR [eax],0x41 11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1 11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe 1204:7e e5 jle 11eb <main+0x27> 1206:83 ec 0c sub esp,0xc 1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c] 120f:50 push eax 1210:e8 84 ff ff ff call 1199 <function> 1215:83 c4 10 add esp,0x10 1218:90 nop 1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4] 121c:c9 leave 121d:8d 61 fc lea esp,[ecx-0x4] 1220:c3 ret ECX EBP - 280 ESP EBP - 4 EBP - 8 EBP - 12 0x00 0x00 0x00 0x00
  • 28. TEXT STACK LOW MEMORY ADDRESS HIGH MEMORY ADDRESS EBP - MAIN 00001199 <function>: 1199:55 push ebp 119a:89 e5 mov ebp,esp 119c:53 push ebx 119d:83 ec 14 sub esp,0x14 … 11aa:83 ec 08 sub esp,0x8 11ad:ff 75 08 push DWORD PTR [ebp+0x8] 11b0:8d 55 e8 lea edx,[ebp-0x18] 11b3:52 push edx 11b4:89 c3 mov ebx,eax 11b6:e8 75 fe ff ff call 1030 <strcpy@plt> 11bb:83 c4 10 add esp,0x10 11be:90 nop 11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4] 11c2:c9 leave 11c3:c3 ret 000011c4 <main>: … 11ce:55 push ebp 11cf:89 e5 mov ebp,esp 11d1:51 push ecx 11d2:81 ec 14 01 00 00 sub esp,0x114 … 11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0 11e9:eb 12 jmp 11fd <main+0x39> 11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c] 11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc] 11f4:01 d0 add eax,edx 11f6:c6 00 41 mov BYTE PTR [eax],0x41 11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1 11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe 1204:7e e5 jle 11eb <main+0x27> 1206:83 ec 0c sub esp,0xc 1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c] 120f:50 push eax 1210:e8 84 ff ff ff call 1199 <function> 1215:83 c4 10 add esp,0x10 1218:90 nop 1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4] 121c:c9 leave 121d:8d 61 fc lea esp,[ecx-0x4] 1220:c3 ret ECX EBP - 280 ESP EBP - 4 EBP - 8 EBP - 12 0x00 0x00 0x00 0x00
  • 29. TEXT STACK LOW MEMORY ADDRESS HIGH MEMORY ADDRESS EBP - MAIN 00001199 <function>: 1199:55 push ebp 119a:89 e5 mov ebp,esp 119c:53 push ebx 119d:83 ec 14 sub esp,0x14 … 11aa:83 ec 08 sub esp,0x8 11ad:ff 75 08 push DWORD PTR [ebp+0x8] 11b0:8d 55 e8 lea edx,[ebp-0x18] 11b3:52 push edx 11b4:89 c3 mov ebx,eax 11b6:e8 75 fe ff ff call 1030 <strcpy@plt> 11bb:83 c4 10 add esp,0x10 11be:90 nop 11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4] 11c2:c9 leave 11c3:c3 ret 000011c4 <main>: … 11ce:55 push ebp 11cf:89 e5 mov ebp,esp 11d1:51 push ecx 11d2:81 ec 14 01 00 00 sub esp,0x114 … 11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0 11e9:eb 12 jmp 11fd <main+0x39> 11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c] 11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc] 11f4:01 d0 add eax,edx 11f6:c6 00 41 mov BYTE PTR [eax],0x41 11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1 11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe 1204:7e e5 jle 11eb <main+0x27> 1206:83 ec 0c sub esp,0xc 1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c] 120f:50 push eax 1210:e8 84 ff ff ff call 1199 <function> 1215:83 c4 10 add esp,0x10 1218:90 nop 1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4] 121c:c9 leave 121d:8d 61 fc lea esp,[ecx-0x4] 1220:c3 ret ECX EBP - 280 ESP EBP - 4 EBP - 8 EBP - 12 0x00 0x00 0x00 0x00 EBP - 276 EBP - 272 EBP - 268
  • 30. TEXT STACK LOW MEMORY ADDRESS HIGH MEMORY ADDRESS EBP - MAIN 00001199 <function>: 1199:55 push ebp 119a:89 e5 mov ebp,esp 119c:53 push ebx 119d:83 ec 14 sub esp,0x14 … 11aa:83 ec 08 sub esp,0x8 11ad:ff 75 08 push DWORD PTR [ebp+0x8] 11b0:8d 55 e8 lea edx,[ebp-0x18] 11b3:52 push edx 11b4:89 c3 mov ebx,eax 11b6:e8 75 fe ff ff call 1030 <strcpy@plt> 11bb:83 c4 10 add esp,0x10 11be:90 nop 11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4] 11c2:c9 leave 11c3:c3 ret 000011c4 <main>: … 11ce:55 push ebp 11cf:89 e5 mov ebp,esp 11d1:51 push ecx 11d2:81 ec 14 01 00 00 sub esp,0x114 … 11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0 11e9:eb 12 jmp 11fd <main+0x39> 11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c] 11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc] 11f4:01 d0 add eax,edx 11f6:c6 00 41 mov BYTE PTR [eax],0x41 11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1 11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe 1204:7e e5 jle 11eb <main+0x27> 1206:83 ec 0c sub esp,0xc 1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c] 120f:50 push eax 1210:e8 84 ff ff ff call 1199 <function> 1215:83 c4 10 add esp,0x10 1218:90 nop 1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4] 121c:c9 leave 121d:8d 61 fc lea esp,[ecx-0x4] 1220:c3 ret ECX EBP - 280 ESP EBP - 4 EBP - 8 EBP - 12 0x00 0x00 0x00 0x00 EBP - 276 EBP - 272 EBP - 268 0x41
  • 31. TEXT STACK LOW MEMORY ADDRESS HIGH MEMORY ADDRESS EBP - MAIN 00001199 <function>: 1199:55 push ebp 119a:89 e5 mov ebp,esp 119c:53 push ebx 119d:83 ec 14 sub esp,0x14 … 11aa:83 ec 08 sub esp,0x8 11ad:ff 75 08 push DWORD PTR [ebp+0x8] 11b0:8d 55 e8 lea edx,[ebp-0x18] 11b3:52 push edx 11b4:89 c3 mov ebx,eax 11b6:e8 75 fe ff ff call 1030 <strcpy@plt> 11bb:83 c4 10 add esp,0x10 11be:90 nop 11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4] 11c2:c9 leave 11c3:c3 ret 000011c4 <main>: … 11ce:55 push ebp 11cf:89 e5 mov ebp,esp 11d1:51 push ecx 11d2:81 ec 14 01 00 00 sub esp,0x114 … 11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0 11e9:eb 12 jmp 11fd <main+0x39> 11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c] 11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc] 11f4:01 d0 add eax,edx 11f6:c6 00 41 mov BYTE PTR [eax],0x41 11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1 11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe 1204:7e e5 jle 11eb <main+0x27> 1206:83 ec 0c sub esp,0xc 1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c] 120f:50 push eax 1210:e8 84 ff ff ff call 1199 <function> 1215:83 c4 10 add esp,0x10 1218:90 nop 1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4] 121c:c9 leave 121d:8d 61 fc lea esp,[ecx-0x4] 1220:c3 ret ECX EBP - 280 ESP EBP - 4 EBP - 8 EBP - 12 0x00 0x00 0x00 0x01 EBP - 276 EBP - 272 EBP - 268 0x41
  • 32. TEXT STACK LOW MEMORY ADDRESS HIGH MEMORY ADDRESS EBP - MAIN 00001199 <function>: 1199:55 push ebp 119a:89 e5 mov ebp,esp 119c:53 push ebx 119d:83 ec 14 sub esp,0x14 … 11aa:83 ec 08 sub esp,0x8 11ad:ff 75 08 push DWORD PTR [ebp+0x8] 11b0:8d 55 e8 lea edx,[ebp-0x18] 11b3:52 push edx 11b4:89 c3 mov ebx,eax 11b6:e8 75 fe ff ff call 1030 <strcpy@plt> 11bb:83 c4 10 add esp,0x10 11be:90 nop 11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4] 11c2:c9 leave 11c3:c3 ret 000011c4 <main>: … 11ce:55 push ebp 11cf:89 e5 mov ebp,esp 11d1:51 push ecx 11d2:81 ec 14 01 00 00 sub esp,0x114 … 11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0 11e9:eb 12 jmp 11fd <main+0x39> 11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c] 11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc] 11f4:01 d0 add eax,edx 11f6:c6 00 41 mov BYTE PTR [eax],0x41 11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1 11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe 1204:7e e5 jle 11eb <main+0x27> 1206:83 ec 0c sub esp,0xc 1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c] 120f:50 push eax 1210:e8 84 ff ff ff call 1199 <function> 1215:83 c4 10 add esp,0x10 1218:90 nop 1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4] 121c:c9 leave 121d:8d 61 fc lea esp,[ecx-0x4] 1220:c3 ret ECX EBP - 280 ESP EBP - 4 EBP - 8 EBP - 12 0x00 0x00 0x00 0xff EBP - 276 EBP - 272 EBP - 268 0x41 }for loop 0x410x410x41 0x410x410x410x41 0x410x410x410x41 . . . 0x410x410x410x41
  • 33. TEXT STACK LOW MEMORY ADDRESS HIGH MEMORY ADDRESS EBP - MAIN 00001199 <function>: 1199:55 push ebp 119a:89 e5 mov ebp,esp 119c:53 push ebx 119d:83 ec 14 sub esp,0x14 … 11aa:83 ec 08 sub esp,0x8 11ad:ff 75 08 push DWORD PTR [ebp+0x8] 11b0:8d 55 e8 lea edx,[ebp-0x18] 11b3:52 push edx 11b4:89 c3 mov ebx,eax 11b6:e8 75 fe ff ff call 1030 <strcpy@plt> 11bb:83 c4 10 add esp,0x10 11be:90 nop 11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4] 11c2:c9 leave 11c3:c3 ret 000011c4 <main>: … 11ce:55 push ebp 11cf:89 e5 mov ebp,esp 11d1:51 push ecx 11d2:81 ec 14 01 00 00 sub esp,0x114 … 11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0 11e9:eb 12 jmp 11fd <main+0x39> 11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c] 11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc] 11f4:01 d0 add eax,edx 11f6:c6 00 41 mov BYTE PTR [eax],0x41 11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1 11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe 1204:7e e5 jle 11eb <main+0x27> 1206:83 ec 0c sub esp,0xc 1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c] 120f:50 push eax 1210:e8 84 ff ff ff call 1199 <function> 1215:83 c4 10 add esp,0x10 1218:90 nop 1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4] 121c:c9 leave 121d:8d 61 fc lea esp,[ecx-0x4] 1220:c3 ret ECX EBP - 280 ESP EBP - 4 EBP - 8 EBP - 12 0x00 0x00 0x00 0xff EBP - 276 EBP - 272 EBP - 268 0x410x410x410x41 0x410x410x410x41 0x410x410x410x41 . . . 0x410x410x410x41 EBP - 284 EBP - 288 EBP - 292
  • 34. TEXT STACK LOW MEMORY ADDRESS HIGH MEMORY ADDRESS EBP - MAIN 00001199 <function>: 1199:55 push ebp 119a:89 e5 mov ebp,esp 119c:53 push ebx 119d:83 ec 14 sub esp,0x14 … 11aa:83 ec 08 sub esp,0x8 11ad:ff 75 08 push DWORD PTR [ebp+0x8] 11b0:8d 55 e8 lea edx,[ebp-0x18] 11b3:52 push edx 11b4:89 c3 mov ebx,eax 11b6:e8 75 fe ff ff call 1030 <strcpy@plt> 11bb:83 c4 10 add esp,0x10 11be:90 nop 11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4] 11c2:c9 leave 11c3:c3 ret 000011c4 <main>: … 11ce:55 push ebp 11cf:89 e5 mov ebp,esp 11d1:51 push ecx 11d2:81 ec 14 01 00 00 sub esp,0x114 … 11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0 11e9:eb 12 jmp 11fd <main+0x39> 11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c] 11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc] 11f4:01 d0 add eax,edx 11f6:c6 00 41 mov BYTE PTR [eax],0x41 11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1 11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe 1204:7e e5 jle 11eb <main+0x27> 1206:83 ec 0c sub esp,0xc 1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c] 120f:50 push eax 1210:e8 84 ff ff ff call 1199 <function> 1215:83 c4 10 add esp,0x10 1218:90 nop 1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4] 121c:c9 leave 121d:8d 61 fc lea esp,[ecx-0x4] 1220:c3 ret ECXEBP - 4 EBP - 8 EBP - 12 0x00 0x00 0x00 0xff EBP - 268 0x410x410x410x41 0x410x410x410x41 0x410x410x410x41 . . . 0x410x410x410x41 ADDRESS OF EBP-267 ESPEBP - 296
  • 35. LOW MEMORY ADDRESS HIGH MEMORY ADDRESS EBP - MAIN 00001199 <function>: 1199:55 push ebp 119a:89 e5 mov ebp,esp 119c:53 push ebx 119d:83 ec 14 sub esp,0x14 … 11aa:83 ec 08 sub esp,0x8 11ad:ff 75 08 push DWORD PTR [ebp+0x8] 11b0:8d 55 e8 lea edx,[ebp-0x18] 11b3:52 push edx 11b4:89 c3 mov ebx,eax 11b6:e8 75 fe ff ff call 1030 <strcpy@plt> 11bb:83 c4 10 add esp,0x10 11be:90 nop 11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4] 11c2:c9 leave 11c3:c3 ret 000011c4 <main>: … 11ce:55 push ebp 11cf:89 e5 mov ebp,esp 11d1:51 push ecx 11d2:81 ec 14 01 00 00 sub esp,0x114 … 11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0 11e9:eb 12 jmp 11fd <main+0x39> 11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c] 11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc] 11f4:01 d0 add eax,edx 11f6:c6 00 41 mov BYTE PTR [eax],0x41 11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1 11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe 1204:7e e5 jle 11eb <main+0x27> 1206:83 ec 0c sub esp,0xc 1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c] 120f:50 push eax 1210:e8 84 ff ff ff call 1199 <function> 1215:83 c4 10 add esp,0x10 1218:90 nop 1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4] 121c:c9 leave 121d:8d 61 fc lea esp,[ecx-0x4] 1220:c3 ret ECXEBP - 4 EBP - 8 EBP - 12 0x00 0x00 0x00 0xff EBP - 268 0x410x410x410x41 0x410x410x410x41 0x410x410x410x41 . . . 0x410x410x410x41 RETURN ADDR ESP ADDRESS OF EBP-267EBP - 296
  • 36. 00001199 <function>: 1199:55 push ebp 119a:89 e5 mov ebp,esp 119c:53 push ebx 119d:83 ec 14 sub esp,0x14 … 11aa:83 ec 08 sub esp,0x8 11ad:ff 75 08 push DWORD PTR [ebp+0x8] 11b0:8d 55 e8 lea edx,[ebp-0x18] 11b3:52 push edx 11b4:89 c3 mov ebx,eax 11b6:e8 75 fe ff ff call 1030 <strcpy@plt> 11bb:83 c4 10 add esp,0x10 11be:90 nop 11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4] 11c2:c9 leave 11c3:c3 ret 000011c4 <main>: … 11ce:55 push ebp 11cf:89 e5 mov ebp,esp 11d1:51 push ecx 11d2:81 ec 14 01 00 00 sub esp,0x114 … 11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0 11e9:eb 12 jmp 11fd <main+0x39> 11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c] 11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc] 11f4:01 d0 add eax,edx 11f6:c6 00 41 mov BYTE PTR [eax],0x41 11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1 11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe 1204:7e e5 jle 11eb <main+0x27> 1206:83 ec 0c sub esp,0xc 1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c] 120f:50 push eax 1210:e8 84 ff ff ff call 1199 <function> 1215:83 c4 10 add esp,0x10 1218:90 nop 1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4] 121c:c9 leave 121d:8d 61 fc lea esp,[ecx-0x4] 1220:c3 ret HIGH MEMORY ADDRESS EBP - MAIN ECX 0x00 0x00 0x00 0xff 0x410x410x410x41 0x410x410x410x41 0x410x410x410x41 . . . 0x410x410x410x41 EBX RETURN ADDR ADDRESS OF LARGE_STRING EBP - 4 ESP EBP - FUNCTION
  • 37. 00001199 <function>: 1199:55 push ebp 119a:89 e5 mov ebp,esp 119c:53 push ebx 119d:83 ec 14 sub esp,0x14 … 11aa:83 ec 08 sub esp,0x8 11ad:ff 75 08 push DWORD PTR [ebp+0x8] 11b0:8d 55 e8 lea edx,[ebp-0x18] 11b3:52 push edx 11b4:89 c3 mov ebx,eax 11b6:e8 75 fe ff ff call 1030 <strcpy@plt> 11bb:83 c4 10 add esp,0x10 11be:90 nop 11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4] 11c2:c9 leave 11c3:c3 ret 000011c4 <main>: … 11ce:55 push ebp 11cf:89 e5 mov ebp,esp 11d1:51 push ecx 11d2:81 ec 14 01 00 00 sub esp,0x114 … 11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0 11e9:eb 12 jmp 11fd <main+0x39> 11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c] 11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc] 11f4:01 d0 add eax,edx 11f6:c6 00 41 mov BYTE PTR [eax],0x41 11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1 11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe 1204:7e e5 jle 11eb <main+0x27> 1206:83 ec 0c sub esp,0xc 1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c] 120f:50 push eax 1210:e8 84 ff ff ff call 1199 <function> 1215:83 c4 10 add esp,0x10 1218:90 nop 1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4] 121c:c9 leave 121d:8d 61 fc lea esp,[ecx-0x4] 1220:c3 ret HIGH MEMORY ADDRESS EBP - MAIN ECX 0x00 0x00 0x00 0xff 0x410x410x410x41 0x410x410x410x41 0x410x410x410x41 . . . 0x410x410x410x41 EBX RETURN ADDR ADDRESS OF LARGE_STRING EBP - 4 . . . EBP - 24 EBP - FUNCTION ESP
  • 38. 00001199 <function>: 1199:55 push ebp 119a:89 e5 mov ebp,esp 119c:53 push ebx 119d:83 ec 14 sub esp,0x14 … 11aa:83 ec 08 sub esp,0x8 11ad:ff 75 08 push DWORD PTR [ebp+0x8] 11b0:8d 55 e8 lea edx,[ebp-0x18] 11b3:52 push edx 11b4:89 c3 mov ebx,eax 11b6:e8 75 fe ff ff call 1030 <strcpy@plt> 11bb:83 c4 10 add esp,0x10 11be:90 nop 11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4] 11c2:c9 leave 11c3:c3 ret 000011c4 <main>: … 11ce:55 push ebp 11cf:89 e5 mov ebp,esp 11d1:51 push ecx 11d2:81 ec 14 01 00 00 sub esp,0x114 … 11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0 11e9:eb 12 jmp 11fd <main+0x39> 11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c] 11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc] 11f4:01 d0 add eax,edx 11f6:c6 00 41 mov BYTE PTR [eax],0x41 11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1 11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe 1204:7e e5 jle 11eb <main+0x27> 1206:83 ec 0c sub esp,0xc 1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c] 120f:50 push eax 1210:e8 84 ff ff ff call 1199 <function> 1215:83 c4 10 add esp,0x10 1218:90 nop 1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4] 121c:c9 leave 121d:8d 61 fc lea esp,[ecx-0x4] 1220:c3 ret HIGH MEMORY ADDRESS EBP - MAIN ECX 0x00 0x00 0x00 0xff 0x410x410x410x41 0x410x410x410x41 0x410x410x410x41 . . . 0x410x410x410x41 EBP - FUNCTION EBX RETURN ADDR ADDRESS OF LARGE_STRING EBP - 4 . . . EBP - 24 EBP - 28 EBP - 32 ESP
  • 39. 00001199 <function>: 1199:55 push ebp 119a:89 e5 mov ebp,esp 119c:53 push ebx 119d:83 ec 14 sub esp,0x14 … 11aa:83 ec 08 sub esp,0x8 11ad:ff 75 08 push DWORD PTR [ebp+0x8] 11b0:8d 55 e8 lea edx,[ebp-0x18] 11b3:52 push edx 11b4:89 c3 mov ebx,eax 11b6:e8 75 fe ff ff call 1030 <strcpy@plt> 11bb:83 c4 10 add esp,0x10 11be:90 nop 11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4] 11c2:c9 leave 11c3:c3 ret 000011c4 <main>: … 11ce:55 push ebp 11cf:89 e5 mov ebp,esp 11d1:51 push ecx 11d2:81 ec 14 01 00 00 sub esp,0x114 … 11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0 11e9:eb 12 jmp 11fd <main+0x39> 11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c] 11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc] 11f4:01 d0 add eax,edx 11f6:c6 00 41 mov BYTE PTR [eax],0x41 11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1 11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe 1204:7e e5 jle 11eb <main+0x27> 1206:83 ec 0c sub esp,0xc 1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c] 120f:50 push eax 1210:e8 84 ff ff ff call 1199 <function> 1215:83 c4 10 add esp,0x10 1218:90 nop 1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4] 121c:c9 leave 121d:8d 61 fc lea esp,[ecx-0x4] 1220:c3 ret HIGH MEMORY ADDRESS EBP - MAIN ECX 0x00 0x00 0x00 0xff 0x410x410x410x41 0x410x410x410x41 0x410x410x410x41 . . . 0x410x410x410x41 EBP - FUNCTION EBX RETURN ADDR ADDRESS OF LARGE_STRING EBP - 4 . . . EBP - 24 EBP - 28 EBP - 32 ESP EBP + 8 ADDRESS OF LARGE_STRINGEBP - 36
  • 40. 00001199 <function>: 1199:55 push ebp 119a:89 e5 mov ebp,esp 119c:53 push ebx 119d:83 ec 14 sub esp,0x14 … 11aa:83 ec 08 sub esp,0x8 11ad:ff 75 08 push DWORD PTR [ebp+0x8] 11b0:8d 55 e8 lea edx,[ebp-0x18] 11b3:52 push edx 11b4:89 c3 mov ebx,eax 11b6:e8 75 fe ff ff call 1030 <strcpy@plt> 11bb:83 c4 10 add esp,0x10 11be:90 nop 11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4] 11c2:c9 leave 11c3:c3 ret 000011c4 <main>: … 11ce:55 push ebp 11cf:89 e5 mov ebp,esp 11d1:51 push ecx 11d2:81 ec 14 01 00 00 sub esp,0x114 … 11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0 11e9:eb 12 jmp 11fd <main+0x39> 11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c] 11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc] 11f4:01 d0 add eax,edx 11f6:c6 00 41 mov BYTE PTR [eax],0x41 11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1 11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe 1204:7e e5 jle 11eb <main+0x27> 1206:83 ec 0c sub esp,0xc 1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c] 120f:50 push eax 1210:e8 84 ff ff ff call 1199 <function> 1215:83 c4 10 add esp,0x10 1218:90 nop 1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4] 121c:c9 leave 121d:8d 61 fc lea esp,[ecx-0x4] 1220:c3 ret HIGH MEMORY ADDRESS EBP - MAIN ECX 0x00 0x00 0x00 0xff 0x410x410x410x41 0x410x410x410x41 0x410x410x410x41 . . . 0x410x410x410x41 EBP - FUNCTION EBX RETURN ADDR ADDRESS OF LARGE_STRING EBP - 4 16 BYTE BUFFER. . . EBP - 24 EBP - 28 EBP - 32 EBP + 8 ADDRESS OF LARGE_STRINGEBP - 36 ADDRESS OF BUFFEREBP - 40 ESP
  • 42. 00001199 <function>: 1199:55 push ebp 119a:89 e5 mov ebp,esp 119c:53 push ebx 119d:83 ec 14 sub esp,0x14 … 11aa:83 ec 08 sub esp,0x8 11ad:ff 75 08 push DWORD PTR [ebp+0x8] 11b0:8d 55 e8 lea edx,[ebp-0x18] 11b3:52 push edx 11b4:89 c3 mov ebx,eax 11b6:e8 75 fe ff ff call 1030 <strcpy@plt> 11bb:83 c4 10 add esp,0x10 11be:90 nop 11bf:8b 5d fc mov ebx,DWORD PTR [ebp-0x4] 11c2:c9 leave 11c3:c3 ret 000011c4 <main>: … 11ce:55 push ebp 11cf:89 e5 mov ebp,esp 11d1:51 push ecx 11d2:81 ec 14 01 00 00 sub esp,0x114 … 11e2:c7 45 f4 00 00 00 00 mov DWORD PTR [ebp-0xc],0x0 11e9:eb 12 jmp 11fd <main+0x39> 11eb:8d 95 f4 fe ff ff lea edx,[ebp-0x10c] 11f1:8b 45 f4 mov eax,DWORD PTR [ebp-0xc] 11f4:01 d0 add eax,edx 11f6:c6 00 41 mov BYTE PTR [eax],0x41 11f9:83 45 f4 01 add DWORD PTR [ebp-0xc],0x1 11fd:81 7d f4 fe 00 00 00 cmp DWORD PTR [ebp-0xc],0xfe 1204:7e e5 jle 11eb <main+0x27> 1206:83 ec 0c sub esp,0xc 1209:8d 85 f4 fe ff ff lea eax,[ebp-0x10c] 120f:50 push eax 1210:e8 84 ff ff ff call 1199 <function> 1215:83 c4 10 add esp,0x10 1218:90 nop 1219:8b 4d fc mov ecx,DWORD PTR [ebp-0x4] 121c:c9 leave 121d:8d 61 fc lea esp,[ecx-0x4] 1220:c3 ret HIGH MEMORY ADDRESS EBP - MAIN ECX 0x00 0x00 0x00 0xff 0x410x410x410x41 0x410x410x410x41 0x410x410x410x41 . . . 0x410x410x410x41 EBP - FUNCTION EBX RETURN ADDR ADDRESS OF LARGE_STRING EBP - 4 16 BYTE BUFFER. . . EBP - 24 EBP - 28 EBP - 32 EBP + 8 ADDRESS OF LARGE_STRINGEBP - 36 ADDRESS OF BUFFEREBP - 40 ESP 0x410x410x410x41 0x410x410x410x41 0x410x410x410x41 0x410x410x410x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41
  • 44. DYNAMIC MEMORY ALLOCATION BUFFER OVERFLOW int main() { char large_string[256]; int i; for(i = 0; i < 255; i++) large_string[i] = 'A'; char buffer[16]; strcpy(buffer, large_string); } int main(int argc, char **argv) { char buffer[16]; gets(buffer); } ▸ What happens if you fill the buffer with a user input? ▸ User can enter an input with the length > 16
  • 45. HIGH MEMORY ADDRESS EBP - MAIN ECX 0x00 0x00 0x00 0xff 0x410x410x410x41 0x410x410x410x41 0x410x410x410x41 . . . 0x410x410x410x41 EBP - FUNCTION EBX RETURN ADDR ADDRESS OF LARGE_STRING 16 BYTE BUFFER 0x410x410x410x41 0x410x410x410x41 0x410x410x410x41 user codemyofAddress 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 USER CODE BUFFER OVERFLOW ▸ Overwrite the return address ▸ Change the program flow DYNAMIC MEMORY ALLOCATION