跳到主要内容

NSSRound#12 Basic 官方Write Up

459 浏览

ordinary forensics | @Mar10

volatility2.6扫描
在cmdscan得到 password:U_find_1t
在filescan得到hint.txt,useful.zip
useful.zip的密码为 U_find_1t
useful.txt是密钥文件,用于在VeraCrypt挂载unknown
挂载成功得到 secret(是img文件挂载得到flag.zip) 挂载ext3成功得到压缩包
压缩包备注:密码格式为username_hostname(注意大小写)

得到username与hostname的命令

python2 vol.py -f ../../forensics.raw --profile=Win7SP1x64 printkey -K 'ControlSet001\Services\Tcpip\Parameters' computername:Princess-Peach python2 vol.py -f ../../forensics.raw --profile=Win7SP1x64 printkey -K 'SAM\Domains\Account\Users\Names' username:Mario ​

得到压缩包密码,解开为最终flag

Bulbasaur | @余

盲水印,推荐使用吾爱破解平台的那个工具

阴阳怪气解码

坏东西| @Y0ung

尝试一下发现压缩包的密码是压缩包文件本身

解压过程中如果注意到文件名称可以发现最后一位都是01,可以联想到二进制

import zipfile import os import libnum now = "99020.zip" z = '' while 1: try: f=zipfile.ZipFile(now,'r') for i in f.namelist(): if '.zip' in i: zipname = i password = now.split('.')[0].encode() f.extractall(pwd=password)f.close() os.remove(now) a=now[4] now=zipname z+=a print(now) print(z) except: break print(z) '001101101010111001100110101001101100111010101110000001001100111010010110000 0010001001110111101100010111010010110001001101010011000000100000011001000110 00000110000000100101001100100011010011110100001101011001'#最后一个压缩包没算进去,手动补1,补在后面 #print(libnum.n2s(int(a[::-1],2)))#'May be 010 editor is useful' ​

image-20230520152525268

010 editor的变量功能,一般来说下载的010都有pdf的模块,这个功能应该也是有的

Secrets in Shadow | @randark

题目名字已经提示了,核心在于/etc/shadow文件内的root用户密码哈希的爆破

题目源码:NSSCTF-Round12-Secrets-in-the-Shadow

以下为Dockerfile内核心逻辑

RUN useradd -m ctf && echo "ctf:ctf" && \ echo "ctf:ctf" | chpasswd --crypt-method SHA512 && \ echo "root:bullshit" | chpasswd --crypt-method SHA512 ​

连入ssh之后,执行cat /etc/shadow ,得到:

root:$6$Vh57Xwpz34U8wthL$Xd0QAbWlZgB4nOhgDPCR/Q50rhAUsVVkIs3MUiglBlMychQjULqAADyTSzTXNuuF0TO.2TzUi574DHY6e8Fma1:19496:0:99999:7::: daemon:*:19472:0:99999:7::: bin:*:19472:0:99999:7::: sys:*:19472:0:99999:7::: sync:*:19472:0:99999:7::: games:*:19472:0:99999:7::: man:*:19472:0:99999:7::: lp:*:19472:0:99999:7::: mail:*:19472:0:99999:7::: news:*:19472:0:99999:7::: uucp:*:19472:0:99999:7::: proxy:*:19472:0:99999:7::: www-data:*:19472:0:99999:7::: backup:*:19472:0:99999:7::: list:*:19472:0:99999:7::: irc:*:19472:0:99999:7::: gnats:*:19472:0:99999:7::: nobody:*:19472:0:99999:7::: _apt:*:19472:0:99999:7::: systemd-network:*:19496:0:99999:7::: systemd-resolve:*:19496:0:99999:7::: messagebus:*:19496:0:99999:7::: systemd-timesync:*:19496:0:99999:7::: sshd:*:19496:0:99999:7::: ctf:$6$5uJJm/D4ZZx/o6$UR.7tXI/DvDp4kNyKizkMLAvjtQeq1wYgI2u1GvYbwhVLA51KEOF/lY.5/0p2zeAZuxsO5jJbps5CDrRr9TIk.:19496:0:99999:7::: ​

那么root的用户密码哈希就是

$6$Vh57Xwpz34U8wthL$Xd0QAbWlZgB4nOhgDPCR/Q50rhAUsVVkIs3MUiglBlMychQjULqAADyTSzTXNuuF0TO.2TzUi574DHY6e8Fma1 ​

通过hashcat/john进行爆破之后,就能得到root的用户密码:

bullshit ​

接下来要么直接su切换到root用户,要么用root连接ssh,继而就可以读取到flag

ability | @randark

题目名字已经提示了,核心在于二进制程序的capabilities

题目源码:NSSCTF-Round12-ability

以下为题目源码的核心逻辑:

setcap 'CAP_DAC_OVERRIDE+ep' /usr/bin/dig ​

通过getcap的全盘扫描,可以得到:

ctf@cc8d459c1be14cfa:~$ getcap -r / 2>/dev/null /usr/bin/dig cap_dac_override=ep ​

具体的关于capabilities的介绍,可以参考网上资料,例如:Linux Capabilities 简介

那么我们就可以直接利用dig这一程序,无视文件的权限设置,直接读取文件,参考GTFOBins - dig:

ctf@cc8d459c1be14cfa:~$ dig -f flag ;; communications error to 127.0.0.11#53: timed out ;; communications error to 127.0.0.11#53: timed out ;; communications error to 127.0.0.11#53: timed out ; <<>> DiG 9.18.12-0ubuntu0.22.04.1-Ubuntu <<>> NSSCTF{b2576364-536d-42cb-9590-b52f0a620c34} ;; global options: +cmd ;; no servers could be reached ​

strange python | @randark

核心在于python random库的伪随机概念,python shell的preload机制,以及二进制程序的capabilities

题目源码:NSSCTF-Round12-strange-python

首先,先连接到题目环境:

┌──(randark㉿kali)-[~] └─$ nc node3.anna.nssctf.cn 28474 Python 3.10.6 (main, Mar 10 2023, 10:55:28) [GCC 11.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> ​

通过dir()函数,可以看到当前状态下的所有变量:

>>> dir() dir() ['__annotations__', '__builtins__', '__doc__', '__flag__', '__loader__', '__name__', '__package__', '__spec__', 'random', 'seed', 'shuffle'] ​

有几个异常点:存在__flag__和random,以及导入了,seed和shuffle

读取异常的变量:

>>> __flag__ __flag__ ['53', 'e3', '56', 'SC', '-4', '1-', 'cf', 'ce', 'b0', 'NS', 'ad', '3e', 'b}', 'TF', '-b', '3d', 'f2', '80', 'e7', '72', '{c', '2-'] >>> seed seed 114514 >>> shuffle shuffle <bound method Random.shuffle of <random.Random object at 0x55e910da2020>> >>> random random <module 'random' from '/usr/lib/python3.10/random.py'> ​

这个题目共有两种思路:

伪随机预测+列表伪随机打乱后还原

可以大概预测flag原先是正常顺序,然后被random.shuffle打乱

以114514作为seed,在本地做测试

import random random.seed(114514) b = [] for i in range(22): b.append(i) print(b) # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21] random.shuffle(b) print(b) # [18, 19, 20, 1, 10, 12, 14, 17, 4, 0, 13, 11, 21, 2, 15, 8, 9, 16, 5, 6, 3, 7] ​

那么以这个index表来还原:

import random import re __flag__ = [] # 填入得到的数据 seed = 114514 b = [] for i in range(22): b.append(i) print(b) random.seed(seed) random.shuffle(b) print(b) for i in range(22): print(__flag__[b.index(i)],end="") ​

利用python的特殊权限态进行文件读取

这里先通过python得到一个交互式的shell:

>>> import pty;pty.spawn("/bin/bash") import pty;pty.spawn("/bin/bash") ctf@61d8d57653564e1a:/$ ​

通过资料,可以得知在python启动交互式终端的时候,会读取PYTHONSTARTUP这一环境变量作为shell启动时的预先加载脚本,那么说明__flag__的加载逻辑肯定在预先加载脚本内:

ctf@61d8d57653564e1a:/$ env ... PYTHONSTARTUP=/opt/python/preload.py FLAG=no_FLAG ... ​

那么在尝试读取/opt/python/preload.py文件的时候,发现权限拒绝,是因为我给这个文件设置了720权限:

-rwx-w---- 1 root root 209 May 20 05:18 preload.py ​

再度回想,为什么python可以读取这个文件并加载运行?是因为我给python上了特殊权限:

ctf@61d8d57653564e1a:/$ getcap -r / 2>/dev/null /usr/bin/python3.10 cap_dac_override=ep ​

那么就可以直接用python对这个脚本进行读取:

ctf@61d8d57653564e1a:/$ python3 -c 'print(open("/opt/python/preload.py").read())' import re import random from random import shuffle seed=114514 random.seed(114514) flag="NSSCTF{************}" flag=re.findall(r'.{2}', flag) shuffle(flag) __flag__=flag del re del flag ​

也可以得到flag

奇怪的tex文件 | @ 探姬

判定并且修复单个文件

其实只要没有被文件后缀误导,去找现代文件体系里面的tex怎么打开就行。

首先还是直接上 010 :

image-20230520152525268

源题目其实是真正的 cm3d2 mod文件,但比赛我哪里敢放真的((逃,所以出题的时候是用标准的 cm3d2 mod文件的文件头(09 43 4D 33 44 32 5F 54 45 58 06)+random_hex_string(44)生成的x

当然你不知道我上面在说什么没有关系,当你用010打开它的时候,大致浏览后,你要清楚的是,这个其实是前面加了一些标识信息的PNG图片文件,所以我们尝试还原第一张图片。

只需要移除PNG头(89 50 4E 47)前面的内容即可:

image-20230520152525268

再另存为PNG文件即可:

image-20230520152525268

脚本自动化

接下来要做的就是批量处理附件中的 44 个 "Tex" 文件。

核心思路大概是:

​ 1.按照顺序读取所有Tex文件

tex_files = glob.glob('*.tex') tex_files = [f for f in tex_files if f[:-4].isdigit()] tex_files.sort(key=lambda x: int(os.path.splitext(x)[0])) ​

​ 2.移除掉 PNG 头(89 50 4E 47)前面的所有内容

def find_and_remove_hex(input_file, hex_str): with open(input_file, 'rb') as f: file_content = f.read() hex_content = file_content.hex() start_index = hex_content.find(hex_str) if start_index == -1: return None cleaned_hex_content = hex_content[start_index:] cleaned_binary_content = bytes.fromhex(cleaned_hex_content) return cleaned_binary_content cleaned_content = find_and_remove_hex(tex_file, '89504e47') ​

​ 3.将文件存储为PNG文件

png_file = os.path.splitext(tex_file)[0] + '.png' cleaned_content = find_and_remove_hex(tex_file, '89504e47') if cleaned_content is not None: with open(png_file, 'wb') as f: f.write(cleaned_content) ​

然后人眼OCR:

image-20230520152525268

exp

import os import glob def find_and_remove_hex(input_file, hex_str): with open(input_file, 'rb') as f: file_content = f.read() hex_content = file_content.hex() start_index = hex_content.find(hex_str) if start_index == -1: return None cleaned_hex_content = hex_content[start_index:] cleaned_binary_content = bytes.fromhex(cleaned_hex_content) return cleaned_binary_content def main(): tex_files = glob.glob('*.tex') for tex_file in tex_files: png_file = os.path.splitext(tex_file)[0] + '.png' cleaned_content = find_and_remove_hex(tex_file, '89504e47') if cleaned_content is not None: with open(png_file, 'wb') as f: f.write(cleaned_content) else: print(f"ERROR") if __name__ == "__main__": main() ​

出题脚本

import os import random import string from PIL import Image, ImageDraw, ImageFont input_string = "NSSCTF{fine!it_1s_ez_f0rU_a_MISCmaster_todo}" image_width = 960 image_height = 1260 font = ImageFont.truetype("arial.ttf", 1145) for i, char in enumerate(input_string): image = Image.new("RGB", (image_width, image_height), color="white") draw = ImageDraw.Draw(image) draw.text((5, 0), char, fill="black", font=font) image.save(f"{i}.png") dir_path = "E:/Users/Probius/Desktop/Round12/" def random_hex_string(length): return ''.join(random.choices(string.hexdigits, k=length)) def process_file(file_path): with open(file_path, "rb") as f: file_data = f.read() hex_string = random_hex_string(44) image_data = bytes.fromhex("09434D3344325F544558" + hex_string) + file_data new_file_path = os.path.splitext(file_path)[0] + ".tex" with open(new_file_path, "wb") as f: f.write(image_data) print(f"Processed file: {file_path} -> {new_file_path}") for filename in os.listdir(dir_path): if filename.endswith(".png"): file_path = os.path.join(dir_path, filename) process_file(file_path) ​

Noisy Cube | @WDLJT

拿到题目观察是 Burp 的流量导出包,但是导入到 Burp 可能会遇到点问题(例如版本不匹配),但是不影响做题,只是观感差一点,前面都在穷举,疑似是 Line0~Line99 的数据,request,但是到 100 以后会提醒 Permission Denied,由于攻击者使用的是 Burp 的攻击器,所以 Payload 的顺序是按数字开头排序的会有点奇怪,如果输入小于 0 的数据会提示报错,然后攻击者尝试利用 ssti 获取文件,他获取了 app.py 执行了 dir 以及 matrix333.txt

我们看到 matrix333.txt 是每一行有一个 int

既然获取到了 app.py 就先来分析下

# -*- coding: utf-8 -*- from flask import Flask, request, render_template_string from jinja2 import Template from Crypto.Util.number import * app = Flask(__name__) with open("./matrix333.txt", 'r') as f: l = f.readlines() @app.route('/') def index(): _ = request.args.get("Line") if _: try: if int(_) >= 100: return "permission denied" else: return long_to_bytes(int(int(l[int(_) - 1]) ^ (int(_)))).decode() except: t = Template("Error in Line:" + _ + "\n") else: template = ''' <div class="center-content error"> <h3>%s </h3><br/> </div> ''' %(_) return render_template_string(template) return t.render() if __name__ == '__main__': app.run(host='0.0.0.0', port=58556) ​

那么 matrix333.txt 中的数据的解密方式为将每一行的 int 与行号异或 然后再使用 long to bytes 即可解出 matrix333.txt 中的 pos 数据,但解出数据后直接进行打点,会发现有明显的分割线,似乎是有明显的划分的,每个小块里面有 8 个数据,我们根据题目名应该是是需要构筑一个 Cube 出来,那么这个时候其实有两个方法,第一个更具这8个点将这个划分后的小 Cube 给填满,另外一个方法就是将这些数据缩成一个点,然后再将这个点放大(其实也不用放大),那我先才去第二个方法。

解密脚本如下:

from Crypto.Util.number import long_to_bytes res = set() with open("./download.dat", "r+", encoding="utf-8") as f: l = f.readlines() for x in range(len(l)): _l = long_to_bytes(int(l[x].strip()) ^ (x+1)).decode().split(" ") if _l[3] == "1": for i,x in enumerate(_l): _l[i] = round(int(x),-1) res.add(tuple(_l[:-1])) ​

然后所有点都是十倍数了这个时候等比缩放也行,构造出 Cube之后

import matplotlib.pyplot as plt x = [] y = [] z = [] for r in res: x.append(r[0]) y.append(r[1]) z.append(r[2]) ax = plt.subplot(projection="3d") ax.scatter(x,y,z, c="r") ax.view_init(elev=90, azim=0) plt.savefig("./save3.png") ax.clear() ax.scatter(y,z,x, c="r") ax.view_init(elev=90, azim=0) plt.savefig("./save1.png") ax.clear() ax.scatter(z,x,y, c="r") ax.view_init(elev=90, azim=0) plt.savefig("./save2.png") ax.clear() ​

或者使用 gnuplot 一样的,手动拖拽下其实发现是二维码,扫了一下,发现是一段 base64 ,有 NSSCTF 的头,那么就把三个角度的都弄出来,扫码之后拼凑一起 base64解密后即为最后答案

11

其实这里或许你也发现了,最后根本不需要构造一个 Cube,你每次忽视一个值,如只看 xy yz xz,出来的 3 个图其实就是最后 Cube 的投影。

完整脚本如下:

import matplotlib.pyplot as plt from Crypto.Util.number import long_to_bytes res = set() with open("./download.dat", "r+", encoding="utf-8") as f: l = f.readlines() for x in range(len(l)): _l = long_to_bytes(int(l[x].strip()) ^ (x+1)).decode().split(" ") if _l[3] == "1": for i,x in enumerate(_l): _l[i] = round(int(x),-1) res.add(tuple(_l[:-1])) x = [] y = [] z = [] for r in res: x.append(r[0]) y.append(r[1]) z.append(r[2]) ax = plt.subplot() ax.scatter(x,y) plt.savefig("./s1.png") ax.clear() ax.scatter(y,z) plt.savefig("./s2.png") ax.clear() ax.scatter(z,x) plt.savefig("./s3.png") ax.clear() ​

22

可能没办法直接识别,拉一拉或者调下绘图比例就行。

出题脚本:

import sys import qrcode from base64 import b64encode as base64 from loguru import logger import random from Crypto.Util.number import * # from secret import flag def create_matrix(input_string: str) -> list: # 创建二维码对象 qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=1, # 调整像素大小 border=0, # 调整边框大小 ) # 将文本添加到二维码对象 qr.add_data(input_string) qr.make(fit=True) # 获取二维码的图像并加载像素数据 img = qr.make_image(fill_color="black", back_color="white") pixels = img.load() # 遍历像素数据并创建矩阵 matrix = [] for y in range(img.size[1]): row = [] for x in range(img.size[0]): pixel = pixels[x, y] if pixel == 0: row.append(1) else: row.append(0) matrix.append(row) logger.info(input_string) logger.info(len(matrix)) logger.info(matrix) return matrix def create_cube(string1: list, string2: list, string3: list) -> list: cube_size = len(string1) if cube_size == len(string2) and cube_size == len(string3): matrix = [[[1 for x in range(cube_size)] for y in range(cube_size)] for z in range(cube_size)] for x in range(cube_size): for y in range(cube_size): if string1[x][y] == 0: for z in range(cube_size): matrix[z][x][y] = 0 if string2[x][y] == 0: for z in range(cube_size): matrix[x][z][y] = 0 if string3[x][y] == 0: for z in range(cube_size): matrix[x][y][z] = 0 logger.info(matrix) return matrix else: logger.error('输入的字符串长度不一致') return [None] def init(flag: str) -> list[int, list]: part_size = int(len(flag)/3) logger.info(f"{part_size=}") string1 = flag[:part_size] string2 = flag[part_size:part_size*2] string3 = flag[part_size*2:] logger.info(f"{string1=}, {string2=}, {string3=}") matrix1 = create_matrix(string1) size = len(matrix1) matrix2 = create_matrix(string2) matrix3 = create_matrix(string3) cube = create_cube(matrix1, matrix2, matrix3) return [size, cube] def encrypt(message: str, line: int) -> str: logger.info(message) logger.info(bytes_to_long(message.encode())) logger.info(str(line), str(bytes_to_long(message.encode()) ^ line)) return str(bytes_to_long(message.encode()) ^ line) def pos_noise(x: int, y: int, z: int) -> list: for _ in range(noise_cnt): yield [random.randint(x - noise_size, x + noise_size), random.randint(y - noise_size, y + noise_size), random.randint(z - noise_size, z + noise_size)] logger.remove() logger.add(sys.stderr, level='SUCCESS') # 只输出警告以上的日志 input_flag = b'' result = init(str(base64(input_flag))) size = result[0] counter = 0 box_size = 10 noise_size = (box_size // 2) - 1 noise_cnt = noise_size ** 3 // 8 logger.success(result) result_list = [] for i in range(size): for j in range(size): for k in range(size): for res in pos_noise((i + 1) * box_size, (j + 1) * box_size, (k + 1) * box_size): temp_list = res temp_list.append(result[1][i][j][k]) result_list.append(temp_list) random.shuffle(result_list) with open('matrix333.txt', 'w') as f: for i in result_list: counter += 1 m = encrypt(f'{i[0]} {i[1]} {i[2]} {i[3]}', counter) f.write(f'{m}\n') ​

My DCIC Trip | @WDLJT

预期解画圆重叠,但是呢因为他是步行距离所以理论上的距离按照 图片一的 3.0km应该是 3/根号2 ~ 3km 的范围,这也是为什么 Hint 半个小时内就得放,主要是题目早早出好了,不太好改,就只能通过放 Hint 的方式来补充了。

按照锦江宾馆官网,然后去同程上按品牌筛选出第一批符合条件的,其实也不用筛选品牌,只是待选项有点多,需要其他几个喜茶门店交叉匹配一下。

按照品牌筛选出,然后以距离排序,可以看到唯一一个

image-20230520153655064

那酒店名称就可以确定是维也纳酒店,分店1就为福州仓山奥体店,那继续看后续,同一家酒店,然后离那边巨远,先把喜茶门店和维也纳酒店搜出来

喜茶酒店

image-20230520153532401

维亚纳

image-20230520153655064

按照这种做法其实只有机场和江田镇的符合,那其他门店距离稍微校验下(记得注意距离计算范围),可以得到福州长乐国际机场店。

flag即为 NSSCTF{维也纳酒店_福州仓山奥体店_福州长乐国际机场店}