-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDDHunter.py
More file actions
85 lines (69 loc) · 3.16 KB
/
Copy pathDDHunter.py
File metadata and controls
85 lines (69 loc) · 3.16 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
#!/usr/bin/python3
import os
import argparse
import re
import time
import pyfiglet
def display_ascii_art():
ascii_art = pyfiglet.figlet_format("DDHunter")
print(ascii_art)
print("By Alayna Ferdarko")
def search_dd_file(dd_file_path, output_dir):
file_signatures = {
"jpg": b"\xFF\xD8\xFF",
"gif": b"GIF",
"png": b"\x89PNG\x0D\x0A\x1A\x0A",
"mp4": b"ftyp",
"mp3": b"\x49\x44\x33",
"pdf": b"%PDF",
"docx": b"\x50\x4B\x03\x04",
"xlsx": b"\x50\x4B\x03\x04",
"pptx": b"\x50\x4B\x03\x04"
}
os.makedirs(output_dir, exist_ok=True)
file_count_dict = {key: 0 for key in file_signatures.keys()}
start_time = time.time()
file_size = os.path.getsize(dd_file_path)
total_bytes_processed = 0
try:
with open(dd_file_path, "rb") as dd_file:
chunk_size = 10 * 1024 * 1024
offset = 0
while chunk := dd_file.read(chunk_size):
total_bytes_processed += len(chunk)
progress = (total_bytes_processed / file_size) * 100
elapsed_time = time.time() - start_time
estimated_time_remaining = (elapsed_time / total_bytes_processed) * (file_size - total_bytes_processed)
print(f"Progress: {progress:.2f}% | Estimated time remaining: {estimated_time_remaining / 60:.2f} minutes", end="\r")
for file_type, signature in file_signatures.items():
offset_in_chunk = 0
while True:
index = chunk.find(signature, offset_in_chunk)
if index == -1:
break
file_count_dict[file_type] += 1
file_count = file_count_dict[file_type]
output_file_path = os.path.join(output_dir, f"recovered_{file_type}_{file_count}.{file_type}")
with open(output_file_path, "wb") as output_file:
output_file.write(chunk[index:index + 10 * 1024 * 1024])
print(f"Recovered {file_type} file at offset {offset + index}: {output_file_path}")
offset_in_chunk = index + len(signature)
offset += len(chunk)
print("\nRecovery summary:")
for file_type, count in file_count_dict.items():
if count > 0:
print(f" {count} {file_type} files recovered")
except FileNotFoundError:
print(f"File not found: {dd_file_path}")
except Exception as e:
print(f"An error occurred: {e}")
def main():
display_ascii_art()
print("DDHunter is running. Please wait while your image is parsed, and your files are recovered.")
parser = argparse.ArgumentParser(description="File carving tool to recover files from a .dd image")
parser.add_argument("dd_image_path", help="Path to the .dd or .001 image file")
parser.add_argument("recovery_folder", help="Directory where recovered files will be saved")
args = parser.parse_args()
search_dd_file(args.dd_image_path, args.recovery_folder)
if __name__ == "__main__":
main()