|
|
|
@ -3,9 +3,9 @@ package socks
|
|
|
|
|
import (
|
|
|
|
|
"errors"
|
|
|
|
|
"io"
|
|
|
|
|
"log"
|
|
|
|
|
"log"
|
|
|
|
|
"net"
|
|
|
|
|
"strconv"
|
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
|
|
"github.com/v2ray/v2ray-core"
|
|
|
|
|
socksio "github.com/v2ray/v2ray-core/io/socks"
|
|
|
|
@ -42,7 +42,7 @@ func (server *SocksServer) AcceptConnections(listener net.Listener) error {
|
|
|
|
|
for server.accepting {
|
|
|
|
|
connection, err := listener.Accept()
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Print(err)
|
|
|
|
|
log.Print(err)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
go server.HandleConnection(connection)
|
|
|
|
@ -55,14 +55,14 @@ func (server *SocksServer) HandleConnection(connection net.Conn) error {
|
|
|
|
|
|
|
|
|
|
auth, err := socksio.ReadAuthentication(connection)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Print(err)
|
|
|
|
|
log.Print(err)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
log.Print(auth)
|
|
|
|
|
log.Print(auth)
|
|
|
|
|
|
|
|
|
|
if !auth.HasAuthMethod(socksio.AuthNotRequired) {
|
|
|
|
|
// TODO send response with FF
|
|
|
|
|
log.Print(ErrorAuthenticationFailed)
|
|
|
|
|
// TODO send response with FF
|
|
|
|
|
log.Print(ErrorAuthenticationFailed)
|
|
|
|
|
return ErrorAuthenticationFailed
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -71,33 +71,32 @@ func (server *SocksServer) HandleConnection(connection net.Conn) error {
|
|
|
|
|
|
|
|
|
|
request, err := socksio.ReadRequest(connection)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Print(err)
|
|
|
|
|
log.Print(err)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response := socksio.NewSocks5Response()
|
|
|
|
|
|
|
|
|
|
response := socksio.NewSocks5Response()
|
|
|
|
|
|
|
|
|
|
if request.Command == socksio.CmdBind || request.Command == socksio.CmdUdpAssociate {
|
|
|
|
|
response := socksio.NewSocks5Response()
|
|
|
|
|
response.Error = socksio.ErrorCommandNotSupported
|
|
|
|
|
socksio.WriteResponse(connection, response)
|
|
|
|
|
log.Print(ErrorCommandNotSupported)
|
|
|
|
|
log.Print(ErrorCommandNotSupported)
|
|
|
|
|
return ErrorCommandNotSupported
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response.Error = socksio.ErrorSuccess
|
|
|
|
|
response.Port = request.Port
|
|
|
|
|
response.AddrType = request.AddrType
|
|
|
|
|
switch response.AddrType {
|
|
|
|
|
case socksio.AddrTypeIPv4:
|
|
|
|
|
copy(response.IPv4[:], request.IPv4[:])
|
|
|
|
|
case socksio.AddrTypeIPv6:
|
|
|
|
|
copy(response.IPv6[:], request.IPv6[:])
|
|
|
|
|
case socksio.AddrTypeDomain:
|
|
|
|
|
response.Domain = request.Domain
|
|
|
|
|
}
|
|
|
|
|
socksio.WriteResponse(connection, response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
response.Error = socksio.ErrorSuccess
|
|
|
|
|
response.Port = request.Port
|
|
|
|
|
response.AddrType = request.AddrType
|
|
|
|
|
switch response.AddrType {
|
|
|
|
|
case socksio.AddrTypeIPv4:
|
|
|
|
|
copy(response.IPv4[:], request.IPv4[:])
|
|
|
|
|
case socksio.AddrTypeIPv6:
|
|
|
|
|
copy(response.IPv6[:], request.IPv6[:])
|
|
|
|
|
case socksio.AddrTypeDomain:
|
|
|
|
|
response.Domain = request.Domain
|
|
|
|
|
}
|
|
|
|
|
socksio.WriteResponse(connection, response)
|
|
|
|
|
|
|
|
|
|
ray := server.vPoint.NewInboundConnectionAccepted(request.Destination())
|
|
|
|
|
input := ray.InboundInput()
|
|
|
|
@ -115,9 +114,9 @@ func (server *SocksServer) dumpInput(conn net.Conn, input chan<- []byte, finish
|
|
|
|
|
for {
|
|
|
|
|
buffer := make([]byte, 256)
|
|
|
|
|
nBytes, err := conn.Read(buffer)
|
|
|
|
|
log.Printf("Reading %d bytes, with error %v", nBytes, err)
|
|
|
|
|
log.Printf("Reading %d bytes, with error %v", nBytes, err)
|
|
|
|
|
if err == io.EOF {
|
|
|
|
|
close(input)
|
|
|
|
|
close(input)
|
|
|
|
|
finish <- true
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
@ -133,7 +132,7 @@ func (server *SocksServer) dumpOutput(conn net.Conn, output <-chan []byte, finis
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
nBytes, _ := conn.Write(buffer)
|
|
|
|
|
log.Printf("Writing %d bytes", nBytes)
|
|
|
|
|
log.Printf("Writing %d bytes", nBytes)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|