Reject socks4 unauthenticated request

This commit is contained in:
世界 2023-09-25 20:43:42 +08:00
parent 5b05b5c147
commit e781e86e32
No known key found for this signature in database
GPG key ID: CD109927C34A63C4

View file

@ -110,6 +110,16 @@ func HandleConnection0(ctx context.Context, conn net.Conn, version byte, authent
}
switch request.Command {
case socks4.CommandConnect:
if authenticator != nil && !authenticator.Verify(request.Username, "") {
err = socks4.WriteResponse(conn, socks4.Response{
ReplyCode: socks4.ReplyCodeRejectedOrFailed,
Destination: request.Destination,
})
if err != nil {
return err
}
return E.New("socks4: authentication failed, username=", request.Username)
}
err = socks4.WriteResponse(conn, socks4.Response{
ReplyCode: socks4.ReplyCodeGranted,
Destination: M.SocksaddrFromNet(conn.LocalAddr()),