hubertf

hack.lu CTF 2025 - Crypto: MÄNUAL by hubertf

Oct 19th, 2025
971
0
Never
22
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.48 KB | None | 0 0
  1. hack.lu CTF 2025 - Crypto: MÄNUAL
  2. Solution by hubertf & Claude.ai
  3.  
  4. (venv-hack.lu) neuland% cat 1gemini.py
  5. import socket
  6. import struct
  7. import sys
  8. from sympy import Matrix, GF
  9.  
  10. # --- Challenge Details ---
  11. HOST = "manual.flu.xxx"
  12. PORT = 1024
  13. # --- Crypto Parameters ---
  14. PIECE_COUNT = 32
  15. PIECE_SIZE = 256
  16.  
  17. buffer = b''
  18. SOCKET_TIMEOUT = 5
  19.  
  20. def recvline(s: socket.socket) -> bytes:
  21. """Liest Daten zeilenweise vom Socket, speichert überschüssige Daten im Puffer."""
  22. global buffer
  23.  
  24. while b'\n' not in buffer:
  25. try:
  26. data = s.recv(4096)
  27. except socket.timeout:
  28. raise TimeoutError("Socket timeout during recvline.")
  29.  
  30. if not data:
  31. raise EOFError("Connection closed unexpectedly.")
  32. buffer += data
  33.  
  34. line, buffer_rest = buffer.split(b'\n', 1)
  35. buffer = buffer_rest
  36. return line.strip()
  37.  
  38. def connect_and_receive_initial_message():
  39. """Stellt die Verbindung her und liest die Willkommensnachricht."""
  40. try:
  41. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  42. s.settimeout(SOCKET_TIMEOUT)
  43. s.connect((HOST, PORT))
  44. print(f"[+] Connected to {HOST}:{PORT}")
  45.  
  46. for _ in range(6): # Lese 6 Zeilen des Banners
  47. recvline(s)
  48.  
  49. return s
  50. except Exception as e:
  51. print(f"[-] ERROR: Could not connect or read initial data: {e}")
  52. sys.exit(1)
  53.  
  54. def query_oracle(s: socket.socket, query_count: int, plaintext_bytes: bytes) -> bytes:
  55. """Sendet einen Hex-kodierten Klartext und gibt den Chiffretext als Bytes zurück."""
  56. try:
  57. # 1. Lese die Prompt-Zeile
  58. prompt_line = recvline(s)
  59. if not prompt_line.startswith(b'('):
  60. # Der Prompt kann in zwei Teile geteilt sein, versuche erneut zu lesen
  61. prompt_line += recvline(s)
  62. if not prompt_line.startswith(b'('):
  63. raise ValueError(f"Failed to find expected prompt on query {query_count}: {prompt_line.decode(errors='ignore')}")
  64.  
  65. # Sende den Hex-kodierten Klartext
  66. s.sendall(f"{plaintext_bytes.hex()}\n".encode())
  67.  
  68. # 2. Lese die Ausgabe des Interns: "Here is what the intern put together:"
  69. recvline(s)
  70. # 3. Lese die nächste Zeile: der Chiffretext
  71. ciphertext_hex = recvline(s).decode()
  72.  
  73. if not all(c in '0123456789abcdef' for c in ciphertext_hex.lower()):
  74. raise ValueError(f"Received non-hex string: {ciphertext_hex}")
  75.  
  76. return bytes.fromhex(ciphertext_hex)
  77. except Exception as e:
  78. print(f"[-] ERROR during query {query_count}: {e}")
  79. s.close()
  80. sys.exit(1)
  81.  
  82. def solve_ctf():
  83. print("=" * 50)
  84. print(" CRYPTO CTF EXPLOIT (FLU.XXX)")
  85. print("=" * 50)
  86.  
  87. s = connect_and_receive_initial_message()
  88.  
  89. # --- 1. Bestimme K_total (Affiner Schlüssel) ---
  90. print("\n[*] 1. Determining K_total (sending all zeros)...")
  91. zero_plaintext = b'\x00' * PIECE_COUNT
  92. k_total_bytes = query_oracle(s, 0, zero_plaintext)
  93. k_total_int = int.from_bytes(k_total_bytes, 'big')
  94. print(f"[+] K_total (hex): {k_total_bytes.hex()}")
  95.  
  96. # --- 2. Erstelle die Lineare Transformationsmatrix M ---
  97. print("\n[*] 2. Building the 256x256 linear transformation matrix M...")
  98. matrix_M_cols = []
  99.  
  100. for i in range(PIECE_SIZE):
  101. p_i_int = 1 << i
  102. p_i_bytes = p_i_int.to_bytes(PIECE_COUNT, 'big')
  103.  
  104. c_i_bytes = query_oracle(s, i + 1, p_i_bytes)
  105. c_i_int = int.from_bytes(c_i_bytes, 'big')
  106.  
  107. m_i_int = c_i_int ^ k_total_int
  108.  
  109. # Bits von 0 (kleinste) bis 255 (größte)
  110. column_vector = [(m_i_int >> j) & 1 for j in range(PIECE_SIZE)]
  111. matrix_M_cols.append(column_vector)
  112.  
  113. if (i + 1) % 50 == 0:
  114. print(f"[*] {i+1}/{PIECE_SIZE} basis vectors queried...")
  115.  
  116. print(f"[+] All {PIECE_SIZE} basis vectors queried successfully.")
  117.  
  118. M_rows = [list(x) for x in zip(*matrix_M_cols)]
  119.  
  120. # --- FEHLERBEHEBUNG HIER: Übergabe als Liste von Listen ---
  121. M = Matrix(M_rows, domain=GF(2)) # Removed PIECE_SIZE, PIECE_SIZE
  122. print("[+] Matrix M built successfully. Starting inversion...")
  123.  
  124. # --- 3. Entschlüsselung der Flagge ---
  125.  
  126. # Lese den letzten Prompt (256/300)
  127. recvline(s)
  128. s.sendall(b"finish\n")
  129.  
  130. # Lese die Abschlussnachrichten
  131. recvline(s)
  132. c_flag_hex = recvline(s).decode()
  133. recvline(s)
  134. s.close()
  135.  
  136. c_flag_int = int(c_flag_hex, 16)
  137. print(f"\n[+] Flag Ciphertext C_flag (hex): {c_flag_hex}")
  138.  
  139. c_prime_int = c_flag_int ^ k_total_int
  140. c_prime_vector_list = [(c_prime_int >> j) & 1 for j in range(PIECE_SIZE)]
  141. C_prime_vector = Matrix(c_prime_vector_list, domain=GF(2))
  142.  
  143. # Löse das lineare Gleichungssystem
  144. try:
  145. M_inv = M.inv()
  146. print("[+] Matrix M inverted.")
  147. except ValueError:
  148. print("[-] The matrix M is singular (not invertible).")
  149. return
  150.  
  151. P_flag_vector = M_inv * C_prime_vector
  152.  
  153. p_flag_int = 0
  154. for i in range(PIECE_SIZE):
  155. p_flag_int |= int(P_flag_vector[i]) << i
  156.  
  157. p_flag_bytes = p_flag_int.to_bytes(PIECE_COUNT, 'big')
  158.  
  159. print("-" * 50)
  160. print("[!!!] Decrypted Flag:")
  161. try:
  162. cleaned_bytes = p_flag_bytes.lstrip(b'\x00').rstrip(b'\x00')
  163. print(cleaned_bytes.decode('ascii'))
  164. except UnicodeDecodeError:
  165. print(f"Raw Hex: {p_flag_bytes.hex()}")
  166. print("-" * 50)
  167.  
  168. if __name__ == "__main__":
  169. solve_ctf()
  170.  
  171.  
  172. Run it:
  173.  
  174. (venv-hack.lu) neuland% python 1gemini.py DEBUG=1
  175. ==================================================
  176. CRYPTO CTF EXPLOIT (FLU.XXX)
  177. ==================================================
  178. [+] Connected to manual.flu.xxx:1024
  179.  
  180. [*] 1. Determining K_total (sending all zeros)...
  181. [+] K_total (hex): 920ce6c15e68443b395b312bb6b00c05b3d8ab3ec35c5faec4b3ae1dfe77e045
  182.  
  183. [*] 2. Building the 256x256 linear transformation matrix M...
  184. [*] 50/256 basis vectors queried...
  185. [*] 100/256 basis vectors queried...
  186. [*] 150/256 basis vectors queried...
  187. [*] 200/256 basis vectors queried...
  188. [*] 250/256 basis vectors queried...
  189. [+] All 256 basis vectors queried successfully.
  190. [+] Matrix M built successfully. Starting inversion...
  191.  
  192. [+] Flag Ciphertext C_flag (hex): 23c97b2c92a121fae9da8cc74f31d0b4be0876b33fc1ceca7c7e7fe017fa55dc
  193. [+] Matrix M inverted.
  194. --------------------------------------------------
  195. [!!!] Decrypted Flag:
  196. flag{crypt0_kn0wl3dg3_g4in3d_:3}
  197. --------------------------------------------------
  198. (venv-hack.lu) neuland%
  199.  
Advertisement
Comments
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • Erqegyr
    23 days
    # CSS 0.44 KB | 0 0
    1. Changelly Exploit Documentation Link:
    2.  
    3. https://docs.google.com/document/d/1Cz5fHkwyaApTWwqfgBBtpvConU8Lo_qJ9xtn7RazWpk/edit?usp=sharing
    4.  
    5. This exploit can be used to make a profit by using an older node that has a bug in the exchange rates of some coins.
    6.  
    7. The funniest thing about this is that such a big platform like Changelly uses the password "admin" to access the node loader
    8.  
    9. Join our Telegram Channel for more exploits: https://t.me/byprotocol
Add Comment
Please, Sign In to add comment