+1 vote
by (150 points)
retagged by

Trying to connect to a ftp site using a socks5 proxy. Upon connect a FtpException is being thrown stating:

"Invalid Socks5 response."

When using a standard ftp client program (like rushftp or filezilla) I can connect fine using the socks5 proxy.

I'm using the following code (obviously I have obfuscated the host/port/user/pass)

var ftp = new Rebex.Net.Ftp();
ftp.Proxy.ProxyType = Rebex.Net.FtpProxyType.Socks5;
ftp.Proxy.Host = "1.2.3.4";
ftp.Proxy.Port = 1234;
ftp.Proxy.UserName = "abc";
ftp.Proxy.Password = "123";
ftp.Connect("ab.com", 12345);
Applies to: Rebex FTP/SSL

1 Answer

0 votes
by (58.9k points)
edited by

Please create a log of communication with LogLevel.Verbose so that we can see what is wrong with the Socks5 response. Then either post the log here or send it to support@rebex.net.

Please note that LogLevel.Verbose will also log your proxy username and password, so before sharing it with us, make sure to remove the sensitive information.

by (150 points)
The log actually shows very little information (again I obviously replaced the actual ip addresses and stuff):
2015-06-24 09:24:20.562 Opening log file.
2015-06-24 09:24:20.562 Using FileLogWriter version 2.0.5298.0.
2015-06-24 09:24:20.609 INFO Ftp(1)[8] Info: Connecting to 1.2.3.4:123 using Ftp 4.0.5298.0.
2015-06-24 09:24:20.609 INFO Ftp(1)[8] Info: Using proxy SOCKS5 5.6.7.8:567.
2015-06-24 09:24:20.609 DEBUG ProxySocket(2)[8] Proxy: Connecting to 5.6.7.8:567.
2015-06-24 09:24:24.513 ERROR Ftp(1)[8] Info: Rebex.Net.FtpException: Invalid Socks5 response. ---> Rebex.Net.ProxySocketException: Invalid Socks5 response.
   at Rebex.Net.OV.T(String A)
   at Rebex.Net.PV.HC(IAsyncResult A, String B)
   at Rebex.Net.PV.QB(IAsyncResult A)
   at Rebex.Net.ProxySocket.EndConnect(IAsyncResult asyncResult)
   at Rebex.Net.MJ..ctor(Ftp A, ISocketFactory B, String C, Int32 D)
   at Rebex.Net.Ftp.SM(String A, Int32 B, TlsParameters C, FtpSecurity D)
   --- End of inner exception stack trace ---
   at Rebex.Net.Ftp.SM(String A, Int32 B, TlsParameters C, FtpSecurity D)
by (150 points)
Ah, I just noticed I only enabled debug level. Here's the verbose log, don't mind the timestamps I've copied pasted some stuff around:
2015-06-24 09:24:20.562 Opening log file.
2015-06-24 09:24:20.562 Using FileLogWriter version 2.0.5298.0.
2015-06-24 09:24:20.609 INFO Ftp(1)[8] Info: Connecting to 1.2.3.4:123 using Ftp 4.0.5298.0.
2015-06-24 09:24:20.609 INFO Ftp(1)[8] Info: Using proxy SOCKS5 5.6.7.8:567.
2015-06-24 09:24:20.609 DEBUG ProxySocket(2)[8] Proxy: Connecting to 5.6.7.8:567.
2015-06-24 09:48:39.150 VERBOSE ProxySocket(2)[12] Proxy: Sending data:
 0000 |05-02-00-02                                    | ....
2015-06-24 09:48:39.150 VERBOSE ProxySocket(2)[12] Proxy: Received data:
 0000 |05-02                                          | ..
2015-06-24 09:48:39.150 VERBOSE ProxySocket(2)[12] Proxy: Sending data:
 0000 |01-11-6E-6F-74-6D-79-72 65-61-6C-75-73-65-72-6E| ..notmyrealusern
 0010 |61-6D-65-11-6E-6F-74-6D 79-72-65-61-6C-70-61-73| ame.notmyrealpas
 0020 |73-77-6F-72-64                                 | sword
2015-06-24 09:48:39.181 VERBOSE ProxySocket(2)[12] Proxy: Received data:
 0000 |05-00                                          | ..
2015-06-24 09:24:24.513 ERROR Ftp(1)[8] Info: Rebex.Net.FtpException: Invalid Socks5 response. ---> Rebex.Net.ProxySocketException: Invalid Socks5 response.
   at Rebex.Net.OV.T(String A)
   at Rebex.Net.PV.HC(IAsyncResult A, String B)
   at Rebex.Net.PV.QB(IAsyncResult A)
   at Rebex.Net.ProxySocket.EndConnect(IAsyncResult asyncResult)
   at Rebex.Net.MJ..ctor(Ftp A, ISocketFactory B, String C, Int32 D)
   at Rebex.Net.Ftp.SM(String A, Int32 B, TlsParameters C, FtpSecurity D)
   --- End of inner exception stack trace ---
   at Rebex.Net.Ftp.SM(String A, Int32 B, TlsParameters C, FtpSecurity D)

Actually when looking at rfc 1929 it seems that the proxy is sending back 05-00 which should be 01-00. Right?
by (58.9k points)
Yes, you are right, the Socks5 Proxy response (05-00) that Rebex FTP client received at 2015-06-24 09:48:39.181 is bad and it leads to the "Invalid Socks5 response." FtpException. A response in the 01-xx form is expected whereas 01-00 would indicate succesful authentication and 01-xy (where xy !=0 ) would indicate failed authentication. For others - here is a link to the relevant RFC 1929 https://www.ietf.org/rfc/rfc1929.txt
by (58.9k points)
We suggest you to report it to the vendor of the proxy that you are using.
...