Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IdHTTP + SOCKS + Socks5

I'm getting a general Indy error when using the IdHTTP client component in conjunction with a SOCKS5 proxy server and using SSL.

  • If I use the IdHTTP component with my SOCKS5 proxy (and a non https URL), everything works without problems.
  • If I use the IdHTTP component with an SSL URL (and no SOCKS5 proxy), everything works without problems.
  • If I use the IdHTTP component with an SSL URL and a SOCKS5 proxy i get following error:

Line 405 of the error output idSocks.pas (raise EIdSocksServerGeneralError.Create(RSSocksServerGeneralError);

Here is my code

var
  HTTP            : TIdHTTP;
  Cookie          : TIdCookieManager;
  SSL             : TIdSSLIOHandlerSocketOpenSSL;
  Params          : TStringList;
  HTMLSource      : String;
  CurrentProxy    : String;
  ProxyPort       : Integer;
  ProxyHost       : String;
  ProxyUsername   : String;
  ProxyPW         : String;
begin
  Synchronize(AddItem);
  HTTP                          := TIdHTTP.Create(NIL);
  Cookie                        := TIdCookieManager.Create(HTTP);
  SSL                           := TIdSSLIOHandlerSocketOpenSSL.Create(HTTP);
  HTTP.CookieManager            := Cookie;
  HTTP.IOHandler                := SSL;
  HTTP.HandleRedirects          := True;
  Params                        := TStringList.Create;
  HTTP.Request.UserAgent        := Task^.Useragent;
  try
    while True do begin
      if terminated then Exit;
      Params.Clear;
      Cookie.CookieCollection.Clear;
      if Task^.Proxytype >= 0 then begin      // if proxy enabled
        CurrentProxy            := Task^.Form.GetProxyFromPool;
        ProxyHost               := ParsingW(':', CurrentProxy, 1);
        ProxyPort               := strtoint(ParsingW(':', CurrentProxy, 2));
        HTTP.ConnectTimeout     := (Task^.Proxytimeout * 1000);
        if Task^.ProxyAuth then begin
          ProxyUsername         := ParsingW(':', CurrentProxy, 3);
          ProxyPW               := ParsingW(':', CurrentProxy, 4);
        end;
      end;
      if Task^.Proxytype = 0 then begin //HTTP(s)
        HTTP.ProxyParams.ProxyServer      := ProxyHost;
        HTTP.ProxyParams.ProxyPort        := ProxyPort;
        if Task^.ProxyAuth then begin
          HTTP.ProxyParams.ProxyUsername  := ProxyUsername;
          HTTP.ProxyParams.ProxyPassword  := ProxyPW;
        end;
      end;
      if (Task^.Proxytype = 1) or (Task^.Proxytype = 2) then begin   // Socks 4 or 5
        SSL.TransparentProxy := TIdSocksInfo.Create(HTTP);
        (SSL.TransparentProxy as TIdSocksInfo).Port             := ProxyPort;
        (SSL.TransparentProxy as TIdSocksInfo).Host             := ProxyHost;
        if Task^.ProxyAuth then begin
          (SSL.TransparentProxy as TIdSocksInfo).Username       := ProxyUsername;
          (SSL.TransparentProxy as TIdSocksInfo).Password       := ProxyPW;
          (SSL.TransparentProxy as TIdSocksInfo).Authentication := saUsernamePassword;
        end else begin
          (SSL.TransparentProxy as TIdSocksInfo).Authentication := saNoAuthentication;
        end;
        if (Task^.Proxytype = 1) then  (SSL.TransparentProxy as TIdSocksInfo).Version := svSocks4;
        if (Task^.Proxytype = 2) then  (SSL.TransparentProxy as TIdSocksInfo).Version := svSocks5;
      end;

Did I miss something or is it not possible to connect to a a SSL site with a Socks5 Proxy?

like image 248
user2791785 Avatar asked Sep 25 '13 09:09

user2791785


People also ask

Can SOCKS5 be detected?

Like most proxies, SOCKS5 won't encrypt your data, and will lower internet speed and stability. PRO TIP: Remember that SOCKS is quite detectable, so it most likely won't get you around national firewalls. Enhance your security with a VPN to help with this.

Is SOCKS5 better than SOCKS4?

SOCKS4: On the authentication level, SOCKS4 is not conducive to tasks requiring authentication, while SOCKS5 is purpose-built to handle a diverse assortment of authentication methods. SOCKS5: SOCKS5 supports User Datagram Protocol (UDP) proxies, while SOCKS4 does not.

Can I use SOCKS5 with VPN?

While SOCKS5 proxies do provide a few of the same benefits as VPNs, they're not a VPN replacement. You shouldn't use them together, however, because routing your traffic multiple times will likely result in slower speeds.


1 Answers

The fact that you are getting an EIdSocksServerGeneralError raised means that TIdHTTP is successfully communicating with the SOCKS proxy and it is validating your request to access it with no authentication, but it is then failing to establish a connection with the target server that you specified in your HTTPS url. The proxy is replying with error code 1 (general failure). Make sure that the url is accurate. Either the proxy cannot resolve the hostname to an IP (try specifying an IP instead of a hostname in the url and see if it makes a difference), or the proxy does not have a valid route to reach that IP, or some other error is occurring on the proxy end. If you have access to the proxy, try looking at its logs to see what actually went wrong.

like image 133
Remy Lebeau Avatar answered Oct 21 '22 09:10

Remy Lebeau