-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvss.py
129 lines (110 loc) · 5.51 KB
/
vss.py
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import os
import sys
import vss_cls
import serch_cls
import argparse
import json
import time
import hashlib
def searc_by_file_name(filename,path):
sech = serch_cls.search()
find_file = sech.find_files(filename,path)
return find_file
def searc_by_hash(hash,path):
sech = serch_cls.search()
find_file = sech.find_hash(hash,path)
return find_file
def searc_by_folder(path,root_dir):
path = path[3:]
path = os.path.join(root_dir, path)
if os.path.exists(path):
print("Exsiting Path: "+path)
sech = serch_cls.search()
find_file = sech.find_folders_files(path)
return find_file
else:
print("Path Doesn't exists in " + root_dir)
################################################################
def copy_file_filename(filename,path,dest_path):
if os.path.exists(dest_path) == True:
if os.path.isdir(dest_path) == True:
copy_file = searc_by_file_name(filename,path)
for cf in copy_file:
fname = os.path.basename(cf)
with open(cf, 'rb') as cp:
cpy = cp.read()
with open(os.path.join(dest_path,fname) , 'wb+') as df:
df.write(cpy)
else:
print('The path you have entered is not a directory')
else:
print('The path you have entered does not exist')
#################################################################
def hash_files(filename):
sech = serch_cls.search()
find_file = sech.hash_file(filename,hashlib.md5())
return find_file
def main(argv=[]):
parser = argparse.ArgumentParser(description="Explore Volume Shadow Copies")
parser.add_argument("-p", "--Path", type=str, help="")
parser.add_argument("-v", "--Vss", type=str, help="Check vss")
parser.add_argument("-s", "--Hash",type=str, help="")
parser.add_argument("-f", "--FileName",type=str, help="")
parser.add_argument("-k", "--Keywords",type=str, help="Type the File Name or Hash or Path")
parser.add_argument("-c", "--CopyFile", nargs= 2 ,type=str, help="Type the File Name")
parser.add_argument("-j", "--JsonOutput", help="Print the output in json format")
args = parser.parse_args()
cs_vss = vss_cls.vss()
IDs = cs_vss.get_devicesIDs()
#################################################################
if args.Vss == "true":
for id in IDs:
print(id['ID'])
if args.Hash == "true":
try:
for id in IDs:
hashes = args.Keywords
if "," in hashes:
hashex = hashes.split(',')
for hash in hashex:
files = searc_by_hash(hash, id['ID'])
for f in files:
file_meta = os.stat(f)
access= time.strftime("%b %d %Y %H:%M:%S", time.localtime(file_meta.st_atime))
modify= time.strftime("%b %d %Y %H:%M:%S", time.localtime(file_meta.st_mtime))
print(" File Name: "+os.path.basename(f)+'\n'+" File Owner: "+str(file_meta.st_uid)+'\n'+" File Size: "+str(file_meta.st_size)+' Bytes \n'+" File Last Accessed: "+access+'\n'+" File Last Modified: "+modify)
else:
files = searc_by_hash(hashes, id['ID'])
for f in files:
file_meta = os.stat(f)
access= time.strftime("%b %d %Y %H:%M:%S", time.localtime(file_meta.st_atime))
modify= time.strftime("%b %d %Y %H:%M:%S", time.localtime(file_meta.st_mtime))
print(" File Name: "+os.path.basename(f)+'\n'+" Path: "+f+'\n'+" File Owner: "+str(file_meta.st_uid)+'\n'+" File Size: "+str(file_meta.st_size)+' Bytes \n'+" File Last Accessed: "+access+'\n'+" File Last Modified: "+modify)
except:
print("No such Hash exists")
################################################################
if args.FileName == "true":
for id in IDs:
files = searc_by_file_name(args.Keywords, id['ID'])
for f in files:
file_meta = os.stat(f)
access= time.strftime("%b %d %Y %H:%M:%S", time.localtime(file_meta.st_atime))
modify= time.strftime("%b %d %Y %H:%M:%S", time.localtime(file_meta.st_mtime))
print(" File Name: "+os.path.basename(f)+'\n'+" Path: "+f+'\n'+" Hash: "+str(hash_files(f))+'\n'+" File Owner: "+str(file_meta.st_uid)+'\n'+" File Size: "+str(file_meta.st_size)+' Bytes \n'+" File Last Accessed: "+access+'\n'+" File Last Modified: "+modify)
################################################################
if args.Path == "true":
for id in IDs:
files = searc_by_folder(args.Keywords, id['ID'])
for f in files:
file_meta = os.stat(f)
access= time.strftime("%b %d %Y %H:%M:%S", time.localtime(file_meta.st_atime))
modify= time.strftime("%b %d %Y %H:%M:%S", time.localtime(file_meta.st_mtime))
print(" File Name: "+os.path.basename(f)+'\n'+" Path: "+f+'\n'+" File Owner: "+str(file_meta.st_uid)+'\n'+" File Size: "+str(file_meta.st_size)+' Bytes \n'+" File Last Accessed: "+access+'\n'+" File Last Modified: "+modify)
################################################################
if args.CopyFile:
args = args.CopyFile
fn,dst = tuple(args)
for id in IDs:
copy_file_filename (fn,id['ID'],dst)
if __name__ == '__main__':
main(sys.argv)