Skip to content

Commit

Permalink
Reject socks4 unauthenticated request
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Sep 30, 2023
1 parent 5b05b5c commit e781e86
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions protocol/socks/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down

0 comments on commit e781e86

Please # to comment.