Exemple #1
0
    def _handle_ABC(self, msg):
        handler_name = msg.method.decode("utf-8").upper()
        # check if Call-ID header exist
        if not msg.header_exist(b"call-id"):
            return

        # Get Call-Id and check if there's already a SipSession
        call_id = msg.headers.get(b"call-id").value

        # ToDo: remove? we don't use it
        # cseq = msg.headers.get(b"cseq").get_raw()

        # Find SipSession and delete it
        if call_id not in g_call_ids or g_call_ids[call_id] is None:
            logger.warn("{!s} request does not match any existing SIP session".format(handler_name))
            icd = incident("dionaea.modules.python.sip.command")
            icd.con = self
            msg_to_icd(msg,d=icd)
            icd.report()
            self.send(msg.create_response(rfc3261.CALL_TRANSACTION_DOSE_NOT_EXIST).dumps())
            return

        try:
            g_call_ids[call_id].handle_msg_in(msg)
        except AuthenticationError:
            logger.warn("Authentication failed for {!s} request".format(handler_name))
Exemple #2
0
    def _handle_ABC(self, msg):
        handler_name = msg.method.decode("utf-8").upper()
        # check if Call-ID header exist
        if not msg.header_exist(b"call-id"):
            return

        # Get Call-Id and check if there's already a SipSession
        call_id = msg.headers.get(b"call-id").value

        # ToDo: remove? we don't use it
        # cseq = msg.headers.get(b"cseq").get_raw()

        # Find SipSession and delete it
        if call_id not in g_call_ids or g_call_ids[call_id] is None:
            logger.warn(
                "{!s} request does not match any existing SIP session".format(
                    handler_name))
            icd = incident("dionaea.modules.python.sip.command")
            icd.con = self
            msg_to_icd(msg, d=icd)
            icd.report()
            self.send(
                msg.create_response(
                    rfc3261.CALL_TRANSACTION_DOSE_NOT_EXIST).dumps())
            return

        try:
            g_call_ids[call_id].handle_msg_in(msg)
        except AuthenticationError:
            logger.warn(
                "Authentication failed for {!s} request".format(handler_name))
Exemple #3
0
    def handle_OPTIONS(self, msg):
        logger.debug("{!s} handle_OPTIONS".format(self))
        icd = incident("dionaea.modules.python.sip.command")
        icd.con = self
        msg_to_icd(msg,d=icd)
        icd.report()

        res = msg.create_response(rfc3261.OK)
        res.headers.append(rfc3261.Header(name="Accept", value="application/sdp"))
        res.headers.append(rfc3261.Header(name="Accept-Language", value="en"))

        self.send(res.dumps())
Exemple #4
0
    def handle_unknown(self, msg):
        logger.debug("{!s} unknown".format(self))
        logger.warn("Unknown SIP header: {}".format(repr(msg.method)[:128]))

        icd = incident("dionaea.modules.python.sip.command")
        icd.con = self
        msg_to_icd(msg, d=icd)
        icd.report()

        res = msg.create_response(rfc3261.NOT_IMPLEMENTED)
        res.dumps()
        self.send(res.dumps())
Exemple #5
0
    def handle_unknown(self, msg):
        logger.debug("{!s} unknown".format(self))
        logger.warn("Unknown SIP header: {}".format(repr(msg.method)[:128]))

        icd = incident("dionaea.modules.python.sip.command")
        icd.con = self
        msg_to_icd(msg, d=icd)
        icd.report()

        res = msg.create_response(rfc3261.NOT_IMPLEMENTED)
        res.dumps()
        self.send(res.dumps())
Exemple #6
0
    def handle_OPTIONS(self, msg):
        logger.debug("{!s} handle_OPTIONS".format(self))
        icd = incident("dionaea.modules.python.sip.command")
        icd.con = self
        msg_to_icd(msg,d=icd)
        icd.report()

        res = msg.create_response(rfc3261.OK)
        res.headers.append(rfc3261.Header(name="Accept", value="application/sdp"))
        res.headers.append(rfc3261.Header(name="Accept-Language", value="en"))

        self.send(res.dumps())
Exemple #7
0
    def handle_msg_in(self, msg):
        self._timers["idle"].reset()
        self._msg_stack.append(("in", msg))

        icd = incident("dionaea.modules.python.sip.command")
        icd.con = self
        msg_to_icd(msg,d=icd)
        icd.report()

        handler_name = msg.method.decode("utf-8").upper()

        try:
            func = getattr(self, "handle_" + handler_name, None)
        except:
            func = None

        if func is not None and callable(func) == True:
            func(msg)
Exemple #8
0
    def handle_msg_in(self, msg):
        self._timers["idle"].reset()
        self._msg_stack.append(("in", msg))

        icd = incident("dionaea.modules.python.sip.command")
        icd.con = self
        msg_to_icd(msg, d=icd)
        icd.report()

        handler_name = msg.method.decode("utf-8").upper()

        try:
            func = getattr(self, "handle_" + handler_name, None)
        except:
            func = None

        if func is not None and callable(func) == True:
            func(msg)
Exemple #9
0
    def handle_REGISTER(self, msg):
        """
        :See: http://tools.ietf.org/html/rfc3261#section-10
        """
        logger.debug("{!s} handle_REGISTER".format(self))

        icd = incident("dionaea.modules.python.sip.command")
        icd.con = self
        msg_to_icd(msg,d=icd)
        icd.report()

        # ToDo: check for request-uri?
        if not msg.headers_exist([b"to", b"from", b"call-id", b"cseq"]):
            logger.warn("REGISTER, header missing")
            # ToDo: return error
            return

        to = msg.headers.get(b"to")
        user_id = to.get_raw().uri.user

        u = self.config.get_user_by_username(self.personality, user_id)

        # given user not found
        if u is None:
            res = msg.create_response(rfc3261.NOT_FOUND)
            self.send(res.dumps())
            return

        if u.password is not None and u.password != "":
            header_auth = msg.headers.get(b"authorization", None)
            if header_auth is None or self._auth is None:
                # ToDo: change nonce
                self._auth = rfc2617.Authentication(
                    method = "digest",
                    algorithm = "md5",
                    nonce = "foobar123",
                    realm = u.realm
                )
                res = msg.create_response(rfc3261.UNAUTHORIZED)
                res.headers.append(rfc3261.Header(name=b"www-authenticate", value=self._auth))
                self.send(res.dumps())
                return

            auth_response = rfc2617.Authentication.froms(header_auth[0].value)

            # ToDo: change realm
            if not self._auth.check(u.username, u.password, "REGISTER", auth_response):
                # ToDo: change nonce
                self._auth = rfc2617.Authentication(
                    method="digest",
                    algorithm="md5",
                    nonce=b"foobar123",
                    realm=u.realm
                )
                res = msg.create_response(rfc3261.UNAUTHORIZED)
                res.headers.append(rfc3261.Header(name=b"www-authenticate", value=self._auth))
                self.send(res.dumps())
                return

            # ToDo: Report authentication incident
            #i = incident("dionaea.modules.python.sip.authentication")
            #i.authenticationSuccessful = expected == authLineDict['response']
            #i.realm = realm
            #i.uri = uri
            #i.nonce = authLineDict['nonce']
            #i.challengeResponse = authLineDict['response']
            #i.expected = expected
            #i.report()

        user = User(user_id, msg=msg)
        g_reg_manager.register(user)

        res = msg.create_response(rfc3261.OK)
        self.send(res.dumps())
Exemple #10
0
    def handle_REGISTER(self, msg):
        """
        :See: http://tools.ietf.org/html/rfc3261#section-10
        """
        logger.debug("{!s} handle_REGISTER".format(self))

        icd = incident("dionaea.modules.python.sip.command")
        icd.con = self
        msg_to_icd(msg, d=icd)
        icd.report()

        # ToDo: check for request-uri?
        if not msg.headers_exist([b"to", b"from", b"call-id", b"cseq"]):
            logger.warn("REGISTER, header missing")
            # ToDo: return error
            return

        to = msg.headers.get(b"to")
        user_id = to.get_raw().uri.user

        u = self.config.get_user_by_username(self.personality, user_id)

        # given user not found
        if u is None:
            res = msg.create_response(rfc3261.NOT_FOUND)
            self.send(res.dumps())
            return

        if u.password is not None and u.password != "":
            header_auth = msg.headers.get(b"authorization", None)
            if header_auth is None or self._auth is None:
                # ToDo: change nonce
                self._auth = rfc2617.Authentication(method="digest",
                                                    algorithm="md5",
                                                    nonce="foobar123",
                                                    realm=u.realm)
                res = msg.create_response(rfc3261.UNAUTHORIZED)
                res.headers.append(
                    rfc3261.Header(name=b"www-authenticate", value=self._auth))
                self.send(res.dumps())
                return

            auth_response = rfc2617.Authentication.froms(header_auth[0].value)

            # ToDo: change realm
            if not self._auth.check(u.username, u.password, "REGISTER",
                                    auth_response):
                # ToDo: change nonce
                self._auth = rfc2617.Authentication(method="digest",
                                                    algorithm="md5",
                                                    nonce=b"foobar123",
                                                    realm=u.realm)
                res = msg.create_response(rfc3261.UNAUTHORIZED)
                res.headers.append(
                    rfc3261.Header(name=b"www-authenticate", value=self._auth))
                self.send(res.dumps())
                return

            # ToDo: Report authentication incident
            #i = incident("dionaea.modules.python.sip.authentication")
            #i.authenticationSuccessful = expected == authLineDict['response']
            #i.realm = realm
            #i.uri = uri
            #i.nonce = authLineDict['nonce']
            #i.challengeResponse = authLineDict['response']
            #i.expected = expected
            #i.report()

        user = User(user_id, msg=msg)
        g_reg_manager.register(user)

        res = msg.create_response(rfc3261.OK)
        self.send(res.dumps())