-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathmemo.py
299 lines (238 loc) · 12.1 KB
/
memo.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
import processCheckingNu
import run
import subprocess
import userassist
import autoscan
from pandas import DataFrame
from userassist import *
dir_path = os.path.dirname(os.path.realpath(__file__))
def memory():
"""
Output from volatility is used for the purpose of process grouping,
traceability, detect suspicious or genuine paths or commands by calling
other functions.
"""
mypath = dir_path + r'\csvFiles\imgs'
for filename in os.listdir(mypath):
filepath = os.path.join(mypath, filename)
os.remove(filepath)
print(Fore.RED + '\nPlease remove white spaces before passing the path of the memory image.')
print(Fore.GREEN)
path = input(r'Provide absolute path of your memory image (e.g. G:\memory-files\memory.img):')
if path == '':
print(Fore.YELLOW + '\nError - empty path')
memory()
if not os.path.exists(path):
print(Fore.YELLOW + '\nError - path could not be found. Please try again')
memory()
output = dir_path + r'\csvFiles\imgs\processTrace.csv'
""" put path of python.exe version 3.7+++ """
py = 'python.exe'
# print (py)
cmd = dir_path + r'\bin\volatility3-master\vol.py -f'
ps_scan = 'windows.psscan.PsScan'
cmdps_scan = py + ' ' + cmd + ' ' + path + ' ' + ps_scan
path_cmd = ' > ' + dir_path + r'\csvFiles\process_cmd.csv'
user_assi = dir_path + r'\csvFiles\userAssist.csv'
mal = py + ' ' + cmd + ' ' + path + ' ' + 'windows.malfind.Malfind'
win_cmd = py + ' ' + cmd + ' ' + path + ' ' + 'windows.cmdline.CmdLine' + path_cmd
error = dir_path + r'\csvFiles\err\err.txt'
print(Fore.WHITE)
key_selection= str(input('\nPress y for automatic analysis or n for manual analysis ? y/n: ')).lower().strip()
print(Fore.GREEN)
if key_selection == 'n':
# Memory information
key = str(input('Memory Information? y/n: ')).lower().strip()
if key == 'y':
imageinfo = 'windows.info'
cmdmem_info = py + ' ' + cmd + ' ' + path + ' ' + imageinfo
print(Fore.WHITE)
try:
proc = subprocess.check_output(cmdmem_info, shell=True, stderr=subprocess.STDOUT, encoding='utf-8', )
print(proc)
except subprocess.CalledProcessError:
print(
Fore.YELLOW + r'Error- Volatility related. Maybe latest windows folder under '
+ dir_path + r'\volatility3-master\volatility\symbols is required ')
print(
Fore.YELLOW + '\nAlso check volatility3-master path to be like ' + dir_path + r'\bin\volatility3-master' + ' and not ' + Fore.WHITE + dir_path + r'\bin\volatility3-master\volatility3-master',
'\n')
print(Fore.YELLOW)
print('-' * 110)
print(Fore.GREEN)
# Process Scanning
key = str(input('Processes Scan y/n: ')).lower().strip()
if key == 'y':
print(Fore.WHITE)
try:
proc_ps = subprocess.check_output(cmdps_scan, shell=True, stderr=subprocess.STDOUT, encoding='utf-8')
with open(output, 'w') as outputfile:
print(proc_ps, file=outputfile)
file = open(output, 'r')
dfp = pd.read_csv(file, delimiter="\t",
names=["PID", "PPID", "ImageFileName", "Offset", "Threads", "Handles", "SessionId",
"Wow64",
"CreateTime", "ExitTime"], header=None)
# print (dfp.head())
dfp = dfp[['PPID', 'PID', 'ImageFileName', 'CreateTime', 'ExitTime']]
file.close()
# print (df.head())
grouped = dfp.groupby(dfp['PPID'])
to_file = dir_path + r'\csvFiles\imgs\processToFile.txt'
fi = open(to_file, 'w')
for name, group in grouped:
print('\n')
fi.write('\n')
fi.write(name)
fi.write('\n')
print(name)
print(DataFrame(group).to_string(index=False, header=True))
fi.write(DataFrame(group).to_string(index=False, header=True))
fi.write('\n')
fi.close()
print(Fore.GREEN)
file_y = str(input(
'\nWould you like to see the above output on a notepad file for later use? y/n: ')).lower().strip()
if file_y == 'y':
subprocess.Popen(['notepad.exe', to_file])
print(
Fore.YELLOW + '\nOne more thing.... Getting dll-list and handles data if available -for later use in ' +
Fore.WHITE + 'Process Traceability\n')
dll = 'windows.dlllist.DllList'
handles = 'windows.handles.Handles'
dllout = dir_path + r'\csvFiles\imgs\dll.csv'
handlesout = dir_path + r'\csvFiles\imgs\handles.csv'
cmd_dll = py + ' ' + cmd + ' ' + path + ' ' + dll + ' ' + ' > ' + dllout
cmd_handles = py + ' ' + cmd + ' ' + path + ' ' + handles + ' > ' + handlesout + ' > ' + handlesout
os.system(cmd_dll + ' 2> ' + error)
os.system(cmd_handles + ' 2> ' + error)
except subprocess.CalledProcessError:
print(
Fore.YELLOW + r'Error- Volatility related. Maybe latest windows folder under '
+ dir_path + r'\volatility3-master\volatility\symbols is required ')
print(
Fore.YELLOW + '\nAlso check volatility3-master path to be like ' + dir_path + r'\bin\volatility3-master' + ' and not ' + Fore.WHITE + dir_path + r'\bin\volatility3-master\volatility3-master',
'\n')
# Process Tree
print(Fore.YELLOW)
print('-' * 110)
print(Fore.GREEN)
key = str(input('Processes Tree y/n: ')).lower().strip()
if key == 'y':
pstree = 'windows.pstree.PsTree'
cmdps_tree = py + ' ' + cmd + ' ' + path + ' ' + pstree
print(Fore.WHITE)
try:
proc_tree = subprocess.check_output(cmdps_tree, shell=True, stderr=subprocess.STDOUT, encoding='utf-8')
print(proc_tree)
except subprocess.CalledProcessError:
print(
Fore.YELLOW + r'Error- Volatility related. Maybe latest windows folder under '
+ dir_path + r'\volatility3-master\volatility\symbols is required ')
print(
Fore.YELLOW + '\nAlso check volatility3-master path to be like ' + dir_path + r'\bin\volatility3-master' + ' and not ' + Fore.WHITE + dir_path + r'\bin\volatility3-master\volatility3-master',
'\n')
print(Fore.YELLOW)
print('-' * 110)
print(Fore.GREEN)
# Anomaly Detection and Process Traceability
print(Fore.GREEN)
key = str(input('Anomaly Detection and Process Traceability y/n: ')).lower().strip()
if key == 'y':
print(Fore.WHITE)
try:
if not os.listdir(dir_path + r'\csvFiles\imgs'):
print(
Fore.YELLOW + '\nYou need to run Process Scan to use process traceability option. Please try again')
memory()
else:
users_path = py + ' ' + cmd + ' ' + path + ' ' + \
' windows.registry.userassist.UserAssist' + ' > ' + user_assi
os.system(win_cmd)
to_file1 = dir_path + r'\csvFiles\imgs\MalAnomaly.txt'
os.system(mal + ' >' + to_file1)
print(Fore.WHITE)
os.system(users_path)
print(Fore.WHITE)
mal_file = open(to_file1, 'r')
print(mal_file.read())
mal_file.close()
print(Fore.GREEN)
file_y1 = str(input(
'\nWould you like to see the above output on a notepad file for later use? y/n: ')).lower().strip()
if file_y1 == 'y':
subprocess.Popen(['notepad.exe', to_file1])
userassist.user_assist(user_assi)
processCheckingNu.processes()
except subprocess.CalledProcessError:
print(
Fore.YELLOW + r'Error- Volatility related. Maybe latest windows folder under '
+ dir_path + r'\volatility3-master\volatility\symbols is required ')
print(
Fore.YELLOW + '\nAlso check volatility3-master path to be like ' + dir_path + r'\bin\volatility3-master' + ' and not ' + Fore.WHITE + dir_path + r'\bin\volatility3-master\volatility3-master',
'\n')
else:
run.user_input()
if key_selection == 'y':
print(Fore.WHITE)
try:
print ('\nChecking processes .... ')
print('\nOne more thing.... sometimes analysis takes a bit of time!')
proc_ps = subprocess.check_output(cmdps_scan, shell=True, stderr=subprocess.STDOUT, encoding='utf-8')
with open(output, 'w') as outputfile:
print(proc_ps, file=outputfile)
file = open(output, 'r')
dfp = pd.read_csv(file, delimiter="\t",
names=["PID", "PPID", "ImageFileName", "Offset", "Threads", "Handles", "SessionId",
"Wow64",
"CreateTime", "ExitTime"], header=None)
# print (dfp.head())
dfp = dfp[['PPID', 'PID', 'ImageFileName', 'CreateTime', 'ExitTime']]
file.close()
# print (df.head())
grouped = dfp.groupby(dfp['PPID'])
to_file = dir_path + r'\csvFiles\imgs\processToFile.txt'
fi = open(to_file, 'w')
for name, group in grouped:
#print('\n')
fi.write('\n')
fi.write(name)
fi.write('\n')
fi.write(DataFrame(group).to_string(index=False, header=True))
fi.write('\n')
fi.close()
print(Fore.WHITE)
# Dll and handles
dll = 'windows.dlllist.DllList'
handles = 'windows.handles.Handles'
dllout = dir_path + r'\csvFiles\imgs\dll.csv'
handlesout = dir_path + r'\csvFiles\imgs\handles.csv'
cmd_dll = py + ' ' + cmd + ' ' + path + ' ' + dll + ' ' + ' > ' + dllout
cmd_handles = py + ' ' + cmd + ' ' + path + ' ' + handles + ' > ' + handlesout + ' > ' + handlesout
print('\nStill checking....')
print('\n')
os.system(cmd_dll + ' 2> ' + error)
os.system(cmd_handles + ' 2> ' + error)
users_path = py + ' ' + cmd + ' ' + path + ' ' + \
' windows.registry.userassist.UserAssist' + ' > ' + user_assi
os.system(win_cmd)
to_file1 = dir_path + r'\csvFiles\imgs\MalAnomaly.txt'
os.system(mal + ' >' + to_file1)
#print(Fore.WHITE)
os.system(users_path)
userassist.user_assist(user_assi)
autoscan.analysis()
subprocess.Popen(['notepad.exe', to_file])
print ( Fore.YELLOW + 'Use the following tool to trace and examine other processes')
processCheckingNu.processes()
except subprocess.CalledProcessError:
print(
Fore.YELLOW + r'Error- Volatility related. Maybe latest windows folder under '
+ dir_path + r'\volatility3-master\volatility\symbols is required ')
print(
Fore.YELLOW + '\nAlso check volatility3-master path to be like ' + dir_path + r'\bin\volatility3-master' + ' and not ' + Fore.WHITE + dir_path + r'\bin\volatility3-master\volatility3-master',
'\n')
else:
print (Fore.YELLOW + 'Error - try again')
memory()
return run.user_input()