Hacker creates Open Source SSH-Snake worm to steal SSH keys

Company analysts Sysdigwhich specializes in cloud security, warned about the emergence of an open-source tool, SSH-Snake, which is used to quietly search for private keys and lateral movement through the victim’s infrastructure.

Researchers describe SSH-Snake as a “self-modifying worm” that uses SSH credentials found on a compromised system to begin spreading across the network. It is also noted that it differs from regular SSH worms in that it avoids the patterns typical of script attacks, and takes the usual lateral movement through the network to a new level, since it is more careful in searching for private keys.

For example, SSH-Snake uses the following direct and indirect methods to discover private keys on infected systems:

  • search common directories and files where SSH keys and credentials are typically stored, including .ssh directories, configuration files, and so on;
  • examining shell history files (e.g. .bash_history, .zsh_history) to look for commands (ssh, scp and rsync) that may have used or referenced SSH private keys;
  • use the find_from_bash_history function to analyze bash history for commands associated with SSH, SCP, and Rsync operations, revealing direct references to private keys, their locations, and associated credentials;
  • examining system logs and network caches (ARP tables) to identify potential targets and gather information that may indirectly lead to the discovery of private keys and where they are used.

SSH-Snake appeared on GitHub in early January 2024, and its developer wrote that it is a “powerful tool” for automatic network traversal using SSH private keys found on systems. In doing so, SSH-Snake creates a complete map of the network and its dependencies, helping to determine how the network may be compromised using SSH and SSH private keys, starting with a specific host.

“It is completely self-replicating and self-propagating, and completely fileless,” reads the project description on GitHub.

At the same time, the creator of SSH-Snake, Joshua Rogers, emphasizes that his tool is intended for legitimate system owners to identify weaknesses in their infrastructure before attackers do so.

“The conventional wisdom is that cyberterrorism happens suddenly and requires a highly reactive approach to security,” Rogers says. “In my experience, systems should instead be designed and maintained with comprehensive security measures in place. If systems were developed and maintained by people of sound minds, and system owners and companies truly cared about security, the consequences of executing such a script would be minimized, as if the actions of SSH-Snake were performed manually by an attacker.”

Sysdig says that one of the most interesting features of SSH-Snake is its ability to modify itself and reduce its size when first launched. To do this, the worm removes comments, unnecessary functions, and whitespace characters from its code.

At the same time, analysts write that the worm is already being used by attackers. Specifically, the researchers discovered a command and control server used by SSH-Snake operators to store information they collected, including credentials and IP addresses of victims. The hackers appear to have exploited known vulnerabilities in Apache ActiveMQ and Atlassian Confluence to gain initial access to victims' networks, and then deployed the worm to continue the attack.

According to experts, in total, the open source tool has already been used in attacks against approximately 100 victims.