Connecting through SOCKS5

Hi!

I have problems connecting to certain FTP server when using SmartFTP (latest dev build) and going through SOCKS5. Contrary when using FlashFXP (I do not really like it but it works in this case) it works without any problem.

Here is the log:








    Resolving host name ***.***.***.***...



    Resolving host name host.ftpsite.com...



    Connecting to Proxy (***.***.***.***) ->  IP: ***.***.***.*** PORT: 1080



    Connected to Proxy (***.***.***.***) -> Time = 0ms



    Socket connected waiting for login sequence.







.



.



.







220 T00 MUCH iNFO (glftpd 1.27_Linux) ready.



    USER Rex



331 Password required for Rex.



    PASS (hidden)



230 User Rex logged in.



    SYST



215 UNIX Type: L8



    FEAT



500 'FEAT': Command not understood.



    REST 100



350 Restarting at 100. Send STORE or RETRIEVE to initiate transfer.



    REST 0



350 Restarting at 0. Send STORE or RETRIEVE to initiate transfer.



    PWD



257 "/" is current directory.



    TYPE A



200 Type set to A.



    PASV



227 Entering Passive Mode (***,***,***,***,***,***)



    Opening data connection IP: ***,***,***,***,***,*** PORT: 38515.



    SOCKS5: Unknow error code.



    QUIT



221- Goodbye



221



    Connection closed.




The problem seems to be in handling SOCKS5 proxy and PASV mode. FlashFXP does it correctly. Here is the log from SOCKS5 proxy (localhost is the SOCK5 proxy, target site is named host.ftpsite.com here):




Aug 20 10:33:03 core sockd[19974]: pass(1): tcp/accept [: 127.0.0.1.36915 -> 127.0.0.1.1080 



Aug 20 10:33:03 core sockd[19975]: pass(3): tcp/connect [: 127.0.0.1.36915 -> host.ftpsite.com.7900




As can be seen FlashFXP correctly opens only one connection and goes through that (first line is SmartFTP connection to SOCKS5, second one SOCKS5 to FTP site itself)

Here's what SmartFTP does:



Aug 20 10:34:09 core sockd[19974]: pass(1): tcp/accept [: 127.0.0.1.36920 -> 127.0.0.1.1080 



Aug 20 10:34:09 core sockd[19975]: pass(3): tcp/connect [: 127.0.0.1.36920 -> host.ftpsite.com.7900 



Aug 20 10:34:14 core sockd[19974]: pass(1): tcp/accept [: 127.0.0.1.36921 -> 127.0.0.1.1080 



Aug 20 10:34:14 core sockd[19975]: pass(3): tcp/connect [: 127.0.0.1.36921 -> host.ftpsite.com.38543 



Aug 20 10:34:14 core sockd[19975]: pass(3): tcp/connect ]: 127.0.0.1.36921 -> host.ftpsite.com.38543: Connection refused 




You can see here that SmartFTP tries to open another connection to FTP site that is refused. And that is where the error appears. BTW I tried all possible combinations of switching PASV in Global/Favorite mode on and off. No way there.

My info is:



+- System -----------------------------







Microsoft Windows XP Professional 



Service Pack 1 (Build 2600)







CPU Speed         : 880 MHz



Total Memory      : 523760 KB



Free Memory       : 270132 KB







+- SmartFTP ---------------------------







Version           : 1.0.978.9



Time Stamp        : 2003-08-19 00:09:29







+- Application DLL --------------------







controls.dll      : 1.6.978.9



ftpapi.dll        : 2.0.978.9



language.dll      : 1.0.978.9



reseng.dll        : 1.3.978.9



smarthook.dll     : 1.0.2.1







+- System DLL -------------------------







shell32.dll       : 6.00.2800.1145 (xpsp2.021108-1929)



shlwapi.dll       : 6.00.2800.1106 (xpsp1.020828-1920)



comctl32.dll      : 6.0 (xpsp1.020828-1920)



riched20.dll      : 5.30.23.1211



schannel.dll      : 5.1.2600.1106 (xpsp1.020828-1920)







+- Internet Explorer ------------------







Version           : 6.0.2800.1106







+- Winsock ----------------------------







Winsock           : 2.2




Hope this helps. Best regards

Rex

I see no problem with SmartFTP here.

What SOCKS5 are you using? Where to get it?

-Mat

I found even 1 more site that shows this behaviour (unfortunately I cannot post exact URL). The SOCKS5 server is sockd from Linux in the case I posted first, the second one is socks5 v1.0 rel 11 on FreeBSD 4.3 But I must say my opinion is (clearly supported by trace posted above in first message) that this is an issue with SmartFTP - it opens additional connection that is refused by SOCKS5 servers and that is why it throws error. If you would please investigate this further and I'll try to reproduce this error on some publicly available system.

Best regards

Rex

Thanks for replying back, we would like to get to the bottom of this -
problem, but please try to boost the reply speed. Would Appreciate it.

I can fairly say, that two weeks is a long time for a reply

But again, people are just coming back from summer vacation etc..

I went for vacation just the next day I started this thread. That is why it took so long. Will get better - I promise...

Rex

First connection is the control connection.

Second connection is the data connection.

Works with all socks servers I've tested.


-Mat

I just got this same error with the latest version of SmartFTP (1.0.983.25).

The ftp site I tried to connect to was ftp.users.on.net (an ISP site), using a SOCKS5 proxy. PASV mode is also enabled.

Name: ftp.users.on.net
Addresses: 203.16.214.52, 203.16.214.53, 203.16.214.49, 203.16.214.50
203.16.214.51

Between examining a packet trace and looking at the SOCKS server log files, I found the following:

- SmartFTP sends the hostname ftp.users.on.net to the SOCKS proxy
- the SOCKS proxy resolves the name, but because it resolves to multiple addresses, it gets a different address each time

So the initial control connection might be opened to 203.16.214.52, but the first data connection will be to 203.16.214.53, the second to 203.16.214.49 and so on.

If I refresh the display in SmartFTP (F5) I can see the SOCKS proxy cycling through the addresses. Eventually it gets back to the first address, and that particular connection works.

I think you should be sending the IP address to the SOCKS server, not the hostname.

In summary, to reproduce this problem:

- use a SOCKS5 server
- connect to an FTP server using the hostname, where the hostname resolved to more than one IP address
- once logged in, try to transfer files or hit F5 to refresh the directory listing multiple times

Please try the latest developer build 1.0.983.26
https://www.smartftp.com/download

I think you've gone backwards... it won't even connect at the start now:

SmartFTP v1.0.983.26
Resolving host name sockshost.local...
Resolving host name ftp.users.on.net...
Connecting to Proxy (sockshost.local) -> IP: x.x.x.x PORT: 1080
Connected to Proxy (sockshost.local) -> Time = 0ms
SOCKS5: Unknow error code.

Compared to:

SmartFTP v1.0.983.22
Resolving host name sockshost.local...
Resolving host name ftp.users.on.net...
Connecting to Proxy (sockshost.local) -> IP: x.x.x.x PORT: 1080
Connected to Proxy (sockshost.local) -> Time = 32ms
Socket connected waiting for login sequence.
220 Welcome to ftp.users.on.net

Hello ..

I fixed the bug. Try 1.0.983.27 from same location as before.

-Mat

Yes, 1.0.983.27 works.

Thanks mb, that was an amazing turnaround time!

Having the exact sme problem with 1.0.984.
Using Socks5 with SocksCap

It has trouble when it switches to passive mode or when it opens a secondary data connection.




SmartFTP v1.0.984.1



    Resolving host name 127.0.0.1...



    Resolving host name **************



    Connecting to Proxy (127.0.0.1) ->  IP: 127.0.0.1 PORT: ****



    Connected to Proxy (127.0.0.1) -> Time = 125ms



    Socket connected waiting for login sequence.



220 **** FTP



    USER *****



331 Password required for ********.



    PASS (hidden)



230 User ******* logged in.



    SYST



215 UNIX Type: L8



    FEAT



211-Extensions supported:



 CLNT



 MDTM



 PASV



 REST STREAM



 SIZE



211 End.



    CLNT SmartFTP 1.0.984



200 "SmartFTP 1.0.984" noted.



    PWD



257 "/" is current directory.



    CWD /



250 CWD command successful. 



    PWD



257 / is current directory.



    TYPE A



200 Type set to A.



    PASV



227 Entering Passive Mode (**,**,***,***,**,**)



    Opening data connection IP: **,**,***,***,**,** PORT: 5912.



    LIST -aL



530 PASV command only accepts connection from client IP address (***.***.***.***!=error).



550 List failed. No port specified.



    NOOP



200 NOOP command successful.




Sometimes it works fine and opens a data port on client end no problem. Most of the time it seems it is not specifying the port on the client end.




SmartFTP v1.0.984.1



    Resolving host name localhost...



    Resolving host name ftp.corel.com...



    Connecting to Proxy (localhost) ->  IP: 127.0.0.1 PORT: 9050



    Connected to Proxy (localhost) -> Time = 0ms



    Socket connected waiting for login sequence.



220 ftp1 FTP server ready.



    USER anonymous



331 Guest login ok, send your complete e-mail address as password.



    PASS (hidden)



230 Guest login ok, access restrictions apply.



    SYST



215 UNIX Type: L8



    FEAT



500 'FEAT': command not understood.



    REST 100



350 Restarting at 100. Send STORE or RETRIEVE to initiate transfer.



    REST 0



350 Restarting at 0. Send STORE or RETRIEVE to initiate transfer.



    PWD



257 "/" is current directory.



    TYPE A



200 Type set to A.



    PASV



227 Entering Passive Mode (216,191,232,161,169,222)



    Opening data connection IP: 216,191,232,161,169,222 PORT: 43486.



    LIST -aL



150-Opening ASCII mode data connection for /bin/ls.



150 Restricting network throughput to 102400 bytes/s.



    306 bytes received successfully. (306 B/s) (00:00:01).



226 Transfer complete.



    CWD /bin/



250 CWD command successful.



    PWD



257 "/bin" is current directory.



    PASV



227 Entering Passive Mode (216,191,232,161,176,93)



    Opening data connection IP: 216,191,232,161,176,93 PORT: 45149.



    LIST -aL



425 Possible PASV port theft, cannot open data connection.



    NOOP



200 NOOP command successful.



When it doesn't work:




530 PASV command only accepts connection from client IP address.



    LIST -aL



550 List failed. No port specified.







02:44:05 SOCKS32.DLL[SmartFTP]: CON S:840 Socket close requested.



02:44:23 SOCKS32.DLL[SmartFTP]: CON S:1192 Socket close requested.



02:45:13 SOCKS32.DLL[SmartFTP]: CON S:1044 Socket close requested.



02:46:13 SOCKS32.DLL[SmartFTP]: CON S:1192 Socket close requested.



02:47:11 SOCKS32.DLL[SmartFTP]: CON S:1192 Socket close requested.




____________________________________________________________
When it works:




257 "/" is current directory.



    TYPE A



200 Type set to A.



    PASV



227 Entering Passive Mode (67,14,***,**,***,***).



    Opening data connection IP: 67,14,***,***,***,*** PORT: 43688.



    LIST -aL



150 Data connection accepted from 140.***.**.***:46094; transfer starting.



    7527 bytes received successfully. (7.35 KB/s) (00:00:01).



226 Transfer ok




Having the EXACT same issue with FlashFXP.

Sometimes SmartFTP does not specify a port in opening a data connection it seems to me. This seems to be a very common problem with people using socks and proxy servers with ftp. I have tried with socks4, socks4A, and socks5.

Jan 09 10:58:06.828 [warn] fetch_from_buf_socks(): Your application (using socks5 on port 171) is giving Tor only an IP address. Applications that do DNS resolves themselves may leak information. Consider using Socks4A (e.g. via privoxy or



socat) instead.