Replies: 10 comments 4 replies
-
Thanks for your feedback! There's a similar issue #83 (in Chinese). Typically, this behaviour is caused by the user-space network stack, which responds to all incoming connections without checking the validation of target address. By doing this, tun2socks can usually handle connections faster and reduce more hanging/half-open TCPs. I understand this may cause some issues and agree that we can make some improvements. But on the other hand, think of tun2socks as a CDN, it does almost the same thing (accepts connections and forwards them or responds to failure pages). So it might also be a |
Beta Was this translation helpful? Give feedback.
-
Ah, I missed that one, that is indeed very similar. Thanks for reopening that feature! Would be great to provide such behavior as an optional feature using a commandline flag. Definitely understand the analogy with a CDN, and in many occasions To be able to perform some testing with the alternative behavior I looked into the code to "hack" this feature into it. I however couldn't easily identify what code should be modified. Do you think it would be possible to change this behavior by changing some lines of code (e.g, by swapping the current sequence of 1) accepting the client TCP connection and 2) connecting to the port on the remote side)? Or is it much more of an architectural change. |
Beta Was this translation helpful? Give feedback.
-
To make this happen, the complexity is a bit more than just changing lines of code. If you want to check the validation of your destination connections before accepting incoming TCPs, you should dig into here, right before calling Line 61 in 4a8bf64 However, since tun2socks handles outgoing proxy connections in the Anyway, it may take some tricks to implement this and I wish you have a good luck. I’m currently too occupied to add this feature. Please let me know if you have any other questions! |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot Jason for this extensive explanation! I have spent some time understanding the code and performing a number of modifications (changing the sequence of checking whether the remote port is open and only then accepting the connection), however currently my limited golang knowledge and a lack of time to climb the learning curve make that for now I will stop working on it. Maybe whenever in the future I have more time, I will pick it up again and might get back to you with some questions. 🙂 |
Beta Was this translation helpful? Give feedback.
-
socks5 server proxy return little information when dial remote fail,we can use it,What #235 do is dial proxy before 3handshake,then decide what to do after get dial fail reason,here is detail: <style> </style>
|
Beta Was this translation helpful? Give feedback.
-
@0990 BTW, to send RST in gVisor, just call Lines 60 to 67 in 4a8bf64 |
Beta Was this translation helpful? Give feedback.
-
@bitsadmin thanks for your advice,in my opinion,the default way is RST(tell client imediately insead of waiting long time),So my suggestion:
|
Beta Was this translation helpful? Give feedback.
-
@xjasonlyu I have commit code:feat:give client no response when socks server return host unreachable,please review when have time. |
Beta Was this translation helpful? Give feedback.
-
Sort of resurrecting an older thread, but i also was doing some testing with this. Ideally, trying to emulate something more akin to how proxychains connects (establish connection with remote end BEFORE establishing connection). was using nmap scanning as an example. With proxychains, can proxy a scan and the connection is built to the target before the connection is returned true. Without proxychains, the connection is established and returned true before it is built with target. Could this behavior be set as a switch? I am NOT a go SME, and reading above, sounds like it would be a bigger shift to do that than i expect. @bitsadmin was wondering if you had any luck cracking this egg or not |
Beta Was this translation helpful? Give feedback.
-
Very late response, but I was busy with various things including publishing a blog article where tun2socks is used[1] to an offensive setup. I just did some quick tests using your fork[2], @0990, and it works as expected, very nice! 😃 As there might be use cases where this behavior is not desired, like @m2abrams15 mentioned it is probably useful to have a command line flag where the behavior can be chosen. Any chance you could add this to your code? After that, would love to see @xjasonlyu merge your pull request! [1] https://blog.bitsadmin.com/living-off-the-foreign-land-windows-as-offensive-platform |
Beta Was this translation helpful? Give feedback.
-
First of all, thanks Jason for this great tool!
I have a question regarding the TCP behavior of the tunnel.
I have set up the tunnel over SOCKS4 and added the relevant route over the
tun
interface. Any TCP ports reachable on the other side work well, however when attempting to connect to a non-existing IP and/or TCP port (sending aSYN
packet), the tunnel interface regardless on whether it is reachable immediately responds with aSYN/ACK
to the client. Only once it identified that the IP/port are not reachable (RST
packet is received or simply no response is received on the SOCKS server end),tun2socks
sends aFIN/ACK
packet to the client.This behavior can be confusing for applications attempting to establish TCP connections. In various cases a better behavior would be that the tunnel responds with a
SYN/ACK
only at the moment it identified that on the other side of the tunnel the port is actually accessible.Summarized, the behavior I would like to see:
RST
) on remote side ->RST
from tunnel to clientSYN/ACK
) on remote side ->SYN/ACK
from tunnel to clientI haven't looked at the SOCKS protocol specification, so not sure whether it can distinguish between 1 and 2, but both
RST
or a timeout would be fine for the client application to realize a connection cannot be established.Is there a way to have
tun2socks
work like that?Beta Was this translation helpful? Give feedback.
All reactions