Пример #1
0
    def testTCPService(self):

        result = TCPService.create('api-tcpservice',
                                   5000,
                                   5005,
                                   comment='blahcomment')
        self.assertTrue(result.href.startswith('http'))

        service = TCPService('api-tcpservice')
        self.assertEqual(service.min_dst_port, 5000)
        self.assertEqual(service.max_dst_port, 5005)
        service.delete()
Пример #2
0
    def testServiceGroup(self):
        """ Test service group creation """
        result = TCPService.create('api-tcp', 5000)
        self.assertTrue(result.href.startswith('http'))

        result = UDPService.create('api-udp', 5001)
        self.assertTrue(result.href.startswith('http'))

        tcp = TCPService('api-tcp')
        udp = UDPService('api-udp')
        result = ServiceGroup.create('api-servicegroup',
                                     members=[tcp.href, udp.href],
                                     comment='test')
        self.assertTrue(result.href.startswith('http'))

        group = ServiceGroup('api-servicegroup')
        # Href in service group
        self.assertIn(tcp.href, group.element)
        self.assertIn(udp.href, group.element)

        group.delete()
        tcp.delete()
        udp.delete()
Пример #3
0
    session.login(url=SMC_URL,
                  api_key=API_KEY,
                  verify=False,
                  timeout=120,
                  api_version=API_VERSION)
    print("session OK")

try:
    # check for all engines
    engine_list = list(Engine.objects.all())

    # Create a match_expression
    me = MatchExpression.create(name='mymatch',
                                service=ApplicationSituation('FTP'),
                                service_ports=TCPService('Any TCP Service'))

    # Get Name for first match_expression
    name = MatchExpression.objects.iterator().first().name

    # Get by name
    print("Retrieve {} by name..".format(name))
    match_expression = MatchExpression.get(name)
    print("match_expression={}".format(match_expression))

    # Get by filter
    print("Retrieve {} by filter..".format(name))
    it = MatchExpression.objects.iterator()
    query1 = it.filter(name)
    if query1.exists():
        print("match_expression={}".format(list(query1.all())))
        session.login(url=URLSMC, api_key=APIKEYSMC, verify=False, timeout=120)
    except BaseException as exception_retournee:
        sys.exit(-1)

    print("session OK")

# Create a Sub Policy
p = FirewallSubPolicy()
p.create("mySubPolicy1")

# add rule to a Sub Policy
p = FirewallSubPolicy('mySubPolicy1')
p.fw_ipv4_access_rules.create(name='newule',
                              sources='any',
                              destinations='any',
                              services=[TCPService('SSH')],
                              action='discard')

print(list(FirewallSubPolicy.objects.all()))

# Create a IPv6 Sub Policy
p = FirewallIPv6SubPolicy()
p.create("myIPv6SubPolicy1")

# add rule to a IPv6 Sub Policy
p = FirewallIPv6SubPolicy('myIPv6SubPolicy1')
p.fw_ipv6_access_rules.create(name='newule',
                              sources='any',
                              destinations='any',
                              services=[TCPService('SSH')],
                              action='discard')
Пример #5
0
    list_vpn = []
    for vpn in vpns:
        print(vpn)
        list_vpn.append(vpn.href)

    sourceVpn = SourceVpn()
    sourceVpn.match_type = "normal"
    sourceVpn.match_vpns = list_vpn

    # add rule to a Policy
    p = FirewallPolicy("myPolicy1")
    p.fw_ipv4_access_rules.create(
        name="newule",
        sources="any",
        destinations="any",
        services=[TCPService("SSH")],
        action="discard",
        match_vpn_options=sourceVpn,
    )

    # add rule without match_vpn_options to a Policy
    p.fw_ipv4_access_rules.create(
        name="newule",
        sources="any",
        destinations="any",
        services=[TCPService("SSH")],
        action="discard",
    )

    # Display SourceVpn for rules
    for rule in p.fw_ipv4_access_rules.all():
Пример #6
0
 def test_tcp_service_with_protocol_agent(self):
     result = TCPService('HTTP')
     self.assertIsInstance(result.protocol_agent, Protocol)
Пример #7
0
Host.create(name=cnameNAT, address=NATIP, comment='Erstellt via Script')

#################
#Network IPv6 Element erstellen
#################

Network.create(name=cnameV6, ipv6_network=IPV6Network, comment='Erstellt via Script')

#################
#IPv6 Sub Policy erstellen
#################

p = FirewallIPv6SubPolicy.create(name=cnameV6)
p.fw_ipv6_access_rules.create_rule_section(name='Outbound')
p.fw_ipv6_access_rules.create(name='Default Outgoing', sources=[Network(cnameV6)], destinations='any', services=[TCPService('SSH'), TCPService('HTTP'), TCPService('HTTPS'), UDPService('NTP (UDP)'), ServiceGroup('DNS')], action='allow', after='Outbound')
p.fw_ipv6_access_rules.create_rule_section(name='Inbound', add_pos=30)

#################
#IPv4 Sub Policy erstellen
#################

q = FirewallSubPolicy.create(name=cnameV4)
q.fw_ipv4_access_rules.create_rule_section(name='Outbound')
q.fw_ipv4_access_rules.create(name='Default Outgoing', sources=[Host(cnameNAT)], destinations='any', services=[TCPService('SSH'), TCPService('HTTP'), TCPService('HTTPS'), UDPService('NTP (UDP)'), ServiceGroup('DNS')], action='allow', after='Outbound')
q.fw_ipv4_access_rules.create_rule_section(name='Inbound', add_pos=30)

#################
#Jump Points einfügen
#Zur vorsicht in die nicht genutzt Policy "Zweite Policy für Firewall XY"
#################