Luoingly's Space

第七届强网杯全国网络安全挑战赛线上赛个人题解

December 17, 2023 · Legacy Blog

孩子啥也不懂打着玩的。

SpeedUp

先看一眼题目,其中定义了:

def f(x):
    res = 0
    while x:
        res += x % 10
        x //= 10
    return res

而后令 x 为 2 的 27 次方的阶乘,flag 为 flag{sha256(f(x))}

显然这个 f(x) 是求 x 的各个位上数字之和,这并不难理解。不过要计算 2 的 27 次方也就是 134217728 的阶乘就稍微有点耗时间了(保守估计跑个三天三夜差不多),所以我们需要找到一个更快的方法(废话,不然题目为什么叫 SpeedUp)。

先求一下 f((2^n)!) 的前几项:

def factorial(n):
    result = 1
    for i in range(2, n + 1):
        result *= i
    return result

def f(x):
    res = 0
    while x:
        res += x % 10
        x //= 10
    return res

for i in range(10):
    print(f(factorial(2**i)), end=" ")
print()

将结果直接丢入一个强大的数字序列百科网站 OEIS 中,可以直接找到一个描述为「Sum of digits of (2^n)!.」的数列 A244060,显然这个数列中 n=27 的项就是我们要求的结果。

查表得当 n=27 时结果为 4495662081,这样就得到了 Flag。

谍影重重 2.0

小明是某间谍组织的一员,他终日监听着我国某重点军事基地的飞行动态,妄图通过分析参数找到我国飞的最快的飞机。我国费尽千辛万苦抓住了他,并在他的电脑上找到了一段他监听的信息,请分析出这段信息中飞的最快的飞机。 格式为 flag{md5(ICAO CODE of the fastest plane)} 附件内所涉及的信息均为公开信息,题目描述也均为虚构,切勿当真。

题给一个 Wireshark 抓包文件,打开后发现其中全是 TCP 流,直接先把数据字段导出来:

tshark -r attach.pcapng -T fields -Y "tcp.payload" -e tcp.payload > attach.dat

完全不需要去猜测这个 TCP 数据包的格式,因为不难注意到 ADS-B 数据包的特征(/8d[0-9a-f]{26}$/),然后也不难找到一个叫做 The 1090 Megahertz Riddle 的网站,其中有着 ADS-B 数据包的详细说明。当然,别急着手搓解码器(有个憨憨去手搓解码器了我不说是谁),稍微留心可以发现这些内容的作者有写过一个 Python 库用于解码 ADS-B 数据包,叫做 pyModeS。解题代码:

import re
import hashlib
import pyModeS as pms

records = []
regex = re.compile(r"^1a33f{12}[0-9a-f]{2}(8[0-9a-f]{27})$")
with open("attach.dat", "rt") as source:
    for line in source:
        match = regex.match(line)
        if match:
            records.append(match.group(1))

velocities = {}
for record in records:
    if pms.crc(record) != 0:
        # Filter out record that has CRC error
        continue
    if pms.df(record) != 17:
        # Filter out record that not using Mode-S
        continue
    if pms.typecode(record) != 19:
        # Filter out record that not about velocity
        continue
    icao, velocity = pms.icao(record), pms.adsb.velocity(record)[0]
    if icao not in velocities:
        velocities[icao] = 0
    if velocity > velocities[icao]:
        velocities[icao] = velocity

the_fastest = max(velocities, key=velocities.get)
md5_of_it = hashlib.md5(the_fastest.upper().encode()).hexdigest()

print("flag{{{}}}".format(md5_of_it))

Tags: #CTF #Writeup #Misc

This article is authored by luoingly and licensed under CC BY-NC 4.0

Permalink: https://luoy.ing/posts/qiangwangbei-s7-writeup/