Skip to content

Commit

Permalink
add json tags to results in coap
Browse files Browse the repository at this point in the history
  • Loading branch information
RicYaben committed Jul 24, 2024
1 parent 0aa9efb commit 2d225c8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
8 changes: 4 additions & 4 deletions modules/coap/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion modules/coap/message/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions modules/coap/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2d225c8

Please sign in to comment.