|
|
Log in / Subscribe / Register

Creating an SSH honeypot

March 11, 2021

This article was contributed by Marta Rybczyńska


FOSDEM

Many developers use SSH to access their systems, so it is not surprising that SSH servers are widely attacked. During the FOSDEM 2021 conference, Sanja Bonic and Janos Pasztor reported on their experiment using containers as a way to easily create SSH honeypots — fake servers that allow administrators to observe the actions of attackers without risking a production system. The conversational-style talk walked the audience through the process of setting up an SSH server to play the role of the honeypot, showed what SSH attacks look like, and gave a number of suggestions on how to improve the security of SSH servers.

$ sudo subscribe today

Subscribe today and elevate your LWN privileges. You’ll have access to all of LWN’s high-quality articles as soon as they’re published, and help support LWN in the process. Act now and you can start with a free trial subscription.

A honeypot is a network-accessible server, typically more weakly protected than ordinary servers. System administrators deploy honeypots to attract attackers and record their actions, which allows the administrators to analyze those actions and improve the defenses of their production systems based on the information gained. Honeypots may reveal new ways for attackers to get in or confirm the most common ones. They exist in different flavors for different types of servers; Bonic and Pasztor concentrated on honeypots providing a publicly accessible SSH server. A number of elements are needed to build such honeypot: the SSH server itself, an environment the attackers will be allowed into (that is able to contain any damage), and a logging (audit) system that will record all of the information on the attacker's actions.

They started with the logging system, which has uses beyond honeypots. In large companies, audit trails are often recorded "in case some super-secret company stuff leaks". The solution Bonic and Pasztor chose for their honeypot was asciinema, a tool for recording and replaying console sessions. The asciinema log consists of JSON fragments, making it easy to parse. It starts with a header (with information like the format version and the terminal size); all subsequent lines are arrays with three items: a timestamp, the mode (input or output), and the content. Interested readers can see what can be done with the tool on the asciinema examples page. Bonic and Pasztor's original idea was to be provide a video-like replay of attacker's sessions.

The second element of the configuration is the SSH server. Pasztor explained that there are multiple projects working on fake SSH servers; they simulate an environment and give simulated results. The problem, from the point of view of a honeypot builder, is that the tool has to simulate a shell and a honeypot needs a directory structure (and content in its files, presumably). Providing all of the necessary files leads to something similar to assembling a virtual machine, Pasztor said, and that not an easy thing to do. He added that honeypots try to prevent the attacker from actually running programs on a machine, as that may cause security problems. If the reason to run the honeypot is just to see what commands the attacker is issuing, a fake server is enough. However, for an in-depth analysis, more will be needed.

They decided to use a standard SSH server (OpenSSH), but then redirect the sessions it creates to a separate, safe environment. Pasztor explained that their initial idea was to use Docker, which, while it is not as separated from the host system as a virtual machine would be, does still create a security boundary. Setting up a Docker container to be run when someone logs in with SSH requires a standard SSH installation and just one line added to sshd_config:

 ForceCommand /usr/bin/docker run -ti ubuntu

The path to the docker executable might need adjusting and ubuntu is the name of the container to use. When someone connects, they will "land in a container and can't do anything about it", Pasztor said.

However, adding asciinema (or probably any other logging tool) to the command leads to something like this:

 ForceCommand /usr/bin/asciinema rec /tmp/ssh.cast –c \
		 "/usr/bin/docker run -ti ubuntu"

This approach adds complexity and is prone to mistakes. The situation gets worse if the honeypot wants to simulate the execution of the command actually sent over the connection (which was overridden by ForceCommand). Without a lot of care, this setup is susceptible to command injection by way of the SSH_ORIGINAL_COMMAND environment variable, which contains the attacker's command (before it was replaced with ForceCommand). If this variable is not properly sanitized, it could allow the attacker to gain access to the host system, which is something "you absolutely do not want" in a honeypot.

To solve this problem, Pasztor developed ContainerSSH, which allows the SSH server to talk to a container (or any other backend) using an HTTP API. Their slides listed Docker, Podman, and Kubernetes as supported backends; all of them provide such an API. When a user connects to ContainerSSH, the server talks to the backend using its API and launches a new container to handle the connection. ContainerSSH can connect to a custom authentication server and dynamically change the configuration for each user. In the honeypot case, they used an option to send the audit log to asciinema and another one to make ContainerSSH accept all users logging in (without the usual requirement for a valid account and password).

They put the server into production and started getting various strange error messages rather than the console log they were hoping for. Pasztor was confused. It turns out most attackers are bots, he explained. They tend to send commands directly via SSH rather than starting a console session, but the original setup was meant for humans, and was designed to log a console session. To solve that problem, they switched to a different format for the audit log. The new format was binary and recorded everything (including passwords). This time the log contained the information the needed to see what was going on.

Some attackers just run a program and want the output of it; they want to get information about the system, the CPU type, for example. Half of the attackers just checked the password and did not do anything else. Others did things Bonic and Pasztor did not expect. For example, some attackers uploaded payloads using the SSH file transfer protocol (SFTP), uncompressed them, ran the resulting programs, and finally deleted their tracks.

Pasztor described another attack as "really interesting". Attackers were looking for GSM devices, or mobile phones directly connected to the system (and accessible via device files like /dev/ttyGSM*). For people who have not worked in traditional IT or in data centers, it might be hard to guess why someone would connect a phone to an SSH server. Pasztor explained that many system administrators use phones or GSM devices to send alert messages. Such a setup is useful if Internet access goes down; the mobile phone will probably still work and can send a message to the administrator. What the attackers probably want to do, instead, is to send spam messages from the monitoring mobile phone number.

SSH attacks used to be different, Pasztor said. Nowadays many programming languages offer SSH libraries or SFTP modules. That has made it easy for attacks to become more sophisticated. For example, attackers will establish one single connection, so connection-rate limits will not constrain them. In that one connection they open multiple channels to execute their payloads.

The talk moved on to recommendations for anyone running an SSH server. The first one is to change the port used by the server (the default is 22). Once this is changed, the system will see few attacks. Bonic remembers reading about port renumbering as a recommendation 10 or 15 years ago and she said it is still valid. Still, it will only protect against bots, not directed attacks.

Their second recommendation is to use keys for authentication and disable passwords "completely if you can". If it is necessary to keep passwords, a good practice is to avoid common combinations like user test and password test. They saw cases where someone used a default password and attackers were in within 20 minutes. Finally, SSH private keys should be protected by a password. If a targeted attack happens, it will often involve a developer's laptop, because developers typically have elevated privileges and direct access to production systems. If that laptop contains unprotected keys, attackers have an easy way into the server. During the question session, some audience members disagreed with the order of the suggestions, and recommend using keys instead of a passwords as the main protection measure.

Pasztor concluded by showing other uses of containers with SSH. ContainerSSH was originally built to solve a web-hosting problem when the owner of a site needs to move data between servers, but has different user names on each server. This can be done with SFTP but can be awkward. Containerized SSH allows the necessary servers to be wrapped with a simple environment and users do not need to deal with the underlying permission system at all.

Another use of ContainerSSH is in education. In traditional education systems, there will be many leftover files after a student completes a set of exercises. With containers, when the student logs out, the container is removed along with all of the leftover files. The use of containers allows easier teaching of Linux and it is now even possible to run a complete Kubernetes cluster in a container. The last use case is in high-security environments. ContainerSSH makes it easy to automatically upload session logs to an external object store, ensuring that the log never lives on the system that is being monitored and, thus, cannot be tampered with by an attacker.

The slides [PDF] and video from the talk are available.

Index entries for this article
Security Internet/Honeypots
GuestArticles Rybczynska, Marta
Conference FOSDEM/2021


to post comments

Creating an SSH honeypot

Posted Mar 12, 2021 5:41 UTC (Fri) by pabs (subscriber, #43278) [Link] (1 responses)

This reminds me of SourceForge's highly restricted SSH setup, although I think they use virtual machines instead of containers.

Creating an SSH honeypot

Posted Apr 6, 2021 13:09 UTC (Tue) by janoszen (guest, #151500) [Link]

You can do that too, micro VMs such as Firecracker can be used to that effect.

Creating an SSH honeypot

Posted Mar 12, 2021 15:24 UTC (Fri) by Trou.fr (subscriber, #26289) [Link]

A trivial thing to implement and which can help against mistakes: whitelisting the users allowed to connect through ssh by allowing only a specific group:

AllowGroups sshok

so your test user you're creating for "just a quick check", will not be allowed to connect.

Creating an SSH honeypot

Posted Mar 13, 2021 8:05 UTC (Sat) by gps (subscriber, #45638) [Link] (11 responses)

Don't forget about fail2ban on your actual ssh servers... And to go clean out the infinitely growing fail2ban database of every compromised address that has probed you on the internet every now and then...

Creating an SSH honeypot

Posted Mar 13, 2021 13:32 UTC (Sat) by jak90 (subscriber, #123821) [Link]

Even if I prefer to whitelist access to port 22 to a few safe addresses and networks (which on most servers contains the whole IPv6 address space), I wish there was a fail2ban plugin that could simply extend IP bans to the whole allocation or even all networks belonging to an AS if it contains more than one or two bad apples.

Creating an SSH honeypot

Posted Mar 13, 2021 16:03 UTC (Sat) by Sesse (subscriber, #53779) [Link] (7 responses)

fail2ban has a critical issue with SSH, though; if someone just connects to port 22 and then hangs, you can quickly eat up the number of SSH children without fail2ban ever noticing (because sshd never logs this).

Creating an SSH honeypot

Posted Mar 14, 2021 3:29 UTC (Sun) by k8to (guest, #15413) [Link] (2 responses)

Though this problem isn't really caused by fail2ban, it's just that fail2ban doesn't assist against this type of denial-of-service. So I don't view this as a fail2ban issue, just a thing it doesn't handle for you.

Since fail2ban is designed mostly to just cut off bot attacks, it seems not that big a deal to me. If you want to handle more active attackers you should be taking other approaches at least in addition.

Creating an SSH honeypot

Posted Mar 14, 2021 23:24 UTC (Sun) by Sesse (subscriber, #53779) [Link] (1 responses)

There are bots that operate like this. Surprisingly many of them.

Creating an SSH honeypot

Posted Mar 16, 2021 13:01 UTC (Tue) by dskoll (subscriber, #1630) [Link]

Almost any network server is vulnerable to this sort of attack; surely SSH has a configuration setting somewhere to close the socket if the client doesn't do anything for a while? Seems to me LoginGraceTime might do the trick here.

And yes, clients can dribble data slowly over a connection to tie up a child process, but again... any network server is vulnerable to this and it's a pretty well-known attack.

Creating an SSH honeypot

Posted Mar 19, 2021 5:49 UTC (Fri) by dtlin (subscriber, #36537) [Link] (3 responses)

That's why I like pam_recent, which (in conjunction with appropriate firewall rules) can start rate-limiting connections as soon as they try to connect, instead of waiting for sshd to log.

Creating an SSH honeypot

Posted Mar 21, 2021 11:28 UTC (Sun) by smurf (subscriber, #17840) [Link] (2 responses)

The "in conjunction with appropriate firewall rules" part is important though, you want to limit the number of open connections. pam_recent kicks in too late to catch a well-written DoS attempt.

Creating an SSH honeypot

Posted Mar 23, 2021 23:38 UTC (Tue) by nix (subscriber, #2304) [Link] (1 responses)

What does this buy you over just turning on ChallengeResponseAuthentication, turning off PasswordAuthentication, and ignoring the fruitless attacks? (They hardly use any bandwidth because they always seem to try possibilities sequentially, though I suppose if you're right at the limit of your bandwidth plan you might just notice it.)

Creating an SSH honeypot

Posted Mar 24, 2021 13:40 UTC (Wed) by smurf (subscriber, #17840) [Link]

It buys you protection from a DoS attack that forks ten gazillion ssh daemons and loads down your gateway box. These do exist.

Creating an SSH honeypot

Posted Mar 18, 2021 16:47 UTC (Thu) by jschrod (subscriber, #1646) [Link] (1 responses)

It's been some time when I looked at fail2ban.

Is it now supported out-of-the-box to issue iptables/nftables command on a different server, as a reaction to an detected break in attempt?

The use case is a firewall in front of several boxes that allow ssh access. If fail2ban detects a break-in attempt in one of those boxes, the rules shall be changed on the firewall. Blocking access just on this specific box is not sufficient.

Creating an SSH honeypot

Posted Mar 18, 2021 18:39 UTC (Thu) by dskoll (subscriber, #1630) [Link]

You can configure the ban/unban actions, so with the right setup, you can do what you need. It's a bit of a pain to do safely and securely, but certainly not impossible.

Creating an SSH honeypot

Posted Mar 14, 2021 20:17 UTC (Sun) by flussence (guest, #85566) [Link] (1 responses)

An anecdote about port numbering: I've been doing this for at least 10 years and IIRC I've had zero unwanted SSH connections as a result (compared to SMTP, which gets one every few minutes). Surprisingly effective, I'd recommend doing it for other services where SRV records are the norm too.

nonstandard SSH port

Posted Mar 21, 2021 3:20 UTC (Sun) by giraffedata (guest, #1954) [Link]

My anecdote: I too have been using a nonstandard SSH port for about 10 years and have seen zero attacks except about two years ago there was an onslaught of password guesses that went on for several months. It was the kind where the guesses come in infrequently from lots of sources, the idea being to try password X on a thousand machines rather than try a thousand passwords on machine X; i.e. it wasn't someone targeting my server in particular.

At first I thought hacking technology had just advanced to where my trick wouldn't work anymore; I was pleased to see the attacks stop.

Creating an SSH honeypot

Posted Mar 15, 2021 12:58 UTC (Mon) by gdt (subscriber, #6284) [Link]

Another useful tactic is to exclusively bind sshd to an additional random IPv6 interface identifier (an interface ID is the least significant 64 bits of the IPv6 address). An interface can hold multiple IPv6 interface IDs without fuss. This gives a search space of 263, which is ~1014 more than the search space of 216 for TCP ports.

Because this is an additional address used solely for incoming SSH the usual operation of the computer doesn't leak beyond the subnet a useful address for a SSH brute force attempt.

This tactic retains the ability to have a DNS name for the SSH service, which can be sometimes be useful.

Creating an SSH honeypot

Posted Mar 19, 2021 17:42 UTC (Fri) by metalheart (guest, #89328) [Link] (1 responses)

Why not use Linux Auditing System to log those activities?

Creating an SSH honeypot

Posted Apr 6, 2021 13:09 UTC (Tue) by janoszen (guest, #151500) [Link]

(Dev here) You can, ContainerSSH just takes a different approach and takes care of locking the "attacker" in a container (or a microVM if you set it up that way).


Copyright © 2021, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds

AltStyle によって変換されたページ (->オリジナル) /