MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / handleRedisConnection

Method handleRedisConnection

internal/api/redis_queue_protocol.go:36–224  ·  view source on GitHub ↗
(conn net.Conn, reader *bufio.Reader)

Source from the content-addressed store, hash-verified

34}
35
36func (s *Server) handleRedisConnection(conn net.Conn, reader *bufio.Reader) {
37 if s == nil || conn == nil {
38 return
39 }
40 if reader == nil {
41 reader = bufio.NewReader(conn)
42 }
43
44 clientIP, localClient := resolveRemoteIP(conn.RemoteAddr())
45 authed := false
46 writer := bufio.NewWriter(conn)
47 defer func() {
48 if errClose := conn.Close(); errClose != nil {
49 log.Errorf("redis connection close error: %v", errClose)
50 }
51 }()
52
53 flush := func() bool {
54 if errFlush := writer.Flush(); errFlush != nil {
55 log.Errorf("redis protocol flush error: %v", errFlush)
56 return false
57 }
58 return true
59 }
60
61 if s.cfg != nil && s.cfg.Home.Enabled {
62 _ = writeRedisError(writer, "ERR redis usage output disabled in home mode")
63 _ = writer.Flush()
64 return
65 }
66
67 for {
68 if !s.managementRoutesEnabled.Load() {
69 return
70 }
71
72 args, errRead := readRESPArray(reader)
73 if errRead != nil {
74 if !errors.Is(errRead, io.EOF) {
75 _ = writeRedisError(writer, "ERR "+errRead.Error())
76 _ = writer.Flush()
77 }
78 return
79 }
80 if len(args) == 0 {
81 _ = writeRedisError(writer, "ERR empty command")
82 if !flush() {
83 return
84 }
85 continue
86 }
87
88 cmd := strings.ToUpper(strings.TrimSpace(args[0]))
89
90 if cmd != "AUTH" && !authed {
91 if s.mgmt != nil {
92 _, statusCode, errMsg := s.mgmt.AuthenticateManagementKey(clientIP, localClient, "")
93 if statusCode == http.StatusForbidden && strings.HasPrefix(errMsg, "IP banned due to too many failed attempts") {

Callers 1

routeMuxConnectionMethod · 0.95

Calls 15

resolveRemoteIPFunction · 0.85
writeRedisErrorFunction · 0.85
readRESPArrayFunction · 0.85
parseAuthPasswordFunction · 0.85
writeRedisSimpleStringFunction · 0.85
parseSubscribeChannelFunction · 0.85
subscribeRedisChannelFunction · 0.85
parsePopCountFunction · 0.85
popRedisQueueItemsFunction · 0.85

Tested by

no test coverage detected