hwgame:-HGAME 2027(Misc部分) - description&#34

📅 2026-11-30 👤 拼多多助力营销技巧 📂 手赚APP 👁️ 474 次阅读

感谢hgame主办方,祝贺hgame越办越好,贴纸很好看

借鉴了一下官方Writeup

Misc

打好基础

拿到是一串emoji

很明显没有key,那就很可能只是base100

之后还是一串乱码,在尝试之后发现base92也能解,怀疑是多重base

放入随波逐流之后直接混合多重解码出了,让我一个个试我估计是想不出,能想出来应该也要试很久,或者就只能跑脚本爆破了

hgame{L4y_a_sO11d_f0unDaTi0n}

shiori不想找女友

拿到手是这样子两个文件

打开png很明显是一堆白点黑点,明显需要我们逐点采样,最后应该是一些黑字

from PIL import Image

import math

img = Image.open("shiori.png").convert("RGB")

px = img.load()

w, h = img.size

start_x, start_y = 10, 10

step_x, step_y = 7, 7

column_num = 450

bits = []

# 逐点采样:按行扫描

y = start_y

while y < h:

x = start_x

while x < w:

r, g, b = px[x, y]

#别的全当白的

if (r, g, b) == (0, 0, 0):

bits.append(1)

elif (r, g, b) == (255, 255, 255):

bits.append(0)

else:

bits.append(0)

x += step_x

y += step_y

# 按 column_num 重排成图

rows = math.ceil(len(bits) / column_num)

out = Image.new("L", (column_num, rows), 255)

out_px = out.load()

for i, b in enumerate(bits):

x = i % column_num

y = i // column_num

out_px[x, y] = 0 if b == 1 else 255

out.save("recovered.png")

print("saved recovered.png, size =", out.size)

得到这样子一张图,不知道是不是主办方密码设错了,这个不是密码

试了试之后发现真正的密码是全小写的,this_is_a_key_for_u

然后就可以打开压缩包了

得到了这样子一个东西,外边看是黑的,点开来看是透明的

不难想到这是因为Alpha通道全是0,所以就全透明了

我们直接改这个通道就好了其实

from PIL import Image

import numpy as np

img = Image.open("shioriori_.jpg").convert("RGBA")

arr = np.array(img)

arr[..., 3] = 255 # 强制不透明

Image.fromarray(arr).save("revealed.png")

print("打印好啦")

就能看见答案和照片了

hgame{bec0use_lilies_are_7he_b1st} (保护一下帅哥隐私)

[REDACTED]

题目的意思是有四段敏感的字符串需要找到

上来习惯性全选后即可发现明显这边有一块,在尝试后发现只需要提取文字即可获得其中内容

In case of an undampened local chrono-logical shift, initiate the SCRAMBLE protocol with passphrase 1:PAR4D0X before notifying the on-site Coordinator.

所以第一部分就是PAR4D0X

接下来下边还有一块黑的,看一眼,同样可以选中其中的文字

可以看到这由三部分组成,符合JWT编码字符串,中间的内容很有可能就是Base64编码的JWT

我们尝试解码

成功得到第二部分,AllCl3arToPr0ceed

第三部分

第三部分很让人怀疑是在右下角这里,但是在图片里,这样子是不太可能直接选中文字提取出来,怀疑可能是一个通道没有正确呈现信息,而别的通道存在

果然在这里,至此我们得到了第三部分,只差第四部分了,但是pdf里边似乎直接看看不出,转战Winhex看看

分析发现PDF有两次startxref,即更新过一次,不是重写的

<>

<>

发现旧版的Pages其实是有三页的,但第一页的1 0 R被删了,但对象本身还在文件,没删,只删了引用,这是PDF的增量式修改功能,基本原理就是每次更新没删内容,只更新了引用表

所以我们可以解压孤儿页内容流

内容流用的是/F1字体,所以可以用ToUnicode来翻译一下就好了

import re, zlib, pathlib

pdf = pathlib.Path("G:\ctf\hgame\Misc\[redacted]\manual.pdf").read_bytes()

def stream(objnum):

m = re.search(rb"\n%d 0 obj\b.*?stream\r?\n(.*?)\r?\nendstream" % objnum, pdf, re.S)

return m.group(1)

# 1) 解压 page(1 0) 的 contents: 2 0

page_stream = zlib.decompress(stream(2)).decode("latin1")

# 2) 抓出 <....> 的十六进制字形码串

hexs = re.search(r"/F1\s+\d+\s+Tf<([0-9A-Fa-f]+)>Tj", page_stream).group(1)

codes = bytes.fromhex(hexs)

# 3) 解压 ToUnicode

cmap = zlib.decompress(stream(63)).decode("latin1").splitlines()

mp = {}

for ln in cmap:

m = re.match(r"<([0-9A-Fa-f]{2})>\s+<([0-9A-Fa-f]{4})>", ln.strip())

if m:

mp[int(m.group(1), 16)] = chr(int(m.group(2), 16))

text = "".join(mp[b] for b in codes)

print(text)

成功得到4:D0cR3qu3st3r_Tutu

当然也可以直接恢复先前版本的引用表,用这个就很方便

https://github.com/enferex/pdfresurrect

安装好之后输入下方命令即可

pdfresurrect manual.pdf -w

也能直接看到4:D0cR3qu3st3r_Tutu

所以最后拼一下就好了

hgame{PAR4D0X_AllCl3arToPr0ceed_Sh4m1R_D0cR3qu3st3r_Tutu}

(这题还蛮好玩的,很适合出在取证比赛吧,整一个只更新引用表的pdf)

Invest on Matrix

这是一场投资,很明显,我们必须去解锁一些hint才能做出这一道题,越少越好,毕竟这个hint都是要分的

大概是将二维码按从左到右、从上到下切成了 25 块,每条 hint 给出对应子块按行优先扁平化后的 25 个值

由于二维码特性,不用买完也能出的

然后我买了1,2,3,4,6,7,8,9,10,11,12,13,14,15,17,18,20,23,24,25,花了242 分

#!/usr/bin/env python3

# -*- coding: utf-8 -*-

import numpy as np

import cv2

SIZE = 25

HINTS = {

1: [1,1,1,1,1,1,0,0,0,0,1,0,1,1,1,1,0,1,1,1,1,0,1,1,1],

2: [1,1,0,1,1,0,1,0,1,1,0,1,0,1,0,0,1,0,0,0,0,1,0,0,1],

3: [0,0,1,0,0,1,1,1,0,1,0,0,0,1,1,0,1,1,0,1,0,1,1,0,0],

4: [0,0,0,1,1,0,0,0,1,0,1,1,0,1,0,1,1,0,1,0,0,0,0,1,0],

6: [1,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,0,1,0,0],

7: [0,1,0,1,0,1,1,0,1,0,0,0,0,1,0,0,1,0,1,0,1,0,1,0,1],

8: [0,0,1,1,0,1,0,1,0,1,0,1,1,1,1,0,0,1,0,0,0,1,0,0,1],

9: [1,0,0,1,0,0,1,0,1,1,0,0,0,0,0,1,1,1,1,1,1,1,0,1,0],

10: [0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,0,1,0,1,1],

11: [1,1,0,1,1,1,1,1,0,1,0,1,1,0,0,1,0,0,0,1,1,0,0,1,1],

12: [1,1,0,1,1,0,0,1,1,0,1,1,0,1,0,0,0,0,0,1,1,1,1,1,0],

13: [1,1,0,1,0,0,0,1,0,1,1,1,1,1,0,1,1,0,1,1,1,0,0,1,0],

14: [1,1,1,0,1,0,0,0,0,1,1,0,1,0,1,1,1,0,1,0,0,0,0,1,0],

15: [1,1,1,1,1,1,0,0,0,1,1,0,0,0,1,0,0,0,1,0,0,1,0,0,1],

17: [0,0,0,1,0,0,1,0,1,1,0,0,0,1,0,1,1,0,0,0,0,1,0,0,0],

18: [1,1,1,0,1,0,0,1,1,1,1,0,0,0,1,1,1,0,0,1,0,1,1,1,1],

20: [0,0,0,1,0,1,1,0,1,1,1,1,1,1,1,1,1,0,1,1,1,0,0,1,1],

23: [1,1,0,1,0,1,0,0,1,1,1,1,0,0,1,1,0,1,1,0,1,0,0,0,1],

24: [1,1,1,1,1,0,0,0,1,1,1,0,1,1,1,1,0,1,0,1,0,1,0,0,0],

25: [1,0,0,0,0,0,0,1,0,1,0,0,1,0,1,0,1,0,0,1,0,0,1,1,1],

}

def build_matrix(hints):

mat = np.full((SIZE, SIZE), -1, dtype=int)

for h, vals in hints.items():

r0 = ((h - 1) // 5) * 5

c0 = ((h - 1) % 5) * 5

mat[r0:r0+5, c0:c0+5] = np.array(vals).reshape(5, 5)

return mat

def bch10(data5):

g = 0x537

v = data5 << 10

while v.bit_length() >= g.bit_length():

v ^= g << (v.bit_length() - g.bit_length())

return v

def read_format_code(mat):

# format copy A

coords = []

for i in range(0, 6): coords.append((8, i))

coords += [(8, 7), (8, 8), (7, 8)]

for i in range(9, 15): coords.append((14 - i, 8))

bits = [int(mat[r, c]) for r, c in coords]

if any(b not in (0, 1) for b in bits):

raise RuntimeError("format bits 不完整")

obs = sum((b & 1) << i for i, b in enumerate(bits))

obs = int(f"{obs:015b}"[::-1], 2)

valid = [(((d << 10) | bch10(d)) ^ 0x5412) for d in range(32)]

if obs not in valid:

raise RuntimeError("format code 校验失败")

return obs

def gen_func_modules(size, format_code):

func = np.zeros((size, size), dtype=bool)

val = np.full((size, size), -1, dtype=int)

def setm(x, y, b):

if 0 <= x < size and 0 <= y < size:

func[y, x] = True

val[y, x] = int(b)

# Finder + separator

for cx, cy in [(3, 3), (size-4, 3), (3, size-4)]:

for dy in range(-4, 5):

for dx in range(-4, 5):

d = max(abs(dx), abs(dy))

setm(cx+dx, cy+dy, 1 if (d != 2 and d != 4) else 0)

# Timing

for i in range(size):

if not func[6, i]: setm(i, 6, 1 if i % 2 == 0 else 0)

if not func[i, 6]: setm(6, i, 1 if i % 2 == 0 else 0)

# Alignment (v2 uses centers [6, 18])

for ay in [6, 18]:

for ax in [6, 18]:

if func[ay, ax]:

continue

for dy in range(-2, 3):

for dx in range(-2, 3):

d = max(abs(dx), abs(dy))

setm(ax+dx, ay+dy, 1 if d != 1 else 0)

# Dark module

setm(8, size-8, 1)

# Format bits (two copies)

fb = [(format_code >> i) & 1 for i in range(15)]

# copy A

for i in range(0, 6): setm(8, i, fb[i])

setm(8, 7, fb[6]); setm(8, 8, fb[7]); setm(7, 8, fb[8])

for i in range(9, 15): setm(14-i, 8, fb[i])

# copy B

for i in range(0, 8): setm(size-1-i, 8, fb[i])

for i in range(8, 15): setm(8, size-15+i, fb[i])

return func, val

def decode(mat):

img = np.where(mat == -1, 0, mat)

img = 1 - img

img = (img * 255).astype(np.uint8)

img = np.pad(img, ((4,4),(4,4)), mode='constant', constant_values=255) # quiet zone

img = cv2.resize(img, (0,0), fx=10, fy=10, interpolation=cv2.INTER_NEAREST)

txt, _, _ = cv2.QRCodeDetector().detectAndDecode(img)

return txt

def main():

mat = build_matrix(HINTS)

print("[+] 已知模块:", np.count_nonzero(mat != -1), "/625")

fmt = read_format_code(mat)

func, fval = gen_func_modules(SIZE, fmt)

# 只补齐未知的功能模块

fill_mask = (mat == -1) & func

mat[fill_mask] = fval[fill_mask]

print("[+] 补功能模块后未知:", np.count_nonzero(mat == -1))

res = decode(mat)

print("[+] decode:", repr(res))

if __name__ == "__main__":

main()

得到最后的flag为hgame{W0RTH_1T?}

或许worth吧

赛后给出了原来的二维码,我放在下边了

Vidar Token

Vidar Token

Vidar Finance has decided to move on-chain.

As an initial foray, we are rewarding those who can hunt down the flags hidden in the depths.

Battle-tested implementation, seasoned with a few custom twists.

You think you’re empowered? Prove it.

On-chain, the truth has nowhere to hide.

Fragments in the hollow,

Punks and Coins collide.

Víðarr's eye still sees

Zenless truth inside...

Layers peel away,

Silent god's REvenge.

Decrypt the hidden way

Where broken worlds converge.

读下题目先,大概翻译一下,说是链上数据可读,不用登陆也能从合约存储、事件等读到很多东西

还有就是估计flag和线索都不会直接明文来,hide住了

最后是REvenge,猜测是需要re逆向的

先开启环境看一看,像一个虚拟浏览器钱包界面

看似是说在非HTTPS环境无法直接连接,但是我用caddy改为https连接后依旧无变化

还是先查看一下源码

发现源码此处写了页面底部只有一个业务脚本被加载,就是这个app.js

一般网页的逻辑都会写在js里,这个页面没有加载别的js,只漏了这个app.js,所以我们跳过去看看,应该会有收获

在这边我们看到了,根本没有检测https环境,不管如何都会显示这一句话

核心逻辑在下方这个checkEligibility里,做的事情很具体

先fetch了一个k.wasm

再导出函数get_entrance()拿到指针

之后可以看到entranceAddress是从k.wasm里边正则提取出来的

const res = await fetch("/wasm/k.wasm");

const { instance } = await WebAssembly.instantiate(wasm, {});

const ptr = instance.exports.get_entrance();

const text = readCString(instance.exports.memory, ptr, 80);

const match = text.match(/ENTRANCE=(0x[a-fA-F0-9]{40})/);

entranceAddress = match ? match[1] : "";

再用同源的RPC连接rpc

const rpcUrl = `${window.location.origin}/rpc`;

const provider = new ethers.JsonRpcProvider(rpcUrl);

最后通过代码审计还能看到代码只调用了await vault.tokenURI(0)这一个合约函数获得的数据

const vault = new ethers.Contract(

entranceAddress,

["function tokenURI(uint256) view returns (string)"],

provider

);

await vault.tokenURI(0);

到这边基本上可以确定是题目入口了,这边出现了合约地址、RPC、合约调用三件套,还和题目中的Punks and Coins collide.呼应,强烈暗示了NTF元数据,而我们的tokenURI正是ERC-721/1155常用的元数据入口

之后我们来获取一下这个entranceAddress,读取一下tokenURI

这边我们自然可以直接把 wasm 下载下来并从里面提取入口地址 ,但是相对来说麻烦很多

既然题目已经fetch了,我们其实可以直接利用console得到

(async () => {

function readCString(mem, offset, max = 128) {

const bytes = new Uint8Array(mem.buffer, offset, max);

let out = "";

for (let i = 0; i < bytes.length; i++) {

if (bytes[i] === 0) break;

out += String.fromCharCode(bytes[i]);

}

return out; 拼多多帮助力入口

}

const res = await fetch("/wasm/k.wasm");

if (!res.ok) throw new Error("failed to fetch wasm");

const wasm = await res.arrayBuffer();

const { instance } = await WebAssembly.instantiate(wasm, {});

const ptr = instance.exports.get_entrance();

const text = readCString(instance.exports.memory, ptr, 200);

const m = text.match(/ENTRANCE=(0x[a-fA-F0-9]{40})/);

console.log("raw:", text);

console.log("entranceAddress:", m ? m[1] : null);

})();

得到entrance,也就是第一个合约的入口地址

ENTRANCE=0x39529fdA4CbB4f8Bfca2858f9BfAeb28B904Adc0

再去调用tokenURI

(async () => {

// 1) 先拿 entranceAddress(复用上面逻辑,写在一起不依赖全局变量)

function readCString(mem, offset, max = 128) {

const bytes = new Uint8Array(mem.buffer, offset, max);

let out = "";

for (let i = 0; i < bytes.length; i++) {

if (bytes[i] === 0) break;

out += String.fromCharCode(bytes[i]);

}

return out;

}

const wasm = await (await fetch("/wasm/k.wasm")).arrayBuffer();

const { instance } = await WebAssembly.instantiate(wasm, {});

const ptr = instance.exports.get_entrance();

const text = readCString(instance.exports.memory, ptr, 200);

const m = text.match(/ENTRANCE=(0x[a-fA-F0-9]{40})/);

const entrance = m ? m[1] : null;

if (!entrance) throw new Error("entrance address not found");

// 2) 走同源 RPC

const rpcUrl = `${window.location.origin}/rpc`;

const provider = new ethers.JsonRpcProvider(rpcUrl);

// 3) 调 tokenURI(0)

const vault = new ethers.Contract(

entrance,

["function tokenURI(uint256) view returns (string)"],

provider

);

const uri = await vault.tokenURI(0);

console.log("entrance:", entrance);

console.log("tokenURI(0):", uri);

})();

发现给了一串base64

解码得到json

{"name":"VidarPunks #0","description":"VidarPunks Vault NFT. Seek your fortune with VidarCoin.","attributes":[{"trait_type":"Linked Coin Address","value":"0xc5273abfb36550090095b1edec019216ad21be6c"}],"vidar_coin":"0xc5273abfb36550090095b1edec019216ad21be6c"}

至此我们得到了下一跳,VidarCoin的合约地址0xc5273abfb36550090095b1edec019216ad21be6c

针对这一个地址,像是ERC20代币地址

所以我们可以直接把这个地址先当ERC20尝试读基本信息

(async () => {

const coin = "0xc5273abfb36550090095b1edec019216ad21be6c";

const rpcUrl = `${window.location.origin}/rpc`;

const provider = new ethers.JsonRpcProvider(rpcUrl);

const erc20 = new ethers.Contract(

coin,

[

"function name() view returns (string)",

"function symbol() view returns (string)",

"function decimals() view returns (uint8)",

"function totalSupply() view returns (uint256)",

],

provider

);

const [name, symbol, decimals, totalSupply] = await Promise.all([

erc20.name().catch(()=>null),

erc20.symbol().catch(()=>null),

erc20.decimals().catch(()=>null),

erc20.totalSupply().catch(()=>null),

]);

console.log({ coin, name, symbol, decimals, totalSupply: totalSupply?.toString?.() ?? totalSupply });

})();

发现了symbol有往下一层解密的潜力,因为一般的symbol都是短字符串,而这边返回的是一串hex

"0x6960606a647c7458603172484d7255346d7e5e4c6f3776584455622a566672705e357b7d3634343430307c"

其实看上去似乎没什么乱码,怀疑是否有戏

我们跟着题目的flag头hgame{尝试XOR

0x69 XOR 0x68 = 0x01

0x60 XOR 0x67 = 0x07

0x60 XOR 0x61 = 0x01

0x6a XOR 0x6d = 0x07

0x64 XOR 0x65 = 0x01

0x7c XOR 0x7b = 0x07

大概可以得到是0x01和0x07交替XOR

写一个简单脚本解密

HEX_CIPHERTEXT = "0x6960606a647c7458603172484d7255346d7e5e4c6f3776584455622a566672705e357b7d3634343430307c"

hx = HEX_CIPHERTEXT.strip().lower()

if hx.startswith("0x"):

hx = hx[2:]

hx = "".join(hx.split())

ct = bytes.fromhex(hx)

result = bytearray()

key = [0x01, 0x07]

for i, b in enumerate(ct):

result.append(b ^ key[i % 2])

try:

plaintext = result.decode("utf-8")

print(plaintext)

except UnicodeDecodeError:

plaintext = result.decode("latin-1")

print(plaintext)

得到flag:hgame{u_a6sOLuT3ly_Kn0w_ERc-Wasw_2zz735317}

由于上述原因,题目设置的flag不是这个

标签: 拼多多助力网站平台 赚钱项目 拼多多助力网 首码项目 手赚APP
拼多多助力营销技巧