[Dreamhack] rev-basic-3

김성진·2022년 8월 8일
0

Dreamhack_Reversing

목록 보기
4/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_1400011B0("Input : ", argv, envp);
  sub_140001210("%256s", v4);
  if ( (unsigned int)sub_140001000(v4) )
    puts("Correct");
  else
    puts("Wrong");
  return 0;
}

140001000을 분석해보자.

📖 sub_140001000

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

  for ( i = 0; (unsigned __int64)i < 0x18; ++i )
  {
    if ( byte_140003000[i] != (i ^ *(unsigned __int8 *)(a1 + i)) + 2 * i )
      return 0i64;
  }
  return 1i64;
}

어우 복잡하다. xor이 우선순위가 가장 낮다.
즉 내가 입력한 i번째 문자에 2i를 더하고 i를 xor한 값이 byte_140003000[i]여야 한다.


📒 Exploit

📖 식 정리

byte_140003000[i]==(i(a1[i]+2i))ibyte_140003000[i]==a1[i]+2ia1[i]==ibyte_140003000[i]2ibyte\_140003000[i] == (i \oplus (a1[i]+2i))\\ i\oplus byte\_140003000[i] == a1[i] + 2i\\ a1[i] == i\oplus byte\_140003000[i] - 2i

로 정리할 수 있다. byte140003000은 여기서 확인 가능하다.

📖 exploit.c

#include <stdio.h>

int byte[24]={73, 96, 103, 116, 99, 103, 66, 102, 128, 120, 105, 105, 123, 153, 109, 136, 104, 148, 159, 141, 77, 165, 157};
int a[24];
int result[24];
//byte____[i] = i^(a1[i]) + 2*i
//byte____[i] - 2*i = i^a[i]
//i^a[i]=result[i]
//a[i]^i=result[i]
//a[i]=result[i]
int main(){
    for(int i=0; i<24; i++) result[i] = byte[i] - 2*i;
    for(int i=0; i<24; i++) a[i] = result[i]^i;
    for(int i=0; i<24; i++) printf("%c", a[i]);
    printf("\n");
    return 0;
}

c로 작성해봤다.

profile
Today I Learned

0개의 댓글