Пример #1
0
def redirection(config, listeners):
    """Setup port forwarding and redirection for the given listeners/config.
    """
    if not Redirector.available():
        log.warn("Connection redirection enabled but not available. "
                     "Ensure 'iptables' is installed and current user has sufficient privileges.")
        return
    
    if Redirector.existing_rules():
        log.warn("Existing rules found in iptables. Not enabling connection redirection in case of conflict.")
        return
    
    redir = Redirector()
    # pass through all listener ports
    for listener in [ x for x in listeners if x.socktype in ['SSL', 'TCP'] ]:
        redir.add_forwarding("tcp", listener.ports)
    # pass through any explicitly excluded ports
    exclusions = list(parseints(config.cfg.get("redirection", "port_exclusions")))
    if exclusions:
        redir.add_forwarding("tcp", exclusions)
    # forward all other ports to generic listener
    generic = config.cfg.get("redirection", "port_forwarding")
    if generic:
        redir.add_forwarding("tcp", outport=generic)
    # forward all protocols to local address
    redir.add_forwarding()
Пример #2
0
def redirection(config, listeners):
    """Setup port forwarding and redirection for the given listeners/config.
    """
    if not Redirector.available():
        log.warn(
            "Connection redirection enabled but not available. "
            "Ensure 'iptables' is installed and current user has sufficient privileges."
        )
        return

    if Redirector.existing_rules():
        log.warn(
            "Existing rules found in iptables. Not enabling connection redirection in case of conflict."
        )
        return

    redir = Redirector()
    # pass through all listener ports
    for listener in [x for x in listeners if x.socktype in ['SSL', 'TCP']]:
        redir.add_forwarding("tcp", listener.ports)
    # pass through any explicitly excluded ports
    exclusions = list(
        parseints(config.cfg.get("redirection", "port_exclusions")))
    if exclusions:
        redir.add_forwarding("tcp", exclusions)
    # forward all other ports to generic listener
    generic = config.cfg.get("redirection", "port_forwarding")
    if generic:
        redir.add_forwarding("tcp", outport=generic)
    # forward all protocols to local address
    redir.add_forwarding()
Пример #3
0
def test_intlist():
    assert [] == list(parseints(''))
    assert [1] == list(parseints('1'))
    assert [1] == list(parseints(' 1 '))
    assert [1, 2, 3] == list(parseints('1,2,3'))
    assert [5, 6, 7, 8] == list(parseints('5-8'))
    assert [2, 3, 4, 5, 7, 8, 9, 10] == list(parseints(' 2, 3,4,5- 5 ,7-9,10'))
    assert [0] == list(parseints('0'))
    assert [1100, 1101, 1102, 1103] == list(parseints('1100-1103'))
Пример #4
0
def test_intlist():
    assert [] == list(parseints(''))
    assert [1] == list(parseints('1'))
    assert [1] == list(parseints(' 1 '))
    assert [1, 2, 3] == list(parseints('1,2,3'))
    assert [5, 6, 7, 8] == list(parseints('5-8'))
    assert [2, 3, 4, 5, 7, 8, 9, 10] == list(parseints(' 2, 3,4,5- 5 ,7-9,10'))
    assert [0] == list(parseints('0'))
    assert [1100, 1101, 1102, 1103] == list(parseints('1100-1103'))
    
Пример #5
0
 def config(self, config):
     self.dirseed = config.get('ftp', 'dirseed')
     PyFTPHandler.banner = config.get('ftp', 'serverstring')
     PyFTPHandler.passive_ports = list(parseints(config.get('ftp', 'pasvrange')))