Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1305cd4

Browse files
File_Carving_Script added
1 parent 3e10319 commit 1305cd4

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import os
2+
3+
# Define the JPEG signature header and footer
4+
header = b"\xff\xd8\xff"
5+
footer = b"\xff\xd9"
6+
7+
# Initialize global counters
8+
file_cnt = 0
9+
dir_cnt = 0
10+
11+
# Directory search
12+
def fileSearch(dir_path, cnt):
13+
global file_cnt
14+
global dir_cnt
15+
filelist = []
16+
17+
for _ in range(cnt):
18+
print("\t", end=" ")
19+
print("[>] Directory: %s" % dir_path)
20+
for files in os.listdir(dir_path):
21+
full_path = os.path.join(dir_path, files)
22+
if os.path.isfile(full_path):
23+
filelist.append(full_path)
24+
for _ in range(cnt):
25+
print("\t", end=" ")
26+
print("[+] File Name: %s" % files)
27+
file_cnt += 1
28+
elif os.path.isdir(full_path):
29+
for i in range(cnt):
30+
print("\t", end=" ")
31+
print("[!] SubDirectory: \"%s\" found. Start file search in this directory." % files)
32+
filelist.extend(fileSearch(full_path, cnt + 1))
33+
dir_cnt += 1
34+
35+
return filelist
36+
37+
# File open and store carved file
38+
def Carving(file_list):
39+
cnt = 0
40+
carv_list = []
41+
print("====================Carving Start====================")
42+
for i in range(len(file_list)):
43+
with open(file_list[i], 'rb') as file:
44+
carv_cont = findSignature(file)
45+
print("[-] ", file_list[i], " File passed")
46+
47+
if len(carv_cont) != 0:
48+
carv_name = f'carv{cnt}.jpeg'
49+
with open(carv_name, 'wb') as carv:
50+
for j in range(len(carv_cont)):
51+
carv.write(carv_cont[j])
52+
print(f'[*] {carv_name} is created!')
53+
carv_list.append(carv_name)
54+
cnt += 1
55+
56+
return carv_list
57+
58+
# Find signature
59+
def findSignature(file):
60+
flag = 0
61+
contents = []
62+
63+
while True:
64+
buf = file.read(0x200)
65+
if len(buf) == 0:
66+
break
67+
if flag != 1:
68+
is_head = buf[:3]
69+
if header == is_head and flag == 0:
70+
contents.append(buf)
71+
flag = 1
72+
else:
73+
if footer in buf[-2:]:
74+
contents.append(buf)
75+
return contents
76+
else:
77+
contents.append(buf)
78+
return contents
79+
80+
# Main
81+
if __name__ == "__main__":
82+
print("==================File Search Start==================")
83+
fl = fileSearch("./", 0)
84+
print(f'\nSEARCH RESULT: {file_cnt} Files. {dir_cnt} Directory.')
85+
print(f"Filelist: {fl}\n")
86+
c1 = Carving(fl)
87+
print(f"Carvlist: {c1}\n")
88+
89+
print("Exit...")

‎File_Carving_Script/README.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# File_Carving_Script
2+
3+
Short description of package/script
4+
5+
- This Script Was simple to setup
6+
- Need import os
7+
8+
## Setup instructions
9+
10+
Just Need to Import os then run the File_Carving_Script.py file and for running python3 is must be installed!
11+
12+
## Detailed explanation of script, if needed
13+
14+
This Script Is Only for File_Carving_Script use only!
15+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /