diff --git a/go.mod b/go.mod index 24c62aa5..eab789b5 100644 --- a/go.mod +++ b/go.mod @@ -40,6 +40,7 @@ require ( github.com/beorn7/perks v1.0.1 // indirect github.com/eclipse/paho.mqtt.golang v1.5.0 github.com/golang-jwt/jwt v3.2.2+incompatible + github.com/google/uuid v1.6.0 github.com/gopcua/opcua v0.5.3 github.com/kr/pretty v0.3.1 // indirect github.com/kr/text v0.2.0 // indirect diff --git a/go.sum b/go.sum index da0ed2b6..7bf38858 100644 --- a/go.sum +++ b/go.sum @@ -29,6 +29,8 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-github/v50 v50.2.0/go.mod h1:VBY8FB6yPIjrtKhozXv4FQupxKLS6H4m6xFZlT43q8Q= github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gopcua/opcua v0.5.3 h1:K5QQhjK9KQxQW8doHL/Cd8oljUeXWnJJsNgP7mOGIhw= github.com/gopcua/opcua v0.5.3/go.mod h1:nrVl4/Rs3SDQRhNQ50EbAiI5JSpDrTG6Frx3s4HLnw4= github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= diff --git a/modules/mqtt/scan.go b/modules/mqtt/scan.go index 553c0783..726ac257 100644 --- a/modules/mqtt/scan.go +++ b/modules/mqtt/scan.go @@ -10,6 +10,7 @@ import ( "sync" paho "github.com/eclipse/paho.mqtt.golang" + "github.com/google/uuid" "github.com/zmap/zgrab2" ) @@ -59,8 +60,12 @@ func (s *scan) getBrokerURL() string { } func (s *scan) getClientOptions() (*paho.ClientOptions, error) { + // we may jump into the same host. Avoid weird issues + id := uuid.New() + uid := fmt.Sprintf("%s-%s", s.scanner.config.ClientID, id[:6]) + opts := paho.NewClientOptions(). - SetClientID(s.scanner.config.ClientID). + SetClientID(uid). SetCleanSession(true). SetAutoReconnect(true). SetOrderMatters(false) @@ -121,7 +126,8 @@ func (s *scan) makeMessageHandler() func(c paho.Client, m paho.Message) { var handler = func(c paho.Client, m paho.Message) { topic := m.Topic() if isFull(topic) { - // ignore the message + // unsubscribe and ignore the message + c.Unsubscribe(topic) return }