-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtractor.py
More file actions
105 lines (85 loc) · 3.94 KB
/
Extractor.py
File metadata and controls
105 lines (85 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import cv2
import numpy as np
import base64
import PyPDF2
import os
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
from cryptography.fernet import Fernet
# --- CORE TOOLS (MUST MATCH SENDER) ---
def get_crypto_tools(password: str):
salt = b'\x00' * 16
kdf = PBKDF2HMAC(algorithm=hashes.SHA256(), length=32, salt=salt, iterations=100000)
key = base64.urlsafe_b64encode(kdf.derive(password.encode()))
return Fernet(key)
# --- RECOVERY ENGINE ---
def recover_from_image(stego_image, output_file, password, is_text=False):
img = cv2.imread(stego_image)
if img is None: return
flat_bits = [str(p & 1) for p in img.flatten()]
full_bin = "".join(flat_bits)
all_bytes = bytearray()
for i in range(0, len(full_bin), 8):
byte = int(full_bin[i:i+8], 2)
all_bytes.append(byte)
if all_bytes.endswith(b"STOP_HERE"): break
cipher = get_crypto_tools(password)
decrypted = cipher.decrypt(bytes(all_bytes[:-9]))
if is_text:
print(f"🔓 TEXT FROM IMAGE: {decrypted.decode()}")
else:
with open(output_file, 'wb') as f: f.write(decrypted)
print(f"🔓 FILE FROM IMAGE RECOVERED: {output_file}")
def recover_from_pdf(stego_pdf, output_file, password, is_text=False):
reader = PyPDF2.PdfReader(stego_pdf)
encrypted_blob = reader.metadata.get('/Subject')
cipher = get_crypto_tools(password)
decrypted = cipher.decrypt(encrypted_blob.encode())
if is_text:
print(f"🔓 TEXT FROM PDF: {decrypted.decode()}")
else:
with open(output_file, 'wb') as f: f.write(decrypted)
print(f"🔓 FILE FROM PDF RECOVERED: {output_file}")
def recover_from_file(stego_file, output_file, password, is_text=False):
with open(stego_file, 'rb') as f: data = f.read()
if b"FILE_SECRET_START" not in data: return
secret_part = data.split(b"FILE_SECRET_START")[1]
cipher = get_crypto_tools(password)
decrypted = cipher.decrypt(secret_part)
if is_text:
print(f"🔓 TEXT FROM FILE: {decrypted.decode()}")
else:
with open(output_file, 'wb') as f: f.write(decrypted)
print(f"🔓 FILE FROM FILE RECOVERED: {output_file}")
# --- PRODUCTION RECOVERY (THE DEMO) ---
PASS = "ismagi_secure_2026"
# --- PRODUCTION RECOVERY (THE DEMO) ---
PASS = "ismagi_secure_2026"
# This is the folder where your hidden files are sitting
HIDDEN_DIR = "the hidden stuff"
# --- FULL PRODUCTION RECOVERY ---
PASS = "ismagi_secure_2026"
HIDDEN_DIR = "the hidden stuff"
# --- FULL PRODUCTION RECOVERY (A through I) ---
PASS = "ismagi_secure_2026"
HIDDEN_DIR = "the hidden stuff"
print("--- STARTING FULL A-I EXTRACTION ---")
# A & H: Photo Hidden in Photo
# recover_from_image(os.path.join(HIDDEN_DIR, "image_in_image.png"), "RECOVERED_A_PHOTO_FROM_IMAGE.png", PASS)
# B. Typed Text inside Photo
recover_from_image(os.path.join(HIDDEN_DIR, "text_in_image.png"), None, PASS, is_text=True)
# # C. File (message.txt) inside PDF
# recover_from_pdf(os.path.join(HIDDEN_DIR, "message_in_pdf.pdf"), "RECOVERED_C_MESSAGE_FROM_PDF.txt", PASS)
# # D. Typed Text inside PDF
# recover_from_pdf(os.path.join(HIDDEN_DIR, "text_in_pdf.pdf"), None, PASS, is_text=True)
# # E. PDF inside Text File
# recover_from_file(os.path.join(HIDDEN_DIR, "pdf_hidden_in_text.txt"), "RECOVERED_E_PDF_FROM_TEXT.pdf", PASS)
# # F. Typed Text inside Text File
# recover_from_file(os.path.join(HIDDEN_DIR, "hidden_in_text.txt"), None, PASS, is_text=True)
# # G. Photo inside Text File
# recover_from_file(os.path.join(HIDDEN_DIR, "photo_hidden_in_text.txt"), "RECOVERED_G_PHOTO_FROM_TEXT.png", PASS)
# # H. PDF inside Photo (Duplicate logic of A, but with different filename)
# recover_from_image(os.path.join(HIDDEN_DIR, "pdf_in_photo.png"), "RECOVERED_H_PDF_FROM_PHOTO.pdf", PASS)
# # I. PDF inside PDF
# recover_from_pdf(os.path.join(HIDDEN_DIR, "pdf_in_pdf.pdf"), "RECOVERED_I_PDF_FROM_PDF.pdf", PASS)
print("--- ALL 9 SCENARIOS RECOVERED ---")