Challenge

Integer Writer のリベンジだ!

(Integer Writer を先に解くことをおすすめします.)

// gcc -o chal main.c
#include <stdio.h>
#include <string.h>
#include <unistd.h>

void win() {
    execve("/bin/sh", NULL, NULL);
}

int main(void) {
    short shorts[100], pos;

    /* disable stdio buffering */
    setbuf(stdin, NULL);
    setbuf(stdout, NULL);
    setbuf(stderr, NULL);

    printf("pos > ");
    scanf("%hd", &pos);
    if (pos >= 100) {
        puts("You're a hacker!");
        return 1;
    }
    printf("val > ");
    scanf("%hd", &shorts[pos]);

    return 0;
}

Solution

Integer Write同様にposは負の値が通ります。

ただし今回は、shorts[pos] に2byte書き込みであるため、ret addrの下位2byteのみが書き換えられます。

posの特定

書き換える値