22 - SSH

Secure Shell (SSH) is a cryptographic network protocol used to securely access and manage remote systems over an untrusted network. It provides encrypted communication, authentication (such as passwords or keys), and secure command execution, file transfer, and tunnelling capabilities.

Usage

circle-exclamation
# Connect via SSH using a password
ssh x7331@10.10.10.1

# Connect via SSH using a private key
chmod 400 id_rsa
ssh -i id_rsa x7331@10.10.10.1

Inline Commands

# Inline command execution
ssh user1@10.10.10.10 -p 2222 'ls /home/user1/'

File Transfer

# Local to remote (upload)
scp file1 user@172.16.10.10:/tmp/file1

# Remote to local (download)
scp user@172.16.10.10:/tmp/file1 ./file1

# Multiple files -> host must end with a directory, i.e., ':~' or ':/'
scp agent.exe proxy x7331@srv02:~ 

If error messages, try -0.

Key Generation

Enumeration

Attacks

Brute Force

Password Spray

Crack Private Keys

SSH supports multiple key types, each with a default filename, thus, when trying to exfiltrate one don't just search for id_rsa!

Key Type
Private Key File
Public Key File

RSA

~/.ssh/id_rsa

~/.ssh/id_rsa.pub

ECDSA

~/.ssh/id_ecdsa

~/.ssh/id_ecdsa.pub

ED25519

~/.ssh/id_ed25519

~/.ssh/id_ed25519.pub

DSA (old)

~/.ssh/id_dsa

~/.ssh/id_dsa.pub

  • ECDSA and ED25519 are newer and generally faster/smaller than RSA.

  • ED25519 is currently the recommended default for many systems (ssh-keygen defaults to it now).

  • RSA is still widely supported, but 4096-bit keys are preferred now due to security standards.

PPK to PEM

Convert a Putty user key file (.ppk) to an SSH .pem file.

For an example of the above process check Keeper.

Last updated