This repository has been archived by the owner on Feb 6, 2023. It is now read-only.
/
redis_open.go
69 lines (62 loc) · 1.73 KB
/
redis_open.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package tcp
import (
"context"
"github.com/LeakIX/l9format"
"github.com/go-redis/redis/v8"
"log"
"net"
"strings"
)
type RedisOpenPlugin struct {
l9format.ServicePluginBase
}
func (RedisOpenPlugin) GetVersion() (int, int, int) {
return 0, 0, 1
}
func (RedisOpenPlugin) GetProtocols() []string {
return []string{"redis"}
}
func (RedisOpenPlugin) GetName() string {
return "RedisOpenPlugin"
}
func (RedisOpenPlugin) GetStage() string {
return "open"
}
func (plugin RedisOpenPlugin) Run(ctx context.Context, event *l9format.L9Event, options map[string]string) bool {
client := redis.NewClient(&redis.Options{
Addr: net.JoinHostPort(event.Ip, event.Port),
Password: "", // no password set
DB: 0, // use default DB
Dialer: plugin.DialContext,
})
defer client.Close()
_, err := client.Ping(ctx).Result()
if err != nil {
log.Println("Redis PING failed, leaving early : ", err)
return false
}
redisInfo, err := client.Info(ctx).Result()
if err != nil {
log.Println("Redis INFO failed, leaving early : ", err)
return false
}
redisInfoDict := make(map[string]string)
redisInfo = strings.Replace(redisInfo, "\r", "", -1)
for _, line := range strings.Split(redisInfo, "\n") {
keyValuePair := strings.Split(line, ":")
if len(keyValuePair) == 2 {
redisInfoDict[keyValuePair[0]] = keyValuePair[1]
}
}
if _, found := redisInfoDict["redis_version"]; found {
event.Service.Software.OperatingSystem, _ = redisInfoDict["os"]
event.Service.Software.Name = "Redis"
event.Service.Software.Version, _ = redisInfoDict["redis_version"]
event.Leak.Severity = l9format.SEVERITY_MEDIUM
event.Summary = "Redis is open\n"
event.Leak.Type = "open_database"
event.Leak.Dataset.Rows = 1
return true
}
return false
}