feat: v2.1.0 核心重构与功能增强

## 架构重构
- 全局变量消除,迁移至 Config/State 对象
- SMB 插件融合(smb/smb2/smbghost/smbinfo)
- 服务探测重构,实现 Nmap 风格 fallback 机制
- 输出系统重构,TXT 实时刷盘 + 双写机制
- i18n 框架升级至 go-i18n

## 性能优化
- 正则表达式预编译
- 内存优化 map[string]struct{}
- 并发指纹匹配
- SOCKS5 连接复用
- 滑动窗口调度 + 自适应线程池

## 新功能
- Web 管理界面
- 多格式 POC 适配(xray/afrog)
- 增强指纹库(3139条)
- Favicon hash 指纹识别
- 插件选择性编译(Build Tags)
- fscan-lab 靶场环境
- 默认端口扩展(62→133)

## 构建系统
- 添加 no_local tag 支持排除本地插件
- 多版本构建:fscan/fscan-nolocal/fscan-web
- CI 添加 snapshot 模式支持仅测试构建

## Bug 修复
- 修复 120+ 个问题,包括 RDP panic、批量扫描漏报、
  JSON 输出格式、Redis 检测、Context 超时等

## 测试增强
- 单元测试覆盖率 74-100%
- 并发安全测试
- 集成测试(Web/端口/服务/SSH/ICMP)
This commit is contained in:
ZacharyZcR
2026-01-11 20:16:23 +08:00
parent 6b13b2e84f
commit 71b92d4408
948 changed files with 92335 additions and 24630 deletions
+125
View File
@@ -0,0 +1,125 @@
//go:build web
package web
import (
"context"
"embed"
"fmt"
"io/fs"
"net/http"
"os"
"os/signal"
"syscall"
"time"
"github.com/shadow1ng/fscan/common"
"github.com/shadow1ng/fscan/common/i18n"
"github.com/shadow1ng/fscan/web/api"
"github.com/shadow1ng/fscan/web/ws"
)
//go:embed dist/*
var distFS embed.FS
// StartServer 启动Web服务器
func StartServer(port int) error {
// 初始化WebSocket Hub
hub := ws.NewHub()
go hub.Run()
// 创建路由
mux := http.NewServeMux()
// API路由
api.RegisterRoutes(mux, hub)
// WebSocket路由
mux.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) {
ws.ServeWs(hub, w, r)
})
// 静态文件服务
distContent, err := fs.Sub(distFS, "dist")
if err != nil {
return fmt.Errorf("failed to get dist fs: %w", err)
}
fileServer := http.FileServer(http.FS(distContent))
// SPA fallback: 对于非API/WS请求,尝试静态文件,否则返回index.html
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
// 检查文件是否存在
path := r.URL.Path
if path == "/" {
path = "/index.html"
}
// 尝试打开文件
f, err := distContent.Open(path[1:]) // 移除开头的/
if err != nil {
// 文件不存在,返回index.htmlSPA路由)
r.URL.Path = "/"
fileServer.ServeHTTP(w, r)
return
}
f.Close()
// 文件存在,正常服务
fileServer.ServeHTTP(w, r)
})
// 创建服务器
addr := fmt.Sprintf(":%d", port)
server := &http.Server{
Addr: addr,
Handler: corsMiddleware(mux),
ReadTimeout: 30 * time.Second,
WriteTimeout: 30 * time.Second,
IdleTimeout: 60 * time.Second,
}
// 优雅关闭
done := make(chan bool)
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-quit
common.LogBase(i18n.GetText("web_shutting_down"))
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
if err := server.Shutdown(ctx); err != nil {
common.LogError(fmt.Sprintf("Server shutdown error: %v", err))
}
close(done)
}()
// 启动服务器
common.LogSuccess(i18n.Tr("web_server_started", port))
common.LogBase(fmt.Sprintf("http://localhost:%d", port))
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
return fmt.Errorf("server error: %w", err)
}
<-done
return nil
}
// corsMiddleware 添加CORS头(开发时需要)
func corsMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)
return
}
next.ServeHTTP(w, r)
})
}