{"id":78,"date":"2023-03-09T15:46:21","date_gmt":"2023-03-09T13:46:21","guid":{"rendered":"https:\/\/dilyan.be\/?p=78"},"modified":"2023-03-31T10:28:59","modified_gmt":"2023-03-31T08:28:59","slug":"firewall-rules-on-openbsd-security-bastion","status":"publish","type":"post","link":"https:\/\/dilyan.be\/?p=78","title":{"rendered":"Firewall rules on OpenBSD security bastion"},"content":{"rendered":"<p>The setup is like that:<\/p>\n<p>Internet (public IP) &#8212; ISP router &#8212; FreeBSD 13.1 host &#8212; OpenBSD 7.2 virtual machine<\/p>\n<p>the OpenBSD is running a) ssh server with Yubikey authorization, b) Wireguard VPN server, c) L2TP VPN as a back-up on the Wireguard. The ISP router is forwarding ports tcp 22 (ssh), tcp 443 (Wireguard), udp 400 and 4500 for the L2TP VPN to the OpenBSD address directly.<\/p>\n<p>The pf.conf rules to make this setup work:<\/p>\n<p>[root@openbsd dilyan]$ cat \/etc\/pf.conf<br \/>\nset block-policy return<br \/>\nset limit table-entries 400000 #due to pfbadhost<br \/>\nset skip on lo<br \/>\next_if = &#8220;vio0&#8221;<br \/>\nvpn_if = &#8220;pppx&#8221;<br \/>\nvpn_net = &#8220;10.0.0.0\/24&#8221;<br \/>\nhome_net = &#8220;192.168.0.0\/24&#8221; #home network thru VPN<br \/>\noffice_net = &#8220;192.168.1.0\/24&#8221; # office network<br \/>\ntable &lt;bruteforce&gt; persist #table for ssh-attackers<br \/>\ntable &lt;pfbadhost&gt; persist file &#8220;\/etc\/pf-badhost.txt&#8221;<\/p>\n<p>antispoof for { $ext_if, $vpn_if }<br \/>\nmatch in all scrub (no-df random-id )<\/p>\n<p>block return # block stateless traffic<br \/>\nblock quick from &lt;bruteforce&gt; #block the ssh-attackers<br \/>\nblock in quick on egress from &lt;pfbadhost&gt;<br \/>\nblock out quick on egress to &lt;pfbadhost&gt;<\/p>\n<p># By default, do not permit remote connections to X11<br \/>\nblock return in on ! lo0 proto tcp to port 6000:6010<br \/>\n# Port build user does not need network<br \/>\nblock return out log proto {tcp udp} user _pbuild<br \/>\nblock all<\/p>\n<p>pass # establish keep-state<br \/>\npass inet proto icmp synproxy state #allow ICMP protocol &#8211; all<br \/>\npass proto { tcp, udp } from { wg0:network, $home_net, $vpn_net, $office_net } to port { ssh, domain }<br \/>\npass proto { tcp, udp } to port { ssh, 500, 4500 } keep state (max-src-conn 5, max-src-conn-rate 3\/60, overload &lt;bruteforce&gt; flush global)<br \/>\npass proto udp from {$ext_if, $office_net} to port { 123 } #allow network time protocol (NTP) port<\/p>\n<p># Rule for WireGuard VPN to NAT traffic to public net#<br \/>\nmatch out on $ext_if from wg0:network to any nat-to $ext_if<\/p>\n<p># Rules for L2TP VPN to work and NAT traffic #<br \/>\npass on $ext_if proto esp # allow ESP protocol on public interface<br \/>\npass on $ext_if proto udp to port { isakmp, ipsec-nat-t } # allow isakmpd UDP traffic through the public interface on ports 500 and 4500<br \/>\npass on enc0 keep state (if-bound) # filter all IPSec traffic on the enc interface<br \/>\npass on $vpn_if from { $vpn_net, $home_net } # allow all trafic in on and out to the VPN network<br \/>\npass on $vpn_if to { $vpn_net, $home_net }<br \/>\nmatch out on $ext_if from $vpn_net to any nat-to $ext_if # nat VPN traffic going out on the public interface with the public IP<\/p>\n<p>These rules will _not_ work on FreeBSD, as their implementation requires grouping the rules in particular order &#8211; Macros, Tables, Options, Normalization, NAT\/Redirections and then Filtering (i.e. you need to rearrange the rules).<\/p>\n<p>Once you open port 22 for ssh service on a public IP address, attackers will start attempts like ~17-20k tries per day. This is why I implemented the table, so an IP that tries to guess a username\/password more than 3 times per 60 minutes to be blocked for a day. This reduced the attacks to less than 12k per day. Then I followed this how-to https:\/\/geoghegan.ca\/pfbadhost.html to block malicious IPs thru the table and the attempts dropped below 9k per day.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The setup is like that: Internet (public IP) &#8212; ISP router &#8212; FreeBSD 13.1 host &#8212; OpenBSD 7.2 virtual machine the OpenBSD is running a) ssh server with Yubikey authorization, b) Wireguard VPN server, c) L2TP VPN as a back-up on the Wireguard. The ISP router is forwarding ports tcp 22 (ssh), tcp 443 (Wireguard), [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,3],"tags":[],"class_list":["post-78","post","type-post","status-publish","format-standard","hentry","category-bsd","category-security"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Firewall rules on OpenBSD security bastion - dilyan.be<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/dilyan.be\/?p=78\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Firewall rules on OpenBSD security bastion - dilyan.be\" \/>\n<meta property=\"og:description\" content=\"The setup is like that: Internet (public IP) &#8212; ISP router &#8212; FreeBSD 13.1 host &#8212; OpenBSD 7.2 virtual machine the OpenBSD is running a) ssh server with Yubikey authorization, b) Wireguard VPN server, c) L2TP VPN as a back-up on the Wireguard. The ISP router is forwarding ports tcp 22 (ssh), tcp 443 (Wireguard), [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/dilyan.be\/?p=78\" \/>\n<meta property=\"og:site_name\" content=\"dilyan.be\" \/>\n<meta property=\"article:published_time\" content=\"2023-03-09T13:46:21+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-03-31T08:28:59+00:00\" \/>\n<meta name=\"author\" content=\"dilyan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"dilyan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/dilyan.be\\\/?p=78#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/dilyan.be\\\/?p=78\"},\"author\":{\"name\":\"dilyan\",\"@id\":\"https:\\\/\\\/dilyan.be\\\/#\\\/schema\\\/person\\\/5d995599960773a9e6162910b0fb6c6d\"},\"headline\":\"Firewall rules on OpenBSD security bastion\",\"datePublished\":\"2023-03-09T13:46:21+00:00\",\"dateModified\":\"2023-03-31T08:28:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/dilyan.be\\\/?p=78\"},\"wordCount\":533,\"articleSection\":[\"BSD\",\"Security\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/dilyan.be\\\/?p=78\",\"url\":\"https:\\\/\\\/dilyan.be\\\/?p=78\",\"name\":\"Firewall rules on OpenBSD security bastion - dilyan.be\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/dilyan.be\\\/#website\"},\"datePublished\":\"2023-03-09T13:46:21+00:00\",\"dateModified\":\"2023-03-31T08:28:59+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/dilyan.be\\\/#\\\/schema\\\/person\\\/5d995599960773a9e6162910b0fb6c6d\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/dilyan.be\\\/?p=78#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/dilyan.be\\\/?p=78\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/dilyan.be\\\/?p=78#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/dilyan.be\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Firewall rules on OpenBSD security bastion\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/dilyan.be\\\/#website\",\"url\":\"https:\\\/\\\/dilyan.be\\\/\",\"name\":\"dilyan.be\",\"description\":\"Dilyan Berkovski&#039;s site\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/dilyan.be\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/dilyan.be\\\/#\\\/schema\\\/person\\\/5d995599960773a9e6162910b0fb6c6d\",\"name\":\"dilyan\",\"sameAs\":[\"https:\\\/\\\/dilyan.be\"],\"url\":\"https:\\\/\\\/dilyan.be\\\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Firewall rules on OpenBSD security bastion - dilyan.be","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/dilyan.be\/?p=78","og_locale":"en_US","og_type":"article","og_title":"Firewall rules on OpenBSD security bastion - dilyan.be","og_description":"The setup is like that: Internet (public IP) &#8212; ISP router &#8212; FreeBSD 13.1 host &#8212; OpenBSD 7.2 virtual machine the OpenBSD is running a) ssh server with Yubikey authorization, b) Wireguard VPN server, c) L2TP VPN as a back-up on the Wireguard. The ISP router is forwarding ports tcp 22 (ssh), tcp 443 (Wireguard), [&hellip;]","og_url":"https:\/\/dilyan.be\/?p=78","og_site_name":"dilyan.be","article_published_time":"2023-03-09T13:46:21+00:00","article_modified_time":"2023-03-31T08:28:59+00:00","author":"dilyan","twitter_card":"summary_large_image","twitter_misc":{"Written by":"dilyan","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/dilyan.be\/?p=78#article","isPartOf":{"@id":"https:\/\/dilyan.be\/?p=78"},"author":{"name":"dilyan","@id":"https:\/\/dilyan.be\/#\/schema\/person\/5d995599960773a9e6162910b0fb6c6d"},"headline":"Firewall rules on OpenBSD security bastion","datePublished":"2023-03-09T13:46:21+00:00","dateModified":"2023-03-31T08:28:59+00:00","mainEntityOfPage":{"@id":"https:\/\/dilyan.be\/?p=78"},"wordCount":533,"articleSection":["BSD","Security"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/dilyan.be\/?p=78","url":"https:\/\/dilyan.be\/?p=78","name":"Firewall rules on OpenBSD security bastion - dilyan.be","isPartOf":{"@id":"https:\/\/dilyan.be\/#website"},"datePublished":"2023-03-09T13:46:21+00:00","dateModified":"2023-03-31T08:28:59+00:00","author":{"@id":"https:\/\/dilyan.be\/#\/schema\/person\/5d995599960773a9e6162910b0fb6c6d"},"breadcrumb":{"@id":"https:\/\/dilyan.be\/?p=78#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/dilyan.be\/?p=78"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/dilyan.be\/?p=78#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/dilyan.be\/"},{"@type":"ListItem","position":2,"name":"Firewall rules on OpenBSD security bastion"}]},{"@type":"WebSite","@id":"https:\/\/dilyan.be\/#website","url":"https:\/\/dilyan.be\/","name":"dilyan.be","description":"Dilyan Berkovski&#039;s site","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/dilyan.be\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/dilyan.be\/#\/schema\/person\/5d995599960773a9e6162910b0fb6c6d","name":"dilyan","sameAs":["https:\/\/dilyan.be"],"url":"https:\/\/dilyan.be\/?author=1"}]}},"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dilyan.be\/index.php?rest_route=\/wp\/v2\/posts\/78","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dilyan.be\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dilyan.be\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dilyan.be\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dilyan.be\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=78"}],"version-history":[{"count":3,"href":"https:\/\/dilyan.be\/index.php?rest_route=\/wp\/v2\/posts\/78\/revisions"}],"predecessor-version":[{"id":83,"href":"https:\/\/dilyan.be\/index.php?rest_route=\/wp\/v2\/posts\/78\/revisions\/83"}],"wp:attachment":[{"href":"https:\/\/dilyan.be\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=78"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dilyan.be\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=78"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dilyan.be\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=78"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}