
題目只給了一個 flag_checker.pkl
使用python3 -m pickle flag_checker.pkl 執行

看來是個 Flag 檢查器
查一下 python 的 pickle module 是什麼

ref: Python 3.8 官方文件
看起來是將 Python 的物件轉換成 binary 的一種方式
恩?儲存一個物件為什麼能觸發 code execution?
查一下 python pickle code execution 就能查到 相關的資訊
理由是因為 Python 提供了一個函式名為 “__reduce__”,功用是執行傳入的兩個參數後執行
且會在 unpickle 時執行 __reduce__
所以只要如類似以下的方式封裝就能執行 code
import pickle
import os
class RCE:
def <strong>reduce</strong>(self):
cmd = ('/bin/sh')
return os.system, (cmd)
if <strong>name</strong> == '<strong>main</strong>':
pickled = pickle.dumps(RCE())Code language: HTML, XML (xml)
而 python 提供了 pickletools 這個 module 能解析 pkl 的資訊
import pickletools
with open("flag_checker.pkl","rb") as f:
print(pickletools.dis(f))Code language: JavaScript (javascript)
能看到其中包的東西

也能看到幾個比較關鍵的
如開頭是”AIS3{“

結尾是 “}”

中間也會有代表輸入的某個位置要等於特定的值

所以大致上能推出 flag 為 AIS3{dAmwjzph__}
但 _ 的地方還是看不太懂
最後索性用爆的方式把剩下的兩個字解開
gen 是自己寫的函式庫,專門產生照順序的字串
import subprocess
from gen import next
flag = "AIS3{dAmwjzph"
ts = ['a','a']
while len(ts) < 3:
test = flag + "".join(ts) + '}'
print(test)
proc = subprocess.run(['python3','-m','pickle','flag_checker.pkl'],input = test,encoding = 'ascii')
ts = next(ts)Code language: JavaScript (javascript)

