本文整理汇总了Python中viper.core.database.Database.delete方法的典型用法代码示例。如果您正苦于以下问题:Python Database.delete方法的具体用法?Python Database.delete怎么用?Python Database.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类viper.core.database.Database
的用法示例。
在下文中一共展示了Database.delete方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete_file
# 需要导入模块: from viper.core.database import Database [as 别名]
# 或者: from viper.core.database.Database import delete [as 别名]
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')
示例2: Commands
# 需要导入模块: from viper.core.database import Database [as 别名]
# 或者: from viper.core.database.Database import delete [as 别名]
class Commands(object):
def __init__(self):
# Open connection to the database.
self.db = Database()
# Map commands to their related functions.
self.commands = dict(
help=dict(obj=self.cmd_help, description="Show this help message"),
open=dict(obj=self.cmd_open, description="Open a file"),
close=dict(obj=self.cmd_close, description="Close the current session"),
info=dict(obj=self.cmd_info, description="Show information on the opened file"),
notes=dict(obj=self.cmd_notes, description="View, add and edit notes on the opened file"),
clear=dict(obj=self.cmd_clear, description="Clear the console"),
store=dict(obj=self.cmd_store, description="Store the opened file to the local repository"),
delete=dict(obj=self.cmd_delete, description="Delete the opened file"),
find=dict(obj=self.cmd_find, description="Find a file"),
tags=dict(obj=self.cmd_tags, description="Modify tags of the opened file"),
sessions=dict(obj=self.cmd_sessions, description="List or switch sessions"),
projects=dict(obj=self.cmd_projects, description="List or switch existing projects"),
)
##
# CLEAR
#
# This command simply clears the shell.
def cmd_clear(self, *args):
os.system("clear")
##
# HELP
#
# This command simply prints the help message.
# It lists both embedded commands and loaded modules.
def cmd_help(self, *args):
print(bold("Commands:"))
rows = []
for command_name, command_item in self.commands.items():
rows.append([command_name, command_item["description"]])
rows = sorted(rows, key=lambda entry: entry[0])
print(table(["Command", "Description"], rows))
print("")
print(bold("Modules:"))
rows = []
for module_name, module_item in __modules__.items():
rows.append([module_name, module_item["description"]])
rows = sorted(rows, key=lambda entry: entry[0])
print(table(["Command", "Description"], rows))
##
# OPEN
#
# This command is used to open a session on a given file.
# It either can be an external file path, or a SHA256 hash of a file which
# has been previously imported and stored.
# While the session is active, every operation and module executed will be
# run against the file specified.
def cmd_open(self, *args):
def usage():
print("usage: open [-h] [-f] [-u] [-l] [-t] <target|md5|sha256>")
def help():
usage()
print("")
print("Options:")
print("\t--help (-h)\tShow this help message")
print("\t--file (-f)\tThe target is a file")
print("\t--url (-u)\tThe target is a URL")
print("\t--last (-l)\tOpen file from the results of the last find command")
print("\t--tor (-t)\tDownload the file through Tor")
print("")
print("You can also specify a MD5 or SHA256 hash to a previously stored")
print("file in order to open a session on it.")
print("")
try:
opts, argv = getopt.getopt(args, "hfult", ["help", "file", "url", "last", "tor"])
except getopt.GetoptError as e:
print(e)
usage()
return
arg_is_file = False
arg_is_url = False
arg_last = False
arg_use_tor = False
for opt, value in opts:
if opt in ("-h", "--help"):
help()
return
elif opt in ("-f", "--file"):
arg_is_file = True
elif opt in ("-u", "--url"):
arg_is_url = True
#.........这里部分代码省略.........
示例3: Commands
# 需要导入模块: from viper.core.database import Database [as 别名]
# 或者: from viper.core.database.Database import delete [as 别名]
class Commands(object):
def __init__(self):
# Open connection to the database.
self.db = Database()
# Map commands to their related functions.
self.commands = dict(
help=dict(obj=self.cmd_help, description="Show this help message"),
open=dict(obj=self.cmd_open, description="Open a file"),
close=dict(obj=self.cmd_close, description="Close the current session"),
info=dict(obj=self.cmd_info, description="Show information on the opened file"),
clear=dict(obj=self.cmd_clear, description="Clear the console"),
store=dict(obj=self.cmd_store, description="Store the opened file to the local repository"),
delete=dict(obj=self.cmd_delete, description="Delete the opened file"),
find=dict(obj=self.cmd_find, description="Find a file"),
)
##
# CLEAR
#
# This command simply clears the shell.
def cmd_clear(self, *args):
os.system('clear')
##
# HELP
#
# This command simply prints the help message.
# It lists both embedded commands and loaded modules.
def cmd_help(self, *args):
print(bold("Commands:"))
rows = []
for command_name, command_item in self.commands.items():
rows.append([command_name, command_item['description']])
print(table(['Command', 'Description'], rows))
print("")
print(bold("Modules:"))
rows = []
for module_name, module_item in __modules__.items():
rows.append([module_name, module_item['description']])
print(table(['Command', 'Description'], rows))
##
# OPEN
#
# This command is used to open a session on a given file.
# It either can be an external file path, or a SHA256 hash of a file which
# has been previously imported and stored.
# While the session is active, every operation and module executed will be
# run against the file specified.
def cmd_open(self, *args):
def usage():
print("usage: open [-h] [-f] [-u] [-t] <target>")
def help():
usage()
print("")
print("Options:")
print("\t--help (-h)\tShow this help message")
print("\t--file (-f)\tThe target is a file")
print("\t--url (-u)\tThe target is a URL")
print("\t--tor (-t)\tDownload the file through Tor")
print("")
print("You can also specify a SHA256 hash to a previously stored")
print("file in order to open a session on it.")
print("")
try:
opts, argv = getopt.getopt(args, 'hfut', ['help', 'file', 'url', 'tor'])
except getopt.GetoptError as e:
print(e)
usage()
return
is_file = False
is_url = False
use_tor = False
for opt, value in opts:
if opt in ('-h', '--help'):
help()
return
elif opt in ('-f', '--file'):
is_file = True
elif opt in ('-u', '--url'):
is_url = True
elif opt in ('-t', '--tor'):
use_tor = True
if len(argv) == 0:
usage()
return
else:
target = argv[0]
#.........这里部分代码省略.........
示例4: Commands
# 需要导入模块: from viper.core.database import Database [as 别名]
# 或者: from viper.core.database.Database import delete [as 别名]
class Commands(object):
def __init__(self):
# Open connection to the database.
self.db = Database()
# Map commands to their related functions.
self.commands = dict(
help=dict(obj=self.cmd_help, description="Show this help message"),
open=dict(obj=self.cmd_open, description="Open a file"),
close=dict(obj=self.cmd_close, description="Close the current session"),
info=dict(obj=self.cmd_info, description="Show information on the opened file"),
notes=dict(obj=self.cmd_notes, description="View, add and edit notes on the opened file"),
clear=dict(obj=self.cmd_clear, description="Clear the console"),
store=dict(obj=self.cmd_store, description="Store the opened file to the local repository"),
delete=dict(obj=self.cmd_delete, description="Delete the opened file"),
find=dict(obj=self.cmd_find, description="Find a file"),
tags=dict(obj=self.cmd_tags, description="Modify tags of the opened file"),
sessions=dict(obj=self.cmd_sessions, description="List or switch sessions"),
projects=dict(obj=self.cmd_projects, description="List or switch existing projects"),
export=dict(obj=self.cmd_export, description="Export the current session to file or zip"),
)
##
# CLEAR
#
# This command simply clears the shell.
def cmd_clear(self, *args):
os.system('clear')
##
# HELP
#
# This command simply prints the help message.
# It lists both embedded commands and loaded modules.
def cmd_help(self, *args):
print(bold("Commands:"))
rows = []
for command_name, command_item in self.commands.items():
rows.append([command_name, command_item['description']])
rows = sorted(rows, key=lambda entry: entry[0])
print(table(['Command', 'Description'], rows))
print("")
print(bold("Modules:"))
rows = []
for module_name, module_item in __modules__.items():
rows.append([module_name, module_item['description']])
rows = sorted(rows, key=lambda entry: entry[0])
print(table(['Command', 'Description'], rows))
##
# OPEN
#
# This command is used to open a session on a given file.
# It either can be an external file path, or a SHA256 hash of a file which
# has been previously imported and stored.
# While the session is active, every operation and module executed will be
# run against the file specified.
def cmd_open(self, *args):
def usage():
print("usage: open [-h] [-f] [-u] [-l] [-t] <target|md5|sha256>")
def help():
usage()
print("")
print("Options:")
print("\t--help (-h)\tShow this help message")
print("\t--file (-f)\tThe target is a file")
print("\t--url (-u)\tThe target is a URL")
print("\t--last (-l)\tThe target is the entry number from the last find command's results")
print("\t--tor (-t)\tDownload the file through Tor")
print("")
print("You can also specify a MD5 or SHA256 hash to a previously stored")
print("file in order to open a session on it.")
print("")
try:
opts, argv = getopt.getopt(args, 'hfult', ['help', 'file', 'url', 'last', 'tor'])
except getopt.GetoptError as e:
print(e)
usage()
return
arg_is_file = False
arg_is_url = False
arg_last = False
arg_use_tor = False
for opt, value in opts:
if opt in ('-h', '--help'):
help()
return
elif opt in ('-f', '--file'):
arg_is_file = True
#.........这里部分代码省略.........
示例5: Commands
# 需要导入模块: from viper.core.database import Database [as 别名]
# 或者: from viper.core.database.Database import delete [as 别名]
class Commands(object):
output = []
def __init__(self):
# Open connection to the database.
self.db = Database()
# Map commands to their related functions.
self.commands = dict(
help=dict(obj=self.cmd_help, description="Show this help message"),
open=dict(obj=self.cmd_open, description="Open a file"),
new=dict(obj=self.cmd_new, description="Create new file"),
close=dict(obj=self.cmd_close, description="Close the current session"),
info=dict(obj=self.cmd_info, description="Show information on the opened file"),
notes=dict(obj=self.cmd_notes, description="View, add and edit notes on the opened file"),
clear=dict(obj=self.cmd_clear, description="Clear the console"),
store=dict(obj=self.cmd_store, description="Store the opened file to the local repository"),
delete=dict(obj=self.cmd_delete, description="Delete the opened file"),
find=dict(obj=self.cmd_find, description="Find a file"),
tags=dict(obj=self.cmd_tags, description="Modify tags of the opened file"),
sessions=dict(obj=self.cmd_sessions, description="List or switch sessions"),
projects=dict(obj=self.cmd_projects, description="List or switch existing projects"),
export=dict(obj=self.cmd_export, description="Export the current session to file or zip"),
)
# Output Logging
def log(self, event_type, event_data):
self.output.append(dict(
type=event_type,
data=event_data
))
##
# CLEAR
#
# This command simply clears the shell.
def cmd_clear(self, *args):
os.system('clear')
##
# HELP
#
# This command simply prints the help message.
# It lists both embedded commands and loaded modules.
def cmd_help(self, *args):
self.log("info", "Commands")
rows = []
for command_name, command_item in self.commands.items():
rows.append([command_name, command_item['description']])
rows.append(["exit, quit", "Exit Viper"])
rows = sorted(rows, key=lambda entry: entry[0])
self.log('table', dict(header=['Command', 'Description'], rows=rows))
self.log("info", "Modules")
rows = []
for module_name, module_item in __modules__.items():
rows.append([module_name, module_item['description']])
rows = sorted(rows, key=lambda entry: entry[0])
self.log('table', dict(header=['Command', 'Description'], rows=rows))
##
# NEW
#
# This command is used to create a new session on a new file,
# useful for copy & paste of content like Email headers
def cmd_new(self, *args):
title = raw_input("Enter a title for the new file: ")
# Create a new temporary file.
tmp = tempfile.NamedTemporaryFile(delete=False)
# Open the temporary file with the default editor, or with nano.
os.system('"${EDITOR:-nano}" ' + tmp.name)
__sessions__.new(tmp.name)
__sessions__.current.file.name = title
print_info("New file with title \"{0}\" added to the current session".format(bold(title)))
##
# OPEN
#
# This command is used to open a session on a given file.
# It either can be an external file path, or a SHA256 hash of a file which
# has been previously imported and stored.
# While the session is active, every operation and module executed will be
# run against the file specified.
def cmd_open(self, *args):
parser = argparse.ArgumentParser(prog="open", description="Open a file", epilog="You can also specify a MD5 or SHA256 hash to a previously stored file in order to open a session on it.")
group = parser.add_mutually_exclusive_group()
group.add_argument('-f', '--file', action="store_true", help="target is a file")
group.add_argument('-u', '--url', action="store_true", help="target is a URL")
group.add_argument('-l', '--last', action="store_true", help="target is the entry number from the last find command's results")
parser.add_argument('-t', '--tor', action="store_true", help="Download the file through Tor")
parser.add_argument("value", metavar='Path, URL, hash or ID', nargs='*', help="Target to open. Hash can be md5 or sha256. ID has to be from the last search.")
try:
#.........这里部分代码省略.........
示例6: Commands
# 需要导入模块: from viper.core.database import Database [as 别名]
# 或者: from viper.core.database.Database import delete [as 别名]
class Commands(object):
def __init__(self):
# Open connection to the database.
self.db = Database()
# Map commands to their related functions.
self.commands = dict(
help=dict(obj=self.cmd_help, description="Show this help message"),
open=dict(obj=self.cmd_open, description="Open a file"),
close=dict(obj=self.cmd_close, description="Close the current session"),
info=dict(obj=self.cmd_info, description="Show information on the opened file"),
clear=dict(obj=self.cmd_clear, description="Clear the console"),
store=dict(obj=self.cmd_store, description="Store the opened file to the local repository"),
delete=dict(obj=self.cmd_delete, description="Delete the opened file"),
find=dict(obj=self.cmd_find, description="Find a file"),
tags=dict(obj=self.cmd_tags, description="Modify tags of the opened file"),
)
##
# CLEAR
#
# This command simply clears the shell.
def cmd_clear(self, *args):
os.system("clear")
##
# HELP
#
# This command simply prints the help message.
# It lists both embedded commands and loaded modules.
def cmd_help(self, *args):
print(bold("Commands:"))
rows = []
for command_name, command_item in self.commands.items():
rows.append([command_name, command_item["description"]])
print(table(["Command", "Description"], rows))
print("")
print(bold("Modules:"))
rows = []
for module_name, module_item in __modules__.items():
rows.append([module_name, module_item["description"]])
print(table(["Command", "Description"], rows))
##
# OPEN
#
# This command is used to open a session on a given file.
# It either can be an external file path, or a SHA256 hash of a file which
# has been previously imported and stored.
# While the session is active, every operation and module executed will be
# run against the file specified.
def cmd_open(self, *args):
def usage():
print("usage: open [-h] [-f] [-u] [-t] <target>")
def help():
usage()
print("")
print("Options:")
print("\t--help (-h)\tShow this help message")
print("\t--file (-f)\tThe target is a file")
print("\t--url (-u)\tThe target is a URL")
print("\t--tor (-t)\tDownload the file through Tor")
print("")
print("You can also specify a SHA256 hash to a previously stored")
print("file in order to open a session on it.")
print("")
try:
opts, argv = getopt.getopt(args, "hfut", ["help", "file", "url", "tor"])
except getopt.GetoptError as e:
print(e)
usage()
return
arg_is_file = False
arg_is_url = False
arg_use_tor = False
for opt, value in opts:
if opt in ("-h", "--help"):
help()
return
elif opt in ("-f", "--file"):
arg_is_file = True
elif opt in ("-u", "--url"):
arg_is_url = True
elif opt in ("-t", "--tor"):
arg_use_tor = True
if len(argv) == 0:
usage()
return
else:
target = argv[0]
#.........这里部分代码省略.........