Пример #1
0
def prepare_loggers(logLevel):
    """
    Sets up the "liveplayer" and "liveplayer.ui" loggers to print messages and send notifications on connect.
    """
    log.prepare_pyrdp_logger(logLevel)
    log.prepare_ssl_session_logger()

    if not os.path.exists("log"):
        os.makedirs("log")

    liveplayer_logger = getLoggerPassFilters(LOGGER_NAMES.LIVEPLAYER)
    liveplayer_logger.setLevel(logLevel)

    liveplayer_ui_logger = getLoggerPassFilters(
        f"{LOGGER_NAMES.LIVEPLAYER}.ui")
    liveplayer_ui_logger.setLevel(logLevel)

    formatter = log.get_formatter()

    stream_handler = logging.StreamHandler()
    file_handler = logging.FileHandler("log/liveplayer.log")
    stream_handler.setFormatter(formatter)
    file_handler.setFormatter(formatter)
    liveplayer_logger.addHandler(stream_handler)
    liveplayer_logger.addHandler(file_handler)

    notify_handler = NotifyHandler()
    notify_handler.setFormatter(
        logging.Formatter("[%(asctime)s] - %(message)s"))
    liveplayer_ui_logger.addHandler(notify_handler)
Пример #2
0
def prepare_loggers(logLevel, sensorID):
    """
        Sets up the "mitm" and the "mitm.connections" loggers.
    """
    log.prepare_pyrdp_logger(logLevel)
    log.prepare_ssl_session_logger()

    if not os.path.exists("log"):
        os.makedirs("log")

    mitm_logger = getLoggerPassFilters(LOGGER_NAMES.MITM)
    mitm_logger.setLevel(logLevel)

    mitm_connections_logger = getLoggerPassFilters(
        LOGGER_NAMES.MITM_CONNECTIONS)
    mitm_connections_logger.setLevel(logLevel)

    formatter = log.get_formatter()

    stream_handler = logging.StreamHandler()
    file_handler = logging.handlers.TimedRotatingFileHandler("log/mitm.log",
                                                             when="D")
    stream_handler.setFormatter(formatter)
    file_handler.setFormatter(formatter)
    mitm_logger.addHandler(stream_handler)
    mitm_logger.addHandler(file_handler)

    # Make sure that the library writes to the file as well
    pyrdp_logger = log.get_logger()
    pyrdp_logger.addHandler(file_handler)

    exceptions_logger = getLoggerPassFilters(LOGGER_NAMES.PYRDP_EXCEPTIONS)
    exceptions_logger.propagate = False
    exceptions_logger.addHandler(file_handler)

    jsonFormatter = JSONFormatter()
    jsonFileHandler = logging.FileHandler("log/mitm.json")
    sensorFilter = SensorFilter(sensorID)

    jsonFileHandler.setFormatter(jsonFormatter)
    jsonFileHandler.setLevel(logging.INFO)
    jsonFileHandler.addFilter(sensorFilter)

    getLoggerPassFilters(
        LOGGER_NAMES.MITM_CONNECTIONS).addHandler(jsonFileHandler)
Пример #3
0
    key: OpenSSL.crypto.PKey = None

    if arguments.in_key is not None:
        try:
            with open(arguments.in_key, "rb") as f:
                keyBytes = f.read()
        except IOError as e:
            print(f"Input key: {e}", file=sys.stderr)
            sys.exit(1)

        key = OpenSSL.crypto.load_privatekey(OpenSSL.crypto.FILETYPE_PEM,
                                             keyBytes)

    logLevel = getattr(logging, arguments.log_level)
    log.prepare_pyrdp_logger(logLevel)
    log.prepare_ssl_session_logger()

    handler = logging.StreamHandler()
    handler.setFormatter(log.get_formatter())
    clonerLog = logging.getLogger("cloner")
    clonerLog.addHandler(handler)
    clonerLog.setLevel(arguments.log_level)

    cloner = CertFetcher(reactor, clonerLog)
    cert = cloner.fetch()

    if not key:
        key = OpenSSL.crypto.PKey()
        key.generate_key(OpenSSL.crypto.TYPE_RSA, cert.get_pubkey().bits())
    else:
        if key.bits() != cert.get_pubkey().bits():