ctfAbout_DAS_2023
PH GaoMisc
坐牢8小时,在希望和绝望之间挣扎,唯一能做出来的题被一个5位数字密码拦住了,真是惭愧。在这里复现一下题目,以及解题思路。
Justpaint
下载下来是一个压缩包,被加密了,通过爆破软件得到密码:
打开压缩包后发现两个文件,一个jbn.pth,一个train.py。将train.py里面的代码拿去拷打ChatGPT,理解这段代码就是训练一个模型让图片能逼近flag,继续拷打GPT,得到完整的flag生成脚本:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| import torch import torch.nn as nn import numpy as np import matplotlib.pyplot as plt from PIL import Image import cv2
class JBN(nn.Module): def __init__(self): super(JBN, self).__init__() self.main = nn.Sequential( nn.Linear(100, 256), nn.ReLU(), nn.Linear(256, 512), nn.ReLU(), nn.Linear(512, 452 * 280), nn.Tanh() )
def forward(self, x): img = self.main(x) img = img.view(-1, 452, 280) return img
def watch_flag(img): flag = cv2.imread('./data/data/flag.png') gray_image = cv2.cvtColor(flag, cv2.COLOR_BGR2GRAY) flag_tensor = torch.from_numpy(np.array(gray_image)) flag_tensor = flag_tensor.unsqueeze(0).transpose(1, 2) img_tensor = img flag_tensor = flag_tensor.unsqueeze(0) img_tensor = img_tensor.unsqueeze(0) loss_fn = torch.nn.MSELoss() loss = loss_fn(flag_tensor.float(), img_tensor) return loss
import torch import cv2
jbn = JBN()
jbn.load_state_dict(torch.load(r"C:\Users\ASUSROG\Desktop\jbn.pth"))
jbn.eval()
random_noise = torch.randn(1, 100)
generated_image = jbn(random_noise)
generated_image = generated_image.squeeze().detach().numpy()
image_path = r"C:\Users\ASUSROG\Desktop\flag.png"
cv2.imwrite(image_path, generated_image * 255)
print(f"生成的图像已保存到 {image_path}。")
|
得到flag.png: