From 8a317800ef6ae1bd6c013d9ba93bd1e1888c31b7 Mon Sep 17 00:00:00 2001 From: Marek Rost Date: Tue, 19 Jun 2018 17:55:14 +0200 Subject: [PATCH 1/6] added username/password authentication according to RFC 1929 --- config.php | 3 +++ start.php | 63 ++++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 55 insertions(+), 11 deletions(-) create mode 100644 config.php diff --git a/config.php b/config.php new file mode 100644 index 0000000..540540a --- /dev/null +++ b/config.php @@ -0,0 +1,3 @@ +$AUTH_ENABLED = 0; +$USERNAME = 'changeme'; +$PASSWORD = '1234'; diff --git a/start.php b/start.php index 55b6fcf..e810232 100644 --- a/start.php +++ b/start.php @@ -1,4 +1,4 @@ -onConnect = function($connection) @@ -35,16 +40,52 @@ $worker->onMessage = function($connection, $buffer) switch($connection->stage) { case STAGE_INIT: + if ($AUTH_ENABLED) + { + $methodslen = ord($buffer[1]); + $methods = array(); + for ($i = 0; $i < strlen($buffer)-3; $i++) + { + array_push($methods, ord($buffer[$i+3])); + } + if (in_array(METHOD_USER_PASS, $methods)) + { + $connection->send("\x05\x02"); + $connection->stage = STAGE_AUTH; + return; + } + echo "client does not support user/pass auth\n"; + $connection->send("\x05\xff"); + $connection->stage = STAGE_DESTROYED; + $connection->close(); + return; + } $connection->send("\x05\x00"); $connection->stage = STAGE_ADDR; return; + case STAGE_AUTH: + $userlen = ord($buffer[1]); + $user = substr($buffer, 2, $userlen); + $passlen = ord($buffer[2 + $userlen]); + $pass = substr($buffer, 3 + $userlen, $passlen); + if ($user == $USERNAME && $pass == $PASSWORD) + { + $connection->send("\x05\x00"); + $connection->stage = STAGE_ADDR; + return; + } + echo "auth failed\n"; + $connection->send("\x05\x01"); + $connection->stage = STAGE_DESTROYED; + $connection->close(); + return; case STAGE_ADDR: $cmd = ord($buffer[1]); if($cmd != CMD_CONNECT) { - echo "bad cmd $cmd\n"; - $connection->close(); - return; + echo "bad cmd $cmd\n"; + $connection->close(); + return; } $header_data = parse_socket5_header($buffer); if(!$header_data) From 53c70b72cef5fd09fab881e68bb6e5142b62f388 Mon Sep 17 00:00:00 2001 From: Marek Rost Date: Tue, 19 Jun 2018 18:11:41 +0200 Subject: [PATCH 2/6] Config fix, updated README --- README.md | 13 ++++++++----- config.php | 2 ++ start.php | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 119352b..44411a1 100644 --- a/README.md +++ b/README.md @@ -6,15 +6,18 @@ Socks5 proxy written in PHP based on [workerman](https://github.com/walkor/Worke 2. ```composer install``` +## Config +Edit file ```config.php``` + ## Start -php start.php start -d +```php start.php start -d``` ## Stop -php start.php stop +```php start.php stop``` ## Status -php start.php status +```php start.php status``` -## Other links -https://github.com/walkor/shadowsocks-php +## Other links +https://github.com/walkor/shadowsocks-php https://github.com/walkor/php-http-proxy diff --git a/config.php b/config.php index 540540a..8f9188b 100644 --- a/config.php +++ b/config.php @@ -1,3 +1,5 @@ +onConnect = function($connection) }; $worker->onMessage = function($connection, $buffer) { + global $AUTH_ENABLED, $USERNAME, $PASSWORD; switch($connection->stage) { case STAGE_INIT: From 5aef507ca5baf189ba3ad5673670b6e83757d789 Mon Sep 17 00:00:00 2001 From: Marek Rost Date: Tue, 19 Jun 2018 18:13:10 +0200 Subject: [PATCH 3/6] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 44411a1..f96f322 100644 --- a/README.md +++ b/README.md @@ -20,4 +20,5 @@ Edit file ```config.php``` ## Other links https://github.com/walkor/shadowsocks-php + https://github.com/walkor/php-http-proxy From 2ba2822baff597212514f53306684aa4de2dd043 Mon Sep 17 00:00:00 2001 From: Marek Rost Date: Tue, 19 Jun 2018 18:14:52 +0200 Subject: [PATCH 4/6] Update README.md --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f96f322..8fce0b9 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # socks5-proxy -Socks5 proxy written in PHP based on [workerman](https://github.com/walkor/Workerman). +Socks5 proxy written in PHP based on [workerman](https://github.com/walkor/Workerman). Now with Username/Password authentication according to RFC 1929. ## Install 1. ```git clone https://github.com/walkor/php-socks5``` @@ -19,6 +19,5 @@ Edit file ```config.php``` ```php start.php status``` ## Other links -https://github.com/walkor/shadowsocks-php - +https://github.com/walkor/shadowsocks-php https://github.com/walkor/php-http-proxy From f9e7afba03626e909ef0a8ab658a098e2242dccb Mon Sep 17 00:00:00 2001 From: Marek Rost Date: Tue, 19 Jun 2018 18:16:40 +0200 Subject: [PATCH 5/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8fce0b9..bbdf7d3 100644 --- a/README.md +++ b/README.md @@ -19,5 +19,5 @@ Edit file ```config.php``` ```php start.php status``` ## Other links -https://github.com/walkor/shadowsocks-php +https://github.com/walkor/shadowsocks-php https://github.com/walkor/php-http-proxy From 0d8a43830ca34e14b996e33189b92b91bfe46f3a Mon Sep 17 00:00:00 2001 From: Marek Rost Date: Tue, 19 Jun 2018 18:17:05 +0200 Subject: [PATCH 6/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bbdf7d3..bc3b711 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # socks5-proxy -Socks5 proxy written in PHP based on [workerman](https://github.com/walkor/Workerman). Now with Username/Password authentication according to RFC 1929. +Socks5 proxy written in PHP based on [workerman](https://github.com/walkor/Workerman). Now with username/password authentication according to RFC 1929. ## Install 1. ```git clone https://github.com/walkor/php-socks5```