mirror of
https://github.com/shadow1ng/fscan.git
synced 2025-09-14 14:06:44 +08:00
fix: 修复LDAP插件结构体和接口兼容性问题
## 主要修复 - 将ScanResult结构体改为plugins.Result - 将Credential结构体改为plugins.Credential - 将GenerateCredentials函数改为plugins.GenerateCredentials - 将RegisterPluginWithPorts改为plugins.RegisterWithPorts - 添加上下文取消检查,提升扫描控制能力 ## 测试结果 - 服务识别模式(-nobr)正常工作:成功识别LDAP 127.0.0.1:389 - 密码爆破模式正常运行,不再报告"未发现弱密码"错误 - 插件接口与新架构完全兼容
This commit is contained in:
parent
7579549e94
commit
8ae94f7813
@ -19,28 +19,30 @@ func NewLDAPPlugin() *LDAPPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
func (p *LDAPPlugin) Scan(ctx context.Context, info *common.HostInfo) *ScanResult {
|
||||
func (p *LDAPPlugin) Scan(ctx context.Context, info *common.HostInfo) *plugins.Result {
|
||||
target := fmt.Sprintf("%s:%s", info.Host, info.Ports)
|
||||
|
||||
if common.DisableBrute {
|
||||
return p.identifyService(ctx, info)
|
||||
}
|
||||
|
||||
credentials := GenerateCredentials("ldap")
|
||||
if len(credentials) == 0 {
|
||||
return &ScanResult{
|
||||
Success: false,
|
||||
Service: "ldap",
|
||||
Error: fmt.Errorf("没有可用的测试凭据"),
|
||||
}
|
||||
}
|
||||
|
||||
credentials := plugins.GenerateCredentials("ldap")
|
||||
|
||||
for _, cred := range credentials {
|
||||
// 检查上下文是否已取消
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return &plugins.Result{
|
||||
Success: false,
|
||||
Service: "ldap",
|
||||
Error: ctx.Err(),
|
||||
}
|
||||
default:
|
||||
}
|
||||
|
||||
if p.testCredential(ctx, info, cred) {
|
||||
common.LogSuccess(fmt.Sprintf("LDAP %s %s:%s", target, cred.Username, cred.Password))
|
||||
return &ScanResult{
|
||||
return &plugins.Result{
|
||||
Success: true,
|
||||
Service: "ldap",
|
||||
Username: cred.Username,
|
||||
@ -49,15 +51,14 @@ func (p *LDAPPlugin) Scan(ctx context.Context, info *common.HostInfo) *ScanResul
|
||||
}
|
||||
}
|
||||
|
||||
return &ScanResult{
|
||||
return &plugins.Result{
|
||||
Success: false,
|
||||
Service: "ldap",
|
||||
Error: fmt.Errorf("未发现弱密码"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func (p *LDAPPlugin) testCredential(ctx context.Context, info *common.HostInfo, cred Credential) bool {
|
||||
func (p *LDAPPlugin) testCredential(ctx context.Context, info *common.HostInfo, cred plugins.Credential) bool {
|
||||
conn, err := p.connectLDAP(ctx, info, cred)
|
||||
if err != nil {
|
||||
return false
|
||||
@ -71,7 +72,7 @@ func (p *LDAPPlugin) testCredential(ctx context.Context, info *common.HostInfo,
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *LDAPPlugin) connectLDAP(ctx context.Context, info *common.HostInfo, creds Credential) (*ldaplib.Conn, error) {
|
||||
func (p *LDAPPlugin) connectLDAP(ctx context.Context, info *common.HostInfo, creds plugins.Credential) (*ldaplib.Conn, error) {
|
||||
target := fmt.Sprintf("%s:%s", info.Host, info.Ports)
|
||||
|
||||
if info.Ports == "636" {
|
||||
@ -80,17 +81,12 @@ func (p *LDAPPlugin) connectLDAP(ctx context.Context, info *common.HostInfo, cre
|
||||
return ldaplib.Dial("tcp", target)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
func (p *LDAPPlugin) identifyService(ctx context.Context, info *common.HostInfo) *ScanResult {
|
||||
func (p *LDAPPlugin) identifyService(ctx context.Context, info *common.HostInfo) *plugins.Result {
|
||||
target := fmt.Sprintf("%s:%s", info.Host, info.Ports)
|
||||
|
||||
conn, err := p.connectLDAP(ctx, info, Credential{})
|
||||
conn, err := p.connectLDAP(ctx, info, plugins.Credential{})
|
||||
if err != nil {
|
||||
return &ScanResult{
|
||||
return &plugins.Result{
|
||||
Success: false,
|
||||
Service: "ldap",
|
||||
Error: err,
|
||||
@ -100,7 +96,7 @@ func (p *LDAPPlugin) identifyService(ctx context.Context, info *common.HostInfo)
|
||||
|
||||
banner := "LDAP"
|
||||
common.LogSuccess(fmt.Sprintf("LDAP %s %s", target, banner))
|
||||
return &ScanResult{
|
||||
return &plugins.Result{
|
||||
Success: true,
|
||||
Service: "ldap",
|
||||
Banner: banner,
|
||||
@ -108,8 +104,7 @@ func (p *LDAPPlugin) identifyService(ctx context.Context, info *common.HostInfo)
|
||||
}
|
||||
|
||||
func init() {
|
||||
// 使用高效注册方式:直接传递端口信息,避免实例创建
|
||||
RegisterPluginWithPorts("ldap", func() Plugin {
|
||||
plugins.RegisterWithPorts("ldap", func() plugins.Plugin {
|
||||
return NewLDAPPlugin()
|
||||
}, []int{389, 636, 3268, 3269})
|
||||
}
|
Loading…
Reference in New Issue
Block a user