LorenzMap/sshcatch
GitHub: LorenzMap/sshcatch
一个基于 Python 的快速部署 SSH 服务器,仅提供隧道转发和 SCP/SFTP 文件传输功能而不开放 shell,专为渗透测试中的受控 SSH 端点场景设计。
Stars: 0 | Forks: 0
# sshcatch
一个用于隧道传输(本地/远程/动态)和简单 SCP / SFTP 传输的快速部署 SSH 服务器 - 它**绝不打开 shell**。
默认情况下,所有功能均被禁用:连接会被记录并关闭。使用下文描述的标志,仅开启你所需的功能。在测试任务中,当你需要一个受控的 SSH endpoint(隧道中继或文件投递点)而无需设置完整的 `sshd` 时,这非常实用。
基于 [asyncssh](https://github.com/ronf/asyncssh) 构建。
这是一个渗透测试工具。请仅将其指向你已获授权测试的系统和网络。
## 安装
使用 `pipx`(推荐,会将其安装到隔离环境中并将 `sshcatch` 添加到你的 `PATH`):
```
pipx install sshcatch
```
使用 `pip`:
```
pip install sshcatch
```
从源码安装:
```
git clone https://github.com/LorenzMap/sshcatch
cd sshcatch
pipx install . # or: pip install .
```
需要 Python 3.10+。首次运行时会在工作目录中自动生成 host key(或者使用 `--host-key` 指定你自己的)。
## 工作原理
在没有任何标志的情况下,sshcatch 处于**仅记录日志**模式:它会接受连接,记录客户端版本、用户名、提供的密码和公钥,然后关闭连接。在你明确要求之前,不会启用任何其他功能。
使用 `-vv` 和 `-q` 调整日志详细程度。或者使用 `-o` 将所有内容输出到日志文件中。
#### 隧道
由于绝不会创建 shell,隧道客户端**必须**传递 `-N`(例如 `ssh -NL ...`),否则它们会立即断开连接。
使用 `--open-auth` 开启隧道意味着**任何人**只要连接上,就可以通过你的主机进行跳板访问!
永远仅支持纯 **TCP** 转发。UNIX-domain-socket 转发(`ssh -L /sock:...` / `-R /sock:...`)和 TUN/TAP 隧道(`ssh -w`)始终会被拒绝,即使设置了 `--forward` / `--reverse` 也是如此。
#### SCP / SFTP
对**符号链接** 的处理非常严格:在上传时,它们会创建一个包含原始目标路径的占位文件。在下载时则会被直接拒绝。
当 host key、`authorized_keys`、日志文件和 sshcatch 脚本本身位于 SCP 目录内时,它们是受**保护**且隐藏的。
上传**绝不覆盖**现有文件。新文件会加上数字后缀(`loot.tar` -> `loot_1.tar`)。系统会自动创建不存在的父文件夹。
重命名、删除和移除目录的操作均会被拒绝。
## 示例
允许一个用户通过 SCP/SFTP 从当前目录拉取/上传文件:
```
# Server
sshcatch -u user:pass --scp-download --scp-upload
# Client
scp user@host:secret.txt .
scp -r loot/ user@host:pete/pc/
sftp user@host
```
允许任何人通过服务器进行隧道传输(本地和动态转发):**使用此功能需谨慎!**
```
# Server
sshcatch --open-auth --forward
# Client
ssh -NL 8080:internal:80 user@host # local forward
ssh -ND 1080 user@host # dynamic (SOCKS)
```
使用 single-mode 向首个成功认证的客户端返回内容,随后关闭服务器,同时将带有时间戳的日志打印到控制台并保存到文件中:
```
# Server
sshcatch -1 -u arthur:42 --version-banner debian \
--pre-auth-banner "What is the answer to life the universe and everything" \
--post-auth-banner "flag{So_Long_and_Thanks_for_All_the_Fish}" \
-o sshcatch.log -t
```
我最喜欢的用法:针对 `./authorized-keys` 中的密钥提供反向隧道和 SCP 上传,同时在 2222 端口伪装成 Ubuntu SSH 服务器:
```
# Server
sshcatch --reverse --authorized-keys ./authorized-keys --scp-upload --version-banner ubuntu -p 2222
# Client
ssh -NR 9000:localhost:22 user@host -p 2222 # reverse tunnel
scp -P 2222 loot.tar user@host:. # upload
```
## 选项
`sshcatch -h` 会打印一份简短的摘要,其中包含你开始使用所需的标志。
下方的完整参考来自 `sshcatch --help`:
```
usage: sshcatch [-h] [--help] [-p PORT] [-b BIND] [-1] [--host-key FILE]
[--version] [-u USER:PASS] [--open-auth]
[--authorized-keys FILE] [--forward] [--reverse]
[--scp-upload] [--scp-download] [--scp-dir DIR]
[--version-banner STRING] [--pre-auth-banner STRING]
[--post-auth-banner STRING] [-q | -v] [-o FILE] [-t] [--plain]
sshcatch - a quick-deploy SSH server for tunneling (local/remote/dynamic)
and simple SCP transfers (NEVER opens a shell!).
By default all features are disabled. Use flags to enable features.
options:
-h show a short help message and exit
--help show the full help and exit
-p PORT, --port PORT listen port (default: 22)
-b BIND, --bind BIND bind address (default: all IPv4/v6 interfaces)
-1, --single close the listener after first successful auth (and
exit when that connection ends)
--host-key FILE server host key file (default: auto-generate)
--version show program's version number and exit
authentication:
-u USER:PASS, --user USER:PASS
allowed user:password (repeatable)
--open-auth accept any credentials (open mode)
--authorized-keys FILE
authorized_keys file for key auth (username
independent)
tunneling:
--forward enable forward tunnels (client: ssh -NL / -ND)
--reverse enable reverse tunnels (client: ssh -NR)
SCP / SFTP file transfer:
--scp-upload enable file upload (SCP/SFTP write) - files get suffix
instead of overwriting
--scp-download enable file download (SCP/SFTP read) - symlinks are
denied
--scp-dir DIR directory for SCP/SFTP (default: cwd) - sensitive
sshcatch files (host-key, authorized_keys, logfile)
are protected
banners:
--version-banner STRING
sent as 'SSH-2.0-STRING' version banner - only first-
glance deception, it can still be identified as
asyncssh - presets (case-insensitive): ubuntu, debian,
dropbear, windows, macos
--pre-auth-banner STRING
banner shown to every client before login
--post-auth-banner STRING
banner shown only to clients that authenticate
successfully
logging:
-q, --quiet print nothing on console
-v, --verbose print additional information to the console
(repeatable)
-o FILE, --output FILE
append the log to FILE (plain with timestamps)
-t, --timestamps prefix console lines with a timestamp
--plain disable ANSI colors on the console
examples: (also check README on Github)
sshcatch Log-only (capture creds)
sshcatch -u user:pass --scp-download Allow one user to download via SCP/SFTP
sshcatch --open-auth --forward Allow ANYONE! to tunnel through this SSH server
# My favorite one
# Allows reverse tunnels and uploads via SCP for the keys in ./authorized_keys
# while posing shallowly as an Ubuntu SSH server on port 2222
sshcatch --reverse --authorized-keys ./authorized-keys --scp-upload --version-banner ubuntu -p 2222
```
## 许可证
MIT
标签:Blue Team, Python, SSH隧道, 凭证捕获, 无后门, 网络转发, 逆向工具