# BKCTF 2023 # Checker Challenge cho 2 file main.lua và checker.lua main.lua ```python= local util = require "checker" -- local util = require("checker") io.write("Input flag: ") local flag = io.read("*l") if util.check(flag, "BKctf2023") then print("Correct!") else print("Wrong...") end ``` File checker.lua đã compile nên không đọc được nên mình dùng [tool này](https://sourceforge.net/projects/unluac/) để decompile Sau khi decompile ```python= local flag = {} function flag.check(v2, v3) local v4 = true local v5 = string.lower(v3) local v6 = { 46, 106, 119, 140, 105, 195, 195, 219, 180, 116, 151, 68, 191, 86, 169, 205, 195, 211, 107, 120, 110, 129, 160, 189, 189, 189, 194, 164, 102, 110, 123, 111 } local v7 = { 219, 117, 231, 96, 201, 195, 228, 201, 255, 228, 195, 252, 219, 234, 213, 138, 138, 138, 96, 240, 228, 207, 195, 249, 207, 96, 261, 195, 219, 252, 99, 30 } if 32 ~= #v2 then v4 = false end for v8 = 1, #v7 do io.write(string.char(v7[v8] / 3)) end for v9 = 1, #v2 do local v10 = v2:byte(v9) ~ v5:byte((v9 - 1) % #v5 + 1) if v9 > 1 then v10 = v10 + v2:byte(v9 - 1) end if v6[v9] ~= v10 then v4 = false end end return v4 end return flag ``` Dưới đây là đoạn mã chuyển từ lua qua python ```python= class Flag: @staticmethod def check(v2, v3): v4 = True v5 = v3.lower() v6 = [ 46, 106, 119, 140, 105, 195, 195, 219, 180, 116, 151, 68, 191, 86, 169, 205, 195, 211, 107, 120, 110, 129, 160, 189, 189, 189, 194, 164, 102, 110, 123, 111 ] v7 = [ 219, 117, 231, 96, 201, 195, 228, 201, 255, 228, 195, 252, 219, 234, 213, 138, 138, 138, 96, 240, 228, 207, 195, 249, 207, 96, 261, 195, 219, 252, 99, 30 ] if len(v2) != 32: v4 = False for v8 in v7: print(chr(v8 // 3), end='') for v9 in range(len(v2)): v10 = ord(v2[v9]) ^ ord(v5[(v9 - 1) % len(v5)]) if v9 > 1: v10 += ord(v2[v9 - 1]) if v6[v9] != v10: v4 = False return v4 # Test v2 = "some_input_string" # Thay bằng chuỗi đầu vào thực tế của bạn v3 = "some_key" # Thay bằng khóa đầu vào thực tế của bạn result = Flag.check(v2, v3) print(result) ``` solve.py ```python= data = [ 46, 106, 119, 140, 105, 195, 195, 219, 180, 116, 151, 68, 191, 86, 169, 205, 195, 211, 107, 120, 110, 129, 160, 189, 189, 189, 194, 164, 102, 110, 123, 111] f =[0]*32 prefix=b"bkctf2023" f[0]= data[0]^prefix[0] for i in range(1,len(data),1): f[i] = (data[i]-f[i-1])^prefix[i%len(prefix)] flag = 'BKSEC{' + ''.join(chr(x) for x in f) + '}' print(flag) ``` Flag: `BKSEC{Lua_len_fl@g,Long_nang_lang_lang}`