From 683198af0a3ea732d763a06c72f0fc82a366c950 Mon Sep 17 00:00:00 2001 From: Thomas Hendrickson Date: Mon, 18 Dec 2023 12:56:59 -0500 Subject: [PATCH 1/3] detect redis over tls --- pkg/plugins/services/redis/redis.go | 41 ++++++++++++++++++++++++++++- pkg/plugins/types.go | 11 ++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/pkg/plugins/services/redis/redis.go b/pkg/plugins/services/redis/redis.go index c4c10f9..a447202 100644 --- a/pkg/plugins/services/redis/redis.go +++ b/pkg/plugins/services/redis/redis.go @@ -24,12 +24,14 @@ import ( ) type REDISPlugin struct{} +type REDISTLSPlugin struct{} type Info struct { AuthRequired bool } const REDIS = "redis" +const REDISTLS = "redistls" // Check if the response is from a Redis server // returns an error if it's not validated as a Redis server @@ -70,13 +72,29 @@ func checkRedis(data []byte) (Info, error) { func init() { plugins.RegisterPlugin(&REDISPlugin{}) + plugins.RegisterPlugin(&REDISTLSPlugin{}) } func (p *REDISPlugin) PortPriority(port uint16) bool { return port == 6379 } -func (p *REDISPlugin) Run(conn net.Conn, timeout time.Duration, target plugins.Target) (*plugins.Service, error) { +func (p *REDISTLSPlugin) PortPriority(port uint16) bool { + return port == 6380 +} + +func (p *REDISTLSPlugin) Run(conn net.Conn, timeout time.Duration, target plugins.Target) (*plugins.Service, error) { + result, err := DetectRedis(conn, timeout) + if err != nil { + return nil, err + } + payload := plugins.ServiceRedisTLS{ + AuthRequired: result.AuthRequired, + } + return plugins.CreateServiceFrom(target, payload, true, "", plugins.TCPTLS), nil +} + +func DetectRedis(conn net.Conn, timeout time.Duration) (*Info, error) { //https://redis.io/commands/ping/ // PING is a supported command since 1.0.0 // [*1(CR)(NL)$4(CR)(NL)PING(CR)(NL)] @@ -109,6 +127,15 @@ func (p *REDISPlugin) Run(conn net.Conn, timeout time.Duration, target plugins.T if err != nil { return nil, nil } + + return &result, nil +} + +func (p *REDISPlugin) Run(conn net.Conn, timeout time.Duration, target plugins.Target) (*plugins.Service, error) { + result, err := DetectRedis(conn, timeout) + if err != nil { + return nil, err + } payload := plugins.ServiceRedis{ AuthRequired: result.AuthRequired, } @@ -119,10 +146,22 @@ func (p *REDISPlugin) Name() string { return REDIS } +func (p *REDISTLSPlugin) Name() string { + return REDISTLS +} + func (p *REDISPlugin) Type() plugins.Protocol { return plugins.TCP } +func (p *REDISTLSPlugin) Type() plugins.Protocol { + return plugins.TCPTLS +} + func (p *REDISPlugin) Priority() int { return 413 } + +func (p *REDISTLSPlugin) Priority() int { + return 414 +} diff --git a/pkg/plugins/types.go b/pkg/plugins/types.go index 6d12926..b4b2849 100644 --- a/pkg/plugins/types.go +++ b/pkg/plugins/types.go @@ -65,6 +65,7 @@ const ( ProtoRDP = "rdp" ProtoRPC = "rpc" ProtoRedis = "redis" + ProtoRedisTLS = "redistls" ProtoRsync = "rsync" ProtoRtsp = "rtsp" ProtoSMB = "smb" @@ -113,6 +114,10 @@ func (e Service) Metadata() Metadata { var p ServiceRedis _ = json.Unmarshal(e.Raw, &p) return p + case ProtoRedisTLS: + var p ServiceRedisTLS + _ = json.Unmarshal(e.Raw, &p) + return p case ProtoHTTP: var p ServiceHTTP _ = json.Unmarshal(e.Raw, &p) @@ -402,6 +407,12 @@ type ServiceRedis struct { func (e ServiceRedis) Type() string { return ProtoRedis } +type ServiceRedisTLS struct { + AuthRequired bool `json:"authRequired:"` +} + +func (e ServiceRedisTLS) Type() string { return ProtoRedisTLS } + type ServiceFTP struct { Banner string `json:"banner"` AnonymousLogin bool `json:"anonymousLogin"` From 71979a7e77182ce830e0dc02ddc213b2fe797a37 Mon Sep 17 00:00:00 2001 From: Thomas Hendrickson Date: Mon, 18 Dec 2023 14:30:55 -0500 Subject: [PATCH 2/3] updates --- pkg/plugins/services/redis/redis.go | 32 +++++++++++------------------ pkg/plugins/types.go | 12 +---------- pkg/runner/report.go | 12 +++++++++-- 3 files changed, 23 insertions(+), 33 deletions(-) diff --git a/pkg/plugins/services/redis/redis.go b/pkg/plugins/services/redis/redis.go index a447202..934478b 100644 --- a/pkg/plugins/services/redis/redis.go +++ b/pkg/plugins/services/redis/redis.go @@ -31,7 +31,7 @@ type Info struct { } const REDIS = "redis" -const REDISTLS = "redistls" +const REDISTLS = "redis" // Check if the response is from a Redis server // returns an error if it's not validated as a Redis server @@ -84,17 +84,10 @@ func (p *REDISTLSPlugin) PortPriority(port uint16) bool { } func (p *REDISTLSPlugin) Run(conn net.Conn, timeout time.Duration, target plugins.Target) (*plugins.Service, error) { - result, err := DetectRedis(conn, timeout) - if err != nil { - return nil, err - } - payload := plugins.ServiceRedisTLS{ - AuthRequired: result.AuthRequired, - } - return plugins.CreateServiceFrom(target, payload, true, "", plugins.TCPTLS), nil + return DetectRedis(conn, target, timeout, true) } -func DetectRedis(conn net.Conn, timeout time.Duration) (*Info, error) { +func DetectRedis(conn net.Conn, target plugins.Target, timeout time.Duration, tls bool) (*plugins.Service, error) { //https://redis.io/commands/ping/ // PING is a supported command since 1.0.0 // [*1(CR)(NL)$4(CR)(NL)PING(CR)(NL)] @@ -127,19 +120,18 @@ func DetectRedis(conn net.Conn, timeout time.Duration) (*Info, error) { if err != nil { return nil, nil } - - return &result, nil -} - -func (p *REDISPlugin) Run(conn net.Conn, timeout time.Duration, target plugins.Target) (*plugins.Service, error) { - result, err := DetectRedis(conn, timeout) - if err != nil { - return nil, err - } payload := plugins.ServiceRedis{ AuthRequired: result.AuthRequired, } - return plugins.CreateServiceFrom(target, payload, false, "", plugins.TCP), nil + if tls { + return plugins.CreateServiceFrom(target, payload, true, "", plugins.TCPTLS), nil + } else { + return plugins.CreateServiceFrom(target, payload, false, "", plugins.TCP), nil + } +} + +func (p *REDISPlugin) Run(conn net.Conn, timeout time.Duration, target plugins.Target) (*plugins.Service, error) { + return DetectRedis(conn, target, timeout, false) } func (p *REDISPlugin) Name() string { diff --git a/pkg/plugins/types.go b/pkg/plugins/types.go index b4b2849..0cac2e9 100644 --- a/pkg/plugins/types.go +++ b/pkg/plugins/types.go @@ -65,7 +65,7 @@ const ( ProtoRDP = "rdp" ProtoRPC = "rpc" ProtoRedis = "redis" - ProtoRedisTLS = "redistls" + ProtoRedisTLS = "redis" ProtoRsync = "rsync" ProtoRtsp = "rtsp" ProtoSMB = "smb" @@ -114,10 +114,6 @@ func (e Service) Metadata() Metadata { var p ServiceRedis _ = json.Unmarshal(e.Raw, &p) return p - case ProtoRedisTLS: - var p ServiceRedisTLS - _ = json.Unmarshal(e.Raw, &p) - return p case ProtoHTTP: var p ServiceHTTP _ = json.Unmarshal(e.Raw, &p) @@ -407,12 +403,6 @@ type ServiceRedis struct { func (e ServiceRedis) Type() string { return ProtoRedis } -type ServiceRedisTLS struct { - AuthRequired bool `json:"authRequired:"` -} - -func (e ServiceRedisTLS) Type() string { return ProtoRedisTLS } - type ServiceFTP struct { Banner string `json:"banner"` AnonymousLogin bool `json:"anonymousLogin"` diff --git a/pkg/runner/report.go b/pkg/runner/report.go index db9e7ff..dc66a34 100644 --- a/pkg/runner/report.go +++ b/pkg/runner/report.go @@ -86,9 +86,17 @@ func Report(services []plugins.Service) error { csvWriter.Flush() default: if len(service.Host) > 0 { - log.Printf("%s://%s:%d (%s)\n", strings.ToLower(service.Protocol), service.Host, service.Port, service.IP) + if service.TLS { + log.Printf("%s://%s:%d (%s) (tls)\n", strings.ToLower(service.Protocol), service.Host, service.Port, service.IP) + } else { + log.Printf("%s://%s:%d (%s)\n", strings.ToLower(service.Protocol), service.Host, service.Port, service.IP) + } } else { - log.Printf("%s://%s:%d\n", strings.ToLower(service.Protocol), service.IP, service.Port) + if service.TLS { + log.Printf("%s://%s:%d (tls)\n", strings.ToLower(service.Protocol), service.IP, service.Port) + } else { + log.Printf("%s://%s:%d\n", strings.ToLower(service.Protocol), service.IP, service.Port) + } } } } From 54ced3f88f29bf40268474c5f8fb7b92e77dc46f Mon Sep 17 00:00:00 2001 From: Thomas Hendrickson Date: Mon, 18 Dec 2023 14:53:18 -0500 Subject: [PATCH 3/3] linter fix --- pkg/plugins/services/redis/redis.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/plugins/services/redis/redis.go b/pkg/plugins/services/redis/redis.go index 934478b..86c0048 100644 --- a/pkg/plugins/services/redis/redis.go +++ b/pkg/plugins/services/redis/redis.go @@ -125,9 +125,8 @@ func DetectRedis(conn net.Conn, target plugins.Target, timeout time.Duration, tl } if tls { return plugins.CreateServiceFrom(target, payload, true, "", plugins.TCPTLS), nil - } else { - return plugins.CreateServiceFrom(target, payload, false, "", plugins.TCP), nil } + return plugins.CreateServiceFrom(target, payload, false, "", plugins.TCP), nil } func (p *REDISPlugin) Run(conn net.Conn, timeout time.Duration, target plugins.Target) (*plugins.Service, error) {