Skip to content

Commit

Permalink
ポートスキャン対策はINPUTチェーンでやる
Browse files Browse the repository at this point in the history
  • Loading branch information
nexryai committed Jun 11, 2024
1 parent a799b1b commit f868b22
Showing 1 changed file with 33 additions and 32 deletions.
65 changes: 33 additions & 32 deletions internal/render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,20 @@ func GenRulesFromConfig(cfg *config.Config) []string {
MkBaseInputRules(true, true, false),
MkAllowLoopbackInterface())

var alwaysDenyIP []string
alwaysDenyIP = append(alwaysDenyIP, cfg.Security.AlwaysDenyIP...)
// 不正なパケットとポートスキャンをブロック
rules = append(rules, MkDropInvalid())
if !cfg.Security.DisablePortScanProtection {
rules = append(rules, MkBlockTcpXmas(), MkBlockTcpNull(), MkBlockTcpMss())
} else {
log.MsgWarn("Port scan protection is DISABLED!")
}

if !cfg.Security.DisableIpFragmentsBlock {
rules = append(rules, MkBlockIPFragments())
}

// AlwaysDenyIPとAlwaysDenyASNのCIDRを格納する
alwaysDenyIP := cfg.Security.AlwaysDenyIP

// alwaysDenyASNをIPのCIDRに変換
for _, denyASN := range cfg.Security.AlwaysDenyASN {
Expand Down Expand Up @@ -314,42 +326,31 @@ func GenRulesFromConfig(cfg *config.Config) []string {
}

// PREROUTINGチェーン
rules = append(rules, MkChainStart("prerouting"))

if cfg.Router.ConfigAsRouter {
rules = append(rules, MkBaseRoutingRule("prerouting"))
} else if len(cfg.Nat) != 0 {
rules = append(rules, MkBaseNatRule())
}

// 不正なパケットととりあえず全部弾くべき攻撃を遮断
// inputチェーンよりpreroutingの方が優先されるのでここに入れる
rules = append(rules, MkDropInvalid())
if !cfg.Security.DisablePortScanProtection {
rules = append(rules, MkBlockTcpXmas(), MkBlockTcpNull(), MkBlockTcpMss())
} else {
log.MsgWarn("Port scan protection is DISABLED!")
}
if cfg.Router.ConfigAsRouter || len(cfg.Nat) != 0 {
rules = append(rules, MkChainStart("prerouting"))

if !cfg.Security.DisableIpFragmentsBlock {
rules = append(rules, MkBlockIPFragments())
}
if cfg.Router.ConfigAsRouter {
rules = append(rules, MkBaseRoutingRule("prerouting"))
} else if len(cfg.Nat) != 0 {
rules = append(rules, MkBaseNatRule())
}

if cfg.Router.ForceDNS != "" {
for _, lanInterface := range cfg.Router.LANInterfaces {
rules = append(rules, MkForceDNS(cfg.Router.ForceDNS, lanInterface, "udp"))
rules = append(rules, MkForceDNS(cfg.Router.ForceDNS, lanInterface, "tcp"))
if cfg.Router.ForceDNS != "" {
for _, lanInterface := range cfg.Router.LANInterfaces {
rules = append(rules, MkForceDNS(cfg.Router.ForceDNS, lanInterface, "udp"))
rules = append(rules, MkForceDNS(cfg.Router.ForceDNS, lanInterface, "tcp"))
}
}
}

// ポート転送有効時のNAT構成
if len(cfg.Nat) != 0 {
for _, r := range cfg.Nat {
rules = append(rules, MkNat(&r))
// ポート転送有効時のNAT構成
if len(cfg.Nat) != 0 {
for _, r := range cfg.Nat {
rules = append(rules, MkNat(&r))
}
}
}

rules = append(rules, MkChainEnd())
rules = append(rules, MkChainEnd())
}

// SYN-flood対策
rules = append(rules, MkChainStart("syn-flood"),
Expand Down

0 comments on commit f868b22

Please sign in to comment.