블로그 이전했습니다. https://jeongzero.oopy.io/
[HackCTF] BabyMips
본문 바로가기
워게임/HackCTF

[HackCTF] BabyMips

728x90

1. 문제


1) mitigation 확인

mips 바이너리다.

2) 문제 확인

qemu로 실행하면 되긴하는데, 귀찮아서 그냥 기드라로 코드만 보자.

3) 코드흐름 파악

/* WARNING: Globals starting with '_' overlap smaller symbols at the same address */

undefined4 main(void)

{
  char cVar1;
  size_t input_len;
  int iStack56;
  char cStack49;
  int index;
  uint uStack44;
  int iStack40;
  char input [28];
  
  memset(input,0,0x1a);
  printf((char *)0xdf0);
  __isoc99_scanf(0xdfc,input);
  input_len = strlen(input);
------------------------------------------------------------
  if (input_len == 0x19) {
    iStack56 = 0;
    while (iStack56 < 6) {
      index = 0x18;
      while (cVar1 = input[24], -1 < index) {
        if (index == 0) {
          input[0] = cStack49;
        }
        else {
          if (index == 0x18) {
            input[24] = input[23];
            cStack49 = cVar1;
          }
          else {
            input[index] = *(char *)((int)&iStack40 + index + 3);
          }
        }
        index = index + -1;
      }
      iStack56 = iStack56 + 1;
    }
-------------------------------------------------------------
    uStack44 = 0;
    while ((int)uStack44 < 0x19) {
      if ((*(uint *)(data + uStack44 * 4) ^ uStack44 ^ (int)input[uStack44]) !=
          *(uint *)(comp + uStack44 * 4)) {
        puts((char *)0xe10);
        return 0;
      }
      uStack44 = uStack44 + 1;
    }
    iStack40 = 0;
    while (iStack40 < 0x19) {
      _IO_putc((int)(char)*(undefined4 *)(comp + iStack40 * 4),_stdout);
      iStack40 = iStack40 + 1;
    }
    puts((char *)0xe1c);
  }
  else {
    puts((char *)0xe00);
  }
  return 0;
}

크게 2부분을 위주로 보면된다. 절취선 위쪽에 있는 로직부터 봐보려 했으나 iStack40 요 변수가 뭔지 모르겠다. 일단 아래부터 봐보자

  • data[i*4] ^ i ^ input[i] == comp[i*4]

요거를 비교한다. data와 input은 전역변수이다. 저 식을 역연산하여 input 값을 알아내면 될것같다.

2. 접근방법


          data                           XREF[2]:     Entry Point (*) ,  00020f58 (*)   
        00020e50 00  00  00       undefine
                 72  00  00 
                 00  09  00 
           00020e50 00              undefine  00h                     [0]                               XREF[2]:     Entry Point (*) ,  00020f58 (*)   
           00020e51 00              undefine  00h                     [1]
           00020e52 00              undefine  00h                     [2]
           00020e53 72              undefine  72h                     [3]
           00020e54 00              undefine  00h                     [4]
           00020e55 00              undefine  00h                     [5]
           00020e56 00              undefine  00h                     [6]
           00020e57 09              undefine  09h                     [7]
           00020e58 00              undefine  00h                     [8]
           00020e59 00              undefine  00h                     [9]
           00020e5a 00              undefine  00h                     [10]
           ....

data를 보면 저렇게 되있다. 0x00 부터 시작하는줄 알았으나, 4바이트 단위로 끊는걸로 보아 0x72이 시작점인것같다.

결론은 data, comp 값을 뽑고 역연산을 통해 input 값을 유추하면 끝이다.

3. 풀이


익스코드

data=[0x72,0x9,0x4,0x10,0x49,0x19,0x3a,0x1c,0x34,0x3b,0x26,0x2a,0x15,0x30,0x52,0x1b,0xd,0xc,0x12,0x38,0x49,0x4,0x2,0x69,0x4b]
comp=[0x43,0x6f,0x6e,0x67,0x72,0x61,0x74,0x7a,0x5f,0x59,0x6f,0x75,0x5f,0x46,0x6f,0x75,0x6e,0x64,0x5f,0x46,0x6c,0x61,0x67,0x21,0x21]

input=[]
for i in range(len(data)):
        input.append(comp[i] ^ data[i] ^ i)


for i in input:
        print(chr(i)),

╭─wogh8732@ubuntu ~/Desktop/wargame/hackctf/reversing/babymips 
╰─$ python ex.py                                                                                                                                                 130 ↵
1 g h t ? } H a c k C T F { 3 a s y _ m 1 p s _ r

4. 몰랐던 개념


728x90

'워게임 > HackCTF' 카테고리의 다른 글

[HackCTF] childfsb  (0) 2021.02.24
[HackCTF] 탈옥  (0) 2020.12.05
[HackCTF] static  (0) 2020.12.03
[HackCTF] keygen  (0) 2020.12.02
[HackCTF] strncmp  (0) 2020.12.01