22 - Pentesting SSH/SFTP
Last updated
Last updated
Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE) Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Bug bounty tip: sign up for Intigriti, a premium bug bounty platform created by hackers, for hackers! Join us at https://go.intigriti.com/hacktricks today, and start earning bounties up to $100,000!
SSH (Secure Shell or Secure Socket Shell) is a network protocol that enables a secure connection to a computer over an unsecured network. It is essential for maintaining the confidentiality and integrity of data when accessing remote systems.
Default port: 22
SSH servers:
openSSH – OpenBSD SSH, shipped in BSD, Linux distributions and Windows since Windows 10
Dropbear – SSH implementation for environments with low memory and processor resources, shipped in OpenWrt
PuTTY – SSH implementation for Windows, the client is commonly used but the use of the server is rarer
CopSSH – implementation of OpenSSH for Windows
SSH libraries (implementing server-side):
wolfSSH – SSHv2 server library written in ANSI C and targeted for embedded, RTOS, and resource-constrained environments
Apache MINA SSHD – Apache SSHD java library is based on Apache MINA
paramiko – Python SSHv2 protocol library
ssh-audit is a tool for ssh server & client configuration auditing.
https://github.com/jtesta/ssh-audit is an updated fork from https://github.com/arthepsy/ssh-audit/
Features:
SSH1 and SSH2 protocol server support;
analyze SSH client configuration;
grab banner, recognize device or software and operating system, detect compression;
gather key-exchange, host-key, encryption and message authentication code algorithms;
output algorithm information (available since, removed/disabled, unsafe/weak/legacy, etc);
output algorithm recommendations (append or remove based on recognized software version);
output security information (related issues, assigned CVE list, etc);
analyze SSH version compatibility based on algorithm information;
historical information from OpenSSH, Dropbear SSH and libssh;
runs on Linux and Windows;
no dependencies
This is discovered by default by nmap. But you can also use sslcan or sslyze.
ssh
In some versions of OpenSSH you can make a timing attack to enumerate users. You can use a metasploit module in order to exploit this:
Some common ssh credentials here and here and below.
If you know some ssh private keys that could be used... let's try it. You can use the nmap script:
Or the MSF auxiliary module:
Or use ssh-keybrute.py
(native python3, lightweight and has legacy algorithms enabled): snowdroppe/ssh-keybrute.
Some systems have known flaws in the random seed used to generate cryptographic material. This can result in a dramatically reduced keyspace which can be bruteforced. Pre-generated sets of keys generated on Debian systems affected by weak PRNG are available here: g0tmi1k/debian-ssh.
You should look here in order to search for valid keys for the victim machine.
crackmapexec using the ssh
protocol can use the option --kerberos
to authenticate via kerberos.
For more info run crackmapexec ssh --help
.
Vendor | Usernames | Passwords |
APC | apc, device | apc |
Brocade | admin | admin123, password, brocade, fibranne |
Cisco | admin, cisco, enable, hsa, pix, pnadmin, ripeop, root, shelladmin | admin, Admin123, default, password, secur4u, cisco, Cisco, _Cisco, cisco123, C1sco!23, Cisco123, Cisco1234, TANDBERG, change_it, 12345, ipics, pnadmin, diamond, hsadb, c, cc, attack, blender, changeme |
Citrix | root, nsroot, nsmaint, vdiadmin, kvm, cli, admin | C1trix321, nsroot, nsmaint, kaviza, kaviza123, freebsd, public, rootadmin, wanscaler |
D-Link | admin, user | private, admin, user |
Dell | root, user1, admin, vkernel, cli | calvin, 123456, password, vkernel, Stor@ge!, admin |
EMC | admin, root, sysadmin | EMCPMAdm7n, Password#1, Password123#, sysadmin, changeme, emc |
HP/3Com | admin, root, vcx, app, spvar, manage, hpsupport, opc_op | admin, password, hpinvent, iMC123, pvadmin, passw0rd, besgroup, vcx, nice, access, config, 3V@rpar, 3V#rpar, procurve, badg3r5, OpC_op, !manage, !admin |
Huawei | admin, root | 123456, admin, root, Admin123, Admin@storage, Huawei12#$, HwDec@01, hwosta2.0, HuaWei123, fsp200@HW, huawei123 |
IBM | USERID, admin, manager, mqm, db2inst1, db2fenc1, dausr1, db2admin, iadmin, system, device, ufmcli, customer | PASSW0RD, passw0rd, admin, password, Passw8rd, iadmin, apc, 123456, cust0mer |
Juniper | netscreen | netscreen |
NetApp | admin | netapp123 |
Oracle | root, oracle, oravis, applvis, ilom-admin, ilom-operator, nm2user | changeme, ilom-admin, ilom-operator, welcome1, oracle |
VMware | vi-admin, root, hqadmin, vmware, admin | vmware, vmw@re, hqadmin, default |
If you are in the local network as the victim which is going to connect to the SSH server using username and password you could try to perform a MitM attack to steal those credentials:
Attack path:
Traffic Redirection: The attacker diverts the victim's traffic to their machine, effectively intercepting the connection attempt to the SSH server.
Interception and Logging: The attacker's machine acts as a proxy, capturing the user's login details by pretending to be the legitimate SSH server.
Command Execution and Relay: Finally, the attacker's server logs the user's credentials, forwards the commands to the real SSH server, executes them, and sends the results back to the user, making the process appear seamless and legitimate.
SSH MITM does exactly what is described above.
In order to capture perform the actual MitM you could use techniques like ARP spoofing, DNS spoofin or others described in the Network Spoofing attacks.
If you want to traverse a network using discovered SSH private keys on systems, utilizing each private key on each system for new hosts, then SSH-Snake is what you need.
SSH-Snake performs the following tasks automatically and recursively:
On the current system, find any SSH private keys,
On the current system, find any hosts or destinations (user@host) that the private keys may be accepted,
Attempt to SSH into all of the destinations using all of the private keys discovered,
If a destination is successfully connected to, repeats steps #1 - #4 on the connected-to system.
It's completely self-replicating and self-propagating -- and completely fileless.
It's common for SSH servers to allow root user login by default, which poses a significant security risk. Disabling root login is a critical step in securing the server. Unauthorized access with administrative privileges and brute force attacks can be mitigated by making this change.
To Disable Root Login in OpenSSH:
Edit the SSH config file with: sudoedit /etc/ssh/sshd_config
Change the setting from #PermitRootLogin yes
to PermitRootLogin no
.
Reload the configuration using: sudo systemctl daemon-reload
Restart the SSH server to apply changes: sudo systemctl restart sshd
There is a common oversight occurs with SFTP setups, where administrators intend for users to exchange files without enabling remote shell access. Despite setting users with non-interactive shells (e.g., /usr/bin/nologin
) and confining them to a specific directory, a security loophole remains. Users can circumvent these restrictions by requesting the execution of a command (like /bin/bash
) immediately after logging in, before their designated non-interactive shell takes over. This allows for unauthorized command execution, undermining the intended security measures.
Here is an example of secure SFTP configuration (/etc/ssh/sshd_config
– openSSH) for the user noraj
:
This configuration will allow only SFTP: disabling shell access by forcing the start command and disabling TTY access but also disabling all kind of port forwarding or tunneling.
If you have access to a SFTP server you can also tunnel your traffic through this for example using the common port forwarding:
The sftp have the command "symlink". Therefor, if you have writable rights in some folder, you can create symlinks of other folders/files. As you are probably trapped inside a chroot this won't be specially useful for you, but, if you can access the created symlink from a no-chroot service (for example, if you can access the symlink from the web), you could open the symlinked files through the web.
For example, to create a symlink from a new file "froot" to "/":
If you can access the file "froot" via web, you will be able to list the root ("/") folder of the system.
On high security environment it’s a common practice to enable only key-based or two factor authentication rather than the simple factor password based authentication. But often the stronger authentication methods are enabled without disabling the weaker ones. A frequent case is enabling publickey
on openSSH configuration and setting it as the default method but not disabling password
. So by using the verbose mode of the SSH client an attacker can see that a weaker method is enabled:
For example if an authentication failure limit is set and you never get the chance to reach the password method, you can use the PreferredAuthentications
option to force to use this method.
Review the SSH server configuration is necessary to check that only expected methods are authorized. Using the verbose mode on the client can help to see the effectiveness of the configuration.
You can find interesting guides on how to harden SSH in https://www.ssh-audit.com/hardening_guides.html
Bug bounty tip: sign up for Intigriti, a premium bug bounty platform created by hackers, for hackers! Join us at https://go.intigriti.com/hacktricks today, and start earning bounties up to $100,000!
Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE) Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)