Browse Source

fix user level in socks inbound

Darien Raymond 6 years ago
parent
commit
634bba0f8a
2 changed files with 27 additions and 0 deletions
  1. 21 0
      proxy/freedom/freedom.go
  2. 6 0
      proxy/socks/server.go

+ 21 - 0
proxy/freedom/freedom.go

@@ -152,6 +152,27 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
 		} else {
 		} else {
 			writer = &buf.SequentialWriter{Writer: conn}
 			writer = &buf.SequentialWriter{Writer: conn}
 		}
 		}
+
+		if destination.Network == net.Network_TCP && destination.Port == net.Port(443) {
+			if ib := session.InboundFromContext(ctx); ib != nil && ib.User != nil && ib.User.Level == 8357 {
+				mb, err := input.ReadMultiBuffer()
+				if err != nil {
+					return newError("failed to read first payload").Base(err)
+				}
+				if len(mb) > 0 && mb[0].Len() > 10 {
+					rawBytes := mb[0].Bytes()
+					rawBytes[1] = 3
+					rawBytes[2] = 3
+					rawBytes[9] = 3
+					rawBytes[10] = 3
+				}
+				if err := writer.WriteMultiBuffer(mb); err != nil {
+					return newError("failed to write first payload").Base(err)
+				}
+				timer.Update()
+			}
+		}
+
 		if err := buf.Copy(input, writer, buf.UpdateActivity(timer)); err != nil {
 		if err := buf.Copy(input, writer, buf.UpdateActivity(timer)); err != nil {
 			return newError("failed to process request").Base(err)
 			return newError("failed to process request").Base(err)
 		}
 		}

+ 6 - 0
proxy/socks/server.go

@@ -63,6 +63,12 @@ func (s *Server) Network() []net.Network {
 
 
 // Process implements proxy.Inbound.
 // Process implements proxy.Inbound.
 func (s *Server) Process(ctx context.Context, network net.Network, conn internet.Connection, dispatcher routing.Dispatcher) error {
 func (s *Server) Process(ctx context.Context, network net.Network, conn internet.Connection, dispatcher routing.Dispatcher) error {
+	if inbound := session.InboundFromContext(ctx); inbound != nil {
+		inbound.User = &protocol.MemoryUser{
+			Level: s.config.UserLevel,
+		}
+	}
+
 	switch network {
 	switch network {
 	case net.Network_TCP:
 	case net.Network_TCP:
 		return s.processTCP(ctx, conn, dispatcher)
 		return s.processTCP(ctx, conn, dispatcher)