From 2d225c80939afee1b689037fc8b91252f6c3ae93 Mon Sep 17 00:00:00 2001 From: RicYaben Date: Wed, 24 Jul 2024 15:15:39 +0100 Subject: [PATCH] add json tags to results in coap --- modules/coap/builder.go | 8 ++++---- modules/coap/message/decoder.go | 6 +++++- modules/coap/scanner.go | 6 +++--- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/modules/coap/builder.go b/modules/coap/builder.go index a7eac198..9cea2ae8 100644 --- a/modules/coap/builder.go +++ b/modules/coap/builder.go @@ -11,8 +11,8 @@ import ( ) type Result struct { - path string - messages []*message.Message + Path string `json:"path"` + Messages []*message.Message `json:"messages"` } type Probe struct { @@ -32,8 +32,8 @@ func (p *Probe) Do(path string) *zgrab2.ScanError { } res := &Result{ - path: path, - messages: msgs, + Path: path, + Messages: msgs, } p.results = append(p.results, res) return nil diff --git a/modules/coap/message/decoder.go b/modules/coap/message/decoder.go index 9f902b56..cda220c2 100644 --- a/modules/coap/message/decoder.go +++ b/modules/coap/message/decoder.go @@ -45,7 +45,11 @@ func (d *decoder) Decode(data []byte, msg *Message) error { if cOpt, ok := opts[OptionContentFormat]; ok { var payload = new(Payload) - cType := uint16(cOpt.Value[0]) + + cType := uint16(0) + if len(cOpt.Value) > 0 { + cType = uint16(cOpt.Value[0]) + } if err := payload.Unmarshal(buf, cType); err != nil { return err } diff --git a/modules/coap/scanner.go b/modules/coap/scanner.go index 7b4ba0af..fc3ce34b 100644 --- a/modules/coap/scanner.go +++ b/modules/coap/scanner.go @@ -79,7 +79,7 @@ type Scanner struct { // Protocol returns the protocol identifer for the scanner. func (scanner *Scanner) Protocol() string { - return "mqtt" + return "coap" } // Init initializes the Scanner. @@ -145,9 +145,9 @@ func (scanner *Scanner) Scan(t zgrab2.ScanTarget) (zgrab2.ScanStatus, interface{ scan := scanner.newCoAPscan(&t) err := scan.Grab() if err != nil { - return err.Unpack(scan.results) + return err.Unpack(&scan.results) } - return zgrab2.SCAN_SUCCESS, scan.results, nil + return zgrab2.SCAN_SUCCESS, &scan.results, nil } // RegisterModule is called by modules/coap.go to register this module with the