Открытый порт на сервере редко остаётся незамеченным. По интернету постоянно гуляют боты, которые перебирают адреса, проверяют доступные службы, пробуют имена и пароли. Иногда они просто смотрят, что им ответит сервер. Иногда после ответа отправляют готовый набор команд. Человека за клавиатурой при этом может вообще не быть.

I have already encountered such a guest in practice. Because of my mistake, the database port was looking outside, and the server was overloaded for several days. After that I became interested. Who is actually trying to connect to an open port, what does he manage to do in a short session, and what does he achieve?

To figure this out, I created a decoy program. It depicts several common server services, responds to clients and records all their actions. But she does not carry out the commands she receives.

In logs with active entries, the bait collected 2406 sessions from 309 IP addresses. Many connections took about a second, but even during this time the client managed to log in and quickly check the system. Below I will explain how the trap works, what exactly got into the log and how to protect yourself from it.


❯ Why not only you need your server

Who's knocking on open ports: I wrote a trap for bots and parsed their commands

It seems that a server with a personal website or a small bot is unlikely to attract anyone's attention. There is no large business on it, and several people know the address.

But the automatic program does not need to know about the project. It checks IP addresses and ports. If the service responds, you can try to talk to it: find out its name, check the login, send a familiar request. The script will check the next address in the same way.

For the owner, this is a background activity that does not interfere with the site’s operation. For the scanner, this is a search for available services. Some clients limit themselves to a short check, others try to go further.

In my case, the problem was not found in the Telegram bot itself. docker-compose had its database port published, although the application was accessing it over the internal network. The working bot did not help to notice the extra external input.

I described the details in previous article. There I considered a likely scenario: connecting to PostgreSQL, gaining access and starting the miner. Without full logs and a snapshot of the system, it was impossible to confirm the entire chain.

This time I didn’t want to reconstruct events in hindsight, but to see the connections themselves. Moreover, let the client go beyond the first greeting and see what he does.

❯ How the trap works

DotBotHunt

This type of trap is called a honeypot. Instead of a useful working service, it offers a believable simulation that is easy to observe.

DotBotHunt uses the honeybot package. The program depicts six services.

Service

Decoy port

What does the client get

SSH

2222

Server greeting and command line simulation

HTTP

8080

Multiple pages and login forms

Telnet

2323

Request for username and password, then prompt

FTP

2121

File server greetings and responses

SMTP

2525

Mail server responses

Redis

6379

Answers similar to those in the Redis database

This is not six installed services and not a separate virtual machine. The program generates the answers itself. To the client, it appears to be server web-01 running Ubuntu 22.04, but this information does not describe the system on which the honeypot is actually running.

The scheme is simple: the client connects to one of the ports, and the honeypot responds on behalf of the corresponding service. On SSH and Telnet, it accepts the first password to see the user's actions after login. All login attempts, entered commands, time and connection address are recorded. The honeypot then returns prepared responses without passing commands to the real shell.

If a client asks about a system, he receives information about a fictitious machine. Trying to download a file does not result in an actual download. SMTP does not send letters, and SSH does not become a tunnel to other people's addresses. Network connections do not open based on client commands.

The first accepted password here does not mean that the bot guessed the secret. This is trap behavior. If it immediately denied entry, I would see less activity after authorization.

To view records there is a local panel and an HTML report. The panel does not need to be published on the Internet.

At the same time, imitation of commands in itself does not make a network program invulnerable. For such experiments, a separate environment without working data, secrets and access to internal services is better. Such a trap is needed for surveillance, and not for protecting projects running nearby.

❯ Parsing logs

The big picture

By the time the report was uploaded, 2406 sessions from 309 IP addresses had accumulated in the log. The entries cover three days: October 7, 11 and 12, 2026. According to this report, SSH accounted for 68% of connections. Other services attracted noticeably less attention.

Who's knocking on open ports: I wrote a trap for bots and parsed their commands

In terms of dates, the picture turned out to be uneven.

  • October 7: 1646 sessions. A large flow of SSH connections, of which 1166 came from one address on the DigitalOcean network.

  • October 11: 84 sessions. This time more than half of the connections were via HTTP.

  • October 12: 676 sessions at the time of upload. Again a lot of SSH, and next to it a repeating script via Redis.

From October 8 to October 10, the server remained on, but did not respond to connections. Therefore, these days do not describe the normal activity of a working trap.

Who's knocking on open ports: I wrote a trap for bots and parsed their commands

One more detail, just two addresses gave 1513 sessions, almost 63% of all connections. The first appeared on the DigitalOcean network, the second on the DMZHOST network. A significant part of the magazine turned out to be not a variety of new visitors, but a repetition of similar actions.

SSH: login and check the machine

Разбор одной из сессий
Разбор одной из сессий

The client logs in as ubuntu at 15:22:05, sends seven commands, and disconnects at 15:22:06.

During this second, it checks system uptime, OS information, and graphics devices. The query set looks like this:

What the client checked

What commands did you use

How long the system has been running

uptime -p

Is there an NVIDIA video card and what is it called

Two request options via nvidia-smi

Which graphics controllers are visible in the system

Three request options via lspci

What kind of system and machine is this

uname with parameter set

Login names changed: ubuntu, root, admin, postgres, bitrix, guest and others. And the actions after entering remained the same. Clients were often represented by the string SSH-2.0-Go. This is an SSH client signature, not a unique botnet name, so it cannot be used to identify the common owner of these addresses.

I was especially interested in five queries for checking graphics devices. They let you know if a machine has a GPU, but don't explain why the client is looking for one.

Such sessions are similar to automatic collection of information about a machine: login, several checks, and logout.

Redis: Attempting to hijack a service

With Redis, everything looked noticeably more aggressive. One address created 100 connections with almost the same scenario. The table contains 83 completed sessions. Each lasted from 36 to 41 seconds. New attempts began approximately once a minute. The client did not stop after failure and repeated the same procedure.

For example, I took the recording from 11:22:13 to 11:22:50. In 37 seconds, the client sent 22 commands. It connected to Redis without authorization, requested information about the server, and sent commands to clear the database. Then I tried to write lines with scripts for downloading and running a file into the database, as well as getting commands executed through Lua.

Who's knocking on open ports: I wrote a trap for bots and parsed their commands

This was no longer a simple port availability check. The client was trying out ways to get Redis to run its code. He tried to load the module, change the settings, prepare the conditions for further actions and achieve a reverse connection. The logs also show multiple attempts to load a module, change the Redis role, load a file, and call system processes.

At the end, the attacker sent the contents of the SSH key and changed the path and name of the database file. Temporary file names and external addresses changed, but the overall attack pattern remained the same.

But the instructions sent and the instructions executed are not the same thing. The honeypot saved the commands without running them or opening connections to the outside. From these records, it is impossible to determine a specific vulnerability or assess whether the entire script would work on real Redis.

If such commands were executed on real Redis, an attacker could scrape or replace data, write malicious instructions to the database, and try to run their code on the server. Then he could gain a foothold in the system, add an SSH key for access, or use the machine for new attacks.

Short checks and other connections

Not every guest tried to go beyond the first answer. In 410 sessions, the client connected, received a service greeting, and immediately disconnected

Such a short check may be the beginning of a more serious scan. Based on the service's response, you can find out its name and version, select appropriate commands, or find a known vulnerability. In these sessions, things didn’t go beyond the first greeting, but the connections themselves show that someone was actively checking the ports.

In HTTP, the most common requests were to /favicon.ico, /login, /manager/html, /sse, and /mcp. There were also requests CONNECT, with which the client tried to create a tunnel through a proxy. The trap did not open such connections, but the request itself shows that someone was checking this possibility.

Among those who connected, there were programs with signatures CensysInspect, Infrawatch and research-scan/1.0. Behind such names there may be research scanners, not just hacking tools. But a signature does not prove good intentions. It shows which client made the request, and not why he made it.

What we were able to understand from the recordings

The most active source did not turn out to be the most dangerous. Most of the statistics were generated by repeated SSH checks, but the most serious activity was seen in Redis. There, the client did not just inspect the service, but tried to change its settings and get his code executed. Therefore, to assess the risk, it is not enough to count connections; you need to look at the logs themselves.

There are also limits to such observation. This is a single trap on specific ports, with predefined responses. The detailed table contains only the last 500 sessions, and IP addresses and network names do not identify operators.

The logs show what the client tried to do after the server responded. But to understand whether the attack would work on a real server, other evidence is needed.


❯ How to protect your server

Who's knocking on open ports: I wrote a trap for bots and parsed their commands

To prevent even the slightest chance of a server being hacked, you should take care of this in advance. Let's look at the main approaches to protecting a server from external threats.

1. Leave only necessary services outside

Before starting a project, it is useful to create a short list of allowed connections.

Component

Who should connect

How to restrict access

Public site or API

Visitors

Open only necessary web ports

SSH and administrative panels

Administrator

Allow access only from trusted IP addresses

Base, cache, queue

Applications

Leave access only on the internal network

Trap Panel

Operator

Use local access or secure SSH connection

To communicate between two containers within the same Compose network, you do not need to publish a port to the Internet. If there are no external clients, publishing the port simply adds unnecessary access and a possible break-in point.

For Redis, the same principle is formulated in the documentation. Only trusted clients should contact you, not the entire Internet.

2. Check the result externally

From inside the server, you need to look at what services are listening on ports and what is published by containers. Then check access from another machine, outside the server network.

For example, in Windows PowerShell:

Test-NetConnection <IP_СЕРВЕРА> -Port 5432

For a PostgreSQL database that should not be accessible externally, the result should be TcpTestSucceeded: False. At the same time, check the public service that should accept connections. If it is also not available, there may be an error in the verification or network rules, and not the correct configuration.

There is a nuance with Docker. Published container ports can bypass traditional UFW rules due to the order in which traffic is processed. Therefore, it is not enough to turn on the firewall and see its status. You need to take into account Docker network rules and check the actual availability of ports from the outside.

If the server uses IPv4 and IPv6, restrictions need to be checked for both protocols. After changing Compose, network diagram or filtering rules, the check should be repeated.

3. Limit the number of unsuccessful attempts

An additional layer of protection is provided by fail2ban. The program monitors the SSH log and, after several unsuccessful login attempts, temporarily blocks the intruder's IP address. A simple setup will usually cut off most automatic connections. The bot does not have time to try many passwords, because after several errors its address is blocked.

This does not cancel other measures. Password brute force becomes almost impossible only with SSH keys, access restrictions and closing unnecessary ports. But fail2ban is good at reducing noise and slowing down automated attacks.

4. Limit rights after login

Network filter, authentication and rights solve different problems. The filter determines where you can connect from, authentication checks the client, and rights limit its actions.

For SSH, you should use keys instead of passwords. Unnecessary password entry is disabled only after checking that key access works. The production application does not need a base superuser account, and the container should not be given privileges or access to the Docker socket unless specifically necessary.

The point of these measures is to prevent an error in one component from giving complete control over the rest of the environment.

Moving SSH to another port does not make it unscannable either. First, you should close unnecessary external access, configure input and rights, and then reduce the remaining noise.

5. Logs and backups before the incident

Logs and backups are needed before the server starts behaving strangely. It's not enough to just turn on the recording. It's worth checking in advance how long the logs are stored, whether they are accessible after a failure, and whether the data can be restored from a backup.

If a hack is suspected, first isolate the affected environment. If possible, save the logs and a disk snapshot, then revoke the compromised secrets and restore the system from a trusted source. Removing a suspicious process does not in itself restore trust in the server.

I came to this conclusion after an incident with my server. I have already provided a detailed analysis of that case in a separate article. In short, then I managed to regain control by reinstalling the system, but along with it some of the traces disappeared. If I had logs and fresh backups, it would be easier to understand what happened and restore work, and there would be less damage.

❯ What happened in the end

DotBotHunt allowed us to look at the actions of clients after connecting, and not just at the consequences of a possible hack. The most interesting were the repeating sequences: they show which steps the program performs automatically and at what point it moves from checking to trying to change something.

However, the trap does not close ports or protect neighboring services. The result was a log for parsing, not a secure server.

For a production project, I would start with something simpler: compare the list of required external services with what is actually available from the Internet. This is exactly the kind of verification that my previous project lacked.


Links
Might be interesting:
Перейти ↩
Перейти ↩

News, product reviews and competitions from the team Timeweb.Cloud - in our Telegram channel ↩