mikisbd

AUTOPWN Réquiem Cipher - thehackerslabs

Jun 7th, 2026 (edited)
57
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.49 KB | Cybersecurity | 0 0
  1. #!/usr/bin/env python3
  2. # AUTOPWN Réquiem Cipher - thehackerslabs - https://labs.thehackerslabs.com/machine/197
  3. import hashlib
  4. import random
  5. from mido import MidiFile
  6. from PIL import Image
  7. import cv2
  8. from Crypto.Cipher import AES
  9. from Crypto.Util.Padding import unpad
  10.  
  11. # 1. Extraer clave AES del canal 2
  12. mid = MidiFile("requiem_cipher.mid")
  13. nibbles = []
  14.  
  15. for track in mid.tracks:
  16.     for msg in track:
  17.         if msg.type == "note_on" and hasattr(msg, 'channel'):
  18.             if msg.channel == 2 and msg.note in [73, 74]:
  19.                 nibbles.append((msg.note, msg.velocity - 40))
  20.  
  21. key_bytes = []
  22. for i in range(0, len(nibbles), 2):
  23.     if i+1 < len(nibbles):
  24.         high_note, high_val = nibbles[i]
  25.         low_note, low_val = nibbles[i+1]
  26.         if high_note == 73 and low_note == 74:
  27.             byte_val = ((high_val & 0xF) << 4) | (low_val & 0xF)
  28.             key_bytes.append(byte_val ^ 0x55)
  29.  
  30. key = bytes(key_bytes[:16])
  31. print(f"[+] Clave AES: {key.hex()}")
  32.  
  33. # 2. Extraer bits del canal 9
  34. bits = []
  35. for track in mid.tracks:
  36.     for msg in track:
  37.         if msg.type == "note_on" and hasattr(msg, 'channel'):
  38.             if msg.channel == 9 and msg.note == 35:
  39.                 bits.append('1' if msg.velocity > 80 else '0')
  40.  
  41. print(f"[+] Bits extraídos: {len(bits)}")
  42.  
  43. # 3. Reordenar bits
  44. seed = int.from_bytes(hashlib.sha256(key).digest()[:4], "big")
  45. rng = random.Random(seed)
  46. indices = list(range(len(bits)))
  47. rng.shuffle(indices)
  48.  
  49. payload_bits = ['0'] * len(bits)
  50. for real_pos, shuffled_pos in enumerate(indices):
  51.     payload_bits[real_pos] = bits[shuffled_pos]
  52. payload_bits = ''.join(payload_bits)
  53.  
  54. # 4. Reconstruir QR
  55. size = int(payload_bits[:8], 2)
  56. print(f"[+] Tamaño QR: {size}x{size}")
  57.  
  58. qr_bits = payload_bits[8:8 + size * size]
  59. img = Image.new("1", (size, size), 1)
  60. for i, bit in enumerate(qr_bits):
  61.     x, y = i % size, i // size
  62.     img.putpixel((x, y), 0 if bit == '1' else 1)
  63.  
  64. img_scaled = img.resize((size * 10, size * 10), Image.NEAREST)
  65. img_scaled.save("qr_recuperado.png")
  66. print("[+] QR guardado")
  67.  
  68. # 5. Leer QR y descifrar
  69. qr_img = cv2.imread("qr_recuperado.png")
  70. detector = cv2.QRCodeDetector()
  71. qr_data, _, _ = detector.detectAndDecode(qr_img)
  72.  
  73. if qr_data:
  74.     iv_hex, ct_hex = qr_data.split(":")
  75.     iv = bytes.fromhex(iv_hex)
  76.     ct = bytes.fromhex(ct_hex)
  77.    
  78.     cipher = AES.new(key, AES.MODE_CBC, iv)
  79.     flag = unpad(cipher.decrypt(ct), 16)
  80.     print(f"\n[+] FLAG: {flag.decode()}")
  81. else:
  82.     print("[-] No se pudo leer el QR")
Advertisement
Comments
  • mikisbd
    141 days
    # text 0.12 KB | 0 0
    1. PRERPARA EL ENTORNO PRIMERO:
    2. # Instalar las librerías necesarias
    3. pip install mido pillow opencv-python pycryptodome
Add Comment
Please, Sign In to add comment