ShellSpells
  • 🧙‍♂️Welcome!
    • ShellSpells
    • FAQs
    • License & Disclaimer
  • 🐧Linux
    • System Ops
      • Transcripts
      • Help
      • System Info
        • Date/Time
        • System Details
        • Patches & Updates
        • Init System Identification
        • Hostname / Host ID
        • Variables
        • Hardware & Resources
      • Filesystem
        • Traverse & Enumerate
        • Drives & Partitions
        • Shares
        • Packages
        • Connected Devices
        • Kernel Modules (Drivers)
      • Users & Groups
        • Enumerate
        • Modify
      • Network
        • Enumerate
        • Modify
      • Scheduled Jobs
        • Enumerate
        • Modify
      • Processes
        • Enumerate
        • Modify
        • Custom Script and Shared Object
        • Process I/O Redirection
      • Services
        • Enumerate
        • Modify
        • Create a Service
      • Startup/Boot Scripts
        • Enumerate
        • Modify
      • Security
        • Antivirus
        • Firewall
        • SSH Keys
      • History & Logs
        • History
        • Logs
    • File Ops
      • Search
        • Filename
        • Content
        • Users (Owners)
        • Time
        • Size
        • Permission
        • Hidden Files
        • Inode
        • Find + Exec
        • Notes
      • Enumerate Metadata
      • Modify Metadata
      • Read Content
      • Modify Content
      • Extract Content
      • Sort / Compare / Count
      • Move
      • Copy
      • Execute
      • Hash
      • Encode/Decode
      • Compress/Decompress
      • Working With Weird Filenames
    • Terminal Ops
      • Keyboard Shortcuts
      • Tmux Shortcuts
  • 🪟Windows
    • System Ops
      • Transcripts
      • Help
      • System Info
        • One-liners
        • Date/Time
        • System Details
        • Hotfixes
        • Domain or Workgroup
        • Data Execution Prevention
        • Variables
        • Hardware & Resources
      • Filesystem
        • Traverse & Enumerate
        • Drives & Partitions
        • Installed Software
        • Drivers
        • Shares
      • Registry
        • Enumerate
        • Modify
        • Forensically Relevant Keys
      • Users & Groups
        • Enumerate
        • Modify
      • Network
        • Enumerate
        • Modify
      • Scheduled Tasks
      • Processes
        • Enumerate
        • Modify
      • Services
        • Enumerate
        • Modify
      • Autorun / Startup
        • Enumerate
        • Modify
      • Security
        • Permissions
          • Enumerate
          • Page
        • Antivirus
        • Firewall
          • Enumerate
          • Modify
        • Audit Policies
        • Remoting
          • Enumerate
          • Modify
          • Registry Locations
        • Stored Credentials
      • Remote Command Execution
      • Active Directory
        • Enumerate
        • Modify
      • History & Logs
        • History
        • Logs
      • PowerShell Config
      • Scripting
      • WMIC Notes
    • File Ops
      • Search
        • Filename
        • Time
        • Size
        • Permissions
        • Attributes
        • Wildcarding
      • Enumerate Metadata
        • One Liners
        • Users (Owners)
        • Timestamps
        • Size
        • Permissions
        • Attributes
      • Modify Metadata
        • Change Owner
        • Timestamps
        • Size
        • Attributes
      • Read Content
      • Modify Content
        • Overwrite
        • Insert
        • Append
        • Replace / Remove
        • Convert Case
        • Alternate Data Streams
      • Extract Content
      • Sort / Compare / Count
        • Sort
        • Count
        • Compare
      • Move
      • Copy
      • Execute
      • Hash
      • Encode/Decode
      • Compress/Decompress
      • Working With Weird Filenames
      • Output Formatting / Filtering
      • File Formatting
      • Operators
  • ⛓️Network
    • Traffic Manipulation
      • iptables
        • Option List
        • General Commands
        • Filter Tables
        • NAT
        • Mangle
        • Filter for SSH Traffic (Example)
      • nftables
    • Packet Capture
      • Syntax
      • TCPDump Examples
    • Packet Analysis
      • Wireshark
  • 🚗Maneuver
    • SSH
    • Control Sockets
    • RDP
    • Windows Port Proxy
  • 🛩️Data Transfer
    • SCP
    • FTP
    • Netcat
      • Netcat Relays
    • Server Interactions
    • Alternate Methods
  • 🪄REGEX
    • Examples
Powered by GitBook
On this page
  • Generate Keys
  • Steal Keys
  • Find Private Keys
  • Find Public Keys

Was this helpful?

  1. Linux
  2. System Ops
  3. Security

SSH Keys

Generate Keys

ssh-keygen -t rsa -b 2048 -C "your_email@example.com"

Key Type -t: rsa: RSA key type. dsa: DSA key type. ecdsa: ECDSA key type. ed25519: Ed25519 key type.

Key Length (-b): Specify the number of bits in the key.

Comment (-C): Add a comment to identify the key (usually an email address).

Output File (-f): Specify the filename for the key pair.

Passphrase (-N): Set a passphrase to protect the private key.

Passphrase (-P): Requests changing the passphrase of a private key file instead of creating a new private key. The program will prompt for the file containing the private key, for the old passphrase, and twice for the new passphrase.

Key Location: By default, keys are saved in ~/.ssh/ directory.

ssh-keygen -t rsa -b 2048 -C "john.doe@example.com" -f ~/.ssh/id_rsa

This command generates an RSA key pair with a key length of 2048 bits and a comment of "john.doe@example.com". The keys will be saved as id_rsa (private key) and id_rsa.pub (public key) in the ~/.ssh/ directory.

Steal Keys

Find Private Keys

find / -name id_rsa

System-wide search for key by name.

locate id_rsa

Searches for key using the locate command.

grep -r -l "BEGIN RSA PRIVATE KEY" /etc/

Search /etc/ for keys

find ~/.ssh -name "id_rsa*" -type f

Search in home dir

find /etc/ssh -name "id_rsa*" -type f

Search for system-wide keys

Find Public Keys

find / -name "*.pub"

System-wide search for key files by name.

locate "*.pub"

Searches for key files using the locate command.

grep -r -l "ssh-rsa" /etc/

Search /etc/ for keys

find ~/ -name "[filename].pub" -type f

Search in home dir

find ~/.ssh -name "id_rsa*.pub" -type f

Search in home dir

Display SSH host key information:

ls -l /etc/ssh/ssh_host*

Look for .ssh and see if you can get the private key.

If you can, copy it to your attack box. Then change it's permissions:

chmod 600 root_key

Use the key to log in to that user that it belongs to.

ssh -i root_key -oPubkeyAcceptedKeyTypes=+ssh-rsa -oHostKeyAlgorithms=+ssh-rsa <user>@<targetIP>
PreviousFirewallNextHistory & Logs

Last updated 1 year ago

Was this helpful?

🐧