Skip to content

Commit

Permalink
include connection code in mqtt
Browse files Browse the repository at this point in the history
  • Loading branch information
RicYaben committed Jan 24, 2025
1 parent 0545466 commit 2da6288
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
7 changes: 6 additions & 1 deletion modules/mqtt/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,16 @@ func (s *scan) Grab() *zgrab2.ScanError {
}

client := paho.NewClient(options)
if t := client.Connect(); t.Wait() && t.Error() != nil {
t := client.Connect()
if t.Wait() && t.Error() != nil {
return zgrab2.NewScanError(zgrab2.SCAN_CONNECTION_REFUSED, t.Error())
}
defer client.Disconnect(250)

if t := t.(*paho.ConnectToken); t != nil {
s.result.ConnectionCode = t.ReturnCode()
}

s.SetFilters()
handler := s.makeMessageHandler()
client.SubscribeMultiple(s.filters, handler)
Expand Down
12 changes: 8 additions & 4 deletions modules/mqtt/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,14 @@ func (module *Module) Description() string {

// A Result object returned from the MQTT module's Scanner.Scan().
type Result struct {
Topics map[string][]string `json:"topics,omitempty"`
Certificates [][]byte `json:"certificate,omitempty"`
Scheme string `json:"scheme"`
Error any `json:"error,omitempty"`
ConnectionCode byte `json:"connection-code"`
Topics map[string][]string `json:"topics,omitempty"`
Certificates [][]byte `json:"certificate,omitempty"`
Scheme string `json:"scheme"`
Error any `json:"error,omitempty"`

// TODO: divide this by scheme. Each result should be enclosed in the given scheme.
// E.g.: tls {connection-code: 0, topics: {}}, ssl {connection-code: 1, topics: {$SYS/broker/version: mosquitto}}...
}

// Scanner implements the zgrab2.Scanner interface.
Expand Down

0 comments on commit 2da6288

Please sign in to comment.