Beispiel #1
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())
Beispiel #2
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())