iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 19
0
Security

CTF30系列 第 19

CTF 12: QR Checker (Misc/QR, SECCON 2018 Online CTF)

註解

之前 PlaidCTF 的 Shop 對我目前來說還太困難,即使看了 writeup 也沒辦法成功說明其中的奧妙。所以目前先不看那條了。

我們先改來看其他題目。這次是前幾天才結束的日本 SECCON 線上賽的題目。

我們會拿到一個頁面:

源碼

#!/usr/bin/env python3
import sys, io, cgi, os
from PIL import Image
import zbarlight
print("Content-Type: text/html")
print("")
codes = set()
sizes = [500, 250, 100, 50]
print('<html><body>')
print('<form action="' + os.path.basename(__file__) + '" method="post" enctype="multipart/form-data">')
print('<input type="file" name="uploadFile"/>')
print('<input type="submit" value="submit"/>')
print('</form>')
print('<pre>')
try:
	form = cgi.FieldStorage()
	data = form["uploadFile"].file.read(1024 * 256)
	image= Image.open(io.BytesIO(data))
	for sz in sizes:
		image = image.resize((sz, sz))
		result= zbarlight.scan_codes('qrcode', image)
		if result == None:
			break
		if 1 < len(result):
			break
		codes.add(result[0])
	for c in sorted(list(codes)):
		print(c.decode())
	if 1 < len(codes):
		print("SECCON{" + open("flag").read().rstrip() + "}")
except:
	pass
print('</pre>')
print('</body></html>')

看起來我們會需要創造出一個在 不同大小下,會產生不同輸出的 qr code
因為這題目是使用 python pillowimage.resize() 來縮圖,所以我們可以猜說,可能是縮圖時會縮壞 ...

根據 Image Module — Pillow (PIL Fork) 3.1.2 documentation 的文件指出,預設是使用 NEAREST 來縮圖。

在文件另外一處,會看到 NEAREST 的定義:

Pick the nearest pixel from the input image. Ignore all other input pixels.

這個意思代表說,縮到 50x50 時,這每個像素都是 500x500 中的一個像素.... 所以我們若可以知道,它是挑那個像素為準的話,我們或許就可以做出一個會縮錯的圖。

我們下篇來研究如何做出這種圖片。


上一篇
CTF ?: How to Recon (Web)
下一篇
CTF 13: QR Checker (Misc/QR, SECCON 2018 Online CTF)
系列文
CTF3030
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言