2024第一次线上赛WP
MISC 办公室爱情(🙂) 办公室爱情wp 你这flag保熟吗(😐) 你这flag保熟吗wp 小明的电脑(😧) 小明的电脑wp 套娃生成器(🤯) 根据提示,在github上找到该项目 总共实现了以下几种娃: dolls_registry = ( (Base16Doll, Base32Doll, Base64Doll, Base85Doll), # Base系列编码,随机选择一种 (RGBAImageBytesDoll,), # 字节编码成 RGBA 图片 (BitReverseDoll, ByteReverseDoll), # 位翻转和字节翻转 (WeakZipDoll,), # 弱密码ZIP (QRCodeDoll,), # 字符串编码成二维码 (MostSignificantByteDoll, LeastSignificantByteDoll), # 隐写LSB/MSB ) 生成逻辑是上面每行的娃随机选择一个,然后打乱顺序递归生成结果。如果生成的结果超过当前娃的最大承载长度,就将这个娃和上一个娃交换位置,然后重新生成。(具体逻辑见 encode.py) 其中,QRCodeDoll 会生成一个二维码图片,由于二维码我没有找到可靠的办法来承载二进制,所以它实际上存储的是 Base64 编码的二进制数据。 另外,对于 RGBAImageBytesDoll、MostSignificantByteDoll 和 LeastSignificantByteDoll,由于存储的数据长度可能不足容量,所以存储的前四字节为大端序的数据长度。 此外,WeakZipDoll 生成的密码选择在五位数字的原因是因为这是在我的机器上 Python 多进程能在 60 秒内稳定破解的最长密码(有考虑过六位数字,但是不能稳定破解,可能需要写 C binding,感觉有点麻烦就放弃了)。 解题脚本见 solve.py,其中具体实现的逻辑是对于输入的特征选择尝试解码的娃,如果解码成功但是结果不清晰就递归解码,直到解码成功且结果清晰(或者持续解码但是直到低于最小可能长度仍然无法解码就失败);如果解码失败就尝试下一个娃。 solve.py: import re import sys from base64 import decodebytes import pwn as p from matryoshka.dolls.base import DollError, DollsBase from matryoshka.dolls.multi_base import Base16Doll, Base32Doll, Base64Doll, Base85Doll from matryoshka.dolls.qrcode_encode import QRCodeDoll from matryoshka.dolls.reverse import BitReverseDoll, ByteReverseDoll from matryoshka.dolls.rgb_bytes import RGBAImageBytesDoll from matryoshka.dolls.significant_byte import ( LeastSignificantByteDoll, MostSignificantByteDoll, ) from matryoshka.dolls.weak_zip import WeakZipDoll def decode( data: bytes, round: int = 1, result_regex=rb"flag{.*?}", accepted_dolls: tuple[type[DollsBase], ...] = (), length_threshold: int = 10, ): def prefixed_print(*args): p.log.info(" ".join(["--" * round + ">", *map(str, args)])) prefixed_print("entering round", round) attempts: list[type[DollsBase]] = [] if data.startswith(b"PK"): # PK is the magic number for ZIP files attempts.append(WeakZipDoll) if data.startswith(b"\x89PNG"): # PNG magic number attempts.append(RGBAImageBytesDoll) attempts.append(LeastSignificantByteDoll) attempts.append(MostSignificantByteDoll) if data.isascii(): # ASCII charset = {bytes([c]) for c in data} if charset == {b"0", b"1"}: attempts.append(QRCodeDoll) else: attempts.append(Base16Doll) attempts.append(Base32Doll) attempts.append(Base64Doll) attempts.append(Base85Doll) attempts.append(BitReverseDoll) attempts.append(ByteReverseDoll) attempts = [attempt for attempt in attempts if attempt not in accepted_dolls] for attempt in attempts: prefixed_print(f"trying {attempt.__name__}") try: result = attempt().decode(data) except DollError as e: prefixed_print(f"failed {attempt.__name__}: {e}") continue if len(result) < length_threshold: prefixed_print(f"failed {attempt.__name__}: length not accepted") continue if re.search(result_regex, result, re.DOTALL): prefixed_print(f"success {attempt.__name__}: {result}") return result prefixed_print("result not clear, recursive decode begin") result = decode(result, round + 1, result_regex, (*accepted_dolls, attempt)) if result: return result prefixed_print("round failed") return None if len(sys.argv) != 3: print(f"Usage: {sys.argv[0]} <host> <port>") sys.exit(1) _, host, port = sys.argv s = p.remote(host, port) s.recvuntil(b"name") s.sendline(b"mix") while True: data = s.recvuntil(b"-----END MATRYOSHKA MESSAGE-----") round_data = re.search(rb"Round (\d+)/(\d+)", data) assert round_data round = int(round_data.group(1)) total_rounds = int(round_data.group(2)) p.log.info(f"Round {round}/{total_rounds}") data_chunk = re.search( b"-----BEGIN MATRYOSHKA MESSAGE-----\n(.*)\n-----END MATRYOSHKA MESSAGE-----", data, re.DOTALL, ) assert data_chunk data = decode(decodebytes(data_chunk.group(1))) assert data s.sendline(data) if round == total_rounds: break s.interactive() CRYPTO baby_rsa(🙂) from Crypto.Util.number import long_to_bytes from gmpy2 import invert, is_prime from tqdm import tqdm primes = [] for xy in tqdm(range(500)): for mn in range(500): prime = xy**(mn+1) - (xy+1)**mn if prime.bit_length() > 2048: break if is_prime(prime): primes.append(prime) c = 15808773921165746378224649554032774095198531782455904169552223303513940968292896814159288417499220739875833754573943607047855256739976161598599903932981169979509871591999964856806929597805904134099901826858367778386342376768508031554802249075072366710038889306268806744179086648684738023073458982906066972340414398928411147970593935244077925448732772473619783079328351522269170879807064111318871074291073581343039389561175391039766936376267875184581643335916049461784753341115227515163545709454746272514827000601853735356551495685229995637483506735448900656885365353434308639412035003119516693303377081576975540948311 for i in range(len(primes)): for j in range(i, len(primes)): pq = primes[i]*primes[j] if len(bin(pq)[2:]) == 2048: try: d = invert(0x10001, (primes[i]-1)*(primes[j]-1)) dec = long_to_bytes(pow(c, d, pq)) if b"flag{" in dec: print(dec) except ValueError: pass 已知((fac[0]+fac[1]+fac[2]) « 1) - 1的值,用其替代n。分解((fac[0]+fac[1]+fac[2]) « 1) - 1求其欧拉函数,进而求解出d和第二段。 ...