island-tropicalSSH Pentesting Notes

Protocol Overview

Basic Information

  • Port: TCP 22 (default)

  • Protocol Type: Encrypted, application layer

  • Purpose: Secure remote access and file transfer

  • Security: Strong encryption and authentication mechanisms

Protocol Versions

  1. SSH-1

    • Legacy protocol

    • Vulnerable to MITM attacks

    • Should be disabled

  2. SSH-2

    • Current standard

    • Improved security

    • Supports multiple authentication methods

Initial Enumeration

Port Scanning

Authentication Methods

Testing Different Auth Methods

Key-Based Authentication Check

Brute Force Attacks

Using Hydra

Using Medusa

Using Ncrack

Common NSE Scripts

SSH Auditing

Using SSH-Audit

File Operations

SCP (Secure Copy)

SFTP Operations

Configuration Files

Server Configuration

  • Main config: /etc/ssh/sshd_config

  • Host keys: /etc/ssh/ssh_host_*_key

  • Known hosts: /etc/ssh/ssh_known_hosts

User Configuration

  • SSH directory: ~/.ssh/

  • Private keys: ~/.ssh/id_*

  • Known hosts: ~/.ssh/known_hosts

  • Authorized keys: ~/.ssh/authorized_keys

Common Vulnerabilities

  1. Configuration Issues:

    • Weak passwords allowed

    • Root login enabled

    • Old protocol versions

    • Weak ciphers/MACs

  2. Authentication Problems:

    • Password authentication enabled

    • Empty passwords allowed

    • Weak private key protection

    • Misconfigured authorized_keys

  3. Version-specific:

    • OpenSSH vulnerabilities

    • Legacy SSH-1 problems

    • Weak key exchange methods

    • Deprecated algorithms

Post Exploitation

Information Gathering

  • Check SSH configuration

  • List authorized keys

  • Examine user permissions

  • Review SSH logs

  • Search for private keys

Privilege Escalation

  • Check for writable config files

  • Look for unprotected keys

  • Test for SSH agent hijacking

  • Examine cron jobs

  • Review sudo permissions

Common SSH Response Codes

Message
Meaning

Permission denied

Authentication failed

Connection refused

Port closed or filtered

Host key verification failed

Changed/unknown host key

Connection timed out

Host unreachable/blocked

Best Practices for Pentesting

  1. Initial Reconnaissance:

    • Identify SSH version

    • Check available algorithms

    • Test authentication methods

    • Review banners/fingerprints

  2. Deep Enumeration:

    • Run SSH audits

    • Test key-based auth

    • Check configuration

    • Verify encryption methods

  3. Documentation:

    • Record findings

    • Note configurations

    • Document vulnerabilities

    • Save evidence

  4. Risk Assessment:

    • Evaluate security posture

    • Check compliance

    • Assess attack surface

    • Recommend hardening steps

Common Dangerous Settings

Setting
Risk

PermitRootLogin yes

Allows direct root access

PasswordAuthentication yes

Enables password attacks

PermitEmptyPasswords yes

Allows blank passwords

Protocol 1

Uses vulnerable protocol

X11Forwarding yes

Potential GUI exploitation

AllowTcpForwarding yes

Possible tunneling abuse

DebianBanner yes

Information disclosure