SSH to usługa, która zapewnia szyfrowaną komunikację ze zdalnymi systemami czy urządzeniami. Można powiedzieć, że usługa SSH jest następcą protokołu Telnet, którego komunikacja nie jest szyfrowana, więc może być podsłuchana.
Dowiedz się więcej: Nmap i SSHSSH oferuje kilka możliwości:
- Szyfrowane połączenie terminalowe (ang. secure shell).
- Szyfrowane kopiowanie (SCP), które umożliwia pobieranie i wysyłanie plików.
- SFTP zapewnia zaawansowany mechanizm przesyłania plików.
- SSH umożliwia tunelowanie i przekierowywanie połączeń, może działać jako VPN.
Protokół SSH domyślnie nasłuchuje na porcie 22 TCP, ale często jest zmieniany przez administratorów na inny.
Komunikacja klient-serwer
Podczas połączenia tworzony jest wspólny sekret z wykorzystaniem algorytmu Diffiego-Hellmana.
Uwierzytelnienie użytkownika może odbywać się na kilka sposobów: poprzez hasło, klucz (RSA, DSA) oraz protokół Kerberos.
Protokół SSH jest podatny na kilka wektorów ataków:
- Siłowe łamanie haseł (brute force).
- Uzyskanie klucza prywatnego lub użycie słabego klucza – zalecane jest stosowanie klucza o długości co najmniej 2048 bitów.
- Błędy w oprogramowaniu.
Teraz, gdy wiem, czym jest SSH i do czego służy, oraz na jakie ataki jest podatny, przejdźmy do skanowania serwera, który umożliwia połączenie SSH na domyślnym porcie.
nmap -Pn -n -p22 -A 192.168.88.14
nmap -Pn -n -p22 -A 192.168.88.14
Host discovery disabled (-Pn). All addresses will be marked 'up' and scan times will be slower.
Starting Nmap 7.91 ( https://nmap.org ) at 2021-09-21 13:43 CDT
Nmap scan report for 192.168.88.14
Host is up (0.00050s latency).
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.4p1 Debian 5 (protocol 2.0)
| ssh-hostkey:
| 3072 5e:21:89:8c:38:89:b8:f0:82:a2:23:1a:9a:b0:1d:99 (RSA)
| 256 b8:02:09:ab:7c:ca:34:a7:54:df:9f:28:36:5d:f2:25 (ECDSA)
|_ 256 8e:8b:78:4f:ff:1d:a1:fe:33:99:7d:25:10:f9:cd:f7 (ED25519)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 0.66 seconds
Dowiedzieliśmy się, że usługa SSH działa w oparciu o OpenSSH w wersji 8.4p1 oraz poznaliśmy 'ssh-hostkey’, czyli odcisk palca serwera (klucze publiczne). Możemy porównać te klucze z innymi; jeśli będą się pokrywać, oznacza to, że ktoś, tworząc kilka serwerów, użył jednej kopii (klona) do utworzenia wielu instancji serwerów.
SSH wykorzystuje mechanizm 'handshake’ do wymiany kluczy i ustalenia algorytmu szyfrowania. Aby dowiedzieć się, jakie to są algorytmy, użyjemy odpowiedniego zapytania.
nmap -Pn -n -p22 --script ssh2-enum-algos 192.168.88.14
PORT STATE SERVICE
22/tcp open ssh
| ssh2-enum-algos:
| kex_algorithms: (9)
| curve25519-sha256
| [email protected]
| ecdh-sha2-nistp256
| ecdh-sha2-nistp384
| ecdh-sha2-nistp521
| diffie-hellman-group-exchange-sha256
| diffie-hellman-group16-sha512
| diffie-hellman-group18-sha512
| diffie-hellman-group14-sha256
| server_host_key_algorithms: (5)
| rsa-sha2-512
| rsa-sha2-256
| ssh-rsa
| ecdsa-sha2-nistp256
| ssh-ed25519
| encryption_algorithms: (6)
| [email protected]
| aes128-ctr
| aes192-ctr
| aes256-ctr
| [email protected]
| [email protected]
| mac_algorithms: (10)
| [email protected]
| [email protected]
| [email protected]
| [email protected]
| [email protected]
| [email protected]
| [email protected]
| hmac-sha2-256
| hmac-sha2-512
| hmac-sha1
| compression_algorithms: (2)
| none
|_ [email protected]
Ok, teraz sprawdzamy, jakie są mechanizmy uwierzytelniania, więc próbujemy zalogować się na serwer z losową nazwą użytkownika. Chodzi o zainicjowanie połączenia; ja użyłem nazwy użytkownika 'user’
ssh -v [email protected]
debug1: Connecting to 192.168.88.14 [192.168.88.14] port 22.
debug1: Connection established.
debug1: identity file /home/secport/.ssh/id_rsa type -1
debug1: identity file /home/secport/.ssh/id_rsa-cert type -1
debug1: identity file /home/secport/.ssh/id_dsa type -1
debug1: identity file /home/secport/.ssh/id_dsa-cert type -1
debug1: identity file /home/secport/.ssh/id_ecdsa type -1
debug1: identity file /home/secport/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/secport/.ssh/id_ecdsa_sk type -1
debug1: identity file /home/secport/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /home/secport/.ssh/id_ed25519 type -1
debug1: identity file /home/secport/.ssh/id_ed25519-cert type -1
debug1: identity file /home/secport/.ssh/id_ed25519_sk type -1
debug1: identity file /home/secport/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /home/secport/.ssh/id_xmss type -1
debug1: identity file /home/secport/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.4p1 Debian-5
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.4p1 Debian-5
debug1: match: OpenSSH_8.4p1 Debian-5 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 192.168.88.14:22 as 'user'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:sUtWCxeB7paaLPjM2nRjWtIKYOZC0TCD6Zzm1zeQaBo
debug1: Host '192.168.88.14' is known and matches the ECDSA host key.
debug1: Found key in /home/secport/.ssh/known_hosts:1
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: /home/secport/.ssh/id_rsa
debug1: Will attempt key: /home/secport/.ssh/id_dsa
debug1: Will attempt key: /home/secport/.ssh/id_ecdsa
debug1: Will attempt key: /home/secport/.ssh/id_ecdsa_sk
debug1: Will attempt key: /home/secport/.ssh/id_ed25519
debug1: Will attempt key: /home/secport/.ssh/id_ed25519_sk
debug1: Will attempt key: /home/secport/.ssh/id_xmss
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,[email protected],ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected],[email protected]>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: /home/secport/.ssh/id_rsa
debug1: Trying private key: /home/secport/.ssh/id_dsa
debug1: Trying private key: /home/secport/.ssh/id_ecdsa
debug1: Trying private key: /home/secport/.ssh/id_ecdsa_sk
debug1: Trying private key: /home/secport/.ssh/id_ed25519
debug1: Trying private key: /home/secport/.ssh/id_ed25519_sk
debug1: Trying private key: /home/secport/.ssh/id_xmss
debug1: Next authentication method: password