This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
ddos:flowspec [2019/07/25 11:05] rb |
ddos:flowspec [2020/07/30 10:12] (current) rb ↷ Page moved and renamed from ddos-flowspec to ddos:flowspec |
||
---|---|---|---|
Line 5: | Line 5: | ||
Правила для фильтрации: | Правила для фильтрации: | ||
- | * destination | + | * Destination |
- | * source | + | * Source |
- | * IP protocols | + | * IP protocols |
- | * TCP/UDP ports (список исходящих портов или портов на которые защищать) | + | * Source or Destination port |
+ | * Destination port | ||
+ | * Source port | ||
* ICMP Type | * ICMP Type | ||
* ICMP Code | * ICMP Code | ||
* TCP Flags | * TCP Flags | ||
* Packet Length | * Packet Length | ||
- | * Diffserv Codepoint | + | * DSCP |
- | * Fragmentation | + | * Fragment encoding |
Действия которые можем применять: | Действия которые можем применять: | ||
- | * Rate Limit | + | * traffic-rate (0 for drop) |
- | * Traffic-Action | + | * Traffic-Action |
- | * Redirect | + | * Redirect |
- | * Traffic-Marking | + | * Traffic-Marking |
==== Пример настройки на Juniper ==== | ==== Пример настройки на Juniper ==== | ||
Line 39: | Line 42: | ||
< | < | ||
firewall-install-disable | firewall-install-disable | ||
+ | </ | ||
+ | |||
+ | Создаем policy-option для принятия нужного правила | ||
+ | |||
+ | < | ||
+ | set policy-options policy-statement p1 term a from rib inetflow.0 | ||
+ | set policy-options policy-statement p1 term a from route-filter 10.13.0.0/ | ||
+ | set policy-options policy-statement p1 term a then accept | ||
+ | set policy-options policy-statement p1 term b then reject | ||
</ | </ | ||
Line 46: | Line 58: | ||
set protocol bgp group TestFlowBgp neighbor 111.222.333.444 family inet unicast | set protocol bgp group TestFlowBgp neighbor 111.222.333.444 family inet unicast | ||
set protocol bgp group TestFlowBgp neighbor 111.222.333.444 family inet flow | set protocol bgp group TestFlowBgp neighbor 111.222.333.444 family inet flow | ||
+ | set protocol bgp group TestFlowBgp neighbor 111.222.333.444 export p1 | ||
+ | </ | ||
+ | |||
+ | Проверить список правил которые мы добавили в FlowSpec | ||
+ | |||
+ | < | ||
+ | show route table inetflow.0 detail | ||
+ | </ | ||
+ | |||
+ | Посмотреть нагрузку на FPC картах | ||
+ | |||
+ | < | ||
+ | show system resource-monitor fpc | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== Пример автоматизации с PyEZ ==== | ||
+ | |||
+ | set-flow-routes.py | ||
+ | |||
+ | < | ||
+ | # $Id$ | ||
+ | # Simple Python script using YAML and Junos PyEz | ||
+ | # to configure local flow routes as per template | ||
+ | |||
+ | from jnpr.junos.utils.config import Configfrom | ||
+ | jnpr.junos import Device | ||
+ | from pprint import pprint | ||
+ | from jnpr.junos.factory import loadyaml | ||
+ | from jnpr.junos.op import * | ||
+ | |||
+ | import yaml | ||
+ | import sys | ||
+ | |||
+ | from glob import glob | ||
+ | from jinja2 import Template | ||
+ | |||
+ | # YAML file. | ||
+ | with open(glob(' | ||
+ | data = yaml.load(fh.read()) | ||
+ | |||
+ | # Jinja2 template file. | ||
+ | with open(glob(' | ||
+ | t_format = t_fh.read() | ||
+ | |||
+ | routesnippet = Template(t_format) | ||
+ | print (routesnippet.render(data)) | ||
+ | </ | ||
+ | |||
+ | Set-flow-routes.py (contd) | ||
+ | |||
+ | < | ||
+ | # Open netconf connection with RR | ||
+ | dev = Device(host=' | ||
+ | dev.open() | ||
+ | |||
+ | # Bind and lock configuration and load it | ||
+ | dev.bind(cfg=Config) | ||
+ | dev.cfg.lock() | ||
+ | dev.cfg.load(template_path=' | ||
+ | |||
+ | # Commit and unlock | ||
+ | dev.cfg.commit() | ||
+ | dev.cfg.unlock() | ||
+ | |||
+ | # Close netconf connection | ||
+ | dev.close() | ||
+ | </ | ||
+ | |||
+ | Set-flow-route.yml | ||
+ | |||
+ | < | ||
+ | --- | ||
+ | # $Id$ | ||
+ | # YAML file covering all possible variables | ||
+ | |||
+ | # Name of flow route | ||
+ | flow_route_name: | ||
+ | # Destination prefix and mask in format: A.B.C.D/Z | ||
+ | destination_address_and_mask: | ||
+ | # DSCP in decimal format | ||
+ | dscp: | ||
+ | # Destination port as alias or in decimal format | ||
+ | destination_port: | ||
+ | # Fragment Junos OS knobs | ||
+ | fragment: | ||
+ | # ICMP code as alias or in decimal format | ||
+ | icmp_code: | ||
+ | # ICMP type as alias or in decimal format | ||
+ | icmp_type: | ||
+ | </ | ||
+ | |||
+ | Set-flow-route.yml (contd) | ||
+ | |||
+ | < | ||
+ | # Full L3 length in bytes | ||
+ | packet_length: | ||
+ | # Source or destination port as alias or in decimal format | ||
+ | port: | ||
+ | # Protocol as alias or in decimal format | ||
+ | protocol: udp | ||
+ | # Source prefix and mask in format: A.B.C.D/Z | ||
+ | source_address_and_mask: | ||
+ | # Source port as alias or in decimal format | ||
+ | source_port: | ||
+ | # TCP flags with Junos OS knobs | ||
+ | tcp_flags: | ||
+ | # Include ' | ||
+ | accept: | ||
+ | # Include existing community to be tagged action | ||
+ | community_name: | ||
+ | # Include ' | ||
+ | discard: discard | ||
+ | # Include ' | ||
+ | next_term: | ||
+ | # Include policer name to be applied as action | ||
+ | rate_limit: | ||
+ | # Include existing RT community to select VRF for redirection | ||
+ | redirect_RT: | ||
+ | # Include ' | ||
+ | sample: | ||
+ | </ | ||
+ | |||
+ | set-flow-route.j2 | ||
+ | |||
+ | < | ||
+ | # Flow-route configure via vRR | ||
+ | |||
+ | routing-options { | ||
+ | flow { | ||
+ | route {{flow_route_name}} { | ||
+ | match { | ||
+ | destination {{destination_address_and_mask}}; | ||
+ | {%-if destination_port is defined and destination_port !=None %} | ||
+ | destination-port {{ destination_port }}; | ||
+ | {%-endif %} | ||
+ | {%-if dscp is defined and dscp !=None %} | ||
+ | dscp {{dscp}}; | ||
+ | {%-endif %} | ||
+ | {%-if fragment is defined and fragment !=None %} | ||
+ | fragment {{fragment}}; | ||
+ | {%-endif %} | ||
+ | {%-if icmp_code is defined and icmp_code !=None %} | ||
+ | icmp-code {{icmp_code}}; | ||
+ | {%-endif %} | ||
+ | {%-if icmp_type is defined and icmp_type !=None %} | ||
+ | icmp-type {{icmp_type}}; | ||
+ | {%-endif %} | ||
+ | {%-if packet_length is defined and packet_length !=None %} | ||
+ | packet-length {{packet_length}}; | ||
+ | {%-endif %} | ||
+ | {%-if port is defined and port !=None %} | ||
+ | port {{port}}; | ||
+ | {%-endif %} | ||
+ | {%-if protocol is defined and protocol !=None %} | ||
+ | protocol {{protocol}}; | ||
+ | {%-endif %} | ||
+ | {%-if source_address_and_mask is defined and source_address_and_mask !=None %} | ||
+ | source {{source_address_and_mask}}; | ||
+ | {%-endif %} | ||
+ | {%-if source_port is defined and source_port !=None %} | ||
+ | source-port {{source_port}}; | ||
+ | {%-endif %} | ||
+ | {%-if tcp_flags is defined and tcp_flags !=None %} | ||
+ | tcp-flags {{tcp_flags}}; | ||
+ | {%-endif %} | ||
+ | } | ||
+ | then { | ||
+ | {%-if accept is defined and accept !=None %} | ||
+ | {{accept}}; | ||
+ | {%-endif %} | ||
+ | {%-if community_name is defined and community_name !=None %} | ||
+ | community {{community_name}}; | ||
+ | {%-endif %} | ||
+ | {%-if discard is defined and discard !=None %} | ||
+ | {{discard}}; | ||
+ | {%-endif %} | ||
+ | {%-if next_term is defined and next_term !=None %} | ||
+ | {{next_term}}; | ||
+ | {%-endif %} | ||
+ | {%-if rate_limit is defined and rate_limit !=None %} | ||
+ | rate-limit {{rate_limit}}; | ||
+ | {%-endif %} | ||
+ | {%-if redirect_RT is defined and redirect_RT !=None %} | ||
+ | routing-instance {{redirect_RT}}; | ||
+ | {%-endif %} | ||
+ | {%-if sample is defined and sample !=None %} | ||
+ | {{sample}}; | ||
+ | {%-endif %} | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
</ | </ | ||
Line 54: | Line 259: | ||
=== Advanced community === | === Advanced community === | ||
- | 9002:666 - традиционный blackhole для префикса, | + | 9002:666 - традиционный blackhole для префикса, |
+ | 9002:667 для фильтрации всего udp трафика\\ | ||
+ | 9002:668 фильтрафия известных амплифаеров (source-port 19, | ||
=== Flowspec === | === Flowspec === | ||
Line 61: | Line 268: | ||
* лимит 10 правил | * лимит 10 правил | ||
+ | * destination обязательно, | ||
* best path до этого адреса/ | * best path до этого адреса/ | ||
* в правилах может быть только discard | * в правилах может быть только discard | ||
+ | |||
===== Fiord ===== | ===== Fiord ===== |