This repository was archived by the owner on Dec 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathDataObjects.py
More file actions
104 lines (84 loc) · 3.17 KB
/
Copy pathDataObjects.py
File metadata and controls
104 lines (84 loc) · 3.17 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
from os import walk
from pathlib import Path
class File(object):
def __init__(self, full_path):
self.file_path = full_path
self.name = None
self.size = None
self.file_type = None
self.parent_folder = None
self._setup()
def __repr__(self):
return f"{self.name}"
def _setup(self):
print(self.file_path)
p = Path(self.file_path)
self.name = p.name
if p.suffix == "":
raise FileNotFoundError(
f"{self.file_path} has to be a file not a folder"
)
self.file_type = p.suffix
self.size = p.stat().st_size # size displayed in bytes
self.parent_folder = str(p.parent)
class Folder(object):
def __init__(self, full_path, include_subfolders=False):
self.folder_path = full_path
self.includes_subfolders = include_subfolders
self.folder_files = ()
self._extract_files(include_subfolders)
def __repr__(self):
return f"{self.folder_path}"
def _extract_files(self, seek_subfolders=False):
all_files = []
for (dirpath, dirnames, filenames) in walk(self.folder_path, topdown=True):
for filename in filenames:
file_path = fr"{dirpath}\{filename}"
print(file_path)
file = File(file_path)
all_files.append(file)
if not seek_subfolders:
break
if all_files:
self.folder_files = tuple(all_files)
def show_files(self, pretty_print=False):
print(self)
if not pretty_print:
print(self.folder_files)
else:
for file in self.folder_files:
print(f"Name: {file.name}\n Size: {file.size}")
class AttackTargets(object):
def __init__(self):
self.targets = [] # a list of file and folder object
def add_target(self, target):
# A target is a tuple in the form ["type", "include_subfolders", "target_path"]
target_type = target[0]
include_subfolders = target[1]
target_path = target[2]
if target_type == "File":
self._add_target_file(target_path=target_path)
else:
self._add_target_folder(target_path=target_path,
include_subfolders=include_subfolders)
def _add_target_file(self, target_path):
raw_target = fr"{target_path}"
t = File(raw_target)
self.targets.append(t)
def _add_target_folder(self, target_path, include_subfolders=False):
raw_target = fr"{target_path}"
t = Folder(raw_target, include_subfolders)
self.targets.append(t)
def get_targets(self):
return self.targets
def show_targets(self, pretty_print=False):
if not self.targets:
print("There are no targets")
for count, item in enumerate(self.targets, 1):
if isinstance(item, File):
print(f"Target {count}.\n{item}")
else:
print(f"Target {count}.\n")
item.show_files(pretty_print)
## Password file location
#https://www.kaggle.com/wjburns/common-password-list-rockyoutxt