本文整理汇总了Python中viper.core.storage.get_sample_path函数的典型用法代码示例。如果您正苦于以下问题:Python get_sample_path函数的具体用法?Python get_sample_path怎么用?Python get_sample_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_sample_path函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: delete_file
def delete_file(file_hash):
success = False
key = ''
if len(file_hash) == 32:
key = 'md5'
elif len(file_hash) == 64:
key = 'sha256'
else:
return HTTPError(400, 'Invalid hash format (use md5 or sha256)')
db = Database()
rows = db.find(key=key, value=file_hash)
if not rows:
raise HTTPError(404, 'File not found in the database')
if rows:
malware_id = rows[0].id
path = get_sample_path(rows[0].sha256)
if db.delete(malware_id):
success = True
else:
raise HTTPError(404, 'File not found in repository')
path = get_sample_path(rows[0].sha256)
if not path:
raise HTTPError(404, 'File not found in file system')
else:
success=os.remove(path)
if success:
return jsonize({'message' : 'deleted'})
else:
return HTTPError(500, 'Unable to delete file')
开发者ID:jorik041,项目名称:viper,代码行数:34,代码来源:api.py
示例2: cmd_delete
def cmd_delete(self, *args):
parser = argparse.ArgumentParser(prog='delete', description="Delete a file")
parser.add_argument('-a', '--all', action='store_true', help="Delete ALL files in this project")
parser.add_argument('-f', '--find', action="store_true", help="Delete ALL files from last find")
try:
args = parser.parse_args(args)
except:
return
while True:
choice = input("Are you sure? It can't be reverted! [y/n] ")
if choice == 'y':
break
elif choice == 'n':
return
if args.all:
if __sessions__.is_set():
__sessions__.close()
samples = self.db.find('all')
for sample in samples:
self.db.delete_file(sample.id)
os.remove(get_sample_path(sample.sha256))
self.log('info', "Deleted a total of {} files.".format(len(samples)))
elif args.find:
if __sessions__.find:
samples = __sessions__.find
for sample in samples:
self.db.delete_file(sample.id)
os.remove(get_sample_path(sample.sha256))
self.log('info', "Deleted {} files.".format(len(samples)))
else:
self.log('error', "No find result")
else:
if __sessions__.is_set():
rows = self.db.find('sha256', __sessions__.current.file.sha256)
if rows:
malware_id = rows[0].id
if self.db.delete_file(malware_id):
self.log("success", "File deleted")
else:
self.log('error', "Unable to delete file")
os.remove(__sessions__.current.file.path)
__sessions__.close()
self.log('info', "Deleted opened file.")
else:
self.log('error', "No session open, and no --all argument. Nothing to delete.")
开发者ID:chubbymaggie,项目名称:viper,代码行数:53,代码来源:commands.py
示例3: run
def run(self, *args):
try:
args = self.parser.parse_args(args)
except SystemExit:
return
while True:
choice = input("Are you sure? It can't be reverted! [y/n] ")
if choice == 'y':
break
elif choice == 'n':
return
db = Database()
if args.all:
if __sessions__.is_set():
__sessions__.close()
samples = db.find('all')
for sample in samples:
db.delete_file(sample.id)
os.remove(get_sample_path(sample.sha256))
self.log('info', "Deleted a total of {} files.".format(len(samples)))
elif args.find:
if __sessions__.find:
samples = __sessions__.find
for sample in samples:
db.delete_file(sample.id)
os.remove(get_sample_path(sample.sha256))
self.log('info', "Deleted {} files.".format(len(samples)))
else:
self.log('error', "No find result")
else:
if __sessions__.is_set():
rows = db.find('sha256', __sessions__.current.file.sha256)
if rows:
malware_id = rows[0].id
if db.delete_file(malware_id):
self.log("success", "File deleted")
else:
self.log('error', "Unable to delete file")
os.remove(__sessions__.current.file.path)
__sessions__.close()
self.log('info', "Deleted opened file.")
else:
self.log('error', "No session open, and no --all argument. Nothing to delete.")
开发者ID:cvandeplas,项目名称:viper,代码行数:51,代码来源:delete.py
示例4: destroy
def destroy(self, request, project=None, db=None, *args, **kwargs):
"""Delete a Malware instance"""
instance = self.get_object()
try:
log.debug("deleting (os.remove) Malware sample at path: {}".format(get_sample_path(instance.sha256)))
os.remove(get_sample_path(instance.sha256))
except OSError:
log.error("failed to delete Malware sample: {}".format(get_sample_path(instance.sha256)))
log.debug("deleting (db.delete_file) from DB for Malware ID: {}".format(instance.id))
db.delete_file(instance.id)
return Response(status=status.HTTP_204_NO_CONTENT)
开发者ID:cvandeplas,项目名称:viper,代码行数:15,代码来源:views.py
示例5: hex_viewer
def hex_viewer():
# get post data
file_hash = request.forms.get("file_hash")
try:
hex_offset = int(request.forms.get("hex_start"))
except:
return '<p class="text-danger">Error Generating Request</p>'
hex_length = 256
# get file path
hex_path = get_sample_path(file_hash)
# create the command string
hex_cmd = "hd -s {0} -n {1} {2}".format(hex_offset, hex_length, hex_path)
# get the output
hex_string = getoutput(hex_cmd)
# Format the data
html_string = ""
hex_rows = hex_string.split("\n")
for row in hex_rows:
if len(row) > 9:
off_str = row[0:8]
hex_str = row[9:58]
asc_str = row[58:78]
asc_str = asc_str.replace('"', """)
asc_str = asc_str.replace("<", "<")
asc_str = asc_str.replace(">", ">")
html_string += '<div class="row"><span class="text-primary mono">{0}</span> <span class="text-muted mono">{1}</span> <span class="text-success mono">{2}</span></div>'.format(
off_str, hex_str, asc_str
)
# return the data
return html_string
开发者ID:noscripter,项目名称:viper,代码行数:34,代码来源:web.py
示例6: run
def run(self, *args):
try:
args = self.parser.parse_args(args)
except SystemExit:
return
if not __sessions__.is_set():
self.log('error', "No open session")
return
if not __project__.name:
src_project = "default"
else:
src_project = __project__.name
db.copied_id_sha256 = []
res = db.copy(__sessions__.current.file.id,
src_project=src_project, dst_project=args.project,
copy_analysis=True, copy_notes=True, copy_tags=True, copy_children=args.children)
if args.delete:
__sessions__.close()
for item_id, item_sha256 in db.copied_id_sha256:
db.delete_file(item_id)
os.remove(get_sample_path(item_sha256))
self.log('info', "Deleted: {}".format(item_sha256))
if res:
self.log('success', "Successfully copied sample(s)")
return True
else:
self.log('error', "Something went wrong")
return False
开发者ID:Rafiot,项目名称:viper,代码行数:33,代码来源:commands.py
示例7: add_file
def add_file(obj, tags=None):
if get_sample_path(obj.sha256):
self.log("warning", 'Skip, file "{0}" appears to be already stored'.format(obj.name))
return False
# Try to store file object into database.
status = self.db.add(obj=obj, tags=tags)
if status:
# If succeeds, store also in the local repository.
# If something fails in the database (for example unicode strings)
# we don't want to have the binary lying in the repository with no
# associated database record.
new_path = store_sample(obj)
self.log("success", 'Stored file "{0}" to {1}'.format(obj.name, new_path))
else:
return False
# Delete the file if requested to do so.
if args.delete:
try:
os.unlink(obj.path)
except Exception as e:
self.log("warning", "Failed deleting file: {0}".format(e))
return True
开发者ID:noscripter,项目名称:viper,代码行数:25,代码来源:commands.py
示例8: size_cluster
def size_cluster(self):
db = Database()
samples = db.find(key='all')
cluster = {}
for sample in samples:
sample_path = get_sample_path(sample.sha256)
if not os.path.exists(sample_path):
continue
try:
cur_size = os.path.getsize(sample_path)
except Exception as e:
self.log('error', "Error {0} for sample {1}".format(e, sample.sha256))
continue
if cur_size not in cluster:
cluster[cur_size] = []
cluster[cur_size].append([sample.md5, sample.name])
for cluster_name, cluster_members in cluster.items():
# Skipping clusters with only one entry.
if len(cluster_members) == 1:
continue
self.log('info', "Cluster size {0} with {1} elements".format(bold(cluster_name), len(cluster_members)))
self.log('table', dict(header=['MD5', 'Name'], rows=cluster_members))
开发者ID:kevthehermit,项目名称:viper,代码行数:28,代码来源:size.py
示例9: autorun_module
def autorun_module(file_hash):
if not file_hash:
return
# We need an open session
if not __sessions__.is_set():
# Open session
__sessions__.new(get_sample_path(file_hash))
for cmd_line in cfg.autorun.commands.split(','):
split_commands = cmd_line.split(';')
for split_command in split_commands:
split_command = split_command.strip()
if not split_command:
continue
root, args = parse(split_command)
try:
if root in __modules__:
module = __modules__[root]['obj']()
module.set_commandline(args)
module.run()
print_info("Running Command {0}".format(split_command))
if cfg.modules.store_output and __sessions__.is_set():
Database().add_analysis(file_hash, split_command, module.output)
if cfg.autorun.verbose:
print_output(module.output)
del(module.output[:])
else:
print_error('{0} is not a valid command. Please check your viper.conf file.'.format(cmd_line))
except:
print_error('Viper was unable to complete the command {0}'.format(cmd_line))
return
开发者ID:dgrif,项目名称:viper,代码行数:30,代码来源:autorun.py
示例10: hex_view
def hex_view(request):
# get post data
file_hash = request.POST['file_hash']
try:
hex_offset = int(request.POST['hex_start'])
except:
return '<p class="text-danger">Error Generating Request</p>'
hex_length = 256
# get file path
hex_path = get_sample_path(file_hash)
# create the command string
hex_cmd = 'hd -s {0} -n {1} {2}'.format(hex_offset, hex_length, hex_path)
# get the output
hex_string = getoutput(hex_cmd)
# Format the data
html_string = ''
hex_rows = hex_string.split('\n')
for row in hex_rows:
if len(row) > 9:
off_str = row[0:8]
hex_str = row[9:58]
asc_str = row[58:78]
asc_str = asc_str.replace('"', '"')
asc_str = asc_str.replace('<', '<')
asc_str = asc_str.replace('>', '>')
html_string += '<div class="row"><span class="text-primary mono">{0}</span> \
<span class="text-muted mono">{1}</span> <span class="text-success mono"> \
{2}</span></div>'.format(off_str, hex_str, asc_str)
# return the data
return HttpResponse(html_string)
开发者ID:kevthehermit,项目名称:ViperV2,代码行数:33,代码来源:views.py
示例11: get_file
def get_file(file_hash):
key = ''
if len(file_hash) == 32:
key = 'md5'
elif len(file_hash) == 64:
key = 'sha256'
else:
return HTTPError(400, 'Invalid hash format (use md5 or sha256)')
db = Database()
rows = db.find(key=key, value=file_hash)
if not rows:
raise HTTPError(404, 'File not found in the database')
path = get_sample_path(rows[0].sha256)
if not path:
raise HTTPError(404, 'File not found in the repository')
response.content_length = os.path.getsize(path)
response.content_type = 'application/octet-stream; charset=UTF-8'
data = ''
for chunk in File(path).get_chunks():
data += chunk
return data
开发者ID:blaquee,项目名称:viper,代码行数:26,代码来源:api.py
示例12: post
def post(self, request, *args, **kwargs):
# Get the project and hash of the file
project = kwargs.get('project', 'default')
file_hash = request.POST.get('file_hash')
try:
hex_offset = int(request.POST.get('hex_start'))
except Exception:
return '<p class="text-danger">Error Generating Request</p>'
hex_length = 256
# get file path
__project__.open(project)
hex_path = get_sample_path(file_hash)
# create the command string
hex_cmd = 'hd -s {0} -n {1} {2}'.format(hex_offset, hex_length, hex_path)
# get the output
hex_string = getoutput(hex_cmd)
# Format the data
html_string = ''
hex_rows = hex_string.split('\n')
for row in hex_rows:
if len(row) > 9:
off_str = row[0:8]
hex_str = row[9:58]
asc_str = row[58:78]
asc_str = asc_str.replace('"', '"')
asc_str = asc_str.replace('<', '<')
asc_str = asc_str.replace('>', '>')
html_string += '<div class="row"><span class="text-primary mono">{0}</span> \
<span class="text-muted mono">{1}</span> <span class="text-success mono"> \
{2}</span></div>'.format(off_str, hex_str, asc_str)
# return the data
return HttpResponse(html_string)
开发者ID:Rafiot,项目名称:viper,代码行数:35,代码来源:views.py
示例13: add_file
def add_file(obj, tags=None):
if get_sample_path(obj.sha256):
self.log('warning', "Skip, file \"{0}\" appears to be already stored".format(obj.name))
return False
if __sessions__.is_attached_misp(quiet=True):
if tags is not None:
tags += ',misp:{}'.format(__sessions__.current.misp_event.event.id)
else:
tags = 'misp:{}'.format(__sessions__.current.misp_event.event.id)
# Try to store file object into database.
status = db.add(obj=obj, tags=tags)
if status:
# If succeeds, store also in the local repository.
# If something fails in the database (for example unicode strings)
# we don't want to have the binary lying in the repository with no
# associated database record.
new_path = store_sample(obj)
self.log("success", "Stored file \"{0}\" to {1}".format(obj.name, new_path))
else:
return False
# Delete the file if requested to do so.
if args.delete:
try:
os.unlink(obj.path)
except Exception as e:
self.log('warning', "Failed deleting file: {0}".format(e))
return True
开发者ID:Rafiot,项目名称:viper,代码行数:32,代码来源:commands.py
示例14: module_cmdline
def module_cmdline(cmd_line, file_hash):
html = ""
cmd = Commands()
split_commands = cmd_line.split(';')
for split_command in split_commands:
split_command = split_command.strip()
if not split_command:
continue
root, args = parse(split_command)
try:
if root in cmd.commands:
cmd.commands[root]['obj'](*args)
html += print_output(cmd.output)
del (cmd.output[:])
elif root in __modules__:
# if prev commands did not open a session open one on the current file
if file_hash:
path = get_sample_path(file_hash)
__sessions__.new(path)
module = __modules__[root]['obj']()
module.set_commandline(args)
module.run()
html += print_output(module.output)
if cfg.modules.store_output and __sessions__.is_set():
Database().add_analysis(file_hash, split_command, module.output)
del (module.output[:])
else:
html += '<p class="text-danger">{0} is not a valid command</p>'.format(cmd_line)
except Exception as e:
html += '<p class="text-danger">We were unable to complete the command {0}</p>'.format(cmd_line)
__sessions__.close()
return html
开发者ID:kevthehermit,项目名称:ViperV2,代码行数:33,代码来源:views.py
示例15: run
def run(self):
super(Strings, self).run()
if self.args is None:
return
if not (self.args.all or self.args.files or self.args.hosts or self.args.network or self.args.interesting):
self.log('error', 'At least one of the parameters is required')
self.usage()
return
if self.args.scan:
db = Database()
samples = db.find(key='all')
for sample in samples:
sample_path = get_sample_path(sample.sha256)
strings = self.get_strings(File(sample_path))
self.process_strings(strings, sample.name)
else:
if not __sessions__.is_set():
self.log('error', "No open session")
return
if os.path.exists(__sessions__.current.file.path):
strings = self.get_strings(__sessions__.current.file)
self.process_strings(strings)
开发者ID:chubbymaggie,项目名称:viper,代码行数:25,代码来源:strings.py
示例16: peid
def peid(self):
def get_signatures():
with file(os.path.join(VIPER_ROOT, 'data/peid/UserDB.TXT'), 'rt') as f:
sig_data = f.read()
signatures = peutils.SignatureDatabase(data=sig_data)
return signatures
def get_matches(pe, signatures):
matches = signatures.match_all(pe, ep_only=True)
return matches
if not self.__check_session():
return
signatures = get_signatures()
peid_matches = get_matches(self.pe, signatures)
if peid_matches:
self.log('info', "PEiD Signatures:")
for sig in peid_matches:
if type(sig) is list:
self.log('item', sig[0])
else:
self.log('item', sig)
else:
self.log('info', "No PEiD signatures matched.")
if self.args.scan and peid_matches:
self.log('info', "Scanning the repository for matching samples...")
db = Database()
samples = db.find(key='all')
matches = []
for sample in samples:
if sample.sha256 == __sessions__.current.file.sha256:
continue
sample_path = get_sample_path(sample.sha256)
if not os.path.exists(sample_path):
continue
try:
cur_pe = pefile.PE(sample_path)
cur_peid_matches = get_matches(cur_pe, signatures)
except:
continue
if peid_matches == cur_peid_matches:
matches.append([sample.name, sample.sha256])
self.log('info', "{0} relevant matches found".format(bold(len(matches))))
if len(matches) > 0:
self.log('table', dict(header=['Name', 'SHA256'], rows=matches))
开发者ID:asymptotic,项目名称:viper,代码行数:58,代码来源:pe.py
示例17: file_view
def file_view(request, sha256=False, project='default'):
if not sha256:
return render(request, '404.html')
print sha256
db = open_db(project)
# Open a session
try:
path = get_sample_path(sha256)
__sessions__.new(path)
except:
return render(request, '404.html')
# Get the file info
file_info = {
'name': __sessions__.current.file.name,
'tags': __sessions__.current.file.tags.split(','),
'path': __sessions__.current.file.path,
'size': __sessions__.current.file.size,
'type': __sessions__.current.file.type,
'mime': __sessions__.current.file.mime,
'md5': __sessions__.current.file.md5,
'sha1': __sessions__.current.file.sha1,
'sha256': __sessions__.current.file.sha256,
'sha512': __sessions__.current.file.sha512,
'ssdeep': __sessions__.current.file.ssdeep,
'crc32': __sessions__.current.file.crc32,
'parent': __sessions__.current.file.parent,
'children': __sessions__.current.file.children.split(',')
}
# Get Any Notes
note_list = []
module_history = []
malware = db.find(key='sha256', value=sha256)
if malware:
notes = malware[0].note
if notes:
for note in notes:
note_list.append({'title': note.title,
'body': note.body,
'id': note.id
})
analysis_list = malware[0].analysis
if analysis_list:
for ana in analysis_list:
module_history.append({'id': ana.id,
'cmd_line': ana.cmd_line
})
# Return the page
return render(request, 'file.html', {'file_info': file_info,
'note_list': note_list,
'error_line': False,
'project': project,
'projects': project_list(),
'module_history': module_history
})
开发者ID:kevthehermit,项目名称:ViperV2,代码行数:57,代码来源:views.py
示例18: pehash
def pehash(self):
if not HAVE_PEHASH:
self.log('error', "PEhash is missing. Please copy PEhash to the modules directory of Viper")
return
current_pehash = None
if __sessions__.is_set():
current_pehash = calculate_pehash(__sessions__.current.file.path)
self.log('info', "PEhash: {0}".format(bold(current_pehash)))
if self.args.all or self.args.cluster or self.args.scan:
db = Database()
samples = db.find(key='all')
rows = []
for sample in samples:
sample_path = get_sample_path(sample.sha256)
pe_hash = calculate_pehash(sample_path)
if pe_hash:
rows.append((sample.name, sample.md5, pe_hash))
if self.args.all:
self.log('info', "PEhash for all files:")
header = ['Name', 'MD5', 'PEhash']
self.log('table', dict(header=header, rows=rows))
elif self.args.cluster:
self.log('info', "Clustering files by PEhash...")
cluster = {}
for sample_name, sample_md5, pe_hash in rows:
cluster.setdefault(pe_hash, []).append([sample_name, sample_md5])
for item in cluster.items():
if len(item[1]) > 1:
self.log('info', "PEhash cluster {0}:".format(bold(item[0])))
self.log('table', dict(header=['Name', 'MD5'], rows=item[1]))
elif self.args.scan:
if __sessions__.is_set() and current_pehash:
self.log('info', "Finding matching samples...")
matches = []
for row in rows:
if row[1] == __sessions__.current.file.md5:
continue
if row[2] == current_pehash:
matches.append([row[0], row[1]])
if matches:
self.log('table', dict(header=['Name', 'MD5'], rows=matches))
else:
self.log('info', "No matches found")
开发者ID:asymptotic,项目名称:viper,代码行数:54,代码来源:pe.py
示例19: file_view
def file_view(request, sha256, project):
if not sha256:
return JsonResponse({'response': '404', 'data': 'Requires a SHA256'})
db = open_db(project)
# Open a session
try:
path = get_sample_path(sha256)
__sessions__.new(path)
except:
return JsonResponse({'response': '404', 'data': 'Unabel to access file'})
# Get the file info
file_info = {
'name': __sessions__.current.file.name,
'tags': __sessions__.current.file.tags.split(','),
'path': __sessions__.current.file.path,
'size': __sessions__.current.file.size,
'type': __sessions__.current.file.type,
'mime': __sessions__.current.file.mime,
'md5': __sessions__.current.file.md5,
'sha1': __sessions__.current.file.sha1,
'sha256': __sessions__.current.file.sha256,
'sha512': __sessions__.current.file.sha512,
'ssdeep': __sessions__.current.file.ssdeep,
'crc32': __sessions__.current.file.crc32,
'parent': __sessions__.current.file.parent,
'children': __sessions__.current.file.children.split(',')
}
# Get Any Notes
note_list = []
module_history = []
malware = db.find(key='sha256', value=sha256)
if malware:
notes = malware[0].note
if notes:
for note in notes:
note_list.append({'title': note.title,
'body': note.body,
'id': note.id
})
analysis_list = malware[0].analysis
if analysis_list:
for ana in analysis_list:
module_history.append({'id': ana.id,
'cmd_line': ana.cmd_line
})
# Return the page
return JsonResponse({'response': '200', 'data': {'file_info': file_info,
'note_list': note_list,
'module_history': module_history
}})
开发者ID:razuz,项目名称:ViperV2,代码行数:53,代码来源:views.py
示例20: get_file
def get_file(sha256):
path = get_sample_path(sha256)
if not path:
raise HTTPError(404, 'File not found')
response.content_length = os.path.getsize(path)
response.content_type = 'application/octet-stream; charset=UTF-8'
data = ''
for chunk in File(path).get_chunks():
data += chunk
return data
开发者ID:RATBORG,项目名称:viper,代码行数:12,代码来源:api.py
注:本文中的viper.core.storage.get_sample_path函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论