SOCKS5 proxy server with HAProxy and Lua
Over the past few days I tried to implement a SOCKS5 server with HAProxy and Lua. The goal was to make a simple and fast SOCKS5 proxy server that leverages the performance, reliability and versatility of HAProxy. It turned out to be fairly simple and easy to write a Lua script that speaks the SOCKS protocol, and leave the connections to HAProxy afterwards.
Here is the GitHub gist that includes the Lua script and HAProxy example config:
It requires a recent (higher than 1.9) haproxy, and the
lua-socket module (to perform DNS resolution), which can be found from most distributions. It supports IPv6 and remote DNS, but doesn't support any kind of authorization (in my case that's left to the ACL in HAProxy). The example config will open a proxy without any authorization and binds to all interfaces, so make sure to adjust the configuration before you put it to work.