Example #1
0
def init_logger(logfile,verbose,disable_col):

	file_logger = logging.FileHandler(logfile)
	
	if disable_col==False:
		try:
			from thirdparty.ansistrm.ansistrm import ColorizingStreamHandler
			cli_logger = ColorizingStreamHandler(sys.stdout)
			cli_logger.level_map[logging.INFO]=(None, 'green', False)
		except ImportError:
			print 'import error'
			cli_logger = logging.StreamHandler(sys.stdout)
	else:
		cli_logger=logging.StreamHandler(sys.stdout)
	
	if verbose==True:
		LOG.setLevel(logging.DEBUG)	
	else:
		LOG.setLevel(logging.WARNING)

	file_formatter = logging.Formatter('[%(asctime)s] %(filename)s[line:%(lineno)d] [in func:%(funcName)s] %(levelname)s %(message)s',
			datefmt='%d %b %Y %H:%M:%S')
	cli_formatter = logging.Formatter('[%(asctime)s] %(filename)s[line:%(lineno)d] [in func:%(funcName)s] %(levelname)s %(message)s',
			datefmt='%H:%M:%S')
	file_logger.setFormatter(file_formatter)
	cli_logger.setFormatter(cli_formatter)

	LOG.addHandler(file_logger)
	LOG.addHandler(cli_logger)

	LOG.debug("logger init completed")
Example #2
0
def main():
    parser = argparse.ArgumentParser(description='A tool that hook all apps you need')

    parser.add_argument('regexps', type=str, nargs='*',
                        help=r'Regexps for the apps you want to hook such as "^com\.baidu\.", '
                             r'empty for hooking all apps')
    parser.add_argument('-i', '--install', action='store_true',
                        help='install frida server to /data/local/tmp automatically')
    parser.add_argument('-p', '--port', type=int,
                        help='reverse tcp port, if specified, manipulate iptables automatically')
    parser.add_argument('-v', action='store_true', help='verbose output')

    args = parser.parse_args()

    if args.v:
        LOGGER.setLevel(logging.DEBUG)

    # set log
    os.makedirs(LOG_DIR, mode=0o700, exist_ok=True)
    log_filename = time.strftime('%Y-%m-%d_%H-%M-%S.log')
    log_file = open(os.path.join(LOG_DIR, log_filename), 'a', encoding='utf-8')
    logger_handler = ColorizingStreamHandler(log_file)
    logger_handler.setFormatter(FORMATTER)
    LOGGER.addHandler(logger_handler)

    Adb.start_server()

    try:
        t = WatchThread(args.install, args.port, args.regexps, True)
        t.start()
        t.join()
    except KeyboardInterrupt:
        LOGGER.info('shutdown, thank you for using frida skeleton')
    except Exception as e:
        LOGGER.error(e)
Example #3
0
def init_logger(logfile, verbose, disable_col):

    file_logger = logging.FileHandler(logfile)

    if disable_col == False:
        try:
            from thirdparty.ansistrm.ansistrm import ColorizingStreamHandler
            cli_logger = ColorizingStreamHandler(sys.stdout)
            cli_logger.level_map[logging.INFO] = (None, 'green', False)
        except ImportError:
            print 'import error'
            cli_logger = logging.StreamHandler(sys.stdout)
    else:
        cli_logger = logging.StreamHandler(sys.stdout)

    if verbose == True:
        LOG.setLevel(logging.DEBUG)
    else:
        LOG.setLevel(logging.WARNING)

    file_formatter = logging.Formatter(
        '[%(asctime)s] %(filename)s[line:%(lineno)d] [in func:%(funcName)s] %(levelname)s %(message)s',
        datefmt='%d %b %Y %H:%M:%S')
    cli_formatter = logging.Formatter(
        '[%(asctime)s] %(filename)s[line:%(lineno)d] [in func:%(funcName)s] %(levelname)s %(message)s',
        datefmt='%H:%M:%S')
    file_logger.setFormatter(file_formatter)
    cli_logger.setFormatter(cli_formatter)

    LOG.addHandler(file_logger)
    LOG.addHandler(cli_logger)

    LOG.debug("logger init completed")
Example #4
0
    def __init__(self,
                 set_level=CUSTOM_LOGGING.SYSINFO,
                 name=os.path.split(os.path.splitext(sys.argv[0])[0])[-1],
                 log_name=time.strftime("%Y-%m-%d.log", time.localtime()),
                 log_path=os.path.join(
                     os.path.dirname(
                         os.path.dirname(
                             os.path.dirname(os.path.abspath(__file__)))),
                     "log"),
                 use_console=True):

        logging.addLevelName(CUSTOM_LOGGING.SYSINFO, "*")
        logging.addLevelName(CUSTOM_LOGGING.SUCCESS, "+")
        logging.addLevelName(CUSTOM_LOGGING.ERROR, "-")
        logging.addLevelName(CUSTOM_LOGGING.WARNING, "!")
        logging.addLevelName(CUSTOM_LOGGING.DEBUG, "DEBUG")

        self.logger = logging.getLogger(name)
        self.set_level(set_level)

        if not os.path.exists(log_path):
            os.makedirs(log_path)

        self.log_handler = logging.FileHandler(os.path.join(
            log_path, log_name),
                                               encoding='utf-8')
        self.log_handler.setFormatter(
            logging.Formatter("[%(asctime)s] [%(levelname)s] %(message)s",
                              "%H:%M:%S"))
        self.logger.addHandler(self.log_handler)

        if use_console:
            try:
                from thirdparty.ansistrm.ansistrm import ColorizingStreamHandler
                try:
                    console_handler = ColorizingStreamHandler(sys.stdout)
                    console_handler.level_map[logging.getLevelName("*")] = (
                        None, "white", False)
                    console_handler.level_map[logging.getLevelName("+")] = (
                        None, "green", False)
                    console_handler.level_map[logging.getLevelName("-")] = (
                        None, "red", False)
                    console_handler.level_map[logging.getLevelName("!")] = (
                        None, "yellow", False)
                    console_handler.level_map[logging.getLevelName(
                        "DEBUG")] = (None, "cyan", False)
                    self.console_handler = console_handler
                except Exception:
                    self.console_handler = logging.StreamHandler(sys.stdout)
            except ImportError:
                self.console_handler = logging.StreamHandler(sys.stdout)
        else:
            self.console_handler = logging.StreamHandler(sys.stdout)

        self.console_handler.setFormatter(
            logging.Formatter("[%(asctime)s] [%(levelname)s] %(message)s",
                              "%H:%M:%S"))
        self.logger.addHandler(self.console_handler)
Example #5
0
logging.addLevelName(CUSTOM_LOGGING.TRAFFIC_IN, "TRAFFIC IN")

LOGGER = logging.getLogger("sqlmapLog")

LOGGER_HANDLER = None
try:
    from thirdparty.ansistrm.ansistrm import ColorizingStreamHandler

    disableColor = False

    for argument in sys.argv:
        if "disable-col" in argument:
            disableColor = True
            break

    if disableColor:
        LOGGER_HANDLER = logging.StreamHandler(sys.stdout)
    else:
        LOGGER_HANDLER = ColorizingStreamHandler(sys.stdout)
        LOGGER_HANDLER.level_map[logging.getLevelName("PAYLOAD")] = (None, "cyan", False)
        LOGGER_HANDLER.level_map[logging.getLevelName("TRAFFIC OUT")] = (None, "magenta", False)
        LOGGER_HANDLER.level_map[logging.getLevelName("TRAFFIC IN")] = ("magenta", None, False)
except ImportError:
    LOGGER_HANDLER = logging.StreamHandler(sys.stdout)

FORMATTER = logging.Formatter("\r[%(asctime)s] [%(levelname)s] %(message)s", "%H:%M:%S")

LOGGER_HANDLER.setFormatter(FORMATTER)
LOGGER.addHandler(LOGGER_HANDLER)
LOGGER.setLevel(logging.WARN)
Example #6
0
LOGGER_HANDLER = None
try:
    from thirdparty.ansistrm.ansistrm import ColorizingStreamHandler

    disableColor = False

    # TODO disable_color in parser.py
    for argument in sys.argv:
        if "disable-col" in argument:
            disableColor = True
            break

    if disableColor:
        LOGGER_HANDLER = logging.StreamHandler(sys.stdout)
    else:
        LOGGER_HANDLER = ColorizingStreamHandler(sys.stdout)
        LOGGER_HANDLER.level_map[logging.getLevelName("*")] = (None, "cyan", False)
        LOGGER_HANDLER.level_map[logging.getLevelName("+")] = (None, "green", False)
        LOGGER_HANDLER.level_map[logging.getLevelName("-")] = (None, "red", False)
        LOGGER_HANDLER.level_map[logging.getLevelName("!")] = (None, "yellow", False)
except ImportError:
    LOGGER_HANDLER = logging.StreamHandler(sys.stdout)

# there can't be -> if conf.DEBUG:
if "debug" in sys.argv:
    FORMATTER = logging.Formatter("\r[%(asctime)s] [%(levelname)s] %(message)s", "%H:%M:%S")
else:
    FORMATTER = logging.Formatter("\r[%(levelname)s] %(message)s", "%H:%M:%S")

LOGGER_HANDLER.setFormatter(FORMATTER)
LOGGER.addHandler(LOGGER_HANDLER)
Example #7
0
@author: xiaoL-pkav [email protected]
@version: 2015/8/31 16:20
"""

import logging
import logging.handlers
import sys
import os
import time

from common import LOG_DOC

from thirdparty.ansistrm.ansistrm import ColorizingStreamHandler

FORMATTER = logging.Formatter('%(asctime)s [%(name)s][%(levelname)s] %(message)s', '%Y-%m-%d %H:%M:%S')
COLOR_LOGGER_HANDLER = ColorizingStreamHandler(sys.stdout)
COLOR_LOGGER_HANDLER.setFormatter(FORMATTER)

LOCAL_LOGGER_HANDLER = logging.handlers.RotatingFileHandler(os.path.join(os.path.join(os.getcwd(), LOG_DOC),
                                                                         time.strftime('%y%m%d')+'-log.log'))
LOCAL_LOGGER_HANDLER.setFormatter(FORMATTER)


def init_logger():
    log_path = os.path.join(os.getcwd(), LOG_DOC)
    if not os.path.isdir(log_path):
        try:
            os.makedirs(log_path)
        except Exception, e:
            raise e
Example #8
0
from thirdparty.ansistrm.ansistrm import ColorizingStreamHandler

# Information about this script
AUTHOR = 'NoaMCORe'
NAME = 'NoaM-UTils'
VERSION = '0.2-dev'
REVISION = getRevisionNumber()
BANNER_STRING = 'pwnspetsnaz/%s%s' % (VERSION, ' (r%s)' % REVISION if REVISION else '')
IS_WIN = subprocess.mswindows

# Legal disclaimer
LEGAL_DISCLAIMER = 'usage of this script to make any procedure without consent of users is illegal. ' \
                   'It is the end user\'s responsibility to obey all applicable local, state and federal laws. ' \
                   'Authors assume no liability and are not responsible for any misuse or damage caused by this script.'

# Logger
logger = logging.getLogger('pwnspetsnazLog')

try:
    import ctypes
    logger_handler = ColorizingStreamHandler(sys.stdout)
    logger_handler.level_map[logging.getLevelName("TRAFFIC OUT")] = (None, 'cyan', None)
    logger_handler.level_map[logging.getLevelName("TRAFFIC IN")] = (None, 'magenta', None)
except ImportError:
    logger_handler = logging.StreamHandler(sys.stdout)

formatter = logging.Formatter("\r[%(asctime)s] [%(levelname)s] %(message)s", "%H:%M:%S")
logger_handler.setFormatter(formatter)
logger.addHandler(logger_handler)
logger.setLevel(logging.INFO)
Example #9
0
def main():
    parser = argparse.ArgumentParser(
        description='A tool that hook all apps you need')

    parser.add_argument(
        'regexps',
        type=str,
        nargs='*',
        help=r'Regexps for the apps you want to hook such as "^com\.baidu\.", '
        r'empty for hooking all apps')
    parser.add_argument(
        '-i',
        '--install',
        action='store_true',
        help='install frida server to /data/local/tmp automatically')
    parser.add_argument(
        '-p',
        '--port',
        type=int,
        help='reverse tcp port, if specified, manipulate iptables automatically'
    )
    parser.add_argument('-v', action='store_true', help='verbose output')

    args = parser.parse_args()

    try:
        if args.v:
            LOGGER.setLevel(logging.DEBUG)

        # set log
        os.makedirs(LOG_DIR, mode=0o700, exist_ok=True)
        log_filename = time.strftime('%Y-%m-%d_%H-%M-%S.log')
        log_file = open(os.path.join(LOG_DIR, log_filename),
                        'a',
                        encoding='utf-8')
        logger_handler = ColorizingStreamHandler(log_file)
        logger_handler.setFormatter(FORMATTER)
        LOGGER.addHandler(logger_handler)

        # set handling interrupt exceptions
        signal.signal(signal.SIGTERM, shutdown)
        signal.signal(signal.SIGINT, shutdown)

        Adb.start_server()

        watch_thread = WatchThread(args.install, args.port, args.regexps)
    except (KeyboardInterrupt, InterruptedError) as e:
        LOGGER.info(e)
        sys.exit(-1)

    try:
        watch_thread.start()
        while True:
            time.sleep(1)
    except MainExit:
        while True:
            try:
                LOGGER.info(
                    'shutdown command received, wait for clean up please...')
                watch_thread.cancel()
                break
            except MainExit:
                pass

    # waiting for sub threads
    while True:
        try:
            while True:
                should_we_exit()
                time.sleep(1)
        except MainExit:
            try:
                n = len(thread_manager.thread_map)
                if n > 0:
                    LOGGER.info(
                        'running sub threads: {}, wait a second please'.format(
                            n))
            except MainExit:
                pass
Example #10
0
from logging.handlers import RotatingFileHandler

INFO, WARNING, ERROR, SUCCESS, HTTPDEBUG = range(11, 16)

logging.addLevelName(INFO, '*')
logging.addLevelName(WARNING, '!')
logging.addLevelName(ERROR, '-')
logging.addLevelName(SUCCESS, '+')
logging.addLevelName(HTTPDEBUG, 'DBG')

logger = logging.getLogger('logger')

try:
    from thirdparty.ansistrm.ansistrm import ColorizingStreamHandler

    handle = ColorizingStreamHandler(sys.stdout)
    handle.level_map[logging.getLevelName('*')] = (None, 'cyan', False)
    handle.level_map[logging.getLevelName('+')] = (None, 'green', False)
    handle.level_map[logging.getLevelName('-')] = (None, 'red', False)
    handle.level_map[logging.getLevelName('!')] = (None, 'yellow', False)
    handle.level_map[logging.getLevelName('DBG')] = (None, 'white', False)
except:
    handle = logging.StreamHandler(sys.stdout)

formatter = logging.Formatter('%(asctime)s [%(levelname)s] %(message)s',
                              '%Y/%m/%d %H:%M:%S')
handle.setFormatter(formatter)
logger.addHandler(handle)

dayTime = datetime.datetime.now().strftime('%Y-%m-%d')
if not os.path.exists('./logs'):