MikroTik - Silna kryptografia w ssh
Posted on czw 27 kwiecień 2017 in MikroTik
W 2012 roku popełniliśmy mały wpis na temat ssh w RouterOS. Sporo wody w Wiśle upłynęło od tego czasu i przynajmniej jedna ważna kwestia się zdezaktualizowała - od dłuższego czasu możliwa jest autentykacja kluczem RSA (do czego zachęcam!). Rzućmy okiem, co jeszcze się zmieniło w kontekście serwera ssh w RouterOS
Ustawienia domyślne - daleko od dzisiejszych standardów
Dokumentacja MikroTik jest raczej uboga w szczegóły dotyczące implementacji protokołu. Najważniejsza sprawa - wspierany algorytmy szyfrujące oraz algorytmy hmac - można zanalizować za pomocą opcji -vvv klienta openSSH (albo wireshark jeśli ktoś woli):
$ ssh -vvv router
OpenSSH_6.7p1 Debian-5+deb8u3, OpenSSL 1.0.1t 3 May 2016
debug1: Reading configuration data /etc/ssh/ssh_config
...
debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-dss,ssh-rsa
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,aes192-cbc,aes256-cbc,blowfish-cbc,3des-cbc,none
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,aes192-cbc,aes256-cbc,blowfish-cbc,3des-cbc,none
debug2: kex_parse_kexinit: hmac-sha1,hmac-md5
debug2: kex_parse_kexinit: hmac-sha1,hmac-md5
debug2: kex_parse_kexinit: none
debug2: kex_parse_kexinit: none
debug2: kex_parse_kexinit:
...
Powyższy fragment listingu prezentuje algorytmy oferowane przez serwer.
No i klops... Z szybkiej analizy wynika, że domyślnie RouterOS używa:
- algorytm 3DES - np. CVE-2016-2183/SWEET32
- algorytm Blowfish - jak wyżej
- AES128 - wystarczy do 2030 (rekomendacja NIST SP 800-131A) :)
- hmac-sha1 i md5 - err... delikatnie mówiąc prehistoria
- używa słabej, 1024bitowej grupy DH
Strong-crypto - remedium
Na szczęście w changelogu do wersji MikroTik RouterOS 6.30 możemy zobaczyć:
Whats' new in 6.30 (2015-Jul-08 09:07):
...
*) ssh - added option '/ip ssh strong-crypto'
...
Jak zwykle dość enigmatycznie. Zajrzyjmy w takim razie do dokumentacji. Tak jest! Opcja powoduje następujące zmiany:
- Algorytmy AES192 i AES256 są preferowane (tak na prawdę wymagane)
- Wyłączony jest algorytm Null (bez szyfrowania)
- Preferowanym algorytmem skrótu jest SHA256
- wyłączony jest algorytm md5
- używa silnej grupy Diffie-Hellman (2048 w przeciwieństwie do domyślnych 1024bit)
Włączamy silną kryptografię:
admin@MikroTik > /ip ssh set strong-crypto=yes
Użyjmy znowu magicznej opcji -vvv z openSSH
$ ssh -vvv router
OpenSSH_6.7p1 Debian-5+deb8u3, OpenSSL 1.0.1t 3 May 2016
debug1: Reading configuration data /etc/ssh/ssh_config
...
ebug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: aes256-ctr,aes192-ctr
debug2: kex_parse_kexinit: aes256-ctr,aes192-ctr
debug2: kex_parse_kexinit: hmac-sha2-256,hmac-sha1
debug2: kex_parse_kexinit: hmac-sha2-256,hmac-sha1
...
Zgodnie z oczekiwaniami :) Lista wspieranych algorytmów szyfrujących została ograniczona do AES256/192 w trybie CTR zaś algorytmy hmac - SHA256 i SHA-1. Używając klienta openSSH warto jeszcze wymusić najsilniejsze, dostępne opcje (uwaga nie działa jeśli strong-crypto=no);
$ cat .ssh/config
VisualHostKey yes
ServerAliveInterval 30
ServerAliveCountMax 5
Host 192.168.88.1
User admin
Ciphers aes256-ctr
MACs hmac-sha2-256
Powyższe opcje wymuszają najsilniejsze wspierane przez MikroTik algorytmy (+ bonus w postaci wizualizacji klucza serwera ;)).