[TOC]
黑客密室逃脱
提示猜文件名,猜几个常见的,app.py读到源码
这里也是脑抽了一下,把密钥看成1236了。。。卡了五分钟左右,解出来的时候已经降到300多分了,加密过程并不复杂,两式相减还原回去即可
from Crypto.Util.number import *
key='secret_key1236'
enc='d9d1c4d9e0abc29d9bb292689863a89899a492a892cccba669689566a0c7c8a6c8a692d0c6dc959898b3'
def simple_encrypt(text, key):
encrypted = bytearray()
for i in range(len(text)):
char = text[i]
key_char = key[i % len(key)]
encrypted.append(ord(char) + ord(key_char))
return encrypted.hex()
enc1=int(enc,16)
enc2=long_to_bytes(enc1)
print(enc2)
def decrypt(text, key):
encrypted = bytearray()
for i in range(len(text)):
char = text[i]
key_char = key[i % len(key)]
encrypted.append(char - ord(key_char))
return encrypted
print(decrypt(enc2,key))
ezEvtx
没啥好说的,随便过滤一下就找到了
flowzip
流量分析一把梭
Enigma
赛博厨子一把梭
星际xml解析器
常规xxe,读文件即可
https://www.cnblogs.com/Eleven-Liu/p/8612821.html
EBC-Train
这个也是在赛后才想明白,aes加密用的是十六字节,将前十一个都填成AAAA发过去,因为ecb模式是分组加密,每一组的加密过程都是一样的,所以不需要写脚本还原加密过程去破解(其实硬写也做不到,因为拿不到key,当时我觉得用户名肯定是key,不然解不了,于是就一直卡在这一步了,实际上用户名是明文),直接将发过来的加密数据取出后几组就是admin的加密了
AES-CBC
from Crypto.Cipher import AES # 导入AES加密模块
from secret import flag # 从secret模块导入flag(假设为明文)
import random, os # 导入random和os模块用于随机数生成
# 为消息填充字节,使其长度为16的倍数
def pad(msg):
return msg + bytes([16 - len(msg) % 16 for _ in range(16 - len(msg) % 16)])
# 对密钥进行随机置换,生成新密钥
def permutation(key):
tables = [hex(_)[2:] for _ in range(16)] # 生成0-15的十六进制表(去掉"0x"前缀)
random.shuffle(tables) # 随机打乱表
newkey = "".join(tables[int(key[_], 16)] for _ in range(len(key))) # 根据原密钥生成新密钥
return newkey
# 生成初始密钥key0及其置换密钥key1
def gen():
key0 = os.urandom(16).hex() # 随机生成16字节密钥并转为十六进制字符串
key1 = permutation(key0) # 对key0进行置换生成key1
return key0, key1
# 使用key0和key1进行双重AES加密
def encrypt(key0, key1, msg):
aes0 = AES.new(key0, AES.MODE_CBC, key1) # 用key0加密,key1作为CBC模式的IV
aes1 = AES.new(key1, AES.MODE_CBC, key0) # 用key1解密,key0作为CBC模式的IV
return aes1.decrypt(aes0.encrypt(msg)) # 先加密后解密生成密文
# 生成密钥对
key0, key1 = gen()
a0, a1 = int(key0, 16), int(key1, 16) # 将密钥转为整数
gift = a0 & a1 # 计算key0和key1的按位与,作为泄露信息
cipher = encrypt(bytes.fromhex(key0), bytes.fromhex(key1), pad(flag)) # 加密填充后的flag
print(f"gift = {gift}")
print(f"key1 = {key1}")
print(f"cipher = {cipher}")
'''
gift = 64698960125130294692475067384121553664
key1 = 74aeb356c6eb74f364cd316497c0f714
cipher = b'6\xbf\x9b\xb1\x93\x14\x82\x9a\xa4\xc2\xaf\xd0L\xad\xbb5\x0e|>\x8c|\xf0^dl~X\xc7R\xcaZ\xab\x16\xbe r\xf6Pl\xe0\x93\xfc)\x0e\x93\x8e\xd3\xd6'
'''
这道题想到思路了,但是忘记dfs怎么写了,脚本没写出来。。。
首先是一个按位与,我们都知道,如果gift的结果是1,那说明参与按位与的两个数在对应位置上一定是1.
由此可以确定大概三十几位key0中一定为1的位
接着,我们计算key1异或gift,得到的结果中如果为1的位,说明key0中对应的位置一定为0
由此又可以确定三十几位
总共就128位,那么剩下的其实只有五十多位了,爆破一下就出来了