fscan/test/ssh-test-env/USAGE.md
ZacharyZcR de286026e8 refactor: 统一插件超时机制实现Context-First架构
- 重构SSH/MySQL/Redis插件超时控制,移除第三方库超时依赖
- 统一使用Go Context超时机制,提升超时控制可靠性和精确度
- 扩展MySQL/Redis/SSH插件默认端口支持,提升扫描覆盖率
- 修复插件系统中ConcurrentScanConfig超时配置缺失问题
- 优化插件检测逻辑,正确识别新架构插件并显示准确状态信息
- 解决插件在错误端口上长时间等待问题,显著提升扫描效率
2025-08-07 14:01:50 +08:00

5.4 KiB
Raw Blame History

fscan SSH插件测试环境使用指南

项目结构

test/ssh-test-env/
├── docker-compose.yml          # Docker Compose配置文件
├── Dockerfile.ssh-server       # SSH服务器镜像构建文件
├── .dockerignore               # Docker构建忽略文件
├── README.md                   # 详细说明文档
├── USAGE.md                    # 使用指南(本文件)
├── test-ssh-plugin.bat         # Windows测试脚本
├── test-ssh-plugin.sh          # Linux/Unix测试脚本
├── test-users.txt              # 测试用户名列表
├── test-passwords.txt          # 测试密码列表
├── ssh-config/
│   └── sshd_config            # SSH服务器配置文件
└── scripts/
    └── start-ssh.sh           # SSH服务器启动脚本

快速开始

1. 环境要求

  • Docker Desktop (Windows/macOS) 或 Docker Engine (Linux)
  • Docker Compose
  • fscan工具已编译

2. 启动测试环境

Windows:

cd test\ssh-test-env
docker-compose up -d

Linux/macOS:

cd test/ssh-test-env
docker-compose up -d

3. 验证环境

# 检查容器状态
docker-compose ps

# 查看服务日志
docker-compose logs ssh-test-server

# 测试SSH连接
ssh root@localhost -p 2222
# 密码: password

自动化测试

Windows

# 运行自动化测试脚本
test-ssh-plugin.bat

Linux/macOS

# 给脚本执行权限
chmod +x test-ssh-plugin.sh

# 运行自动化测试脚本
./test-ssh-plugin.sh

手动测试示例

基础功能测试

# 1. SSH服务检测
./fscan -h 127.0.0.1:2222 -m ssh

# 2. 指定用户密码测试
./fscan -h 127.0.0.1:2222 -m ssh -user root -pwd password

# 3. 多用户测试
./fscan -h 127.0.0.1:2222 -m ssh -user admin -pwd 123456

# 4. 弱密码扫描
./fscan -h 127.0.0.1:2222 -m ssh -userfile test/ssh-test-env/test-users.txt -pwdfile test/ssh-test-env/test-passwords.txt

高级测试场景

# 超时测试
./fscan -h 127.0.0.1:2222 -m ssh -timeout 10

# 多线程测试
./fscan -h 127.0.0.1:2222 -m ssh -t 10

# 无端口扫描模式仅SSH
./fscan -h 127.0.0.1:2222 -m ssh -np

测试用户账户

管理员级账户

用户名 密码 权限 用途
root password root 系统管理员
root2 password user+sudo 备用root账户
admin 123456 user+sudo 管理员账户
test test123 user+sudo 测试管理员

普通用户账户

用户名 密码 权限 用途
user user user 普通用户
guest guest user+chroot 受限用户
web web123 user Web服务用户
service service123 user 服务用户

数据库用户

用户名 密码 用途
oracle oracle Oracle数据库用户
mysql mysql MySQL数据库用户
postgres postgres PostgreSQL用户
redis redis123 Redis用户
mongodb mongo123 MongoDB用户

特殊用户

用户名 密码 特点
ftp ftp FTP服务用户
anonymous 无密码 极不安全测试账户

常见问题排除

1. 端口冲突

问题: 端口2222已被占用 解决: 修改docker-compose.yml中的端口映射

ports:
  - "2223:22"  # 改为其他端口

2. 容器启动失败

问题: SSH服务启动失败 解决:

# 查看详细日志
docker-compose logs ssh-test-server

# 重新构建镜像
docker-compose build --no-cache ssh-test-server

3. SSH连接被拒绝

问题: 无法连接到SSH服务 解决:

# 检查容器状态
docker-compose ps

# 检查端口映射
docker port fscan-ssh-test

# 等待服务完全启动
sleep 10

4. fscan测试失败

问题: fscan无法检测到SSH服务 解决:

  1. 确认fscan已正确编译
  2. 检查命令行参数
  3. 增加调试输出
  4. 验证网络连通性

性能优化建议

1. 构建优化

  • 使用.dockerignore减少构建上下文
  • 合并Docker命令减少层数
  • 使用多阶段构建(如需要)

2. 运行优化

  • 设置合适的资源限制
  • 配置健康检查
  • 使用合适的重启策略

3. 测试优化

  • 批量测试时使用适当的线程数
  • 设置合理的超时时间
  • 使用Docker网络进行隔离测试

清理环境

停止服务

docker-compose down

完全清理

# 删除所有相关资源
docker-compose down -v --rmi all

# 清理未使用的Docker资源
docker system prune -f

安全注意事项

  1. 仅用于测试: 此环境包含多个安全漏洞
  2. 网络隔离: 不要暴露到公网
  3. 及时清理: 测试完成后立即停止容器
  4. 密码管理: 测试密码文件包含真实弱密码,注意保护

扩展功能

添加新的测试用户

  1. 修改Dockerfile.ssh-server
  2. RUN命令中添加新用户
  3. 更新test-users.txttest-passwords.txt
  4. 重新构建镜像

自定义SSH配置

  1. 修改ssh-config/sshd_config
  2. 重启容器以应用更改

集成到CI/CD

# GitHub Actions示例
- name: Start SSH Test Environment
  run: |
    cd test/ssh-test-env
    docker-compose up -d
    sleep 15    

- name: Test SSH Plugin
  run: |
    ./fscan -h 127.0.0.1:2222 -m ssh -np    

- name: Cleanup
  run: |
    cd test/ssh-test-env
    docker-compose down