SocksSvc
v1.07
Welcome to SocksSvc, a collection of freeware MFC classes to
implement a simple Socks server.
The idea behind SocksSvc was originally to learn about the Socks protocol and
how it is implemented on Win32.
For detailed information about the Socks Protocol you should
read RFC 1928 (Socks 5),
RFC 1929 (Username / Password
authentication for Socks 5) and the
Socks 4 specification.
Please note that SocksSvc is only meant as a simple tutorial on writing
server side TCP applications and it should not be treated as code which is an
enterprise grade socks proxy. For that I would suggest the user look at
something like Squid which is a HTTP
proxy or Dante.
The classes which constitute SocksSvc are:
CSocksServerSettings: This class contains the settings which are used
to configure the Socks server. Example member variables in this class include the
port to listen on and the valid protocols to support. If you are developing a stand
alone socks server based on SocksSvc, you could for example store all the variables
for the CSocksServerSettings instance in an ini file or in the registry.
CSocksServer: This is the actual class which implements the Socks server.
It has a number of very simple functions to allow you to control the state of the
socks server such as Start and Stop. Internally a background thread is spun off
to handle the client connections.
CSocksClient: This class is used in the CSocksServer class to handle
client connections. It handles the parsing of client requests and returning the
appropriate response. A number of virtual functions are provided to allow end user
customisation.
Various other help classes and structures are provided including a number of
classes I have already developed independent of SocksSvc.
Features
- Supports Socks 4 and / or Socks 5.
- Supports Socks 5 username / password authentication.
- Supports Socks 5 anonymous authentication.
- Supports Socks 5 DNS proxying
- Supports listening on a specific IP address.
- Supports making outbound connections on a specific IP address.
- Compact and easy to follow implementation.
- The code can be used in a console application without any problems.
- The classes are fully Unicode compliant and include Unicode built options
in the workspace file.
- Uses a thread pool to improve server performance.
Copyright
- You are allowed to include the source code in any product (commercial, shareware,
freeware or otherwise) when your product is released in binary form.
- You are allowed to modify the source code in any way you want except you
cannot modify the copyright details at the top of each module.
- If you want to distribute source code with your application, then you are
only allowed to distribute versions released by the author. This is to maintain
a single distribution point for the source code.
Usage
- To use the class in your code add all the header and cpp files from the
sample app except main.cpp and stdafx.h/cpp.
- Your code will need to include MFC either statically or dynamically.
- To see the class in action, have a look at the code in InitInstance in the
module "main.cpp" on how to start up and stop the server.
- Please note that if you want to compile the code, then you will need to
download a number of classes from my web site, independent of the files in the
Socks download. They include CWaitableTimer, CDirectedThreadPoolQueue, CIOCPThreadPoolQueue,
CThreadPoolServer and CWSocket source code separately from my web site at
www.naughter.com and copy in the various
files into your SocksSvc's source code directory. These downloads are from my
W3MFC (www.naughter.com/w3mfc.html)
and WaitableTimer (www.naughter.com/waitabletimer.html) pages.
- The code requires at a minimum VC 2013 and will not compile with earlier
versions of Visual C++.
History
V1.07 (30 November 2017)
- Replaced CString::operator LPC*STR() calls with CString::GetString calls
V1.06 (10 February 2017)
- Updated copyright details.
- Replaced BOOL with bool throughout codebase
- Replaced NULL with nullptr throughout codebase
- Updated the code to compile cleanly in VC 2013 - 2015. The code now
requires at a minimum VC 2013
- Updated the code to handle IPv6 Socks v5 support
- Added SAL annotations to all the code
- Fixed up logic in CSocksClient::DoSocks5Negotiation to pick an
appropriate socks5 client method
- Reworked all CSocksSocket::Read methods to avoid the use of "new".
- Updated all the CSocksSocket::Read methods to handle WSAEWOULDBLOCK
errors.
- Updated CSocksClient::Relay method to handle WSAEWOULDBLOCK errors.
- Updated CSocksClient::SendConnectionResponsev5 method to return
bound server address and port number in IPv4 and IPv6 connection responses.
V1.05 (15 January 2007)
- Updated copyright details.
- Removed CSocksClient destructor as it was not really required.
- Optimized CSocksClient constructor code
- Code now uses newer C++ style casts instead of C style casts.
- General review of code base for correctness.
- Removed unused code from CSocksClient::AllowThisOutboundConnection and CSocksClient::OnEndRelay
- Updates to allow the code to clean compile on VC 2005
- Optimized CSocksServerSettings constructor code
- Optimized CSocksServer constructor code
- Optimized CSocksConnectionRequest constructor code
- Optimized CSocks5RequestDetails constructor code
- Fixed a number of memory leaks in the CSocksSocket::Read methods
- Updated code to compile with latest version of the author's CWSocket
class
V1.04 (13 February 2006)
- Updated the documentation to use the same style as the web site.
- Updated the copyright details of each module.
- Fixed graceful disconnect issues in CSocksSocket::Read and CSocksClient::Relay.
- Replaced all calls to CopyMemory with memcpy.
- Replaced all calls to ZeroMemory with memset.
V1.03 (7 September 2005)
- Updated the code to compile cleanly using the latest version of CWSocket.
- Updated the copyright details.
- Addition of a "SOCKSSVC_EXT_CLASS" which allows the code to be easily incorporated
into an MFC extension DLL.
- Removed the m_bListenBind variable from the CSocksServerSettings as m_bListenBindAddress
on its own is sufficient to specify whether binding should occur.
- Removed the m_bConnectBind variable from the CSocksServerSettings as m_bConnectBindAddress
on its own is sufficient to specify whether binding should occur.
- Fixed a potential buffer overflow issue in the parsing of SOCKS4 connections
requests.
- Fixed a typo in the logging of an error if socks 4 clients are not allowed.
V1.02 (13 January 2004)
- Used newer form of #pragma pack to avoid problems with non standard packing
sizes.
V1.01 (3 March 2003)
- Fixed a bug in CSocksSocket::Read(CSocks5RequestDetails&,...) which was
causing the port details to be read incorrectly from clients.
V1.0 (19 February 2003)
Contacting the Author
PJ Naughter
Email: pjna@naughter.com
Web: http://www.naughter.com
30 November 2017