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;
}
Integer Write同様にposは負の値が通ります。
ただし今回は、shorts[pos] に2byte書き込みであるため、ret addrの下位2byteのみが書き換えられます。
posの特定
shorts は rbp-0xd0 に配置されます。scanf("%hd", &shorts[pos]) 呼び出しの戻りアドレスは rbp-0xe8 に置かれます。pos が-12でret addrを上書きできます。書き換える値
winの下位2byteだけを狙います。win のオフセットは 0x11e9。mainのオフセットとも近く、下位2byteの書き換えで十分そうです。