Skip to content

Commit

Permalink
Merge pull request AlessandroZ#389 from cclauss/runtime-info
Browse files Browse the repository at this point in the history
Add platform info to BANG BANG banner
  • Loading branch information
AlessandroZ authored Apr 10, 2019
2 parents bbe295f + b020f9e commit 2d4cc19
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 54 deletions.
34 changes: 15 additions & 19 deletions Linux/lazagne/config/write_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os

from lazagne.config.constant import constant
from platform import uname
from time import gmtime, strftime


Expand All @@ -31,20 +32,15 @@ def __init__(self):
| ! BANG BANG ! |
| |
|====================================================================|
'''
Python {}.{}.{} on'''.format(*sys.version_info) + " {0} {4}: {5}\n".format(*uname())
# Python 3.7.3 on Darwin x86_64: i386

def set_color(self, color=None):
b = Bcolors()
if color == 'white':
sys.stdout.write(b.TITLE)
elif color == 'red':
sys.stdout.write(b.FAIL)
elif color == 'green':
sys.stdout.write(b.OK)
elif color == 'cyan':
sys.stdout.write(b.WARNING)
else:
sys.stdout.write(b.ENDC)
sys.stdout.write({'white': b.TITLE,
'red': b.FAIL,
'green': b.OK,
'cyan': b.WARNING}.get(color, b.ENDC))

# Print banner
def first_title(self):
Expand Down Expand Up @@ -102,9 +98,9 @@ def print_logging(self, function, prefix='[!]', message='', color=False):

def try_unicode(self, obj, encoding='utf-8'):
try:
if isinstance(obj, basestring):
if not isinstance(obj, unicode):
obj = unicode(obj, encoding)
if isinstance(obj, basestring): # noqa: F821
if not isinstance(obj, unicode): # noqa: F821
obj = unicode(obj, encoding) # noqa: F821
except Exception:
pass
return obj
Expand Down Expand Up @@ -136,7 +132,7 @@ def checks_write(self, values, category):
constant.finalResults["Passwords"].append([{"Category": category}, values])

def print_output(self, software_name, pwd_found):

if pwd_found:
# If the debug logging level is not apply => print the title
if not logging.getLogger().isEnabledFor(logging.INFO):
Expand Down Expand Up @@ -267,7 +263,7 @@ def parse_json_result_to_buffer(json_string, color=False):
buffer += '%s: %s\r\n' % (dic, password_by_category[dic].encode('utf-8'))
except Exception:
buffer += '%s: %s\r\n' % (
dic, password_by_category[dic].encode(encoding='utf-8', errors='replace'))
dic, password_by_category[dic].encode(encoding='utf-8', errors='replace'))
buffer += '\r\n'

except Exception as e:
Expand All @@ -280,7 +276,7 @@ def write_in_file(result):
"""
Write output to file (json and txt files)
"""
if constant.output == 'json' or constant.output == 'all':
if constant.output in ('json', 'all'):
try:
# Human readable Json format
pretty_json = json.dumps(result, sort_keys=True, indent=4, separators=(',', ': '))
Expand All @@ -293,7 +289,7 @@ def write_in_file(result):
except Exception as e:
print_debug('ERROR', u'Error writing the output file: {error}'.format(error=e))

if constant.output == 'txt' or constant.output == 'all':
if constant.output in ('txt', 'all'):
try:
with open(os.path.join(constant.folder_name, constant.file_name_results + '.txt'), 'a+b') as f:
a = parse_json_result_to_buffer(result)
Expand All @@ -304,4 +300,4 @@ def write_in_file(result):
file=os.path.join(constant.folder_name, constant.file_name_results + '.txt'))
)
except Exception as e:
print_debug('ERROR', u'Error writing the output file: {error}'.format(error=e))
print_debug('ERROR', u'Error writing the output file: {error}'.format(error=e))
30 changes: 13 additions & 17 deletions Mac/lazagne/config/write_output.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
from lazagne.config.constant import constant
from platform import uname
from time import gmtime, strftime
import logging
import getpass
Expand Down Expand Up @@ -30,20 +31,15 @@ def __init__(self):
| ! BANG BANG ! |
| |
|====================================================================|
'''
Python {}.{}.{} on'''.format(*sys.version_info) + " {0} {4}: {5}\n".format(*uname())
# Python 3.7.3 on Darwin x86_64: i386

def set_color(self, color=None):
b = Bcolors()
if color == 'white':
sys.stdout.write(b.TITLE)
elif color == 'red':
sys.stdout.write(b.FAIL)
elif color == 'green':
sys.stdout.write(b.OK)
elif color == 'cyan':
sys.stdout.write(b.WARNING)
else:
sys.stdout.write(b.ENDC)
sys.stdout.write({'white': b.TITLE,
'red': b.FAIL,
'green': b.OK,
'cyan': b.WARNING}.get(color, b.ENDC))

# Print banner
def first_title(self):
Expand Down Expand Up @@ -101,9 +97,9 @@ def print_logging(self, function, prefix='[!]', message='', color=False):

def try_unicode(self, obj, encoding='utf-8'):
try:
if isinstance(obj, basestring):
if not isinstance(obj, unicode):
obj = unicode(obj, encoding)
if isinstance(obj, basestring): # noqa: F821
if not isinstance(obj, unicode): # noqa: F821
obj = unicode(obj, encoding) # noqa: F821
except Exception:
pass
return obj
Expand Down Expand Up @@ -257,7 +253,7 @@ def parse_json_result_to_buffer(json_string, color=False):
title_color=title,
password_category=all_passwords[0]['Category'],
reset_color=reset
)
)
for password_by_category in all_passwords[1]:
buffer += '\r\n{green_color}Password found !!!{reset_color}\r\n'.format(
green_color=green,
Expand All @@ -282,7 +278,7 @@ def write_in_file(result):
"""
Write output to file (json and txt files)
"""
if constant.output == 'json' or constant.output == 'all':
if constant.output in ('json', 'all'):
try:
# Human readable Json format
pretty_json = json.dumps(result, sort_keys=True, indent=4, separators=(',', ': '))
Expand All @@ -293,7 +289,7 @@ def write_in_file(result):
except Exception as e:
print_debug('ERROR', 'Error writing the output file: %s' % e)

if constant.output == 'txt' or constant.output == 'all':
if constant.output in ('txt', 'all'):
try:
with open(os.path.join(constant.folder_name, constant.file_name_results + '.txt'), 'a+b') as f:
a = parse_json_result_to_buffer(result)
Expand Down
30 changes: 12 additions & 18 deletions Windows/lazagne/config/write_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import traceback

from time import gmtime, strftime
from platform import uname

from lazagne.config.winstructure import string_to_unicode, char_to_int, python_version
from .constant import constant
Expand All @@ -30,23 +31,16 @@ def __init__(self):
| ! BANG BANG ! |
| |
|====================================================================|
'''
Python {}.{}.{} on'''.format(*sys.version_info) + " {0} {4}: {5}".format(*uname())
# Python 3.7.3 on Darwin x86_64: i386

self.FILTER = ''.join([(len(repr(chr(x))) == 3) and chr(x) or '.' for x in range(256)])

def set_color(self, color='white', intensity=False):
c = None
if color == 'white':
c = 0x07
elif color == 'red':
c = 0x04
elif color == 'green':
c = 0x02
elif color == 'cyan':
c = 0x03
c = {'white': 0x07, 'red': 0x04, 'green': 0x02, 'cyan': 0x03}.get(color, None)

if intensity:
c = c | 0x08
c |= 0x08

ctypes.windll.kernel32.SetConsoleTextAttribute(std_out_handle, c)

Expand Down Expand Up @@ -91,9 +85,9 @@ def try_unicode(self, obj, encoding='utf-8'):
if python_version == 3:
return obj
try:
if isinstance(obj, basestring):
if not isinstance(obj, unicode):
obj = unicode(obj, encoding)
if isinstance(obj, basestring): # noqa: F821
if not isinstance(obj, unicode): # noqa: F821
obj = unicode(obj, encoding) # noqa: F821
except UnicodeDecodeError:
return repr(obj)
return obj
Expand Down Expand Up @@ -234,7 +228,7 @@ def print_output(self, software_name, pwd_found):
passwd = string_to_unicode(pwd[password_category[0].capitalize()])
if passwd and passwd not in constant.password_found:
constant.password_found.append(passwd)
except Exception as e:
except Exception:
pass

# Password field is empty
Expand Down Expand Up @@ -329,7 +323,7 @@ def parse_json_result_to_buffer(json_string):
for dic in password_by_category:
try:
buffer += u'%s: %s\r\n' % (
dic, constant.st.try_unicode(password_by_category[dic]))
dic, constant.st.try_unicode(password_by_category[dic]))
except Exception as e:
print_debug(u'ERROR', u'Error retrieving the password encoding: %s' % e)
buffer += u'\r\n'
Expand All @@ -344,7 +338,7 @@ def write_in_file(result):
Write output to file (json and txt files)
"""
if result:
if constant.output == 'json' or constant.output == 'all':
if constant.output in ('json', 'all'):
try:
# Human readable Json format
pretty_json = json.dumps(result, sort_keys=True, indent=4, separators=(',', ': '))
Expand All @@ -357,7 +351,7 @@ def write_in_file(result):
except Exception as e:
print_debug('ERROR', u'Error writing the output file: {error}'.format(error=e))

if constant.output == 'txt' or constant.output == 'all':
if constant.output in ('txt', 'all'):
try:
with open(os.path.join(constant.folder_name, constant.file_name_results + '.txt'), 'a+b') as f:
a = parse_json_result_to_buffer(result)
Expand Down

0 comments on commit 2d4cc19

Please sign in to comment.