From d697585fdcc10fa26992c9238f469b40dbcee371 Mon Sep 17 00:00:00 2001 From: anonym Date: Thu, 12 Mar 2026 14:09:44 +0100 Subject: [PATCH] Correctly handle usernames/passwords longer than 127 bytes chr() only works for lengths shorter than 128. For instance, for a 128 characters long username `chr(128).encode()` computes to `b'\xc2\x80'`, resulting in an invalid SOCKSv5 username/password request packet. --- socks.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/socks.py b/socks.py index 83b1435..3ea4462 100644 --- a/socks.py +++ b/socks.py @@ -488,9 +488,9 @@ def _SOCKS5_request(self, conn, cmd, dst): "Server requested username/password" " authentication") - writer.write(b"\x01" + chr(len(username)).encode() + writer.write(b"\x01" + (len(username)).to_bytes() + username - + chr(len(password)).encode() + + (len(password)).to_bytes() + password) writer.flush() auth_status = self._readall(reader, 2)