Comments (6)
I've been thinking before about this, because it really would be useful. But
I've reached similar conclusions. There doesn't seem to be an easy way to
redirect connections to where they would go in the absence of tun2socks. So I
see making the OS route them to where you want the only way to go.
But that is highly platform dependent. Unfortunately, from my googling, it
doesn't seem possible on Windows, at least on the network layer. It may be
possible on the socket layer using the "Layered Service Provider" interface.
But it's fair to say it would be a great undertaking, and at least I don't have
the time or need for such a feature.
Original comment by [email protected]
on 15 Dec 2013 at 9:26
- Changed state: WontFix
from badvpn.
Thanks for your reply. Actually I figured out how to do it very easily on
Windows!
It works by checking the ports on new connections and when it sees a port it
should ignore it does not connect to the SOCKS server but instead connects
directly to the destination IP and of course does not do any of the socks
initialization stuff, it just sends and receives the data directly.
The problem of course is that with routing setup the new connection will just
go straight back to tun2socks again and end up in a never ending loop. The
trick is before connecting to the destination IP/port you bind the new socket
to the main interface IP, that forces Windows to use that interface therefore
bypassing the routing table.
Because I get tun2socks to connect to a local proxy before that proxy connects
out to a remote server I do this myself locally without changing the tun2socks
code but I'm sure it can be done very easily in that code too.
So currently the code goes something like...
1) New connection received by tun2socks
2) Connect to provided socks server
3) Authenticate with socks & send dest info
4) Start tunnelling data between source and proxy
For ports to be ignored
1) New connection received by tun2socks
2) New socket created and bound to main interface IP (not TAP)
3) Socket connects to destination IP/port
4) Start tunnelling data between source and dest
Works beautifully here!
Original comment by [email protected]
on 16 Dec 2013 at 9:21
from badvpn.
Wow, that's wonderful. Such a nice trick!
From what I understand, you've already gotten it to work? In that case would
you mind sharing the code? If it's that easy it just may get into "official"
tun2socks distribution ;)
Original comment by [email protected]
on 16 Dec 2013 at 9:27
- Changed state: Accepted
from badvpn.
Oh sorry I missed the bit about your local proxy.
Original comment by [email protected]
on 16 Dec 2013 at 9:43
from badvpn.
I can yeah but as I said I made the change in my local socks code, not in
tun2socks.. I know my way around my code so I implemented the change in a few
minutes.. changing tun2socks would take me quite a bit longer!
The binding code is simple enough:
struct sockaddr_in sa_loc;
memset(&sa_loc, 0, sizeof(struct sockaddr_in));
sa_loc.sin_family = PF_INET;
sa_loc.sin_port = htons(0);
sa_loc.sin_addr.s_addr = inet_addr((const char*)localIP);
bind(handle, (struct sockaddr *)&sa_loc, sizeof(struct sockaddr));
Getting the main interface IP is a little more tricky and the way I do it has
to be done BEFORE the routing table is modified so I do it when my app starts
up.
1) GetIpForwardTable() to get the routing table
2) Look for the route with 0.0.0.0
3) Call GetIpAddrTable() and using the IFIndex from GetIpForwardTable return
the first (address) field
Sorry I don't have this as a complete code solution as I'm doing half of it in
my C++ socks code and the other have in my C# service code.
Original comment by [email protected]
on 16 Dec 2013 at 9:43
from badvpn.
Oh, I forgot to mention that an entry needs to exist in the routing table for
0.0.0.0 using the main interface, just with a higher metric than the route for
tun2socks
Original comment by [email protected]
on 16 Dec 2013 at 10:11
from badvpn.
Related Issues (20)
- Need source IP passing to SOCKS HOT 15
- How to build tun2socks on Windows HOT 4
- How to build tun2socks on Windows HOT 1
- wont work on Windows Xp (faild to get ConnectEx) HOT 5
- calling net.ipv4.dhcp on tun device fails HOT 7
- cant write to file HOT 4
- [deleted issue]
- Feature request: UDP support
- Can not intilise tun2socks DeviceIoControl(TAP_IOCTL_GET_MTU) failed HOT 1
- tun2socks on Win7 doesn't work HOT 6
- Can not intilise tun2socks DeviceIoControl(TAP_IOCTL_GET_MTU) failed HOT 1
- How can i log the sites visited by badvpn HOT 1
- This is a little bit complicated. HOT 4
- No SOCKS authentication HOT 9
- Connects/routes perfectly but after 5 minutes connections revert to normal route? HOT 13
- Possible to forward DNS lookups through socks server? HOT 6
- Failed to parse arguments if <human_name_of_TUN_device> contains spaces HOT 2
- Where does the badvpn-udpgw process run at ? HOT 1
- tun2socks not picking up traffic straight after reboot HOT 19
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from badvpn.