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

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

by EunBird 2022. 5. 30.

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

 

rev-basic-4

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

dreamhack.io

 

์ด์ „ rev-basic ๋ฌธ์ œ๋“ค๊ณผ ๋น„์Šทํ•˜๋‹ค.

 

 

๋””์ปดํŒŒ์ผ๋œ main์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

sub_140001000 ํ•จ์ˆ˜๊ฐ€ ์ฐธ์ด๋˜๋ฉด Correct๊ฐ€ ์ถœ๋ ฅ๋˜๋Š” ๊ฒƒ์œผ๋กœ ๋ณด์ธ๋‹ค.

ํ™•์ธํ•ด๋ณด๊ฒ ๋‹ค.

 

for ๋ฌธ์„ 0x1C ๋ฒˆ, ์ฆ‰, 28๋ฒˆ ๋Œ๋ฆฌ๋Š”๋ฐ,

์กฐ๊ฑด๋ฌธ์€

 ((unsigned __int8)(16 * *(_BYTE *)(a1 + i)) | ((int)*(unsigned __int8 *)(a1 + i) >> 4)) != byte_140003000[i]

์ด๋‹ค. 

 ((unsigned __int8)(16 * *(_BYTE *)(a1 + i)) | ((int)*(unsigned __int8 *)(a1 + i) >> 4)) != byte_140003000[i]

 

์œ„ ์กฐ๊ฑด๋ฌธ์„ ์‚ด์ง ์ •๋ฆฌํ•ด์„œ ์จ๋ณด์ž๋ฉด,

 

( 16 * a1[i] )  ||  (a1[i] >> 4 ) != byte_140003000[i] ์ด๋‹ค.

 

1. 16 * a1[i]

2.  a1[i] >> 4

3. ( 16 * a1[i] )  ||  (a1[i] >> 4 )

๊ณผ ๊ฐ™์€ ์ˆœ์„œ๋กœ ํ•˜๋‚˜์”ฉ ์ง„ํ–‰ํ•˜๊ฒ ๋‹ค.

 

 

1.16 * a1[i]

๋‹ค์Œ ๊ทธ๋ฆผ์„ ํ†ตํ•ด [ 16(10) * 16์ง„์ˆ˜ ]๊ฐ€ ์–ด๋–ค ์˜๋ฏธ๋ฅผ ๊ฐ–๊ณ  ์žˆ๋Š”์ง€ ํ™•์ธํ•ด๋ณด์ž

0xA
* 16 (๊ณฑํ•˜๊ธฐ 10์ง„์ˆ˜)
= 0xA0

์œ„์ฒ˜๋Ÿผ [16์ง„์ˆ˜] * 16(10์ง„์ˆ˜) = [16์ง„์ˆ˜]0 ์ด๋‹ค.

0xA * 16 = 0xA0

์ฆ‰, ํ•˜๋‚˜์˜ 16์ง„์ˆ˜์—๋‹ค๊ฐ€ ์‹ญ์ง„์ˆ˜ 16์„ ๊ณฑํ•˜๋ฉด ๊ทธ ๊ฒฐ๊ณผ๋Š” ์›๋ž˜์˜ 16์ง„์ˆ˜์˜ ๋งจ ์˜ค๋ฅธ์ชฝ์— 0์„ ํ•˜๋‚˜ ๋ถ™ํžˆ๋Š” ๊ฒƒ๊ณผ ๊ฐ™๋‹ค๋Š” ๊ฒƒ์ด๋‹ค.

 

 

 

2.  a1[i] >> 4

์ด๋ฒˆ์—๋Š” a1[i] >> 4   ์—ฐ์‚ฐ์ธ๋ฐ, 

>> ๋Š” ๋น„ํŠธ๋‹จ์œ„์˜ ์‰ฌํ”„ํŠธ ์—ฐ์‚ฐ์ž์ด๋‹ค.

 

์˜ˆ๋ฅผ ๋“ค์ž๋ฉด, 

 0xA >> 4    

 0000 1010 >> 4

 0000 0101   <-- ์‰ฌํ”„ํŠธ ํ•œ๋ฒˆ

 0000 0010  <-- ์‰ฌํ”„ํŠธ ๋‘๋ฒˆ

 0000 0001  <-- ์‰ฌํ”„ํŠธ ์„ธ๋ฒˆ

 0000 0000  <-- ์‰ฌํ”„ํŠธ ๋„ค๋ฒˆ   ์˜ ์˜๋ฏธ์ด๋‹ค.

 

์ฆ‰, 0xA >>4 ๋Š” 0x0 ์ด ๋œ๋‹ค. 

 

 

 

3. ( 16 * a1[i] )  ||  (a1[i] >> 4 )

 

์ด์ œ ํ•ฉ์ณ์„œ ํ™•์ธํ•  ๊ฒƒ์ธ๋ฐ,

 ( 16 * a1[i] )  ||  (a1[i] >> 4 ) ์€ OR ๋‘ ์—ฐ์‚ฐ์œผ๋กœ ๋‚˜์˜จ ๋‘ ๊ฐ’์„ OR ์—ฐ์‚ฐ์‹œํ‚จ๋‹ค.

 

์ž…๋ ฅ๊ฐ’์ด 0xA ๋ผ๊ณ  ๊ฐ€์ •ํ•˜๊ณ  ๋ชจ๋‘ ์ •๋ฆฌํ•˜๋ฉด,

( 16 * a1[i] )  ||  (a1[i] >> 4 ) != byte_140003000[i]

0xA0 || 0x0 != byte_140003000[i]

1010 0000 || 0000 0000 != byte_140003000[i]

1010 0000 != byte_140003000[i]

 

์ฆ‰, 1010 0000 ๊ณผ  byte_140003000[i] ๋ฅผ ๋น„๊ตํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

๊ทธ๋Ÿฐ๋ฐ, 1010 0000 ์€ ์ฒ˜์Œ ์ž…๋ ฅํ–ˆ๋˜ 0xA ๋ฅผ 2์ง„์ˆ˜์—์„œ 4๋น„ํŠธ๋ผ๋ฆฌ ์•ž๋’ค๋กœ ๋’ค์ง‘์€ ๊ฐ’์ด๋‹ค.

 

-->

0xA   = 0000 1010 (2)

0xA0 = 1010 0000 (2)

๋ผ๋Š” ๊ฒƒ์ด๋‹ค.

 

 

 


๋”ฐ๋ผ์„œ  byte_140003000[i] ์— ์ €์žฅ๋˜์–ด ์žˆ๋Š” ๋ฌธ์ž๋“ค์„

๊ฑฐ๊พธ๋กœ ๋‹ค์‹œ ์•ž๋’ค๋กœ 4๋น„ํŠธ์”ฉ ๋’ค์ง‘์œผ๋ฉด

Correct๋ฅผ ์ถœ๋ ฅํ•  ์ˆ˜ ์žˆ๋Š” ์ž…๋ ฅ๊ฐ’์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค.

byte_140003000[i]

์ด๋ฅผ ์ฝ”๋“œ๋กœ ์ถœ๋ ฅํ•ด๋ณด๊ฒ ๋‹ค.

 

 byte_140003000[i] ์— ์ €์žฅ๋˜์–ด ์žˆ๋Š” ๊ฐ’๋“ค์€

 

24h, 27h, 13h, C6h, C6h,

13h, 16h, E6h, 47h, F5h,

26h, 96h, 47h, F5h, 46h,

27h, 13h, 26h, 26h, C6h,

56h, F5h, C3h, C3h, F5h,

E3h, E3h

๋กœ 27๊ฐœ ์ด๋‹ค.

 

์ด ๊ฐ’๋“ค์„ for๋ฌธ์„ ํ†ตํ•ด ๊ฐ๊ฐ 2์ง„์ˆ˜์—์„œ ์•ž๋’ค๋กœ4๋น„ํŠธ์”ฉ ๋ฐ”๊พธ๋Š” ์—ฐ์‚ฐ์„ ๋˜‘๊ฐ™์ด ํ•ด์ฃผ๋ฉด 

correct๋ฅผ ์œ„ํ•œ ์ž…๋ ฅ๊ฐ’์„ ์•Œ ์ˆ˜ ์žˆ์„ ๊ฒƒ์ด๋‹ค.

#include <stdio.h>

int main(){
    int byte_140003000[27] = 
    { 
    0x24, 0x27, 0x13, 0xC6, 0xC6, 
    0x13, 0x16, 0xE6, 0x47,0xF5, 
    0x26, 0x96, 0x47, 0xF5, 0x46, 
    0x27, 0x13, 0x26, 0x26, 0xC6, 
    0x56, 0xF5, 0xC3, 0xC3, 0xF5, 
    0xE3,0xE3};

                               
    for(int i = 0; i<27; i++){
        printf("%c", (16 * byte_140003000[i]) & 0xF0 | (byte_140003000[i] >> 4));
    }
   
    return 0;
}

๋”ฐ๋ผ์„œ flag ๋Š” Br1ll1ant_bit_dr1bble_<<_>>  ์ด๋‹ค.

 

 

728x90

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

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

๋Œ“๊ธ€