Proxy .NET through Socks4/5

Asked by At

So, I am writing some code and am pulling in 3rd party projects to achieve a specific set of functionality. Namely, talking to AD, getting kerberos tickets, doing user impersonation if a username/password is supplied to the program etc.

The issue I've run into is that many of these things depend on Windows kernel libraries (netapi.dll, win32.dll to name a few). I need to be able to run this one Linux as well. So I tried .NET core. Well, being core I was never able to find an alternative to these libraries, and of course WINE doesn't work for them either. So I am left with one option. Socks proxies.

So how in the world, can I proxy an entire application (console app) through a socks4 or socks5 proxy. PS, I am NOT talking HTTP. An example would be the following (just a simple AD lookup):

public void PrintAllUsers()
        {
            Console.WriteLine("[+] Domain Users");
            Console.WriteLine("-----------------");
            GroupPrincipal gp = GetGroup("Domain Users");
            Console.WriteLine("[+] Count (" + gp.Members.Count + ")");
            foreach (Principal pc in gp.Members)
            {
                if (pc.StructuralObjectClass.ToLower() == "user")
                {
                    PrintUserData(pc as UserPrincipal);
                }

                if (pc.StructuralObjectClass.ToLower() == "computer")
                {
                    PrintComputerData(pc as ComputerPrincipal);

                }
            }

            Console.WriteLine("-----------------");
        }

1 Answers

0
Elepover Hedop On

Unfortunately, .NET Core itself doesn't support SOCKS proxies, neither 4 or 5, it only supports HTTP proxies.

However there's an open source library that can add SOCKS5 proxy support to your application. Try this: https://github.com/MihaZupan/HttpToSocks5Proxy

And with the two methods above combined, your application should be able to access Internet resources through a SOCKS5 proxy.