Add native protocol service plugins
测试构建 / 代码检查 (push) Has been cancelled
测试构建 / 单元测试和构建 (push) Has been cancelled
测试构建 / 构建验证 (push) Has been cancelled

This commit is contained in:
ZacharyZcR
2026-05-23 15:51:50 +08:00
parent 73cbe803c4
commit 8d30ee334c
16 changed files with 812 additions and 2 deletions
+81
View File
@@ -0,0 +1,81 @@
//go:build plugin_bacnet || !plugin_selective
package services
import (
"context"
"encoding/binary"
"fmt"
"time"
"github.com/shadow1ng/fscan/common"
"github.com/shadow1ng/fscan/plugins"
)
var bacnetWhoIs = []byte{0x81, 0x0a, 0x00, 0x0c, 0x01, 0x20, 0xff, 0xff, 0x00, 0xff, 0x10, 0x08}
type BACnetPlugin struct {
plugins.BasePlugin
}
func NewBACnetPlugin() *BACnetPlugin {
return &BACnetPlugin{BasePlugin: plugins.NewBasePlugin("bacnet")}
}
func (p *BACnetPlugin) Scan(ctx context.Context, info *common.HostInfo, session *common.ScanSession) *ScanResult {
timeout := session.Config.Timeout
if timeout <= 0 {
timeout = 3 * time.Second
}
target := fmt.Sprintf("%s:%d", info.Host, info.Port)
conn, err := session.DialUDP(ctx, target, timeout)
if err != nil {
return &ScanResult{Success: false, Service: "bacnet"}
}
defer conn.Close()
if _, err := conn.Write(bacnetWhoIs); err != nil {
return &ScanResult{Success: false, Service: "bacnet"}
}
buf := make([]byte, 1476)
n, err := conn.Read(buf)
if err != nil {
return &ScanResult{Success: false, Service: "bacnet"}
}
banner, ok := parseBACnetResponse(buf[:n])
if !ok {
return &ScanResult{Success: false, Service: "bacnet"}
}
return &ScanResult{
Success: true,
Type: plugins.ResultTypeService,
Service: "bacnet",
Banner: banner,
}
}
func parseBACnetResponse(data []byte) (string, bool) {
if len(data) < 6 || data[0] != 0x81 {
return "", false
}
length := int(binary.BigEndian.Uint16(data[2:4]))
if length != len(data) {
return "", false
}
for i := 4; i+1 < len(data); i++ {
if data[i] == 0x10 && data[i+1] == 0x00 {
return "BACnet I-Am response", true
}
}
return "", false
}
func init() {
RegisterUDPPluginWithPorts("bacnet", func() Plugin {
return NewBACnetPlugin()
}, []int{47808})
}