Слайд 2What is libc ?
Prog.elf
libc.so
ld-linux-x86-64.so
55cdfefe3000
7f11866a7000
7f1186c82000
![What is libc ? Prog.elf libc.so ld-linux-x86-64.so 55cdfefe3000 7f11866a7000 7f1186c82000](/_ipx/f_webp&q_80&fit_contain&s_1440x1080/imagesDir/jpg/858975/slide-1.jpg)
Слайд 3What is libc ?
Prog.elf .text
Prog.elf .data
Prog.elf .bss
Prog.elf .plt
libc.so .text
libc.so .data
libc.so .bss
libc.so .plt
55cdfefe3000
7f11866a7000
![What is libc ? Prog.elf .text Prog.elf .data Prog.elf .bss Prog.elf .plt](/_ipx/f_webp&q_80&fit_contain&s_1440x1080/imagesDir/jpg/858975/slide-2.jpg)
Слайд 4What is libc ?
// libc.so
printf
…
ret
Puts
…
ret
System
…
ret
// You program
main
call printf
ret
plt:
jmp printf
![What is libc ? // libc.so printf … ret Puts … ret](/_ipx/f_webp&q_80&fit_contain&s_1440x1080/imagesDir/jpg/858975/slide-3.jpg)
Слайд 5ret2libc
We know version of libc.so
We know address of libc.so
We know any function
![ret2libc We know version of libc.so We know address of libc.so We](/_ipx/f_webp&q_80&fit_contain&s_1440x1080/imagesDir/jpg/858975/slide-4.jpg)
address at libc.so
Слайд 6ret2libc
int main (){
char buf [16];
gets(buf);
}
ret from main
ebp before main
char buf[16]
![ret2libc int main (){ char buf [16]; gets(buf); } ret from main](/_ipx/f_webp&q_80&fit_contain&s_1440x1080/imagesDir/jpg/858975/slide-5.jpg)
Слайд 7ret2libc
.stack ; segment with stack
Main:
push ebp
mov ebp, esp
sub esp, 16
lea edx, buf
push
![ret2libc .stack ; segment with stack Main: push ebp mov ebp, esp](/_ipx/f_webp&q_80&fit_contain&s_1440x1080/imagesDir/jpg/858975/slide-6.jpg)
edx
call gets
add esp, 4
leave
Ret
…………………………………….
10. system :
11. …
12 ret
13. Printf:
14. …
15. ret
Ret from main
?eip
Слайд 8ret2libc
.stack ; segment with stack
Ret from main
?eip
old ebp
Main:
push ebp
mov ebp, esp
sub esp,
![ret2libc .stack ; segment with stack Ret from main ?eip old ebp](/_ipx/f_webp&q_80&fit_contain&s_1440x1080/imagesDir/jpg/858975/slide-7.jpg)
16
lea edx, buf
push edx
call gets
add esp, 4
leave
Ret
…………………………………….
10. system :
11. …
12 ret
13. Printf:
14. …
15. ret
Слайд 9ret2libc
.stack ; segment with stack
Ret from main
?eip
old ebp
ebp=8
1
2
3
4
5
6
7
8
9
Main:
push ebp
mov ebp, esp
sub esp,
![ret2libc .stack ; segment with stack Ret from main ?eip old ebp](/_ipx/f_webp&q_80&fit_contain&s_1440x1080/imagesDir/jpg/858975/slide-8.jpg)
16
lea edx, buf
push edx
call gets
add esp, 4
leave
Ret
…………………………………….
10. system :
11. …
12 ret
13. Printf:
14. …
15. ret
Слайд 10ret2libc
.stack ; segment with stack
Ret from main
?eip
old ebp
ebp=8
1
2
3
4
5
6
7
8
9
Char buf[16]
Main:
push ebp
mov ebp, esp
sub
![ret2libc .stack ; segment with stack Ret from main ?eip old ebp](/_ipx/f_webp&q_80&fit_contain&s_1440x1080/imagesDir/jpg/858975/slide-9.jpg)
esp, 16
lea edx, buf
push edx
call gets
add esp, 4
leave
Ret
…………………………………….
10. system :
11. …
12 ret
13. Printf:
14. …
15. ret
Слайд 11ret2libc
.stack ; segment with stack
Ret from main
?eip
old ebp
ebp=8
1
2
3
4
5
6
7
8
9
Char buf[16]
edx=4
Main:
push ebp
mov ebp, esp
sub
![ret2libc .stack ; segment with stack Ret from main ?eip old ebp](/_ipx/f_webp&q_80&fit_contain&s_1440x1080/imagesDir/jpg/858975/slide-10.jpg)
esp, 16
lea edx, buf
push edx
call gets
add esp, 4
leave
Ret
…………………………………….
10. system :
11. …
12 ret
13. Printf:
14. …
15. ret
Слайд 12ret2libc
.stack ; segment with stack
Ret from main
?eip
old ebp
ebp=8
1
2
3
4
5
6
7
8
9
Char buf[16]
edx=4
4
Main:
push ebp
mov ebp, esp
sub
![ret2libc .stack ; segment with stack Ret from main ?eip old ebp](/_ipx/f_webp&q_80&fit_contain&s_1440x1080/imagesDir/jpg/858975/slide-11.jpg)
esp, 16
lea edx, buf
push edx
call gets
add esp, 4
leave
Ret
…………………………………….
10. system :
11. …
12 ret
13. Printf:
14. …
15. ret
Слайд 13ret2libc
.stack ; segment with stack
Ret from main|AAAA
?eip
old ebp|AAAA
ebp=8
1
2
3
4
5
6
7
8
9
AAAA
AAAA
AAAA
AAAA
edx=4
4
Main:
push ebp
mov ebp, esp
sub esp,
![ret2libc .stack ; segment with stack Ret from main|AAAA ?eip old ebp|AAAA](/_ipx/f_webp&q_80&fit_contain&s_1440x1080/imagesDir/jpg/858975/slide-12.jpg)
16
lea edx, buf
push edx
call gets
add esp, 4
leave
Ret
…………………………………….
10. system :
11. …
12 ret
13. Printf:
14. …
15. ret
Слайд 14ret2libc
.stack ; segment with stack
Ret from main|AAAA
?eip
old ebp|AAAA
ebp=8
1
2
3
4
5
6
7
8
9
AAAA
AAAA
AAAA
AAAA
edx=4
Main:
push ebp
mov ebp, esp
sub esp,
![ret2libc .stack ; segment with stack Ret from main|AAAA ?eip old ebp|AAAA](/_ipx/f_webp&q_80&fit_contain&s_1440x1080/imagesDir/jpg/858975/slide-13.jpg)
16
lea edx, buf
push edx
call gets
add esp, 4
leave
Ret
…………………………………….
10. system :
11. …
12 ret
13. Printf:
14. …
15. ret
Слайд 15ret2libc
.stack ; segment with stack
Ret from main|syscall
?eip
ebp=AAAA
1
2
3
4
5
6
7
8
9
edx=4
Main:
push ebp
mov ebp, esp
sub esp, 16
lea
![ret2libc .stack ; segment with stack Ret from main|syscall ?eip ebp=AAAA 1](/_ipx/f_webp&q_80&fit_contain&s_1440x1080/imagesDir/jpg/858975/slide-14.jpg)
edx, buf
push edx
call gets
add esp, 4
leave
Ret
…………………………………….
10. system :
11. …
12 ret
13. Printf:
14. …
15. ret
Слайд 19ret2libc
.stack ; segment with stack
Ret from main|syscall
?eip
ebp=AAAA
1
2
3
4
5
6
7
8
9
edx=4
Main:
push ebp
mov ebp, esp
sub esp, 16
lea
![ret2libc .stack ; segment with stack Ret from main|syscall ?eip ebp=AAAA 1](/_ipx/f_webp&q_80&fit_contain&s_1440x1080/imagesDir/jpg/858975/slide-18.jpg)
edx, buf
push edx
call gets
add esp, 4
leave
Ret
…………………………………….
10. system :
11. …
12 ret
13. Printf:
14. …
15. ret
Слайд 209. ret
…………………………………….
10. system :
11. …
12 ret
13. Printf:
14. …
15. ret
ret2libc
.stack ; segment with stack
?eip
ebp=AAAA
1
2
3
4
5
6
7
8
9
10
11
edx=4
![9. ret ……………………………………. 10. system : 11. … 12 ret 13. Printf:](/_ipx/f_webp&q_80&fit_contain&s_1440x1080/imagesDir/jpg/858975/slide-19.jpg)
Слайд 219. ret
…………………………………….
10. system:
11. …
12 ret
13. Printf:
14. …
15. ret
ret2libc
.stack ; segment with stack
?eip
ebp=AAAA
1
2
3
4
5
6
7
8
9
10
11
edx=4
Ret from main|syscall
Ref to “/bin/sh”
Ret
![9. ret ……………………………………. 10. system: 11. … 12 ret 13. Printf: 14.](/_ipx/f_webp&q_80&fit_contain&s_1440x1080/imagesDir/jpg/858975/slide-20.jpg)
from syscall
Слайд 24What about randomization
/proc/sys/kernel/randomize_va_space
0 – No randomization. Everything is static.
1 – Conservative randomization.
![What about randomization /proc/sys/kernel/randomize_va_space 0 – No randomization. Everything is static. 1](/_ipx/f_webp&q_80&fit_contain&s_1440x1080/imagesDir/jpg/858975/slide-23.jpg)
Shared libraries, stack, mmap(), VDSO and heap are randomized.
2 – Full randomization. In addition to elements listed in the previous point, memory managed through brk() is also randomized.
Слайд 25Static compile
Prog.elf
libc.so
ld-linux-x86-64.so
55cdfefe3000
7f11866a7000
7f1186c82000
![Static compile Prog.elf libc.so ld-linux-x86-64.so 55cdfefe3000 7f11866a7000 7f1186c82000](/_ipx/f_webp&q_80&fit_contain&s_1440x1080/imagesDir/jpg/858975/slide-24.jpg)
Слайд 26Static compile (-s)
Prog.elf
libc.so
ld-linux-x86-64.so
Prog.elf
libc.so
ld-linux-x86-64.so
![Static compile (-s) Prog.elf libc.so ld-linux-x86-64.so Prog.elf libc.so ld-linux-x86-64.so](/_ipx/f_webp&q_80&fit_contain&s_1440x1080/imagesDir/jpg/858975/slide-25.jpg)
Слайд 27Static compile (-s)
Works in any linux with any libc installed
ELF contains entire
![Static compile (-s) Works in any linux with any libc installed ELF](/_ipx/f_webp&q_80&fit_contain&s_1440x1080/imagesDir/jpg/858975/slide-26.jpg)
libraries
Very big binary
You can find many functions an gadgets - dangerous
Слайд 28GDB commands
gdb:
maint info sections – show sections
shell ps aux | grep test
![GDB commands gdb: maint info sections – show sections shell ps aux](/_ipx/f_webp&q_80&fit_contain&s_1440x1080/imagesDir/jpg/858975/slide-27.jpg)
– show process pid
cat /proc/[PID]/maps – show sections of process
find [START ADDRESS], [END ADDRESS], “[STRING]”
shell:
ldd test