Пример #1
0
def exit_function(signum, frame):
    global exit_fn_called
    if exit_fn_called:
        return
    exit_fn_called = True
    l = logging.getLogger("server")
    signame = "SIGTERM"
    if signum == signal.SIGINT:
        signame = "SIGINT"
    if signum == signal.SIGQUIT:
        signame = "SIGQUIT"
    l.info("%s CAUGHT" % (signame, ))
    m_param.set_decrypting(0, always_on_db)
    m_param.set_recording(0, always_on_db)
    m_param.set_id_session(0, always_on_db)
    mono_mitm.stop_mitm()
    always_on_db.close()
    sys.exit(0)  #TODO find a better way to quit
Пример #2
0
def tcp_message(flow):
    l1 = logging.getLogger("mitm")
    l = logging.getLogger("mono_mitm.callback")
    global current_id_session, recording, decrypting, db
    global ip_server, ip_client, port_server, port_client
    global id_conver
    number = len(flow.messages)
    lm = flow.messages[-1]  #last_message
    #if this is the first message of the flow , we update our values
    if (number == 1):
        l.debug("Number ONE : first message of the flow")
        mono_param.set_decrypting(1, db)
        #reset vars
        current_id_session = mono_param.get_id_session(db)
        id_conver = -1
        ip_server = flow.server_conn.address.host  #supposedly unresolved ip
        ip_client = flow.client_conn.address.host
        port_server = flow.server_conn.address.port
        port_client = flow.client_conn.address.port
        #flow.server_conn.ip_address.host is the resolved ip

    if (current_id_session > 0):
        #mitm summary
        m = {
            "from_client": lm.from_client,
            "packet_length": len(lm.content),
            "ip_src": ip_client if lm.from_client else ip_server,
            "ip_dst": ip_server if lm.from_client else ip_client,
            "port_src": port_client if lm.from_client else port_server,
            "port_dst": port_server if lm.from_client else port_client,
            "payload": lm.content,
            "selected": 0,
            "timestamp": lm.timestamp,
            "sni": flow.server_conn.sni
        }
        #create mitm and add it to db
        (id_packet, packet) = mono_mitm.mitm_into_db(m, current_id_session, db)
        #add packet to mitm conversation
        conv = mono_conversation.add_packet_to_conversations(
            id_packet, packet, db, current_id_session, id_conv=-1, mitm=True)
        l.info("adding packet %s to current_session %s " %
               (id_packet, current_id_session))
        l.debug(str(packet))
        id_conver = conv["id_conversation"]
Пример #3
0
 def test_set_get(self):
     #setup
     print("\n#test_set_get")
     db = connect(mc.db_host, mc.db_user_name, mc.db_password,
                  mc.db_db_name)  #host, user, password, db
     mono_param.set_recording(0, db)
     self.assertEqual(mono_param.get_recording(db), 0)
     mono_param.set_recording(1, db)
     self.assertEqual(mono_param.get_recording(db), 1)
     mono_param.set_decrypting(0, db)
     self.assertEqual(mono_param.get_decrypting(db), 0)
     mono_param.set_decrypting(1, db)
     self.assertEqual(mono_param.get_decrypting(db), 1)
     mono_param.set_id_session(0, db)
     self.assertEqual(mono_param.get_id_session(db), 0)
     mono_param.set_id_session(33, db)
     self.assertEqual(mono_param.get_id_session(db), 33)
     #print "packet1_time: %s packet_time2 %s"%(format(packet.time, '.10f'), format(packet2.time, '.10f') )
     db.close()
Пример #4
0
    logging.getLogger("mono_session.callback").setLevel(logging.WARNING)
    logging.getLogger("mono_mitm.callback").setLevel(logging.INFO)
    #speficic log levels
    #    logging.getLogger("mono_param").setLevel(logging.INFO)
    #    logging.getLogger("mono_packet").setLevel(logging.INFO)
    #    logging.getLogger("mono_mitm").setLevel(logging.INFO)
    #    logging.getLogger("mono_tools").setLevel(logging.INFO)
    #    logging.getLogger("mono_conversation").setLevel(logging.INFO)
    #    logging.getLogger("mono_packet_conversation").setLevel(logging.INFO)
    #    logging.getLogger("mono_session").setLevel(logging.INFO)
    #logging level for dependencies
    logging.getLogger("werkzeug").setLevel(logging.ERROR)
    logging.getLogger("watchdog").setLevel(logging.ERROR)
    context = None
    #default settings
    m_param.set_decrypting(0, always_on_db)
    m_param.set_recording(0, always_on_db)
    m_param.set_id_session(0, always_on_db)
    signal.signal(signal.SIGTERM, exit_function)
    signal.signal(signal.SIGINT, exit_function)
    signal.signal(signal.SIGQUIT, exit_function)
    if mc.use_tls:
        context = (mc.certificate, mc.key)

    app.run(host='0.0.0.0',
            port=mc.server_port,
            debug=mc.flask_debug,
            ssl_context=context)
    ### TODO try catch SIGTERM + close always on db connector
#@application.route('/')
#def showMachineList():