Esempio n. 1
0
    def cleanup(self):
        '''This doesn't flush the whole set of rules. It just removes any lingering test suite rules
        '''
        from xv_leak_tools.network.macos.pf_firewall import PFCtl
        if self._pfctl is None:
            self._pfctl = PFCtl()

        self._pfctl.cleanup()
Esempio n. 2
0
    def block_ip(self, ip):
        from xv_leak_tools.network.macos.pf_firewall import PFCtl
        L.info("Adding outgoing IP block for {}".format(ip))

        # Delay initialize the PFCtl object to prevent VPN application connect from removing our
        # reference to the pf firewall. Some VPN apps take full ownership of the firewall which can
        # mean that the firewall will be disabled unless we initialize here.
        if self._pfctl is None:
            self._pfctl = PFCtl()

        self._current_rules += MacOSFirewall._block_ip_rules(ip)
        self._pfctl.set_rules(self._current_rules)
Esempio n. 3
0
    def block_ip(self, ip):
        from xv_leak_tools.network.macos.pf_firewall import PFCtl

        # Delay initialize the PFCtl object to prevent VPN application connect from removing our
        # reference to the pf firewall. Some VPN apps take full ownership of the firewall which can
        # mean that the firewall will be disabled unless we initialize here.
        self._pfctl = PFCtl()
        L.info("Adding outgoing IP block for {}".format(ip))
        self._pfctl.set_leak_test_rules([
            "block in quick from {} no state".format(ip),
            "block out quick to {} no state".format(ip)
        ])
def punch_hole_in_firewall(ips):
    if current_os() == 'macos':
        pf = PFCtl()
        ip_list = '{ ' + ', '.join(ips) + ' }'
        pf.set_rules([
            "pass in quick from {} no state".format(ip_list),
            "pass out quick to {} no state".format(ip_list)
        ])
    elif current_os() == 'windows':
        L.warning(
            "Ignoring option to open up firewall for {} on Windows".format(
                ', '.join(ips)))
    else:
        raise XVEx('Editing the firewall is only supported for PF/macOS')
Esempio n. 5
0
class MacOSFirewall(Firewall):
    def __init__(self, device, config):
        super().__init__(device, config)
        self._pfctl = None

    def block_ip(self, ip):
        from xv_leak_tools.network.macos.pf_firewall import PFCtl

        # Delay initialize the PFCtl object to prevent VPN application connect from removing our
        # reference to the pf firewall. Some VPN apps take full ownership of the firewall which can
        # mean that the firewall will be disabled unless we initialize here.
        self._pfctl = PFCtl()
        L.info("Adding outgoing IP block for {}".format(ip))
        self._pfctl.set_leak_test_rules([
            "block in quick from {} no state".format(ip),
            "block out quick to {} no state".format(ip)
        ])

    def unblock_ip(self):
        if self._pfctl is not None:
            self._pfctl.clear_leak_test_rules()
Esempio n. 6
0
class MacOSFirewall(Firewall):
    def __init__(self, device, config):
        super().__init__(device, config)
        self._pfctl = None
        self._current_rules = []

    @staticmethod
    def _block_ip_rules(ip):
        return [
            "block in quick from {} no state".format(ip),
            "block out quick to {} no state".format(ip)
        ]

    def block_ip(self, ip):
        from xv_leak_tools.network.macos.pf_firewall import PFCtl
        L.info("Adding outgoing IP block for {}".format(ip))

        # Delay initialize the PFCtl object to prevent VPN application connect from removing our
        # reference to the pf firewall. Some VPN apps take full ownership of the firewall which can
        # mean that the firewall will be disabled unless we initialize here.
        if self._pfctl == None:
            self._pfctl = PFCtl()

        self._current_rules += MacOSFirewall._block_ip_rules(ip)
        self._pfctl.set_rules(self._current_rules)

    def unblock_ip(self, ip):
        if self._pfctl is None:
            return

        rules_to_remove = self._block_ip_rules(ip)
        for rule_to_remove in rules_to_remove:
            self._current_rules = [
                rule for rule in self._current_rules if rule != rule_to_remove
            ]
        self._pfctl.set_rules(self._current_rules)