mirror of
https://github.com/shadow1ng/fscan.git
synced 2026-09-23 03:31:53 +08:00
## 架构重构
- 全局变量消除,迁移至 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)
148 lines
3.6 KiB
Go
148 lines
3.6 KiB
Go
package core
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/shadow1ng/fscan/common"
|
|
)
|
|
|
|
// TestNewLocalScanStrategy 测试本地扫描策略构造函数
|
|
func TestNewLocalScanStrategy(t *testing.T) {
|
|
strategy := NewLocalScanStrategy()
|
|
|
|
if strategy == nil {
|
|
t.Fatal("NewLocalScanStrategy 返回 nil")
|
|
}
|
|
|
|
if strategy.BaseScanStrategy == nil {
|
|
t.Error("BaseScanStrategy 未初始化")
|
|
}
|
|
|
|
// 验证过滤器类型
|
|
if strategy.filterType != FilterLocal {
|
|
t.Errorf("filterType: 期望 FilterLocal(%d), 实际 %d", FilterLocal, strategy.filterType)
|
|
}
|
|
|
|
// 验证策略名称
|
|
if strategy.strategyName != "本地扫描" {
|
|
t.Errorf("strategyName: 期望 '本地扫描', 实际 %q", strategy.strategyName)
|
|
}
|
|
}
|
|
|
|
// TestLocalScanStrategy_PrepareTargets 测试PrepareTargets
|
|
func TestLocalScanStrategy_PrepareTargets(t *testing.T) {
|
|
strategy := NewLocalScanStrategy()
|
|
|
|
tests := []struct {
|
|
name string
|
|
input common.HostInfo
|
|
expected int
|
|
}{
|
|
{
|
|
name: "空HostInfo",
|
|
input: common.HostInfo{},
|
|
expected: 1,
|
|
},
|
|
{
|
|
name: "带Host的HostInfo",
|
|
input: common.HostInfo{
|
|
Host: "localhost",
|
|
},
|
|
expected: 1,
|
|
},
|
|
{
|
|
name: "完整HostInfo",
|
|
input: common.HostInfo{
|
|
Host: "127.0.0.1",
|
|
Port: 80,
|
|
},
|
|
expected: 1,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
targets := strategy.PrepareTargets(tt.input)
|
|
|
|
// 验证返回列表长度
|
|
if len(targets) != tt.expected {
|
|
t.Errorf("PrepareTargets() 返回长度 = %d, 期望 %d", len(targets), tt.expected)
|
|
}
|
|
|
|
// 验证返回的第一个元素与输入相同
|
|
if len(targets) > 0 {
|
|
if targets[0].Host != tt.input.Host {
|
|
t.Errorf("targets[0].Host = %q, 期望 %q", targets[0].Host, tt.input.Host)
|
|
}
|
|
if targets[0].Port != tt.input.Port {
|
|
t.Errorf("targets[0].Port = %q, 期望 %q", targets[0].Port, tt.input.Port)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestLocalScanStrategy_PrepareTargets_ImmutabilityCheck 测试PrepareTargets不修改输入
|
|
func TestLocalScanStrategy_PrepareTargets_ImmutabilityCheck(t *testing.T) {
|
|
strategy := NewLocalScanStrategy()
|
|
|
|
original := common.HostInfo{
|
|
Host: "192.168.1.1",
|
|
Port: 22,
|
|
}
|
|
|
|
// 保存原始值副本
|
|
originalHost := original.Host
|
|
originalPort := original.Port
|
|
|
|
// 调用PrepareTargets
|
|
targets := strategy.PrepareTargets(original)
|
|
|
|
// 验证原始输入未被修改
|
|
if original.Host != originalHost {
|
|
t.Errorf("输入被修改: original.Host = %q, 期望 %q", original.Host, originalHost)
|
|
}
|
|
if original.Port != originalPort {
|
|
t.Errorf("输入被修改: original.Port = %d, 期望 %d", original.Port, originalPort)
|
|
}
|
|
|
|
// 验证返回值与输入相等
|
|
if len(targets) != 1 {
|
|
t.Fatalf("targets长度 = %d, 期望 1", len(targets))
|
|
}
|
|
|
|
if targets[0].Host != originalHost {
|
|
t.Errorf("targets[0].Host = %q, 期望 %q", targets[0].Host, originalHost)
|
|
}
|
|
}
|
|
|
|
// TestLocalScanStrategy_TypeAssertion 测试类型继承关系
|
|
func TestLocalScanStrategy_TypeAssertion(t *testing.T) {
|
|
strategy := NewLocalScanStrategy()
|
|
|
|
// 验证类型继承
|
|
if strategy.BaseScanStrategy == nil {
|
|
t.Error("LocalScanStrategy 未嵌入 BaseScanStrategy")
|
|
}
|
|
|
|
// 验证可以访问BaseScanStrategy的方法
|
|
err := strategy.ValidateConfiguration()
|
|
if err != nil {
|
|
t.Errorf("ValidateConfiguration() 应返回 nil, 实际: %v", err)
|
|
}
|
|
}
|
|
|
|
// TestLocalScanStrategy_FieldAccess 测试字段访问
|
|
func TestLocalScanStrategy_FieldAccess(t *testing.T) {
|
|
strategy := NewLocalScanStrategy()
|
|
|
|
// 通过BaseScanStrategy访问私有字段
|
|
if strategy.strategyName == "" {
|
|
t.Error("strategyName 不应为空")
|
|
}
|
|
|
|
if strategy.filterType != FilterLocal {
|
|
t.Errorf("filterType 应为 FilterLocal, 实际 %d", strategy.filterType)
|
|
}
|
|
}
|