Stack and Buffer Overflow
Author : Md. Monowarul Amin, BSc. In SWE (Batch-20), IUT
1
Objective
2
Process’ memory
Code
How generate the binary for this…
Flags’ Description
3
Buffer Overflow Overview
although no one called it.
4
Representation of main() in stack
ebp(previous)
ebp(main)
stack
of the previous function.
esp
Representation of main() in stack
6
ebp(previous)
ebp(main)
ebx
ecx
1(a)
2(b)
stack
Local Variables
of the previous function.
ebp - 4
ebp - 8
ebp - 12
ebp - 16
esp
Representation of main() in stack
ebp(previous)
ebx
ecx
1(a)
2(b)
-
-
2(b)
1(a)
ebp(main)
Function
parameters
of the previous function.
ebp - 4
ebp - 8
ebp - 12
ebp - 16
ebp - 20
ebp - 24
ebp - 28
ebp - 32
esp
Representation of main() in stack
8
ebp(previous)
ebx
ecx
1(a)
2(b)
-
-
2(b)
1(a)
ret
ebp(main)
stack
of the previous function.
ebp - 4
ebp - 8
ebp - 12
ebp - 16
ebp - 20
ebp - 24
ebp - 28
ebp - 32
ebp - 36
esp
Inside Callee()’s Stack
9
ebp(main)
ebx
-
91(f)
(c)
buff
buff
buff
buff
buff
ebp(callee)
stack
of the main().
ret
ebp - 4
ebp - 8
ebp - 12
ebp - 16
ebp - 20
ebp - 24
ebp - 28
ebp - 32
ebp - 36
gets() inserts
esp
Overwriting Variable’s value
10
ebp(main)
ebx
-
91(f)
(c)
buff
buff
buff
buff
buff
ebp(callee)
stack
ret
ebp - 4
ebp - 8
ebp - 12
ebp - 16
ebp - 20
ebp - 24
ebp - 28
ebp - 32
ebp - 36
gets() inserts
esp
Modify Variable’s value(contd…)
python2 -c "print('A' * 24 + '\x01\x00\x00\x00')" |./buffer_overflow1
Jumping to Another Function
12
ebp(main)
ebx
-
91(f)
(c)
buff
buff
buff
buff
buff
ebp(callee)
stack
ret
ebp - 4
ebp - 8
ebp - 12
ebp - 16
ebp - 20
ebp - 24
ebp - 28
ebp - 32
ebp - 36
gets() inserts
Jumping to Another Function(contd..)
13
ebp(main)
ebx
-
91(f)
(c)
buff
buff
buff
buff
buff
ebp(callee)
stack
Payload
ret
ebp - 4
ebp - 8
ebp - 12
ebp - 16
ebp - 20
ebp - 24
ebp - 28
ebp - 32
ebp - 36
gets() inserts
python2 -c "print('A' * 40 + '\x96\x91\x04\x08')" | ./buffer_overflow1
Note: Why the address inserted in this way?
As our system is Little Endian
Reference
14
Thank You