plaidctf2015 uncorrupt png
代码的执行时间挺长的,好囧!
参考了https://13c5.wordpress.com/2015/04/20/plaidctf-2015-png-uncorrupt/的代码
通过这个题目,也对Png文件格式更深入地理解了!
使用这个代码的前提是将png signature里面的0x0a修改为0x0d0a
from itertools import combinations
import binascii
import os def find_all(source,aim):
start=
while True:
start=source.find(aim,start)
if start==-:
return
yield start
start +=len(aim) def repair(source,aim,filedes,num,crc):
matchlist=list(find_all(source,'\x0a')) for subnet in combinations(matchlist,num):
subnet=sorted(subnet)
temp=''
if(num==):
temp=source[:subnet[]]+'\x0d\x0a'+source[subnet[]+:subnet[]]+'\x0d\x0a'+source[subnet[]+:subnet[]]+'\x0d\x0a'+source[subnet[]+:]
if(num==):
temp=source[:subnet[]]+'\x0d\x0a'+source[subnet[]+:subnet[]]+'\x0d\x0a'+source[subnet[]+:]
if(num==):
temp=source[:subnet[]]+'\x0d\x0a'+source[subnet[]+:]
if "%08x" % (binascii.crc32(temp)&0xFFFFFFFF)==crc:
filedes.write(temp)
filedes.write(binascii.a2b_hex(crc))
filedes.flush()
print "success"
break;
print "fail" uncfile=open("corrupt_735acee15fa4f3be8ecd0c6bcf294fd4.png","rb")
cocfile=open("correct.png","wb")
#first write
correct=uncfile.read(0x6d)
cocfile.write(correct)
cocfile.flush() correct=uncfile.read(0x4)#length
cocfile.write(correct)
cocfile.flush() uncorrect=uncfile.read(0x20000-0x1+0x4)
crc=uncfile.read(0x4)
crc=binascii.hexlify(crc)
print crc
repair(uncorrect,'\x0a',cocfile,,crc)#
#second write
correct=uncfile.read(0x4)#length
cocfile.write(correct)
cocfile.flush()
uncorrect=uncfile.read(0x20000-0x3+0x4)
crc=uncfile.read(0x4)
crc=binascii.hexlify(crc)
print crc
repair(uncorrect,'\x0a',cocfile,,crc)#
#third write
correct=uncfile.read(0x4)#length
cocfile.write(correct)
cocfile.flush()
uncorrect=uncfile.read(0x20000-0x1+0x4)
crc=uncfile.read(0x4)
crc=binascii.hexlify(crc)
print crc
repair(uncorrect,'\x0a',cocfile,,crc)#
#fourth write
correct=uncfile.read(0x4+0x4+0x20000+0x4)
cocfile.write(correct)
cocfile.flush()
#fifth write
correct=uncfile.read(0x4)#length
cocfile.write(correct)
cocfile.flush()
uncorrect=uncfile.read(0x20000-0x3+0x4)
crc=uncfile.read(0x4)
crc=binascii.hexlify(crc)
print crc
repair(uncorrect,'\x0a',cocfile,,crc)#
#6th
correct=uncfile.read(0x4)#length
cocfile.write(correct)
cocfile.flush()
uncorrect=uncfile.read(0x20000-0x1+0x4)
crc=uncfile.read(0x4)
crc=binascii.hexlify(crc)
print crc
repair(uncorrect,'\x0a',cocfile,,crc)#
#7th
correct=uncfile.read(0x4)
cocfile.write(correct)
cocfile.flush()
uncorrect=uncfile.read(0x20000-0x2+0x4)
crc=uncfile.read(0x4)
crc=binascii.hexlify(crc)
print crc
repair(uncorrect,'\x0a',cocfile,,crc)#
#8th
correct=uncfile.read(0x4+0x4+0x20000+0x4)
cocfile.write(correct)
cocfile.flush()
#9th
correct=uncfile.read(0x4)
cocfile.write(correct)
cocfile.flush()
uncorrect=uncfile.read(0x20000-0x1+0x4)
crc=uncfile.read(0x4)
crc=binascii.hexlify(crc)
print crc
repair(uncorrect,'\x0a',cocfile,,crc)#
#10th
correct=uncfile.read(0x4+0x4+0x216f)
cocfile.write(correct)
cocfile.flush() uncfile.close()
cocfile.close()
结果:
参考文献:
http://blog.csdn.net/gogor/article/details/5265710
http://www.libpng.org/pub/png/apps/pngcheck.html
http://www.libpng.org/pub/png/book/chapter08.html
http://stackoverflow.com/questions/27238021/png-images-not-loaded
https://13c5.wordpress.com/2015/04/20/plaidctf-2015-png-uncorrupt/
plaidctf2015 uncorrupt png的更多相关文章
- plaidctf2015 ebp
很容易看出是格式化字符串漏洞.这里的格式化字符串漏洞不像传统的那样,格式化字符串是放在bss段中,并没放在栈上,因此利用起来有些困难. 不过,我们可以利用ebp,可以修改函数的ebp,从而能控制函数的 ...
- [PWN]fsb with stack frame
0x00: 格式化字符串漏洞出现的时间很早了,偶然在前一段时间学到了一个其他的利用姿势,通过栈桢结构去利用格式化字符串漏洞. 原文链接:http://phrack.org/issues/59/7.ht ...
随机推荐
- AFNetWorking网络请求
NetWorkAPIClient.h #import <Foundation/Foundation.h> #import "AFHTTPRequestOperationManag ...
- OpenCV2马拉松第14圈——边缘检測(Sobel,prewitt,roberts)
收入囊中 差分在边缘检測的角色 Sobel算子 OpenCV sobel函数 OpenCV Scharr函数 prewitt算子 Roberts算子 葵花宝典 差分在边缘检測究竟有什么用呢?先看以下的 ...
- Android,使用Json发送数据中,使用的Java转义字符 KanKan原创
kankan原创 与php后台发送数据的时候.要求用到这样的格式. private void sendJson(){ //初始化自己定义的handler CashHandler handler = n ...
- Hyperion Essbase BusinessRule 函数学习--2
@AVG Returns the average of all values in expList. [返回表达式列表的平均值] Syntax @AVG (SKIPNONE | SKIPMISSING ...
- java学习之部分笔记
1.枚举类型 2.String的方法Index的用法.StringBuffer 的用法.Math的用法.Date类 3.用abstract修饰的类就是抽象类.抽象方法不能有主体.抽象类中,可以有抽象方 ...
- C#中equals方法和==的区别
Msdn中对equals方法的解释是:确定指定的对象是否等于当前对象. Equals方法是比较对象的内容,而==则是比较整个对象是否相等. Equals方法判断的是堆中的值,而==则判断的是堆栈中的值 ...
- 在Vim中查看文件编码
:set fileencoding 即可显示文件编码格式. 如果你只是想查看其它编码格式的文件或者想解决 用Vim查看文件乱码的问题,那么在 ~/.vimrc 文件中添加以下内容: set encod ...
- HDU 5740 - Glorious Brilliance
题意: 给出已0 1染色的无向图(不一定联通),一次操作为一对相邻点颜色互换. 问使任意相邻点颜色不同,最少需要多少次操作 分析: 交换两点的代价即为两点间最短路. 故用BFS找出所有点到任意点的最短 ...
- c# ListView
// Attempt to run the file. System.Diagnostics.Process.Start(filename); //folderCol 可以存放一个路径的 栈(用于返回 ...
- avalon中常用的事件
ms-on-change 相当于失去焦点事件. ms-on-input 相当于watch事件 http://www.runoob.com/jsref/event-oninput.html