简体   繁体   中英

Connect to SOCKS proxy that requires authentication

I'm using Fiddler Core in my project and have had success routing requests through a SOCKS proxy that does not require authentication.

oS["x-OverrideGateway"] = string.Format("socks={0}:{1}", ProxyHost, ProxyPort);

Now I'm trying to connect to a SOCKS proxy that requires authentication. I've tried adding the below, per this non-SOCKS guide: Authenticate With CBT .

oS["X-AutoAuth"] = Auth;

Where Auth is a string containing the credentials in the form username:password . But the connection always fails with a Bad Gateway exception. I've been successful connecting to the same SOCKS proxy using curl and following it's guidelines for an authenticated SOCKS proxy.

After X-AutoAuth didn't work I reflected some of the code and found that this authentication mechanism is not used for SOCKS.

Rather unfortunately, Fiddler (and FiddlerCore) does not support SOCKS5 as of yet.

You could, however, request this at https://fiddler.ideas.aha.io/ .

We faced a similar issue and created a NuGet library which helps you "transform" SOCKS v4 traffic to SOCKS v5, and we added authentication support as well.

This small example shows how can you hook up FiddlerCore and a SOCKS5 proxy with username and password:

var localEndpoint = new IPEndPoint(IPAddress.Loopback, 4321);
var remoteEndpoint = new IPEndPoint(IPAddress.Parse("remote proxy IP"), 8080);
ISocksRelayServer relay = new SocksRelayServer.SocksRelayServer(localEndpoint, remoteEndpoint)
{
    Username = "...",
    Password = "..."
};

// Debug to console
relay.OnLogMessage += (sender, s) => Console.WriteLine($"OnLogMessage: {s}");
relay.OnLocalConnect += (sender, endpoint) => Console.WriteLine($"OnLocalConnect: {endpoint}");
relay.OnRemoteConnect += (sender, endpoint) => Console.WriteLine($"OnRemoteConnect: {endpoint}");

// Start relay server
relay.Start();

// Start FiddlerCore
FiddlerApplication.Startup(...);

// Set upstream gateway before requests
FiddlerApplication.BeforeRequest += session =>
{
    session["x-OverrideGateway"] = relay.LocalEndPoint.ToString();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM