initial commit

This commit is contained in:
Krystian Dużyński
2022-11-04 21:20:16 +01:00
commit cb6a0f8d27
31 changed files with 880 additions and 0 deletions

42
example/0_0-initial.rsc Normal file
View File

@@ -0,0 +1,42 @@
/system identity set name="MT"
/interface bridge
add name="bridge"
/interface ethernet
set [ find default-name=sfp1 ] disabled=yes
/interface list
add name=LAN
add name=WAN
/ip address
add address=192.168.1.1/24 interface="bridge"
/interface list member
add interface="bridge" list=LAN
/interface bridge port
add bridge="bridge" interface=ether2
add bridge="bridge" interface=ether3
add bridge="bridge" interface=ether4
add bridge="bridge" interface=ether5
add bridge="bridge" interface=ether6
add bridge="bridge" interface=ether7
add bridge="bridge" interface=ether8
add bridge="bridge" interface=ether9
add bridge="bridge" interface=ether10
/user set admin password="{{ admin_pass }}"
#######################
# SSH
#######################
{{ load_file("host-keys/ssh_host_private_key_dsa", "ssh_host_private_key_dsa.txt") }}
{{ load_file("host-keys/ssh_host_private_key_rsa", "ssh_host_private_key_rsa.txt") }}
/ip ssh import-host-key private-key-file=ssh_host_private_key_dsa.txt
/ip ssh import-host-key private-key-file=ssh_host_private_key_rsa.txt
{{ load_file("~/.ssh/id_rsa.pub", "pcl_id_rsa.pub.txt") }}
/user ssh-keys import user=admin public-key-file=pcl_id_rsa.pub.txt

1
example/0_1-security.rsc Normal file
View File

@@ -0,0 +1 @@
{% include 'security.rsc' %}

1
example/0_2-firewall.rsc Normal file
View File

@@ -0,0 +1 @@
{% include 'firewall_router.rsc' %}

11
example/1-logging.rsc Normal file
View File

@@ -0,0 +1,11 @@
/system logging action remove [find default=no]
/system logging remove [find default=no]
/system logging action
add name=pc2 remote=192.168.1.2 remote-port=1514 target=remote
/system logging
add action=pc2 prefix=MT topics=critical
add action=pc2 prefix=MT topics=error
add action=pc2 prefix=MT topics=warning
add action=pc2 prefix=MT topics=info

13
example/2-ntp.rsc Normal file
View File

@@ -0,0 +1,13 @@
/system ntp client
set enabled=yes primary-ntp=162.159.200.123 secondary-ntp=162.159.200.1
/system ntp server
set enabled=yes
/ip firewall filter
add chain="user-input" action=jump jump-target="user-input-ntp" comment="NTP rules"
add chain="user-input-ntp" \
action=accept \
in-interface-list=LAN protocol=udp dst-port=123 \
comment="accept NTP (LAN)"
{{ rollback_delete_chain("user-input-ntp") }}

View File

@@ -0,0 +1,7 @@
/ip firewall nat
add chain="user-dstnat" action=jump jump-target="user-dstnat-port-forwarding" comment="port forwarding"
add chain="user-dstnat-port-forwarding" action=dst-nat comment="port forwarding -> HTTP" dst-port=80,443 in-interface=ether1-WAN protocol=tcp to-addresses=192.168.1.2
add chain="user-dstnat-port-forwarding" action=dst-nat comment="port forwarding -> SSH" dst-port=1234 in-interface-list=WAN protocol=tcp to-addresses=192.168.1.2 to-ports=22322
{{ rollback_delete_chain("user-dstnat-port-forwarding") }}

6
example/README.md Normal file
View File

@@ -0,0 +1,6 @@
# Important notes
* These example files are provided **ONLY** as an example of project structure.
Although it contains a lot of solutions from my configuration files,
it is not meant to be used as an example Mikrotik configuration,
* Example generated SSH keys **SHOULD NOT** be used in your project.

View File

@@ -0,0 +1,83 @@
:do {
/ip firewall filter
remove [find chain=input]
remove [find chain=forward action!=passthrough]
remove [find chain=output]
remove [find chain=icmp]
remove [find jump-target="user-input"]
remove [find jump-target="user-forward"]
remove [find jump-target="user-output"]
remove [find chain="core-icmp"]
/ip firewall nat
remove [find chain=srcnat]
remove [find chain=dstnat]
} on-error={}
/ip firewall filter
# INPUT
add chain=input action=accept comment="accept established,related,untracked" connection-state=established,related,untracked
add chain=input action=drop comment="drop connection-state=invalid" connection-state=invalid
add chain=input action=drop comment="drop banned" src-address-list=bans
add chain=input action=jump comment="check ICMP" jump-target="core-icmp" protocol=icmp
add chain=input action=accept comment="accept SSH and HTTP (LAN only)" in-interface-list=LAN protocol=tcp dst-port=22,80
add chain=input action=accept comment="accept WinBox and API (LAN only)" in-interface-list=LAN protocol=tcp dst-port=8291,8728
add chain=input action=accept comment="accept DNS and DHCP (LAN only)" in-interface-list=LAN protocol=udp dst-port=53,67,68
# add chain=input action=accept comment="accept to local loopback (for CAPsMAN)" dst-address=127.0.0.1
add chain=input action=jump jump-target="user-input" comment="forward to user-input"
add chain=input action=drop comment="drop all not coming from LAN" in-interface-list=!LAN
add chain=input action=drop comment="drop all other"
# FORWARD
add chain=forward action=fasttrack-connection comment="fasttrack" connection-state=established,related
add chain=forward action=accept comment="accept established,related,untracked" connection-state=established,related,untracked
add chain=forward action=drop comment="drop connection-state=invalid" connection-state=invalid
add chain=forward action=drop comment="drop banned" src-address-list=bans
add chain=forward action=jump comment="check ICMP" jump-target="core-icmp" src-address-list=lan in-interface-list=LAN protocol=icmp
add chain=forward action=accept comment="accept DSTNATed from WAN to LAN" connection-state=new in-interface-list=WAN out-interface-list=LAN dst-address-list=lan connection-nat-state=dstnat
add chain=forward action=accept comment="accept all from LAN to WAN" connection-state=new in-interface-list=LAN src-address-list=lan out-interface-list=WAN
add chain=forward action=accept comment="accept all between LAN interfaces" connection-state=new in-interface-list=LAN src-address-list=lan out-interface-list=LAN dst-address-list=lan
# add chain=forward action=accept comment="accept in ipsec policy" ipsec-policy=in,ipsec
# add chain=forward action=accept comment="accept out ipsec policy" ipsec-policy=out,ipsec
add chain=forward action=jump jump-target="user-forward" comment="forward to user-forward"
add chain=forward action=drop comment="drop all other"
# OUTPUT
add chain=output action=jump jump-target="user-output" comment="forward to user-output"
add chain="core-icmp" protocol=icmp icmp-options=0:0 action=accept comment="echo reply"
add chain="core-icmp" protocol=icmp icmp-options=3:0 action=accept comment="net unreachable"
add chain="core-icmp" protocol=icmp icmp-options=3:1 action=accept comment="host unreachable"
add chain="core-icmp" protocol=icmp icmp-options=3:4 action=accept comment="host unreachable fragmentation required"
add chain="core-icmp" protocol=icmp icmp-options=8:0 action=accept comment="allow echo request"
add chain="core-icmp" protocol=icmp icmp-options=11:0 action=accept comment="allow time exceed"
add chain="core-icmp" protocol=icmp icmp-options=12:0 action=accept comment="allow parameter bad"
add chain="core-icmp" action=drop comment="deny all other types"
/ip firewall nat
add chain=srcnat action=masquerade comment="masquerade to WAN" ipsec-policy=out,none out-interface-list=WAN
add chain=srcnat action=jump jump-target="user-srcnat" comment="forward to user-srcnat"
add chain=dstnat action=jump jump-target="user-dstnat" comment="forward to user-dstnat"
# Address lists
/ip firewall address-list
add list=bogons address=0.0.0.0/8 comment="Self-Identification [RFC 3330]"
add list=bogons address=127.0.0.0/8 comment="Loopback [RFC 3330]"
add list=bogons address=10.0.0.0/8 comment="Private[RFC 1918] - CLASS A" disabled=no
add list=bogons address=172.16.0.0/12 comment="Private[RFC 1918] - CLASS B" disabled=no
add list=bogons address=192.168.0.0/16 comment="Private[RFC 1918] - CLASS C" disabled=yes
add list=bogons address=169.254.0.0/16 comment="Link Local [RFC 3330]"
add list=bogons address=192.88.99.0/24 comment="6to4 Relay Anycast [RFC 3068]"
add list=bogons address=198.18.0.0/15 comment="NIDB Testing"
add list=bogons address=192.0.2.0/24 comment="Reserved - IANA - TestNet1"
add list=bogons address=198.51.100.0/24 comment="Reserved - IANA - TestNet2"
add list=bogons address=203.0.113.0/24 comment="Reserved - IANA - TestNet3"
add list=bogons address=224.0.0.0/4 comment="MC, Class D, IANA" disabled=no
{% call register_cleanup() %}
/ip firewall address-list remove [find list=bogons]
{% endcall %}

View File

@@ -0,0 +1,59 @@
:do {
/ip firewall filter
remove [find chain=input]
remove [find chain=forward action!=passthrough]
remove [find chain=output]
remove [find chain=icmp]
remove [find jump-target="user-input"]
remove [find jump-target="user-forward"]
remove [find jump-target="user-output"]
remove [find chain="core-icmp"]
/ip firewall nat
remove [find chain=srcnat]
remove [find chain=dstnat]
} on-error={}
/ip firewall filter
# INPUT
add chain=input action=accept comment="accept established,related,untracked" connection-state=established,related,untracked
add chain=input action=drop comment="drop connection-state=invalid" connection-state=invalid
add chain=input action=drop comment="drop banned" src-address-list=bans
add chain=input action=jump comment="check ICMP" jump-target="core-icmp" protocol=icmp
add chain=input action=accept comment="accept SSH and HTTP (LAN only)" in-interface-list=LAN protocol=tcp dst-port=22,80
add chain=input action=accept comment="accept WinBox and API (LAN only)" in-interface-list=LAN protocol=tcp dst-port=8291,8728
# add chain=input action=accept comment="accept to local loopback (for CAPsMAN)" dst-address=127.0.0.1
add chain=input action=jump jump-target="user-input" comment="forward to user-input"
add chain=input action=drop comment="drop all not coming from LAN" in-interface-list=!LAN
add chain=input action=drop comment="drop all other"
# FORWARD
add chain=forward action=jump jump-target="user-forward" comment="forward to user-forward"
add chain=forward action=drop comment="drop all other"
# OUTPUT
add chain=output action=jump jump-target="user-output" comment="forward to user-output"
add chain="core-icmp" protocol=icmp icmp-options=0:0 action=accept comment="echo reply"
add chain="core-icmp" protocol=icmp icmp-options=3:0 action=accept comment="net unreachable"
add chain="core-icmp" protocol=icmp icmp-options=3:1 action=accept comment="host unreachable"
add chain="core-icmp" protocol=icmp icmp-options=3:4 action=accept comment="host unreachable fragmentation required"
add chain="core-icmp" protocol=icmp icmp-options=8:0 action=accept comment="allow echo request"
add chain="core-icmp" protocol=icmp icmp-options=11:0 action=accept comment="allow time exceed"
add chain="core-icmp" protocol=icmp icmp-options=12:0 action=accept comment="allow parameter bad"
add chain="core-icmp" action=drop comment="deny all other types"

View File

@@ -0,0 +1,24 @@
{ :local ver [/system resource get version]; :global vermajor [:pick $ver 0 [:find $ver "."]] }
/ip neighbor discovery-settings set discover-interface-list=none
/ip ipsec policy set 0 disabled=yes
:if ($vermajor = 7) do={ /ipv6 settings set disable-ipv6=yes }
:if ($vermajor = 6) do={ /system package disable ipv6 }
/tool mac-server set allowed-interface-list=none
/tool mac-server mac-winbox set allowed-interface-list=none
/tool mac-server ping set enabled=no
/ip service set api disabled=yes
/ip service set api-ssl disabled=yes
/ip service set ftp disabled=yes
/ip service set telnet disabled=yes
/ip service set winbox disabled=no
/tool bandwidth-server set enabled=no
/ip ssh set strong-crypto=yes host-key-size=4096 forwarding-enabled=both always-allow-password-login=yes
/ip settings set rp-filter={{ rp_filter | default("strict") }} secure-redirects=no tcp-syncookies=yes

9
example/config.yml Normal file
View File

@@ -0,0 +1,9 @@
has_flash: false
host: 192.168.1.1
include_dirs:
- common/
variables:
admin_pass: "pass"

View File

@@ -0,0 +1,9 @@
-----BEGIN PRIVATE KEY-----
MIIBSgIBADCCASsGByqGSM44BAEwggEeAoGBAI3m06Sl+2TgMzx9an3BRwuMD56J
VrrWrTlVdcNYaxgquiv3osjFHs+kEAn8jY+pPFKCM9lpfoTj8FT0qPkKtsZ+LcB9
YrxS4bsW8LGvnQScpZcrqFze4Ec0AF+7vYhP9pBHESlxlgEsOIDZvBsVErS/U7WM
wgnIgrY0e/i2GaJZAhUAi0LIo6w4dKsjKCMN/j6X5/1YKAkCgYA8Hr5VfkCNYbMf
J7amr+SilmkBLuQUn0+pV4FvGdPCa9EY0gxCP+0N82aintU7HfqOqE9pdtwFrbXU
+/GyXJIuNME3y4JAvdFkJ18vAUVM0+7rGQ22BxdwrkBT3DUXV+9xjkYAh+6mpWOf
S6Iyga1TE3nNlHtaP6KgBS7tdlcBxwQWAhRurYPs9TMeP1mlge45J3hbBO4Jbg==
-----END PRIVATE KEY-----

View File

@@ -0,0 +1 @@
ssh-dss AAAAB3NzaC1kc3MAAACBAI3m06Sl+2TgMzx9an3BRwuMD56JVrrWrTlVdcNYaxgquiv3osjFHs+kEAn8jY+pPFKCM9lpfoTj8FT0qPkKtsZ+LcB9YrxS4bsW8LGvnQScpZcrqFze4Ec0AF+7vYhP9pBHESlxlgEsOIDZvBsVErS/U7WMwgnIgrY0e/i2GaJZAAAAFQCLQsijrDh0qyMoIw3+Ppfn/VgoCQAAAIA8Hr5VfkCNYbMfJ7amr+SilmkBLuQUn0+pV4FvGdPCa9EY0gxCP+0N82aintU7HfqOqE9pdtwFrbXU+/GyXJIuNME3y4JAvdFkJ18vAUVM0+7rGQ22BxdwrkBT3DUXV+9xjkYAh+6mpWOfS6Iyga1TE3nNlHtaP6KgBS7tdlcBxwAAAIBFHqQTevlpTRONMZ40oxL4/DOz8If1ja7WTx4hH3HXWtvDEZii57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Hio18zyfyQsZGzaASE/JjbKRAu8MbvjyfNe0l
BXEJFED7/W2i2I+n249338LxF/36mY92O29/vn4TczCn+y1Kb4JX3HlPOQIt8+99
KBtBPtYyy4pziwbrBwBGeobg57lgBTGu+oeQcyvx+XnmJMVii8R3heilARl9/sI7
cjehjXMSKGohb25xt9sk3QKBwHHpzCekB+00eeuo3vniIkcshqP3LZiBeQganuF0
W/1ML+Ew/sZCsWL9GErbP1D0o+oZbNv61dIEMbVLSZFBulghz047THFeYfSD2BW4
qUB1zOlIwMbFirrf5SuIcwE2W+0SboWD48xRxtE1cwSgDU/PY5DPuzZSHDopATa5
aNtzlI80LV5+t9IYkVBdzsYHk7RNKN8JBDqIrsb+byiGKG2ATjiFHlxq2lCNrqc1
k438geLC6lhQaxj0UMS1/PvURQ==
-----END PRIVATE KEY-----

View File

@@ -0,0 +1,11 @@
-----BEGIN PUBLIC KEY-----
MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEA87rfcjP7LwChfd4uvxOx
8ZJw3SnUWQ0uL2I2gZIhIPmyiOGmx/z3gzdN/aI7px0u9a4aDs2lNAlN3B+a/8n9
Bu7d8k42fhwLcHV/o2VBiExRKxE7XgHGK8G/2heaMT+ivdr4eRH8o8sAHfZeJ/2W
I6Md2/9lL5+wuNvmpbUnxDpF0bbE36PRp5JEWBhT8gvlN0Tdxlz9uBpu1tmQ0ZoN
Ya1JFWjRqsc/qMgslBXr7KY0clwzJp4cBvCZevO/yZXeDjpoQ/vjL/KlF8WlTqxe
WnsvRz2byQiJLXqRTT1V3cdX9M6Zqu1FPHZIISvdP+JMaBhXuU7fSsYeLPYwCnUU
YQop012Servr6wwd9Bb+bUb28GtXheUddo02ry0g7yo0+GjAVw71yzugfnZLxIHa
xTK2j/4rljfRH3L+Mx/8/FGBOddKLth/hcI0QUq6kTs59sGjbGNZyx6A4XD93K8e
shwALGu8cVEreaobdmiahctD5wiONY/qqQhPlWk+l6TtAgMBAAE=
-----END PUBLIC KEY-----