본문 바로가기
스터디/system

[IDA-Analysis] Binary Wargames Level1

by 깝태 2011. 8. 17.

안녕하세요, 이 게시판에서는 ELF 파일, 즉 바이너리 파일을 받아 C 언어로 소스화
하면서 모르는것은 알아가면서 필요한 키 값을 찾아가는 문제를 풀어가는 게시판입니다.

파일은 제공되지 않으며 만약 이렇게 분석을 하실 생각이라면 아이다 프로가 필요합니다.

이번 문제풀이의 목표는 본 파일에서 암호화를 하는데 똑같은 방법으로 "Deep into the system" 을 암호화해야 합니다.
단, UTC 2012년 12월12일 12시12분 12초  (24시간기준) 에 프로그램을 실행 했을 때의 암호화된 값을 적어야 한다.

무슨말이냐면 유닉스 시스템 용어로 타임스탬프라고 1970년 1월 1일 00:00:00를 기준으로 경과한 초를 의미하는데
이 점을 이용해 UTC 2012년 12월 12일 12시 12분 12초 에의 타임스탬프 값을 구해 대입하면 기준이 될 수 있다.

아이다 프로로 열은 바이너리 파일을 바로 C 언어로 소스화 시킬것이며 완벽하지 않을 수도 있으니 이해바랍니다 ^^

일단 프로그램을 실행하면

Normal : Sur3x5F The Valueable System Hacking Crew God damn it :)
Encrypted : Xzw8}:K%Ymj%[fqzjfgqj%X~xyjr%Mfhpnsl%Hwj|%Lti%ifrs%ny%?.

다음과 같은 문자열이 뜹니다. 저 평문을 Deep into the system 으로 하여 
2012년 12월 12일 12시 12분 12초를 기준으로 암호화를 진행하여 나오는 암호문이 정답입니다.

다음과 같은 함수들이 목록에 있습니다.

sub_8048450        .text  08048450 00000057 R . . . B . .
sub_80484B0        .text  080484B0 00000023 R . . . B . .
sub_80484D4        .text  080484D4 0000010E R . . . B . .
sub_80485E2        .text  080485E2 0000001D R . . . B . .
sub_8048600        .text  08048600 00000005 R . . . B . .
sub_8048610        .text  08048610 0000005A R . . . B . .
sub_804866A        .text  0804866A 00000004 R . . . . . .
sub_8048670        .text  08048670 0000002A R . . . B . .

중요해보이거나 직접적으로 포함되어있는 함수만 소스화를 하겠습니다.

int main()
{
  unsigned int seed;
  char cipher;
  int ps;
  int sum;

  ps = 0;
  seed = time(0); // 
  srand(seed);
  sum = rand() % 5; 
  malloc(30); // 30바이트 임시 공간 생성
  write(1, "Normal : ", 9);
  puts("Sur3x5F The Valueable System Hacking Crew God damn it :)");
  write(1, "Encrypted : ", 12);
  while ( aSur3x5fTheValu[v3] ) 
  {
    cipher = Encrypted(aSur3x5fTheValu[ps], sum); 
    // cipher 함수를 호출하며 인자로 평문[0] 과 암호기준, 시드값을 전달합니다.
    putchar(cipher);
    ++v3;
  }
  return puts(&s); // printf("\n"); 과 같은 역할을 한다.
}

int cipher(unsigned a1, int a2)
{
  return a2 + a1 + 2;
}

일단 준비물은 모두 준비하였습니다.

문자열 = Deep into the system
타임스탬프 값 = 1355314332

정식 소스로 짜내겠습니다.

#include<stdio.h>
#include<stdlib.h>

int encrypted(unsigned a1, int a2);

int main()
{
  unsigned int seed;
  char cipher;
  int ps;
  int sum;

  ps = 0;
  seed = 1355314332;
  srand(seed);
  sum = rand() % 5;
  // srand 값으로 하면 계속 실행했을때마다 계속 랜덤되는 값이 나오는게 맞는말이지만
  // srand(time(0)) 의 경우이고, srand(고정값) 으로 랜덤을 돌렸을때는 rand() 를 하였을때도 계속 고정된값이 나온다.
  malloc(30); // 임시 메모리 공간 30바이트 생성
  write(1, "Normal : ", 9);
  puts("Deep into the system Encrypted :)");
  write(1, "Encrypted : ", 12);
  while("Deep into the system"[ps])
  {
    cipher = encrypted("Deep into the system"[ps], sum); // cipher 함수를 호출하며 인자로 평문[0] 과 암호기준, 시드값을 전달합니다.

    putchar(cipher);
    ++ps;
  }

  printf("\n");
  return 0;
}

int encrypted(unsigned a1, int a2)
{
  return a2 + a1 + 2;
}

[gate@localhost xodnr]$ ./seeme 
Normal : Deep into the system :) 
Encrypted : Ghhs#lqwr#wkh#v|vwhp

정상적으로 정답이 출력되었습니다.