#!/bin/bash set -e echo "========================================" echo "fscan SSH Plugin Test Script" echo "========================================" echo # 检查Docker是否运行 if ! docker version >/dev/null 2>&1; then echo "Error: Docker is not running or not installed" echo "Please start Docker and try again" exit 1 fi echo "Step 1: Starting SSH test environment..." docker-compose up -d # 等待容器启动 echo "Waiting for SSH service to start..." sleep 10 echo echo "Step 2: Checking container status..." docker-compose ps echo echo "Step 3: Testing SSH connectivity..." echo "Testing basic SSH connection..." # 等待SSH服务完全启动 echo "Waiting for SSH service to be ready..." for i in {1..30}; do if nc -z localhost 2222 2>/dev/null; then echo "SSH service is ready!" break fi if [ $i -eq 30 ]; then echo "Warning: SSH service may not be ready yet" docker-compose logs ssh-test-server fi sleep 1 done echo echo "Step 4: fscan SSH plugin tests" echo # 检查fscan是否存在 if [ ! -f "../../fscan" ] && [ ! -f "../../fscan.exe" ]; then echo "Warning: fscan binary not found in project root" echo "Please build fscan first:" echo " go build -o fscan" echo echo "Manual test commands:" echo " ./fscan -h 127.0.0.1:2222 -m ssh" echo " ./fscan -h 127.0.0.1:2222 -m ssh -user root -pwd password" echo " ./fscan -h 127.0.0.1:2222 -m ssh -user admin -pwd 123456" show_manual_commands exit 0 fi # 确定fscan二进制文件路径 FSCAN_BIN="" if [ -f "../../fscan" ]; then FSCAN_BIN="../../fscan" elif [ -f "../../fscan.exe" ]; then FSCAN_BIN="../../fscan.exe" fi echo "Using fscan binary: $FSCAN_BIN" echo echo "Test 1: Basic SSH service detection" $FSCAN_BIN -h 127.0.0.1:2222 -m ssh -np echo echo "Test 2: SSH with specific credentials" $FSCAN_BIN -h 127.0.0.1:2222 -m ssh -user root -pwd password echo echo "Test 3: SSH with weak password detection" $FSCAN_BIN -h 127.0.0.1:2222 -m ssh -user admin -pwd 123456 echo echo "Test 4: SSH brute force simulation (limited users)" $FSCAN_BIN -h 127.0.0.1:2222 -m ssh -userfile test-users.txt -pwdfile test-passwords.txt show_manual_commands() { echo echo "========================================" echo "Test completed!" echo "========================================" echo echo "Container is still running for manual testing." echo echo "Manual test commands:" echo " ssh root@localhost -p 2222 (password: password)" echo " ssh admin@localhost -p 2222 (password: 123456)" echo " ssh test@localhost -p 2222 (password: test123)" echo echo "Available test users:" cat test-users.txt | while read user; do case $user in root) echo " $user:password" ;; admin) echo " $user:123456" ;; test) echo " $user:test123" ;; user) echo " $user:user" ;; guest) echo " $user:guest" ;; oracle) echo " $user:oracle" ;; mysql) echo " $user:mysql" ;; postgres) echo " $user:postgres" ;; redis) echo " $user:redis123" ;; mongodb) echo " $user:mongo123" ;; ftp) echo " $user:ftp" ;; web) echo " $user:web123" ;; service) echo " $user:service123" ;; anonymous) echo " $user:" ;; esac done echo echo "To stop the test environment:" echo " docker-compose down" echo echo "To view SSH server logs:" echo " docker-compose logs -f ssh-test-server" echo } show_manual_commands