[Dreamhack] rev-basic-4

김성진·2022년 8월 8일
0

Dreamhack_Reversing

목록 보기
5/13

📒 Description


📒 C code

📖 main

int __cdecl main(int argc, const char **argv, const char **envp)
{
  char v4[256]; // [rsp+20h] [rbp-118h] BYREF

  memset(v4, 0, sizeof(v4));
  sub_1400011C0("Input : ", argv, envp);
  sub_140001220("%256s", v4);
  if ( (unsigned int)sub_140001000(v4) )
    puts("Correct");
  else
    puts("Wrong");
  return 0;
}

📖 sub_140001000

__int64 __fastcall sub_140001000(__int64 a1)
{
  int i; // [rsp+0h] [rbp-18h]

  for ( i = 0; (unsigned __int64)i < 0x1C; ++i )
  {
    if ( ((unsigned __int8)(16 * *(_BYTE *)(a1 + i)) | ((int)*(unsigned __int8 *)(a1 + i) >> 4)) != byte_140003000[i] )
      return 0i64;
  }
  return 1i64;
}

음 ... 엄........ 그냥 우선순위 적당히 정리해주고 해결해주면 되겠다.

[우선순위 정리]
https://dojang.io/mod/page/view.php?id=188


📒 Exploit

📖 식 정리

편의상 a1 -> array
byte_140003000 -> byte_array

(__int8(16array[i])  __int8(a[i]>>4))==byte_array[i](\_\_int8(16 * array[i]) \ |\ \_\_int8(a[i] >>4)) == byte\_array[i]

더이상 정리할 게 없네 ... 그냥 브루트 포싱을 하자.

📖 exploit.c

#include <stdio.h>
int a[] = {36, 39, 19, 198, 198, 19, 22, 230, 71, 245, 38, 150, 71, 245, 70, 39, 19, 38, 38, 198, 86, 245, 195, 195, 245, 227, 227, 0,0,0,0,0};
int b[32];
int main(){
    for(int i = 0; i<28; i++){
        for(int j = 0; j < 256; j++){
            if((0xFF&(j*16) | 0XFF&(j) >> 4) == a[i]){
                b[i]=j;
                printf("%c\n", j);
                break;
            }
            else printf("i : %d, j : %d\n", i, j);
        }
    }
    for(int i=0; i<28; i++){
        printf("%c", b[i]);
    }
    printf("\n");
    return 0;
}

int8로 type casting을 하므로 0xFF를 & 해주었다.

profile
Today I Learned

0개의 댓글