Challenge

パワー・オーバー・パワー

// gcc chal.c -o chal -no-pie -fno-stack-protector

#include <stdio.h>

__asm__("pop %rax\\nret\\n");

int main(void) {
    char buf[0x20];
    puts("what's your name");
    fgets(buf, 0x48, stdin);
    return 0;
}

__attribute__((constructor)) void setup() {
    setbuf(stdin, NULL);
    setbuf(stdout, NULL);
}

> checksec chal
[*] '/root/alpaca-bside/useful-gadget/chal'
    Arch:       amd64-64-little
    RELRO:      Partial RELRO
    Stack:      No canary found
    NX:         NX enabled
    PIE:        No PIE (0x400000)
    SHSTK:      Enabled
    IBT:        Enabled
    Stripped:   No

Solution

方針

  1. 1段目で puts@got をリークして libc base を求め入力前に戻る
  2. 2段目で one_gadget に飛ぶ(それかsystem(’/bin/sh’)を呼ぶ)

libc leak

puts(puts@got)を実行してputs@libcをleakする。さらにputs@pltに戻る。

入力レイアウト

one gadget

次のガジェットを使う

0xef52b execve("/bin/sh", rbp-0x50, [rbp-0x78])
constraints:
  address rbp-0x50 is writable
  rax == NULL || {"/bin/sh", rax, NULL} is a valid argv
  [[rbp-0x78]] == NULL || [rbp-0x78] == NULL || [rbp-0x78] is a valid envp