mirror of
https://github.com/shadow1ng/fscan.git
synced 2026-09-22 19:21:52 +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)
207 lines
5.7 KiB
Go
207 lines
5.7 KiB
Go
//go:build plugin_smb || !plugin_selective
|
|
|
|
package services
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/shadow1ng/fscan/common"
|
|
"github.com/shadow1ng/fscan/common/i18n"
|
|
"github.com/shadow1ng/fscan/plugins"
|
|
)
|
|
|
|
// SmbPlugin 统一SMB检测插件
|
|
// 融合了原有的 smb, smb2, smbinfo, smbghost 四个插件
|
|
type SmbPlugin struct {
|
|
plugins.BasePlugin
|
|
}
|
|
|
|
func NewSmbPlugin() *SmbPlugin {
|
|
return &SmbPlugin{
|
|
BasePlugin: plugins.NewBasePlugin("smb"),
|
|
}
|
|
}
|
|
|
|
func (p *SmbPlugin) Scan(ctx context.Context, info *common.HostInfo, config *common.Config, state *common.State) *plugins.Result {
|
|
target := info.Target()
|
|
|
|
// 检查端口
|
|
if info.Port != 445 && info.Port != 139 {
|
|
return &ScanResult{
|
|
Success: false,
|
|
Service: "smb",
|
|
Error: fmt.Errorf("SMB插件仅支持139和445端口"),
|
|
}
|
|
}
|
|
|
|
// 1. 协议探测和信息收集
|
|
smbTarget, err := probeTarget(info.Host, info.Port, config.Timeout)
|
|
if err != nil {
|
|
state.IncrementTCPFailedPacketCount()
|
|
return &ScanResult{
|
|
Success: false,
|
|
Service: "smb",
|
|
Error: fmt.Errorf("SMB协议探测失败: %w", err),
|
|
}
|
|
}
|
|
state.IncrementTCPSuccessPacketCount()
|
|
|
|
// 输出信息收集结果
|
|
p.logSMBInfo(target, smbTarget)
|
|
|
|
// 2. 漏洞检测 (仅SMBv2+且端口445)
|
|
if smbTarget.Protocol == SMBProtocol2 && info.Port == 445 {
|
|
if checkSMBGhost(info.Host, config.Timeout) {
|
|
smbTarget.Vulnerable = &SMBVuln{CVE20200796: true}
|
|
common.LogSuccess(i18n.Tr("smbghost_vuln", target))
|
|
}
|
|
}
|
|
|
|
// 如果禁用暴力破解,只返回信息收集结果
|
|
if config.DisableBrute {
|
|
return p.buildInfoResult(smbTarget)
|
|
}
|
|
|
|
// 3. 根据协议版本选择认证器
|
|
auth := p.getAuthenticator(smbTarget.Protocol)
|
|
|
|
// 4. 未授权访问检测
|
|
if result := p.testUnauthorizedAccess(ctx, info, auth, config, state); result != nil && result.Success {
|
|
var successMsg string
|
|
if config.Credentials.Domain != "" {
|
|
successMsg = fmt.Sprintf("SMB %s 未授权访问 - %s\\%s:%s", target, config.Credentials.Domain, result.Username, result.Password)
|
|
} else {
|
|
successMsg = fmt.Sprintf("SMB %s 未授权访问 - %s:%s", target, result.Username, result.Password)
|
|
}
|
|
common.LogSuccess(successMsg)
|
|
return result
|
|
}
|
|
|
|
// 5. 弱密码检测
|
|
credentials := plugins.GenerateCredentials("smb", config)
|
|
if len(credentials) == 0 {
|
|
return p.buildInfoResult(smbTarget)
|
|
}
|
|
|
|
creds := make([]Credential, len(credentials))
|
|
for i, c := range credentials {
|
|
creds[i] = Credential{Username: c.Username, Password: c.Password}
|
|
}
|
|
|
|
authFn := p.createAuthFunc(info, auth, config, state)
|
|
testConfig := DefaultConcurrentTestConfig(config)
|
|
|
|
result := TestCredentialsConcurrently(ctx, creds, authFn, "smb", testConfig)
|
|
|
|
if result.Success {
|
|
var successMsg string
|
|
if config.Credentials.Domain != "" {
|
|
successMsg = fmt.Sprintf("SMB %s %s\\%s:%s", target, config.Credentials.Domain, result.Username, result.Password)
|
|
} else {
|
|
successMsg = fmt.Sprintf("SMB %s %s:%s", target, result.Username, result.Password)
|
|
}
|
|
common.LogSuccess(successMsg)
|
|
}
|
|
|
|
return result
|
|
}
|
|
|
|
// getAuthenticator 根据协议版本返回认证器
|
|
func (p *SmbPlugin) getAuthenticator(protocol SMBProtocol) SMBAuthenticator {
|
|
if protocol == SMBProtocol1 {
|
|
return &SMB1Authenticator{}
|
|
}
|
|
return &SMB2Authenticator{}
|
|
}
|
|
|
|
// createAuthFunc 创建认证函数
|
|
func (p *SmbPlugin) createAuthFunc(info *common.HostInfo, auth SMBAuthenticator, config *common.Config, state *common.State) AuthFunc {
|
|
return func(ctx context.Context, cred Credential) *AuthResult {
|
|
result, _ := auth.Authenticate(ctx, info.Host, info.Port, cred, config.Credentials.Domain, config.Timeout)
|
|
if result.Success {
|
|
state.IncrementTCPSuccessPacketCount()
|
|
} else {
|
|
state.IncrementTCPFailedPacketCount()
|
|
}
|
|
return result
|
|
}
|
|
}
|
|
|
|
// testUnauthorizedAccess 测试未授权访问
|
|
func (p *SmbPlugin) testUnauthorizedAccess(ctx context.Context, info *common.HostInfo, auth SMBAuthenticator, config *common.Config, state *common.State) *ScanResult {
|
|
target := info.Target()
|
|
|
|
unauthorizedCreds := []Credential{
|
|
{Username: "", Password: ""},
|
|
{Username: "guest", Password: ""},
|
|
{Username: "anonymous", Password: ""},
|
|
}
|
|
|
|
for _, cred := range unauthorizedCreds {
|
|
shareInfo, err := auth.ListShares(ctx, info.Host, info.Port, cred, config.Credentials.Domain, config.Timeout)
|
|
if err == nil && len(shareInfo) > 0 {
|
|
var output strings.Builder
|
|
displayUser := cred.Username
|
|
if displayUser == "" {
|
|
displayUser = "<empty>"
|
|
}
|
|
output.WriteString(fmt.Sprintf("SMB %s 匿名访问 - %s:%s", target, displayUser, cred.Password))
|
|
for _, share := range shareInfo {
|
|
output.WriteString(fmt.Sprintf("\n%s", share))
|
|
}
|
|
|
|
common.LogSuccess(output.String())
|
|
|
|
return &ScanResult{
|
|
Success: true,
|
|
Type: plugins.ResultTypeCredential,
|
|
Service: "smb",
|
|
Username: cred.Username,
|
|
Password: cred.Password,
|
|
Banner: "SMB匿名访问",
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// logSMBInfo 输出SMB信息
|
|
func (p *SmbPlugin) logSMBInfo(target string, info *SMBTarget) {
|
|
msg := fmt.Sprintf("SMBInfo %s", target)
|
|
if info.OSVersion != "" {
|
|
msg += fmt.Sprintf(" [%s]", info.OSVersion)
|
|
}
|
|
if info.ComputerName != "" {
|
|
msg += fmt.Sprintf(" %s", info.ComputerName)
|
|
}
|
|
msg += fmt.Sprintf(" %s", info.Protocol.String())
|
|
common.LogSuccess(msg)
|
|
}
|
|
|
|
// buildInfoResult 构建信息收集结果
|
|
func (p *SmbPlugin) buildInfoResult(info *SMBTarget) *ScanResult {
|
|
result := &ScanResult{
|
|
Success: true,
|
|
Type: plugins.ResultTypeService,
|
|
Service: "smb",
|
|
Banner: info.Summary(),
|
|
}
|
|
|
|
// 如果发现漏洞,标记为漏洞类型
|
|
if info.Vulnerable != nil && info.Vulnerable.CVE20200796 {
|
|
result.Type = plugins.ResultTypeVuln
|
|
result.Banner = fmt.Sprintf("%s CVE-2020-0796", info.Summary())
|
|
}
|
|
|
|
return result
|
|
}
|
|
|
|
func init() {
|
|
RegisterPluginWithPorts("smb", func() Plugin {
|
|
return NewSmbPlugin()
|
|
}, []int{139, 445})
|
|
}
|