GithubHelp home page GithubHelp logo

psocksd's Introduction

psocksd

The SOCKS tunnel / proxy server daemon written in PHP

Features

The SOCKS protocol family can be used to easily tunnel TCP connections independent of the actual application level protocol, such as HTTP, SMTP, IMAP, Telnet, etc. In this mode, a SOCKS server acts as a generic proxy allowing higher level application protocols to work through it.

  • SOCKS proxy server with support for SOCKS4, SOCKS4a and SOCKS5 protocol versions (all at the same time)
  • Optionally require username / password authentication (SOCKS5 only)
  • Zero configuration, easy to use command line interface (CLI) to change settings without restarting server
  • Incoming SOCKS requests can be forwarded to another SOCKS server to act as a tunnel gateway, perform transparent protocol translation or add SOCKS authentication for clients not capable of doing it themselves.
    • Tunnel endpoint can be changed during runtime (via CLI command).
    • Particularly useful when used as an intermediary server and using ever-changing public SOCKS tunnel end points.
  • Using an async event-loop, it is capable of handling multiple concurrent connections in a non-blocking fashion
  • Built upon the shoulders of reactphp/react and clue/socks, it uses well-tested dependencies instead of reinventing the wheel.

Usage

Once installed, you can start psocksd and listen for incoming SOCKS connections by running:

$ php psocksd.phar

Using this command, psocksd will start listening on the default adress localhost:9050.

Listen address

If you want to listen on another address, you can supply an explicit listen address like this:

# start SOCKS daemon on port 9051 instead
$ php psocksd.phar 9051

# explicitly listen on the given interface
$ php psocksd.phar 192.168.1.2:9050

# listen on all interfaces (allow access to SOCKS server from the outside)
$ php psocksd.phar *:9050

# explicitly only support SOCKS5 and reject other protocol versions
$ php psocksd.phar socks5://localhost:9050

# require client to send the given authentication information
$ php psocksd.phar socks5://username:password@localhost:9051

Interactive CLI

By default, psocksd will run an interactive command line interface. This means that it keeps running in the foreground and accepts commands from STDIN.

You can pass the --no-interaction argument to disable this interactive mode so that it does not accept any commands from STDIN. The interactive mode is always disabled on Windows, because it's impossible to read from STDIN without blocking the whole daemon.

You can run the help command in order to see all available commands and their usage:

> help
psocksd help:
[…]

You can run the ping command in order to test creating a TCP/IP connection through the given SOCKS server:

> ping 192.168.1.200:1080
ping www.google.com:80
ping test OK (⌚ 0.378s)

You can run the exit or quit command (or hit CTRL+D or CTRL-C) in order to exit the program:

> exit
exiting...

Client configuration

Once psocksd is started, it accepts incoming SOCKS client connections. Therefor, you have to configure your client program (webbrowser, email client etc.) to actually use the SOCKS server.

The exact configuration depends on your program, but quite a few programs allow you to use a SOCKS proxy. So depending on the above list address, supply the following information:

Proxy-Type: SOCKS4 or SOCKS5
Socks-Host: localhost
Socks-Port: 9050

Install

You can grab a copy of clue/psocksd in either of the following ways.

As a phar (recommended)

You can simply download a pre-compiled and ready-to-use version as a Phar to any directory. Simply download the latest psocksd.phar file from our releases page:

Latest release

That's it already. You can now verify everything works by running this:

$ cd ~/Downloads
$ php psocksd.phar

If you prefer a global (system-wide) installation without having to type the .phar extension each time, you may invoke:

$ chmod 0755 psocksd.phar
$ sudo mv psocksd.phar /usr/local/bin/psocksd

You can verify everything works by running:

$ psocksd

Updating phar

There's no separate update procedure, simply overwrite the existing phar with the new version downloaded.

Manual Installation from Source

The manual way to install psocksd is to clone (or download) this repository and use composer to download its dependencies. Obviously, for this to work, you'll need PHP, git and curl installed:

$ sudo apt-get install php5-cli git curl
$ git clone https://github.com/clue/psocksd.git
$ curl -s https://getcomposer.org/installer | php
$ php composer.phar install

If you want to build the above mentioned psocksd.phar yourself, you have to install clue/phar-composer and can simply invoke:

$ php phar-composer.phar build ~/workspace/psocksd

Updating manually

If you have followed the above install instructions, you can update psocksd by issuing the following two commands:

$ git pull
$ php composer.phar install

Docker

This project is also available as a docker image. Using the clue/psocksd image is as easy as running this:

$ docker run -d -p 9050:9050 clue/psocksd

License

MIT-licensed

psocksd's People

Contributors

clue avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

psocksd's Issues

Heads up! Development focus on LeProxy

If you're currently using this project, you may want to check out its successor https://github.com/leproxy/leproxy instead 🎉 LeProxy is the new HTTP/SOCKS proxy server for everybody!

This project may see some smaller adjustments / fixes in the future, but all development efforts and new features will focus on LeProxy instead.

Socks5 auth with Firefox?

Is there any way to let Firefox auth against a psocksd socks5-proxy?
Firefox dont ask me for credentials and the server logs:

error: SOCKS5 protocol error - No acceptable authentication mechanism found

Why not run into my server?

I'm trying to run psocksd into my server but i get a fatal error. I'm runing Ubuntu 16.04 with PHP 7.

I just downloaded the latest phar release and executed the file with root rights. How can i solve this?

root@pharingphp:~# php psocksd.phar 7777
PHP Fatal error:  Uncaught Error: Call to undefined function Clue\React\Stdio\mb_strwidth() in phar:///root/psocksd.phar/vendor/clue/stdio-react/src/Readline.php:572
Stack trace:
#0 phar:///root/psocksd.phar/vendor/clue/stdio-react/src/Readline.php(371): Clue\React\Stdio\Readline->strwidth('')
#1 phar:///root/psocksd.phar/vendor/clue/stdio-react/src/Readline.php(96): Clue\React\Stdio\Readline->redraw()
#2 phar:///root/psocksd.phar/src/App.php(87): Clue\React\Stdio\Readline->setPrompt('> ')
#3 phar:///root/psocksd.phar/src/App.php(49): Clue\Psocksd\App->start(Array)
#4 [internal function]: Clue\Psocksd\App->Clue\Psocksd\{closure}(Array)
#5 phar:///root/psocksd.phar/vendor/clue/commander/src/Route.php(77): call_user_func(Object(Closure), Array)
#6 phar:///root/psocksd.phar/vendor/clue/commander/src/Router.php(179): Clue\Commander\Route->__invoke(Array)
#7 phar:///root/psocksd.phar/vendor/clue/commander/src/Router.php(152): Clue\Commander\Router->handleArgs(Array)
#8 phar:///root/psocksd.phar/src/App.php(58): Clue\Commander\Route in phar:///root/psocksd.phar/vendor/clue/stdio-react/src/Readline.php on line 572

As you can see, i'm runing stock PHP 7 provided on official repos:

root@pharingphp:~# php --version
PHP 7.0.15-0ubuntu0.16.04.4 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.15-0ubuntu0.16.04.4, Copyright (c) 1999-2017, by Zend Technologies

Thanks in advance for your help.

whitelist IP

Hello,

is there any way, so I specify allow only 'source IPs' from specific array, or so? (especially via the CLI)

Thank you

shadowsocks compatibility

shadowsocks is a very sophisticated secure socks server. supporting it is advantages since it has a very good cross platform client and its protocol is encrypted unliked regular socks. yesss, android, windows, linux, mac, ios, etc
It alreasy has Python,C, C++, Go implementaion
https://shadowsocks.org

Help with backend connection

Hello,

Not really an issue, little help wanted :) How could I add some/modify headers of http request or connect curl to backend connection of this library?

I got to this part, but couldn`t figure out how to add curl output back to client, or manipulate outgoing connection:

File: Clue/Socks-React/Server.php
return $that->connectTarget($stream, $target);

I would like to add this $target to curl and make use of advanced curl http calls, and then return output to the client.

Thanks for help,

Basic System.d Service

Here is a bash script for installing psocksd as linux service :)

cd /tmp
wget https://github.com/clue/psocksd/releases/download/v0.4.0/psocksd.phar -O psocksd.phar
mv psocksd.phar /usr/local/bin/
sudo adduser psocksd -s /sbin/nologin
echo "[Unit]
Description=psocksd Service (PHP Socks Server)
After=network.target

[Service]
Type=simple
User=psocksd
ExecStart=/usr/bin/php /usr/local/bin/psocksd.phar socks5://priv8:[email protected]:5555--no-interaction
Restart=on-abort

[Install]
WantedBy=multi-user.target" > /etc/systemd/system/psocksd.service
sudo systemctl daemon-reload
sudo systemctl start psocksd
systemctl enable psocksd

Multiple phpsocks implementation is confusing

When i found this project, i spend about 20 minutes deciding which repository is what i'm looking for.
They seemed very similar, php-socks-react, php-socks-server, psocksd, php-socks
I think it requires a bit of clarification.

UDP SOCKS5

Is it hard to to impelement UDP Socks5 in psocksd? It says #129 error: SOCKS5 protocol error - Only CONNECT requests supported

How do cascading proxies?

I have remote socks5 for example 1.1.1.1:3333, and i want to create socks in my server php psocksd *:9050 socks my server = 2.2.2.2:9050, but client connecting to 2.2.2.2:9050 but load from other 1.1.1.1:3333 socks. How connect to 2.2.2.2:9050 and display 1.1.1.1 ip?
For example: client -> my socks -> other socks. How do cascading proxies?

Add ping/test command to check remote SOCKS servers

Once #4 is done, we should add an additional test/ping command to check remote SOCKS servers for connectivity.

E.g. bin/psocksd test socks5://username:password@remote
=> Support a variety of SOCKS URLs
=> error exit code / output

Multiple outgoing interfaces with smart selection based on latency to destination network

I have this weird idea that I want to try.

I am a traveler, right now I am in Bali now, Thailand before.
In both of those asian countries I've noticed the same problem - the ISPs route most of the connections to Europe through USA which slows down the speed alot.

To get a proper connection with Europe I sometimes use a VPN service (in Singapore for example, where they have better routing). But that on the other hand slows down my connections with USA.

So, I came up with this idea that I think is only doable with your PHP daemon.

When a new connection is being established, send out pings to the destination host through all available network interfaces (that will be the primary connection + the VPN connection). And once the replies are back, establish the outgoing socket through the faster interface. It adds a little overhead to every new connection, but the resulting speeds can be faster.

Example: So, for example, when I ping "vk.com" through a primary connection, I get 400ms (because it goes through USA) and 288ms through VPN (because it goes through europe). So, I would prefect to talk to "vk.com" through my VPN interface.

But, "youtube.com" would be faster through my primary connection, because they have geo distribution, the ping on the primary connection would be 50ms, but through VPN - 250ms.
So, I would prefer to talk to "youtube.com" through my primary connection.

Fix installation

The locked version react/socket-client:v0.3.2 no longer exists. Also refs #15.

$ composer install
…
 - Installing react/socket-client (v0.3.2)
Downloading: 100%
Invalid zip file, retrying...
- Installing react/socket-client (v0.3.2)
Downloading: 100%
Failed to download react/socket-client from dist: '/home/me/workspace/psocksd/vendor/react/socket-client/React/SocketClient/0ea07960f245a9e667fa61c4cc251c71.2' is not a zip archive.
Now trying to download from source
- Installing react/socket-client (v0.3.2)
Cloning v0.3.2
v0.3.2 is gone (history was rewritten?)


[RuntimeException]
Failed to execute git checkout 'v0.3.2' && git reset --hard 'v0.3.2'
error: pathspec 'v0.3.2' did not match any file(s) known to git. 

See https://gist.github.com/clue/ee13a1f0f13c9eb1d9f6 for full log

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.