本文整理汇总了Python中viper.common.out.print_error函数的典型用法代码示例。如果您正苦于以下问题:Python print_error函数的具体用法?Python print_error怎么用?Python print_error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了print_error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: download
def download(url, tor=False):
def create_connection(address, timeout=None, source_address=None):
sock = socks.socksocket()
sock.connect(address)
return sock
if tor:
if not HAVE_SOCKS:
print_error("Missing dependency, install socks (`pip install SocksiPy`)")
return None
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, '127.0.0.1', 9050)
socket.socket = socks.socksocket
socket.create_connection = create_connection
try:
req = Request(url)
req.add_header('User-agent', 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)')
res = urlopen(req)
data = res.read()
except HTTPError as e:
print_error(e)
except URLError as e:
if tor and e.reason.errno == 111:
print_error("Connection refused, maybe Tor is not running?")
else:
print_error(e)
except Exception as e:
print_error("Failed download: {0}".format(e))
else:
return data
示例2: add_note
def add_note(self, sha256, title, body):
session = self.Session()
if sys.version_info < (3, 0):
# on Python2 make sure to only handle ASCII
try:
title.decode('ascii')
body.decode('ascii')
except UnicodeError as err:
raise Python2UnsupportedUnicode("Non ASCII character(s) in Notes not supported on Python2.\n"
"Please use Python >= 3.4".format(err), "error")
malware_entry = session.query(Malware).filter(Malware.sha256 == sha256).first()
if not malware_entry:
return
try:
new_note = Note(title, body)
malware_entry.note.append(new_note)
session.commit()
self.added_ids.setdefault("note", []).append(new_note.id)
except SQLAlchemyError as e:
print_error("Unable to add note: {0}".format(e))
session.rollback()
finally:
session.close()
示例3: logo
def logo():
print(""" _
(_)
_ _ _ ____ _____ ____
| | | | | _ \| ___ |/ ___)
\ V /| | |_| | ____| |
\_/ |_| __/|_____)_| v{}
|_|
""".format(__version__))
db = Database()
count = db.get_sample_count()
try:
db.find('all')
except Exception:
print_error("You need to update your Viper database. Run 'python update.py -d'")
sys.exit()
if __project__.name:
name = __project__.name
else:
name = 'default'
print(magenta("You have " + bold(count)) +
magenta(" files in your " + bold(name)) +
magenta(" repository"))
示例4: new
def new(self, path=None, misp_event=None):
if not path and not misp_event:
print_error("You have to open a session on a path or on a misp event.")
return
session = Session()
total = len(self.sessions)
session.id = total + 1
if path:
if self.is_set() and misp_event is None and self.current.misp_event:
session.misp_event = self.current.misp_event
# Open a section on the given file.
session.file = File(path)
# Try to lookup the file in the database. If it is already present
# we get its database ID, file name, and tags.
row = Database().find(key='sha256', value=session.file.sha256)
if row:
session.file.id = row[0].id
session.file.name = row[0].name
session.file.tags = ', '.join(tag.to_dict()['tag'] for tag in row[0].tag)
if row[0].parent:
session.file.parent = '{0} - {1}'.format(row[0].parent.name, row[0].parent.sha256)
session.file.children = Database().get_children(row[0].id)
print_info("Session opened on {0}".format(path))
if misp_event:
if self.is_set() and path is None and self.current.file:
session.file = self.current.file
refresh = False
if (self.current is not None and self.current.misp_event is not None and
self.current.misp_event.event.id is not None and
self.current.misp_event.event.id == misp_event.event.id):
refresh = True
session.misp_event = misp_event
if refresh:
print_info("Session on MISP event {0} refreshed.".format(misp_event.event.id))
elif not misp_event.event.id:
print_info("Session opened on a new local MISP event.")
else:
print_info("Session opened on MISP event {0}.".format(misp_event.event.id))
if session.file:
# Loop through all existing sessions and check whether there's another
# session open on the same file and delete it. This is to avoid
# duplicates in sessions.
# NOTE: in the future we might want to remove this if sessions have
# unique attributes (for example, an history just for each of them).
for entry in self.sessions:
if entry.file and entry.file.sha256 == session.file.sha256:
self.sessions.remove(entry)
# Add new session to the list.
self.sessions.append(session)
# Mark the new session as the current one.
self.current = session
示例5: store_sample
def store_sample(file_object):
sha256 = file_object.sha256
if not sha256:
print_error("No hash")
return None
folder = os.path.join(
__project__.get_path(),
'binaries',
sha256[0],
sha256[1],
sha256[2],
sha256[3]
)
if not os.path.exists(folder):
os.makedirs(folder, 0o750)
file_path = os.path.join(folder, sha256)
if not os.path.exists(file_path):
with open(file_path, 'wb') as stored:
for chunk in file_object.get_chunks():
stored.write(chunk)
else:
print_warning("File exists already")
return None
return file_path
示例6: delete_tag
def delete_tag(self, tag_name, sha256):
session = self.Session()
try:
# First remove the tag from the sample
malware_entry = session.query(Malware).filter(Malware.sha256 == sha256).first()
tag = session.query(Tag).filter(Tag.tag == tag_name).first()
try:
malware_entry = session.query(Malware).filter(Malware.sha256 == sha256).first()
malware_entry.tag.remove(tag)
session.commit()
except:
print_error("Tag {0} does not exist for this sample".format(tag_name))
# If tag has no entries drop it
count = len(self.find("tag", tag_name))
if count == 0:
session.delete(tag)
session.commit()
print_warning("Tag {0} has no additional entries dropping from Database".format(tag_name))
except SQLAlchemyError as e:
print_error("Unable to delete tag: {0}".format(e))
session.rollback()
finally:
session.close()
示例7: is_attached_misp
def is_attached_misp(self, quiet=False):
if not self.is_set():
if not quiet:
print_error("No session opened")
return False
if not self.current.misp_event:
if not quiet:
print_error("Not attached to a MISP event")
return False
return True
示例8: is_attached_file
def is_attached_file(self, quiet=False):
if not self.is_set():
if not quiet:
print_error("No session opened")
return False
if not self.current.file:
if not quiet:
print_error("Not attached to a file")
return False
return True
示例9: find
def find(self, key, value=None, offset=0):
session = self.Session()
offset = int(offset)
rows = None
if key == 'all':
rows = session.query(Malware).all()
elif key == 'ssdeep':
ssdeep_val = str(value)
rows = session.query(Malware).filter(Malware.ssdeep.contains(ssdeep_val)).all()
elif key == 'any':
prefix_val = str(value)
rows = session.query(Malware).filter(Malware.name.startswith(prefix_val) |
Malware.md5.startswith(prefix_val) |
Malware.sha1.startswith(prefix_val) |
Malware.sha256.startswith(prefix_val) |
Malware.type.contains(prefix_val) |
Malware.mime.contains(prefix_val)).all()
elif key == 'latest':
if value:
try:
value = int(value)
except ValueError:
print_error("You need to specify a valid number as a limit for your query")
return None
else:
value = 5
rows = session.query(Malware).order_by(Malware.id.desc()).limit(value).offset(offset)
elif key == 'md5':
rows = session.query(Malware).filter(Malware.md5 == value).all()
elif key == 'sha1':
rows = session.query(Malware).filter(Malware.sha1 == value).all()
elif key == 'sha256':
rows = session.query(Malware).filter(Malware.sha256 == value).all()
elif key == 'tag':
rows = session.query(Malware).filter(self.tag_filter(value)).all()
elif key == 'name':
if '*' in value:
value = value.replace('*', '%')
else:
value = '%{0}%'.format(value)
rows = session.query(Malware).filter(Malware.name.like(value)).all()
elif key == 'note':
value = '%{0}%'.format(value)
rows = session.query(Malware).filter(Malware.note.any(Note.body.like(value))).all()
elif key == 'type':
rows = session.query(Malware).filter(Malware.type.like('%{0}%'.format(value))).all()
elif key == 'mime':
rows = session.query(Malware).filter(Malware.mime.like('%{0}%'.format(value))).all()
else:
print_error("No valid term specified")
return rows
示例10: edit_note
def edit_note(self, note_id, body):
session = self.Session()
try:
session.query(Note).get(note_id).body = body
session.commit()
except SQLAlchemyError as e:
print_error("Unable to update note: {0}".format(e))
session.rollback()
finally:
session.close()
示例11: delete_parent
def delete_parent(self, malware_sha256):
session = self.Session()
try:
malware = session.query(Malware).filter(Malware.sha256 == malware_sha256).first()
malware.parent = None
session.commit()
except SQLAlchemyError as e:
print_error("Unable to delete parent: {0}".format(e))
session.rollback()
finally:
session.close()
示例12: delete_note
def delete_note(self, note_id):
session = self.Session()
try:
note = session.query(Note).get(note_id)
session.delete(note)
session.commit()
except SQLAlchemyError as e:
print_error("Unable to delete note: {0}".format(e))
session.rollback()
finally:
session.close()
示例13: add_analysis
def add_analysis(self, sha256, cmd_line, results):
results = json.dumps(results)
session = self.Session()
malware_entry = session.query(Malware).filter(Malware.sha256 == sha256).first()
if not malware_entry:
return
try:
malware_entry.analysis.append(Analysis(cmd_line, results))
session.commit()
except SQLAlchemyError as e:
print_error("Unable to store analysis: {0}".format(e))
session.rollback()
finally:
session.close()
示例14: add_note
def add_note(self, sha256, title, body):
session = self.Session()
malware_entry = session.query(Malware).filter(Malware.sha256 == sha256).first()
if not malware_entry:
return
try:
malware_entry.note.append(Note(title, body))
session.commit()
except SQLAlchemyError as e:
print_error("Unable to add note: {0}".format(e))
session.rollback()
finally:
session.close()
示例15: tag_filter
def tag_filter(self, value):
if not value:
return None
if "|" in value and "&" in value:
print_error("Do not use &' and '|' at the same time.")
return None
if "|" in value:
filt = Malware.tag.any(Tag.tag.in_(value.lower().split("|")))
elif "&" in value:
tags = []
for tt in value.lower().split("&"):
tags.append(Malware.tag.any(Tag.tag == tt))
filt = and_(*tags)
else:
filt = Malware.tag.any(Tag.tag == value.lower())
return filt