sjinks/tiny-ssh-honeypot
GitHub: sjinks/tiny-ssh-honeypot
基于 libassh 和 libev 构建的轻量级低交互 SSH 蜜罐,以极低资源消耗捕获 SSH 暴力破解和扫描行为。
Stars: 5 | Forks: 0
# tiny-ssh-honeypot
[](https://github.com/sjinks/tiny-ssh-honeypot/actions/workflows/build.yml)
[](https://github.com/sjinks/tiny-ssh-honeypot/actions/workflows/docker.yml)
[](https://github.com/sjinks/tiny-ssh-honeypot/actions/workflows/codeql.yml)
[](https://github.com/sjinks/tiny-ssh-honeypot/actions/workflows/static-analysis.yml)
`tiny-ssh-honeypot` 是一个轻量级的低交互 SSH 蜜罐。它是 [`ssh-honeypotd`](https://github.com/sjinks/ssh-honeypotd) 的一个衍生版本,功能更少,但资源消耗更低。
与 `ssh-honeypotd` 不同,`tiny-ssh-honeypot` 是一个单线程的事件驱动应用程序。其架构允许在消耗更少内存的同时处理更多的连接。`tiny-ssh-honeypot` 底层使用 [libassh 1.1](http://www.nongnu.org/libassh/) 和 [libev 4.x](http://software.schmorp.de/pkg/libev.html)。
## 编译
tiny-ssh-honeypot 使用 [CMake](https://cmake.org/documentation/) 作为其构建系统。
该项目有两个可选依赖:
1. [libassh](https://www.nongnu.org/libassh/) 1.1
2. [libev](http://software.schmorp.de/pkg/libev.html) 4.x
如果缺少这些依赖,构建脚本将尝试下载并构建它们。
下载地址为:
* libassh: http://download.savannah.nongnu.org/releases/libassh/libassh-1.1.tar.gz
* libev: http://dist.schmorp.de/libev/Attic/libev-4.33.tar.gz
**注意:** 构建脚本会构建所下载库的静态版本。
构建脚本定义了以下命令行选项:
* `BUILD_STATIC_BINARY`(默认为 `OFF`):是否构建静态二进制文件;
* `FORCE_EXTERNAL_LIBEV`(默认为 `OFF`):是否忽略系统的 `libev`;
* `FORCE_EXTERNAL_LIBASSH`(默认为 `OFF`):是否忽略系统的 `libassh`。
要构建该程序,你需要 `cmake`、一个 C 编译器(例如 `clang` 或 `gcc`)以及一个 make 工具(`make`)。该程序可在 Linux 上构建,也可能(或可能不会)在其他系统(如 Windows)上构建。
```
cmake -S . -B build
cmake --build build
```
## 构建 Docker 镜像
如果你安装了 [Buildx](https://docs.docker.com/buildx/working-with-buildx/):
```
docker buildx build --pull --tag wildwildangel/tiny-ssh-honeypot .
```
否则,如果你启用了 [BuildKit](https://docs.docker.com/develop/develop-images/build_enhancements/):
```
docker build --pull --tag wildwildangel/tiny-ssh-honeypot .
```
或者,对于早于 23.0 版本的 Docker,
```
DOCKER_BUILDKIT=1 docker build --pull --tag wildwildangel/tiny-ssh-honeypot .
```
注意:[BuildKit 是 Docker Desktop 以及 Docker Engine v23.0 及更高版本用户的默认构建器。](https://docs.docker.com/build/buildkit/#getting-started)
## 用法
tiny-ssh-honeypot [选项]
长选项的必填参数对于短选项同样也是必填的。
* `-k`, `--host-key FILE`:包含私钥主机密钥(RSA, DSA, ECDSA, ED25519)的文件。作为一种回退机制,程序将尝试自动生成 RSA 和 ED25519 密钥。
* `-b`, `--address ADDRESS`:要绑定的 IP 地址(默认值:0.0.0.0)。你可以多次指定此选项。
* `-p`, `--port PORT`:要绑定的端口(默认值:22)。
* `-h`, `--help`:显示帮助信息并退出。
* `-v`, `--version`:输出版本信息并退出。
## 日志格式
与 `ssh-honeypotd` 不同,`tiny-ssh-honeypot` 不会尝试模仿 `sshd` 的输出,而是以不同的方式记录其日志。做出此决定的原因是,一些开发人员发现很难[为失败的 SSH 登录编写健壮的正则表达式](https://wildwolf.name/configservers-login-failure-daemon-is-vulnerable-to-denial-of-service-attacks/),从而使他们的系统面临潜在的拒绝服务攻击。
`tiny-ssh-honeypot` 生成的所有可操作消息均采用以下格式:
```
[source_ip:source_port => target_ip:target_port]: message
```
`tiny-ssh-honeypot` 会生成以下消息:
* **incoming connection**:有一个新的传入连接。
* **closing connection**:客户端已断开连接。如果在这两条消息之间没有关于失败登录尝试的消息,则可能意味着有人正在扫描你服务器的端口(读取服务标识字符串)。
* **did not receive identification string**:客户端未能标识自己并断开连接。此消息可能表明存在扫描器。
* **login attempt for user: \[user] (password: \[password])**:登录尝试失败。
* **connection closed by authenticating user**:客户端已标识自己并通过了 KEX(密钥交换)阶段,但在用户标识自己之前断开了连接。
* **SSH error: \[error]**:发生协议错误。例如,当客户端意外断开连接时可能会发生错误(*IO error*)。
* **input overflow**:不应发生。这意味着用户名或密码的长度超过了 `INT_MAX` 常量的值。
## 结合 Docker 使用
```
docker run -d \
--network=host \
--cap-drop=all \
--cap-add=NET_BIND_SERVICE \
--restart=always \
--read-only \
--user=10001:10001 \
wildwildangel/tiny-ssh-honeypot:latest -t
```
如果需要,这些变量使得在同一台机器上运行多个蜜罐变得很容易。
## 结合 Kubernetes 使用
`tiny-ssh-honeypot.yaml`:
```
---
apiVersion: v1
kind: Namespace
metadata:
name: honeypots
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: tiny-ssh-honeypot
namespace: honeypots
spec:
selector:
matchLabels:
name: tiny-ssh-honeypot
template:
metadata:
labels:
name: tiny-ssh-honeypot
spec:
hostNetwork: true
containers:
- name: tiny-ssh-honeypot
image: wildwildangel/tiny-ssh-honeypot
resources:
limits:
cpu: 100m
memory: 8Mi
requests:
cpu: 50m
memory: 8Mi
securityContext:
capabilities:
drop:
- all
add:
- NET_BIND_SERVICE
readOnlyRootFilesystem: true
runAsNonRoot: true
runAsUser: 10001
runAsGroup: 10001
allowPrivilegeEscalation: false
ports:
- containerPort: 22
hostPort: 22
protocol: TCP
```
```
kubectl apply -f tiny-ssh-honeypot.yaml
```
## 与 Wazuh 集成
`tiny-ssh-honeypot_decoders.xml`:
```
syslog
^tiny-ssh-honeypot$
firewall
^tiny-ssh-honeypot(?:\[\d+\])?:
syslog
^[0-9a-f]{12}$
tiny-ssh-honeypot(?:\[\d+\])?:
tiny-ssh-honeypot
\[([0-9a-fA-F:.]+?):(\d+) => ([0-9a-fA-F:.]+?):(\d+)\]: login attempt for user: (.*?) \(password:
srcip, srcport, dstip, dstport, srcuser
tiny-ssh-honeypot
\[([0-9a-fA-F:.]+?):(\d+) => ([0-9a-fA-F:.]+?):(\d+)\]: did not receive identification string
srcip, srcport, dstip, dstport
```
`tiny-ssh-honeypot_rules.xml`:
```
tiny-ssh-honeypot
login attempt for user
Tiny SSH Honeypot: login attempt
authentication_failed,
4100
tiny-ssh-honeypot
login attempt for user
Tiny SSH Honeypot: login attempt
authentication_failed,
101000, 101001
\S+
Tiny SSH Honeypot: login attempt for user $(srcuser)
authentication_failed,
101000, 101001
127.0.0.1
Tiny SSH Honeypot: ignore local testing
no_log
101000, 101001
Tiny SSH Honeypot: brute-force login attempts from $(srcip)
bruteforce, authentication_failed,
tiny-ssh-honeypot
did not receive identification string
Tiny SSH Honeypot: connection without SSH identification from $(srcip)
scan, network,
102000
Tiny SSH Honeypot: repeated probes from $(srcip)
scan, network,
```
标签:Bash脚本, BOF, CMake, Docker, LangChain, libassh, libev, PFX证书, SSH, 事件驱动, 低交互蜜罐, 凭据收集, 单线程, 威胁情报, 子域名突变, 安全防御评估, 客户端加密, 开发者工具, 恶意登录记录, 攻击检测, 欺骗防御, 红队行动, 网络安全, 蜜罐, 证书利用, 请求拦截, 轻量级, 隐私保护, 静态编译