~/service-ssh

SSH

CPTS Notes2 min read

TL;DR

SSH (Secure Shell). Encrypted remote shell, file transfer, and tunneling on TCP 22. OpenSSH is the common server. It authenticates by password or by a public and private key pair. SSH-2 is current, and SSH-1 is broken.

First checks: the OpenSSH version from the banner, whether password auth is on, and any private key you have found.

Enumeration

Sweep and audit.

sudo nmap -p22 -sV -oA scans/ssh $TARGET # banner: OpenSSH version and OS
ssh-audit $TARGET # key-exchange, host-key, and MAC algorithms, weak ones flagged

Check the auth methods.

ssh -v user@$TARGET # verbose login, lists the auth methods

The verbose output lists the methods that can continue (publickey, password, keyboard-interactive). -o PreferredAuthentications=password forces password auth for brute-forcing.

Common misconfigurations

  • Password authentication enabled, so logins are brute-forceable.
  • PermitRootLogin yes.
  • PermitEmptyPasswords yes.
  • A reused or weak private key, or a key file with loose permissions.
  • SSH-1 (Protocol 1) accepted.

Version exploits

Read the OpenSSH version from the banner first.

  • regreSSHion (CVE-2024-6387): unauthenticated RCE as root in OpenSSH 8.5p1 up to 9.7 on glibc Linux. A signal-handler race, slow to win (hours) and rarely practical, but notable.
  • User enumeration (CVE-2018-15473): OpenSSH before 7.7 leaks valid usernames through response timing.

Attack playbook

SSH is the login once you hold a credential or a key.

  1. Use a found private key. Keys turn up in shares, backups, and .ssh directories.
    chmod 600 key # owner-only permissions on the key
    ssh -i key user@$TARGET # log in with the key
  2. Reuse credentials. Passwords found elsewhere often work here.
  3. Brute or spray. Last resort, slow, and fail2ban blocks it. Spray one password across users. See Spraying and Defaults.
    nxc ssh $TARGET -u users.txt -p passwords.txt # brute a user and password list
    hydra -L users.txt -P passwords.txt ssh://$TARGET # hydra does the same
  4. Run a command.
    nxc ssh $TARGET -u <user> -p <pass> -x 'id' # run one command, no full session

Practice boxes

Box Difficulty SSH’s role
Keeper Easy Credentials from a KeePass note log in over SSH for a user shell.

SSH is rarely the vector itself. It is the shell after you find a credential or a private key.