문제 설명


우분투에서 문제 접속해 보니

이렇게 뭔가... 파일 목록? 이 뜬다.

7번째 열에 ff 파일, 8번째 열에 fs 파일이 있는 걸 확인할 수 있다.

이렇게 보면 파일의 차이점을 전혀 분간할 수 없음.

접근 권한이나 날짜나 다 똑같음

 

그래서 하단 input command에 두 파일의 차이점을 확인하는 명령어인 diff을 사용해 입력해 봤다.

엥..

 

일단 문제로 돌아가서 문제 코드 먼저 살펴봄

// Name: chall.c
// Compile Option: gcc chall.c -o chall -fno-stack-protector

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>

#define FLAG_SIZE 0x45

void alarm_handler() {
    puts("TIME OUT");
    exit(-1);
}

void initialize() {
    setvbuf(stdin, NULL, _IONBF, 0);
    setvbuf(stdout, NULL, _IONBF, 0);

    signal(SIGALRM, alarm_handler);
    alarm(30);
}


int main(int argc, char *argv[]) {
    char cmd[50];
    char input[21];
    char filter[] = {'&', ';', '|', '$', '`', '*','[', ']', '{', '}', '\\', '^', '~', '?', '#', '!'};

    initialize();
    system("ls -al");
    printf("Input Command: \n");
    scanf("%20[^\n]", input);

    // filtering
    for (int i = 0; i < strlen(input); i++){
        for (int j = 0; j < sizeof(filter); j++){
            if(input[i] == filter[j]){
                printf("filtered.\n");
                exit(0);
            }
        }
    }

    snprintf(cmd, 49, "(%s) > /dev/null", input);

    system(cmd);
    system("cat ./out");
    printf("Terminated\n");

    return 0;
}

일단 input 값으로 받아서 웬만한 특수문자들은 다 필터링하는 것같고,

입력된 명령어를 cmd 배열에 저장한 다음에 /dev/null과 결합돼서 수행한다.

 

그런데 실행한 명령어의 결과를 출력값으로 주는 게 아니라, cat ./out을 호출해서 out 파일에 담긴 내용을 출력해버린다!

지금껏 계속 what's different? 가 나오는 이유 역시 out 파일에 담긴 내용이 'what's different?'였기 때문이었던 걸 추측해 볼 수 있다. 

해결 방법은 생각보다 간단할 것 같아서 바로 해봤다.

diff ff fs 의 결과값을 그냥 out으로 리다이렉션 시켰더니 풀렸다!

풀이 완료

 

'SWUFORCE > 워게임 풀이' 카테고리의 다른 글

[Dreamhack] file-special-bit (misc)  (0) 2024.08.20
[Dreamhack] addition-quiz (misc)  (0) 2024.08.20
[Dreamhack] littlevsbig (misc)  (0) 2024.08.06
[Dreamhack] image-storage (web)  (1) 2024.07.22
[wargame.kr] login filtering (web)  (0) 2024.07.16

+ Recent posts