Files
fscan/plugins/services/zookeeper.go
T
ZacharyZcR 6d61b661f4
测试构建 / 代码检查 (push) Has been cancelled
测试构建 / 单元测试和构建 (push) Has been cancelled
测试构建 / 构建验证 (push) Has been cancelled
fix: 修复实机测试发现的可靠性问题 (v2.2.0-rc.1)
- UDP 插件在 -p 指定端口时被跳过
- Redis exploit 无超时保护 / readReply 吞没非超时错误
- service_probe 连接丢失后静默成功
- SNMP 探测成功但终端无输出
- SSH 爆破不稳定 (并发过高 + 自适应超时过短 + 限流误判)
- 进度条 isActive 竞态

新增 Config.ModuleTimeout() 协议级超时下限 (≥3s)
新增 ErrorTypeThrottle 限流错误分类
2026-06-14 22:23:52 +08:00

77 lines
1.8 KiB
Go

//go:build plugin_zookeeper || !plugin_selective
package services
import (
"context"
"strings"
"time"
"github.com/shadow1ng/fscan/common"
"github.com/shadow1ng/fscan/plugins"
)
type ZooKeeperPlugin struct {
plugins.BasePlugin
}
func NewZooKeeperPlugin() *ZooKeeperPlugin {
return &ZooKeeperPlugin{BasePlugin: plugins.NewBasePlugin("zookeeper")}
}
func (p *ZooKeeperPlugin) Scan(ctx context.Context, info *common.HostInfo, session *common.ScanSession) *ScanResult {
timeout := session.Config.ModuleTimeout()
if timeout <= 0 {
timeout = 3 * time.Second
}
addr := info.Target()
conn, err := session.DialTCP(ctx, "tcp", addr, timeout)
if err != nil {
return &ScanResult{Success: false, Service: "zookeeper"}
}
defer conn.Close()
_ = conn.SetDeadline(time.Now().Add(timeout))
if _, err := conn.Write([]byte("ruok")); err != nil {
return &ScanResult{Success: false, Service: "zookeeper"}
}
buf := make([]byte, 512)
n, err := conn.Read(buf)
if err != nil || n == 0 {
return &ScanResult{Success: false, Service: "zookeeper"}
}
banner, ok := parseZooKeeperResponse(buf[:n])
if !ok {
return &ScanResult{Success: false, Service: "zookeeper"}
}
return &ScanResult{
Success: true,
Type: plugins.ResultTypeService,
Service: "zookeeper",
Banner: banner,
}
}
func parseZooKeeperResponse(data []byte) (string, bool) {
resp := strings.TrimSpace(string(data))
if resp == "imok" {
return "ZooKeeper ruok=imok", true
}
lower := strings.ToLower(resp)
if strings.Contains(lower, "zookeeper") || strings.Contains(lower, "zk_version") ||
strings.Contains(lower, "mode:") || strings.Contains(lower, "not in the whitelist") {
return truncateRunes(resp, 200), true
}
return "", false
}
func init() {
RegisterPluginWithPorts("zookeeper", func() Plugin {
return NewZooKeeperPlugin()
}, []int{2181})
}