mirror of
https://github.com/shadow1ng/fscan.git
synced 2025-09-14 14:06:44 +08:00

- 创建通用SMB框架,包含抽象接口、凭据管理和并发扫描引擎 - SMB2插件代码量从492行减少到159行,减少68%代码量 - 统一错误分类和处理机制,提高代码可维护性 - 支持密码和哈希两种认证方式,保持向后兼容性 - 模块化设计便于单元测试和功能扩展
78 lines
1.6 KiB
Go
78 lines
1.6 KiB
Go
package common
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
// TargetInfo SMB目标信息
|
|
type TargetInfo struct {
|
|
Host string
|
|
Port int
|
|
Domain string
|
|
}
|
|
|
|
// Credential SMB认证凭据
|
|
type Credential struct {
|
|
Username string
|
|
Password string
|
|
Hash []byte
|
|
IsHash bool
|
|
}
|
|
|
|
// ConnectionResult 连接结果
|
|
type ConnectionResult struct {
|
|
Success bool
|
|
Shares []string
|
|
HasAdminAccess bool
|
|
Error error
|
|
}
|
|
|
|
// ScanConfig 扫描配置
|
|
type ScanConfig struct {
|
|
MaxConcurrent int
|
|
Timeout time.Duration
|
|
GlobalTimeout time.Duration
|
|
}
|
|
|
|
// SmbConnector SMB连接器接口
|
|
type SmbConnector interface {
|
|
// Connect 建立SMB连接并进行认证
|
|
Connect(ctx context.Context, target *TargetInfo, cred *Credential) (*ConnectionResult, error)
|
|
|
|
// GetProtocolName 获取协议名称
|
|
GetProtocolName() string
|
|
|
|
// GetDefaultPort 获取默认端口
|
|
GetDefaultPort() int
|
|
}
|
|
|
|
// CredentialManager 凭据管理器接口
|
|
type CredentialManager interface {
|
|
// GenerateCredentials 生成认证凭据列表
|
|
GenerateCredentials() []Credential
|
|
|
|
// HandleAuthFailure 处理认证失败
|
|
HandleAuthFailure(username string, err error)
|
|
|
|
// IsUserLocked 检查用户是否被锁定
|
|
IsUserLocked(username string) bool
|
|
|
|
// GetCredentialCount 获取凭据总数
|
|
GetCredentialCount() int
|
|
}
|
|
|
|
// ScanResult 扫描结果
|
|
type ScanResult struct {
|
|
Success bool
|
|
Credential Credential
|
|
Shares []string
|
|
Error error
|
|
}
|
|
|
|
// Scanner 并发扫描器接口
|
|
type Scanner interface {
|
|
// Scan 执行并发扫描
|
|
Scan(ctx context.Context, target *TargetInfo, connector SmbConnector,
|
|
credMgr CredentialManager, config *ScanConfig) (*ScanResult, error)
|
|
} |