def ksr_route_reqinit(self, msg):
        if not KSR.is_myself(KSR.pv.get("$si")):
            if not KSR.pv.is_null("$sht(ipban=>$si)"):
                # ip is already blocked
                KSR.dbg("request from blocked IP - " + KSR.pv.get("$rm") +
                        " from " + KSR.pv.get("$fu") + " (IP:" +
                        KSR.pv.get("$si") + ":" + KSR.pv.get("$sp") + ")\n")
                return -255

            if KSR.pike.pike_check_req() < 0:
                KSR.err("ALERT: pike blocking " + KSR.pv.get("$rm") +
                        " from " + KSR.pv.get("$fu") + " (IP:" +
                        KSR.pv.get("$si") + ":" + KSR.pv.get("$sp") + ")\n")
                KSR.pv.seti("$sht(ipban=>$si)", 1)
                return -255

        if not KSR.pv.is_null("$ua"):
            if (KSR.pv.get("$ua").find("friendly-scanner") != -1
                    or KSR.pv.get("$ua").find("sipcli") != -1):
                KSR.sl.sl_send_reply(200, "Processed")
                return -255

        if KSR.maxfwd.process_maxfwd(10) < 0:
            KSR.sl.sl_send_reply(483, "Too Many Hops")
            return -255

        if (KSR.pv.get("$rm") == "OPTIONS" and KSR.is_myself(KSR.pv.get("$ru"))
                and KSR.pv.is_null("$rU")):
            KSR.sl.sl_send_reply(200, "Keepalive")
            return -255

        if KSR.sanity.sanity_check(1511, 7) < 0:
            KSR.err("Malformed SIP message from " + KSR.pv.get("$si") + ":" +
                    KSR.pv.get("$sp") + "\n")
            return -255
Example #2
0
    def ksr_onreply_manage(self, msg):
        KSR.dbg("incoming reply\n");
        scode = KSR.pv.get("$rs");
        if scode>100 and scode<299 :
            self.ksr_route_natmanage(msg);

        return 1;
    def ksr_onreply_manage(self, msg):
        KSR.dbg("incoming reply\n");
        scode = KSR.pv.get("$rs");
        if scode>100 and scode<299 :
            self.ksr_route_natmanage(msg);

        return 1;
Example #4
0
    def ksr_reply_route(self, msg):
        KSR.dbg("response handling - python script\n")

        if KSR.sanity.sanity_check(17604, 6)<0 :
            KSR.err("Malformed SIP response from "
                    + KSR.pv.get("$si") + ":" + str(KSR.pv.get("$sp")) +"\n")
            KSR.set_drop()
            return -255

        return 1
    def ksr_route_reqinit(self, msg):
        if not KSR.is_myself(KSR.pv.get("$si")) :
            if not KSR.pv.is_null("$sht(ipban=>$si)") :
                # ip is already blocked
                KSR.dbg("request from blocked IP - " + KSR.pv.get("$rm")
                        + " from " + KSR.pv.get("$fu") + " (IP:"
                        + KSR.pv.get("$si") + ":" + str(KSR.pv.get("$sp")) + ")\n");
                return -255;

            if KSR.pike.pike_check_req()<0 :
                KSR.err("ALERT: pike blocking " + KSR.pv.get("$rm")
                        + " from " + KSR.pv.get("$fu") + " (IP:"
                        + KSR.pv.get("$si") + ":" + str(KSR.pv.get("$sp")) + ")\n");
                KSR.pv.seti("$sht(ipban=>$si)", 1);
                return -255;

        if KSR.corex.has_user_agent() > 0 :
            ua = KSR.pv.gete("$ua")
            if (ua.find("friendly-scanner")!=-1
                    or ua.find("sipcli")!=-1) :
                KSR.sl.sl_send_reply(200, "Processed");
                return -255;

        if KSR.maxfwd.process_maxfwd(10) < 0 :
            KSR.sl.sl_send_reply(483,"Too Many Hops");
            return -255;

        if (KSR.is_OPTIONS()
                and KSR.is_myself_ruri()
                and KSR.corex.has_ruri_user() < 0) :
            KSR.sl.sl_send_reply(200,"Keepalive");
            return -255;

        if KSR.sanity.sanity_check(1511, 7)<0 :
            KSR.err("Malformed SIP message from "
                    + KSR.pv.get("$si") + ":" + str(KSR.pv.get("$sp")) +"\n");
            return -255;
Example #6
0
    def ksr_route_reqinit(self, msg):
        if not KSR.is_myself(KSR.pv.get("$si")) :
            if not KSR.pv.is_null("$sht(ipban=>$si)") :
                # ip is already blocked
                KSR.dbg("request from blocked IP - " + KSR.pv.get("$rm")
                        + " from " + KSR.pv.get("$fu") + " (IP:"
                        + KSR.pv.get("$si") + ":" + str(KSR.pv.get("$sp")) + ")\n")
                return -255

            if KSR.pike.pike_check_req()<0 :
                KSR.err("ALERT: pike blocking " + KSR.pv.get("$rm")
                        + " from " + KSR.pv.get("$fu") + " (IP:"
                        + KSR.pv.get("$si") + ":" + str(KSR.pv.get("$sp")) + ")\n")
                KSR.pv.seti("$sht(ipban=>$si)", 1)
                return -255

        if KSR.corex.has_user_agent() > 0 :
            ua = KSR.pv.gete("$ua")
            if (ua.find("friendly")!=-1 or ua.find("scanner")!=-1
                    or ua.find("sipcli")!=-1 or ua.find("sipvicious")!=-1) :
                KSR.sl.sl_send_reply(200, "Processed")
                return -255

        if KSR.maxfwd.process_maxfwd(10) < 0 :
            KSR.sl.sl_send_reply(483,"Too Many Hops")
            return -255

        if (KSR.is_OPTIONS()
                and KSR.is_myself_ruri()
                and KSR.corex.has_ruri_user() < 0) :
            KSR.sl.sl_send_reply(200,"Keepalive")
            return -255

        if KSR.sanity.sanity_check(17895, 7)<0 :
            KSR.err("Malformed SIP message from "
                    + KSR.pv.get("$si") + ":" + str(KSR.pv.get("$sp")) +"\n")
            return -255
Example #7
0
    def ksr_request_route(self, msg):

        KSR.dbg("method " + KSR.pv.get("$rm") + " r-uri " + KSR.pv.get("$ru"))

        if KSR.is_method("REGISTER"):
            KSR.sl.send_reply(200, "OK")

        elif KSR.is_method("INVITE"):
            #Lookup our public IP address
            try:
                ip = requests.get('https://api.ipify.org').text
            except:
                ip = "Failed to resolve"

            #Add that as a header
            KSR.hdr.append("X-KEMI: I came from KEMI at " + str(ip) + "\r\n")

            #Set host IP to 10.1.1.1
            KSR.sethost("10.1.1.1")

            #Forward the request on
            KSR.forward()
        else:
            KSR.sl.send_reply(500, "Got no idea...")
Example #8
0
 def ksr_branch_manage(self, msg):
     KSR.dbg("new branch ["+ str(KSR.pv.get("$T_branch_idx"))
                 + "] to "+ KSR.pv.get("$ru") + "\n");
     self.ksr_route_natmanage(msg);
     return 1;
 def ksr_branch_manage(self, msg):
     KSR.dbg("new branch ["+ str(KSR.pv.get("$T_branch_idx"))
                 + " to "+ KSR.pv.get("$ru") + "\n");
     self.ksr_route_natmanage(msg);
     return 1;