본문 바로가기

Layer7/CTF & Wargame

Write-up: [고등해커3] [Reversing] OXR

코드는 아래와 같다

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<stdio.h>
#include<string.h>
char table[]={100108107989610488771984124188780124877478161248776124808723818712481168594};
int main(){
    char input[34];
    int i;
    int count=0;
    printf("input:");
    scanf("%s",input);
    for(i=0;i<strlen(input);i++){
        input[i]^=0x23;
    }
    for(i=0;i<strlen(input);i++){
        if (input[i]==table[i])
            count+=1;
    }
    if (count!=strlen(table)){
        puts("Wrong");
    }
    else
        puts("Correct");
}
cs

입력받은 값을 ^ 0x23 연산해서 다시 저장한뒤, 그 값이 table[]과 일치하면 Correct가 뜬다.

 

그럼 table[]값을 역으로 계산해주면 답이 나오는데 XOR를 잘 몰라서 그냥 브루드 포싱으로 해결했다.

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
39
40
41
42
43
44
45
#include<stdio.h>
#include<string.h>
char table[]={    1001081079896
                10488771984,
                124188780124
                87747816124
                87761248087
                23818712481
                168594};
int main(){
    char input[34];
    int i;
    char j;
    int count=0;
 
    //input
    for (i = 0; i < 33++i)
    {
        input[i] = 'N';
        for (j = 0; j < 200++j)
        {
            if ((j^0x23== table[i])
            {
                printf("%c", j);
                input[i] = j^0x23;
                break;
            }
        }
    }
    puts("");
 
    //compare
    for(i=0;i<strlen(input);i++){
        if (input[i]==table[i])
            count+=1;
    }
 
    //result
    if (count!=strlen(table)){
        puts(table);
        puts("Wrong");
    }
    else
        puts("Correct");
}
cs

 

이차원 배열을 사용해서 0부터 200까지 하나씩 0x23을 XOR해 그 값이 일치하면 input[]에 넣어주고 j를 출력시켜주었다.

200인 이유는 XOR하기 전의 값의 범위를 몰라서 적당히 큰 수를 넣어주었기 때문이다,