CTF-MISC图片求正确宽高破解和修改总结
图片宽高破解
根据像素求宽高
以青少年CTFmisc 简简单单的题目为例:
我鼠标右侧属性查看相册
右键属性,像素为900150=13500,去掉文件头后是675000/3=225000,明显多了很多,于是用225000除以900=250,所以正确的为900250
脚本求正确宽高
png图片:已知正确的IHDR块的CRC值时,爆破宽度和高度
import zlib
import struct
# 同时爆破宽度和高度
filename = "misc32.png"
with open(filename, 'rb') as f:
all_b = f.read()
data = bytearray(all_b[12:29])
n = 4095
for w in range(n):
width = bytearray(struct.pack('>i', w))
for h in range(n):
height = bytearray(struct.pack('>i', h))
for x in range(4):
data[x+4] = width[x]
data[x+8] = height[x]
crc32result = zlib.crc32(data)
#替换成图片的crc
if crc32result == 0xE14A4C0B:
print("宽为:", end = '')
print(width, end = ' ')
print(int.from_bytes(width, byteorder='big'))
print("高为:", end = '')
print(height, end = ' ')
print(int.from_bytes(height, byteorder='big'))
png图片:IHDR块的CRC的值错误,已知高度的情况下爆破宽度
import zlib
import struct
filename = "misc34.png"
with open(filename, 'rb') as f:
all_b = f.read()
#w = all_b[16:20]
#h = all_b[20:24]
for i in range(901,1200): #界定宽度的范围
name = str(i) + ".png"
f1 = open(name,"wb")
im = all_b[:16]+struct.pack('>i',i)+all_b[20:]
f1.write(im)
f1.close()
jpg图片:已知高度,爆破宽度
import zlib
import struct
filename = "misc35.jpg"
with open(filename, 'rb') as f:
all_b = f.read()
#w = all_b[159:161]
#h = all_b[157:159]
for i in range(901,1200): #界定宽度范围
name = str(i) + ".jpg"
f1 = open(name,"wb")
im = all_b[:159]+struct.pack('>h',i)+all_b[161:]
f1.write(im)
f1.close()
gif图片:已知高度爆破宽度
import zlib
import struct
filename = "misc36.gif"
with open(filename, 'rb') as f:
all_b = f.read()
for i in range(920,951):
name = str(i) + ".gif"
f1 = open(name,"wb")
im = all_b[:38]+struct.pack('>h',i)[::-1]+all_b[40:]
f1.write(im)
f1.close()
如何修改宽高
010 Editor修改
用010 Editor打开PNG文件,通过模板打开,按F5键运行该脚本,模板结果按快捷键(Alt + 4)