I started to hack a very minimal SOCKS5 server in python using the twisted framework. Apparently, TCP/CONNECT works just fine, and that's all I wanted (BIND, UDP, Authentication are missing). This is the first time I did anything with twisted and I have to say that it is quite easy and convenient, although the documentation could need some improvements.

This hack could be used as a basis for further experiments. For instance, it might be more convenient to log network traffic using a SOCKS proxy instead of using a full network analyzer as e.g. Wireshark. Also, this might be used to insert or modify HTTP headers for HTTP requests or routing traffic through additional proxies, depending on intended destination.

Well, code is here but be aware that it's rather an example than anything else, including lack of good error handling and printing annoying information to stdout. On the other hand, it's just 128 lines ;-)
pys5.py