[Dreamhack] rev-basic-5

김성진·2022년 8월 10일
1

Dreamhack_Reversing

목록 보기
6/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((__int64)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 < 0x18; ++i )
  {
    if ( *(unsigned __int8 *)(a1 + i + 1) + *(unsigned __int8 *)(a1 + i) != byte_140003000[i] )
      return 0i64;
  }
  return 1i64;
}

i 번째 원소와 다음 원소의 합이 배열의 i번째 값이면 되나보다. 근데 24번째 원소는 0이다. 엄청난 힌트이다.


📒 Exploit

arr[i]+arr[i+1]=byte[i]arr[i] + arr[i+1] = byte[i]

여기서 마지막 byte 배열의 값이 0이다. 그러므로 우리가 입력할 마지막 값은 76이다.

📖 exploit.c

#include <stdio.h>
/*
 173, 216, 2 dup(203), 157, 151, 203, 196, 146, 161
.data:0000000140003000                                         ; DATA XREF: sub_140001000+48↑o
.data:0000000140003000                 db 210, 215, 210, 214, 168, 165, 220, 199, 173, 163, 161
.data:0000000140003000                 db 152, 76, 9 dup(0)

*(unsigned __int8 *)(a1 + i + 1) + *(unsigned __int8 *)(a1 + i) != byte_140003000[i]
a[i+1] + a[i] = byte[i]
a[1] + a[1+i] = byte[i]
a[0] + a[1] = 173 = b[0] =? a[i] = b[0] - a[i+1]
a[1] + a[2] = 216

=> 2(a[0] + a[1] + a[2] ... a[24]) = 

a[22] + a[23] = 152
a[23] + a[24] = 76
a[23] = 76
a[22] = 76
*/

int byte[32] = {173, 216, 203, 203, 157, 151, 203, 196, 146, 161, 210, 215, 210, 214, 168, 165, 220, 199, 173, 163, 161, 152, 76, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int a[32];

int main(){
    a[22] = 76;
    for(int i=21; i>=0; i--) a[i] = byte[i] - a[i+1];
    for(int i=0; i<23; i++) printf("%c", a[i]);
    printf("\n");
    return 0;
}
profile
Today I Learned

0개의 댓글