๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
  • Welcome.
:: DreamHack ๐Ÿšฉ/wargame - reverse

[ dreamhack ] - [ reversing | rev-basic-7]

by EunBird 2022. 6. 1.

 

https://dreamhack.io/wargame/challenges/21/

 

rev-basic-7

Reversing Basic Challenge #7 ์ด ๋ฌธ์ œ๋Š” ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ฌธ์ž์—ด ์ž…๋ ฅ์„ ๋ฐ›์•„ ์ •ํ•ด์ง„ ๋ฐฉ๋ฒ•์œผ๋กœ ์ž…๋ ฅ๊ฐ’์„ ๊ฒ€์ฆํ•˜์—ฌ correct ๋˜๋Š” wrong์„ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์ด ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. ํ•ด๋‹น ๋ฐ”์ด๋„ˆ๋ฆฌ๋ฅผ ๋ถ„์„ํ•˜์—ฌ correct๋ฅผ ์ถœ

dreamhack.io

 

์ด๋ฒˆ ๋ฆฌ๋ฒ„์‹ฑ ๋ฌธ์ œ๋„ ์ด์ „๊ณผ ์œ ํ˜•์€ ๋น„์Šทํ•˜๋‹ค.

๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ๋””์ปดํŒŒ์ผ๋œ ์ฝ”๋“œ์—์„œ 

if๋ฌธ์˜ ์กฐ๊ฑด๋ฌธ์„ ํ™•์ธํ•˜์—ฌ Correct๋ฅผ ์ถœ๋ ฅํ•˜๊ฒŒ ํ•˜๋Š” 

์ž…๋ ฅ๊ฐ’์„ ์ฐพ์•„๋‚ด๋Š” ๊ฒƒ์ด๋‹ค.

 

 

if ๋ฌธ์˜ ์กฐ๊ฑด๋ฌธ์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

(i ^ (unsigned __int8)__ROL1__(*(_BYTE *)(a1 + i), i & 7)) != byte_140003000[i]

 

์ด ์‹์„ ๋น„๊ต์  ๊ฐ„๋‹จํ•˜๊ฒŒ ์ •๋ฆฌํ•˜๋ฉด,

( i xor ROL( a1[ i ] , i & 7 ) ) != byte_140003000[i]

๊ฐ€ ๋œ๋‹ค.

 

์ด๋•Œ, ROL ์€ 

ROL : ex) 0011 1010 -> ROL -> 0111 0100

๊ณผ ๊ฐ™์€ ์—ฐ์‚ฐ์„ ์˜๋ฏธํ•œ๋‹ค.

 

์ฆ‰, ์œ„์˜ ROL( a1[i] , i & 7 ) ์ด ์˜๋ฏธํ•˜๋Š” ๊ฒƒ์€ a1[i] ๋ฅผ i & 7 ๋งŒํผ ROL ์—ฐ์‚ฐํ•˜๋ผ๋Š” ์˜๋ฏธ์ด๋‹ค.

์ฆ‰ ์œ„์˜ ์กฐ๊ฑด๋ฌธ์„ ๋‹ค์‹œ ์ •๋ฆฌํ•ด๋ณด์ž๋ฉด,

a1 ๊ฐ’์„ i & 7 ๋งŒํผ ROL ์—ฐ์‚ฐ์„ ์‹œํ‚จ ํ›„, 

i ์™€ ํ•ด๋‹น ์—ฐ์‚ฐ๊ฐ’์„ xor ์—ฐ์‚ฐํ•œ ๊ฒฐ๊ณผ๊ฐ’์„ byte_140003000 ๊ฐ’๊ณผ ๋น„๊ตํ•˜๋Š” ๊ฒƒ์ด๋‹ค. 

 

์ด์ œ ์—ญ์—ฐ์‚ฐ์„ ์‹œ๋„ํ•  ๊ฒƒ์ธ๋ฐ,

xor ์—ฐ์‚ฐ์˜ ์„ฑ์งˆ์„ ์‚ฌ์šฉํ•˜์—ฌ ์‹์„ ๋ฐ”๊ฟ”๋ณด๊ฒ ๋‹ค.

 

1. ์–‘๋ณ€์— xor i ์—ฐ์‚ฐ

ROL( a1[i] , i & 7 ) != i xor byte_140003000[i] 

 

2. ์–‘๋ณ€์— ROR( , i & 7) ์—ฐ์‚ฐ --> ROR์—ฐ์‚ฐ์€ ROL ์—ฐ์‚ฐ์˜ ๋ฐ˜๋Œ€์ด๋‹ค.

a1[i] = ROR(i xor byte_140003000[ i ] , i & 7)

 

C๋กœ ์ž‘์„ฑํ•œ ์—ญ์—ฐ์‚ฐ ์ฝ”๋“œ

#include<stdio.h>

int ror(int x, int n) {
    int shift = x >> n;
    int src = x << (8-n);
    src &= 255;
    return shift | src;
}

int main(){

        unsigned char byte00[32] = {0x52, 0xDF, 0xB3, 0x60, 0xF1, 0x8B, 0x1C, 0xB5, 0x57, 0xD1, 0x9F, 0x38, 0x4B, 0x29, 0xD9,
                        0x26, 0x7F, 0xC9, 0xA3, 0xE9, 0x53, 0x18, 0x4F, 0xB8, 0x6A, 0xCB, 0x87, 0x58, 0x5B, 0x39, 0x1E, 0x00};
        unsigned char input[32]={0,};

        int i;
        int num[32];
        for (i=0 ; i<32 ; i++){
                num[i] = i ^ byte00[i];
                input[i] = ror(num[i], i&7);
        }

        int j;
        for (j=0 ; j<32 ; j++){
                printf("%c", input[j]);
        }
        printf("\n");
        return 0;
}

 

 

 

 

๋”ฐ๋ผ์„œ FLAG ๋Š” 

Roll_the_left!_Roll_the_right!>

์ž„์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค.

 

 

 

 

 

 

 

 

 

 

 

728x90

':: DreamHack ๐Ÿšฉ > wargame - reverse' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[ dreamhack ] - [ reversing | rev-basic-6]  (0) 2022.05.31
[ dreamhack ] - [ reversing | rev-basic-5 ]  (0) 2022.05.31
[ dreamhack ] - [ reversing | rev-basic-4 ]  (0) 2022.05.30
reversing | [CodeEngn] Malware L07  (0) 2022.05.30
[dreamhack] - [reversing | rev-basic-2]  (0) 2022.05.30

๋Œ“๊ธ€