sudo passwd root
su
apt-get update
apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt-get update
apt-get install docker-ce docker-ce-cli containerd.io
sudo systemctl start docker

아래의 에러가 발생한다면..

root@DESKTOP-3NGJPPV:/home/server/kiloton-main# sudo systemctl start docker
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down

아래처럼 파일을 수정하고, wsl --shutdown으로 종료 후 wsl을 재시작한다.

sudo vim /etc/wsl.conf
[boot]
systemd=true

 

bogus control flow (bcf)

핵심 : 불투명 술어로 코드 제어

예시

int x = 1;
if (x + x == 3)
{
	// 불투명 술어 거짓. 실행되면 안되므로 더미 코드가 들어감
}
if (x - 1 == 0)
{
	// 불투명 술어 참. 실행되어야 하는 코드
}
#include <stdio.h>
#include <time.h>
#include <stdlib.h>

int main()
{
        srand(time(NULL));  
        int i = rand() % 3;      

        if (i == 0)
        {
               printf("0\n");
        }
        else if (i == 1)
        {
               printf("1\n");
        }
        else if (i == 2)
        {
               printf("2\n");
        }
        else if (i == 3)
        {
               printf("3\n");
        }

        return i;
}

IDA Result (Original)

int __cdecl main(int argc, const char **argv, const char **envp)
{
  unsigned int v3; // w0
  int v5; // [xsp+8h] [xbp-8h]

  v3 = time(0LL);
  srand(v3);
  v5 = rand() % 3;
  if ( v5 )
  {
    switch ( v5 )
    {
      case 1:
        printf("1\n");
        break;
      case 2:
        printf("2\n");
        break;
      case 3:
        printf("3\n");
        break;
    }
  }
  else
  {
    printf("0\n");
  }
  return v5;
}

IDA Result (Obfuscation)

int __cdecl main(int argc, const char **argv, const char **envp)
{
  unsigned int v3; // w0
  int v4; // w19

  v3 = time(0LL);
  srand(v3);
  v4 = rand() % 3;
  switch ( v4 )
  {
    case 2:
      puts("2");
      break;
    case 1:
      if ( ((x + x * x) & 1) != 0 && y > 9 )
        goto LABEL_16;
      while ( 1 )
      {
        puts("1");
        if ( ((x + x * x) & 1) == 0 || y < 10 )
          break;
LABEL_16:
        puts("1");
      }
      break;
    case 0:
      if ( ((x + x * x) & 1) != 0 && y > 9 )
        goto LABEL_13;
      while ( 1 )
      {
        puts("0");
        if ( ((x + x * x) & 1) == 0 || y < 10 )
          break;
LABEL_13:
        puts("0");
      }
      break;
  }
  return v4;
}

 

  케이스1 (ret) 케이스2 (br) 케이스3 (b) 케이스4 (b) 케이스5 (br) 케이스6 (ret)
IDA 7.7 분석 안됨 분석 안됨 분석 안됨 정상 분석 됨 정상 분석 됨 분석 꼬임
Binary Ninja 3.3 분석 안됨 정상 분석 됨 정상 분석 됨 정상 분석 됨 정상 분석 됨 분석 꼬임

 

케이스 1 (ret)

int main(int argc, char const *argv[])
{
    printf("hello world!\n");
    __asm__ volatile(
        "adr x30,0x0 \n\t"
        "add x30,x30,0xc \n\t"
        "ret \n\t"
        );
    printf("test 1\n");
    printf("test 2\n");

    return 0;
}

IDA 7.7 분석 결과

 
방해 asm 이후 함수가 끝난 것으로 표시됨

분석이 asm 이후 되지 않음
분석이 asm 이후 되지 않음

Binary Ninja 3.3.3996 분석 결과

방해 asm 이후 함수가 끝난 것으로 표시됨
분석이 asm 이후 되지 않음

 

케이스 2 (br)

int main(int argc, char const *argv[])
{
    printf("hello world!\n");
    __asm__ volatile(
        "adr x30,0x0 \n\t"
        "add x30,x30,0xc \n\t"
        "br x30 \n\t"
        );
    printf("test 1\n");
    printf("test 2\n");

    return 0;
}

IDA 7.7 분석 결과

분석이 asm 이후 되지 않음

Binary Ninja 3.3.3996 분석 결과

정상적으로 분석 됨

케이스 3 (b)

#include <ctime>
int main(int argc, char const *argv[])
{
    printf("hello world!\n");
   
    // 항상 false가 되어야 실행되지 않는다.
    // 최적화 되지 않기 위해 불투명 술어로 코딩한다.
    if (rand() < 0) {
        __asm__(
            "b 0x4\n"
            ".long 12345678\n"
        );
    }
    printf("test 1\n");
    printf("test 2\n");

    return 0;
}

IDA 7.7 분석 결과

함수 전체가 분석 안됨

Binary Ninja 3.3.3996 분석 결과

정상적으로 분석 됨

 

케이스 4 (b)

#include <ctime>
int main(int argc, char const *argv[])
{
    printf("hello world!\n");
   
    // 항상 false가 되어야 실행되지 않는다.
    // 최적화 되지 않기 위해 불투명 술어로 코딩한다.
    if (rand() < 0) {
        __asm__(
            "b 0x4\n"
            "add sp,sp,#0x100\n"
            "add sp,sp,#0x100\n"
        );
    }
    printf("test 1\n");
    printf("test 2\n");

    return 0;
}

IDA 7.7 분석 결과

정상적으로 분석 됨

Binary Ninja 3.3.3996 분석 결과

정상적으로 분석 됨

케이스 5 (br)

int main(int argc, char const *argv[])
{
    printf("hello world!\n");

    if (rand() < 0) {
        __asm__(
            "mov x8,#0x1\n"
            "adr x9, #0x10\n"
            "mul x8, x9, x8\n"
            ".long 0x12345678\n"
            "br x8\n"
        );
    }
    printf("test 1\n");
    printf("test 2\n");

    return 0;
}

IDA 7.7 분석 결과

정상적으로 분석 됨

Binary Ninja 3.3.3996 분석 결과

정상적으로 분석 됨

케이스 6 (ret)

int main(int argc, char const *argv[])
{
    printf("hello world!\n");

    if (rand() < 0) {
        __asm__(
            "adr x8,#0xc\n"
            "mov x30,x8\n"
            "ret\n"
        );
    }
    printf("test 1\n");
    printf("test 2\n");

    return 0;
}

IDA 7.7 분석 결과

분석 꼬임

Binary Ninja 3.3.3996 분석 결과

분석 꼬임

 

 

+ Recent posts