版权声明:莫者 https://blog.csdn.net/weixin_40709439/article/details/81543861
解题链接: http://ctf5.shiyanbar.com/stega/IHDR.png
有点坑哈,点开链接发现图片因存在错误而无法显示,一开始我是以为题目炸了,直接跳过。后来才知道。。。坑
可以利用脚本下载
import requests
import io,sys
sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf-8')#控制输出的编码,可以不要
response = requests.get('http://ctf5.shiyanbar.com/stega/IHDR.png')
cat_img = str(response.text).encode('utf-8')
#出现bytes错误,TypeError: a bytes-like object is required, not 'str'
#str通过encode()方法可以编码为指定的bytes
print(cat_img)
with open('ihdr1.png','wb') as f:
f.write(cat_img)
f.close()
可是发现图片无法正常打开,拉到winhex发现发件头错误。修改过来,应该是可以了,但不知为啥还是不行,怀疑是requests的text获取的字节流有差错。
百度发现
resp.text返回的是Unicode型的数据。
resp.content返回的是bytes型也就是二进制的数据。
也就是说,如果你想取文本,可以通过r.text。
如果想取图片,文件,则可以通过r.content。
(resp.json()返回的是json格式数据)
那就改为content
import requests
# import io,sys
# sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf-8')
response = requests.get('http://ctf5.shiyanbar.com/stega/IHDR.png')
cat_img = response.content
print(cat_img)
with open('ihdr1.png','wb') as f:
f.write(cat_img)
f.close()
再补上一段,urllib库的
#!/usr/bin/python
# -*- coding: utf-8 -*-
import urllib.request
response = urllib.request.urlopen('http://ctf5.shiyanbar.com/stega/IHDR.png')
cat_img = response.read()
print(cat_img)
with open('ihdr1.png','wb') as f:
f.write(cat_img)
f.close()
打开图片,where key?
图片三步法
记事本或者编辑器查看
下载Adobe Fireworks cs5
打开ihdr.png。无法打开???
最后在系统自带的画图工具打开后,另存为ihdr2.png .终于