GithubHelp home page GithubHelp logo

gotun2socks's Introduction

gotun2socks

A Golang implementation of tun2socks, including a library and a binary program.

The binary program works on Linux, OS X and Windows.

Usage

Windows users need to install TAP-windows driver first.

The binary program will create tun/tap device, config its IP address. On Windows, it also configs DNS resolvers of the opened tun/tap device.

Users need to change routing table so that packets are sent through the tun/tap device. Generaly the process includes changing default route to the tun/tap device, and exclude IP addresses of remote servers to go through the original network device so that traffic forwarded from local SOCKS5 proxy to remote servers would not loop back. See Tun2Socks Introduction for how to change routing table. Linux and OS X users may also need to change system DNS resolvers in case the resolvers are not accessible by remote servers.

UDP forwarding

This implementation forwards UDP using standard SOCKS5 UDP request/reply. Thus to make UDP-based protocols (such as DNS) work, it needs to be chained with a UDP-enabled SOCKS5 proxy.

Credits

gotun2socks's People

Contributors

yinghuocho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gotun2socks's Issues

local DNS result map support. eg ip -> domain

When I use the shadowsocks-libev version ss-local with udp relay. it worked for all.
But when I use the python version shadowsocks with udp relay, it not worked for contaminated DNS domain, eg www.google.com.
Sense shadowsocks-libev handles the DNS map, and conversion it to domain it self. like 5.6.7.8 -> google.com. I should sure it later.

So it is like

socks5 udp: ip -> domain
socks5 connect: domain -> ip

macOS无法正常工作

另外一个问题:

macOS 下, signal 似乎无法正常工作, Ctrl + C 后,程序无法终止。

Redirect icmp to localhost or just fake icmp reply ?

Since i want to use this project to play game and some game do some restriction that player can only match or join servers whose latency(test via icmp) below threshold, so if you can redirect icmp to localhost or gateway, even just fake icmp reply, the server will allow you to join.

too many connection to socks5 server ;but never connected

env

system : win10 ; win7;win8;(test three version of windows)
golang: 1.10.3
socks5: gost https://github.com/ginuerzh/gost
gotun2socks: master

My steps are as follows:

1: install tap-0901 released by open-vpn
2: run gost socks5 server local port 9999
3: run gotun2socks command: gotun2socks.exe -local-socks-addr "127.0.0.1:9999"
the cmd show:

2018/06/29 14:03:31 tracking 1 UDP connections
......(same to above ,but number of udp num)
2018/06/29 14:03:31 tracking 1208 UDP connections
......
2018/06/29 14:03:31 tracking 3333 UDP connections

then socks server show: outofmemory
log like this:

2018/06/29 17:27:01 socks.go:606: [socks5-udp] 127.0.0.1:65117 - [::]:56923 BIND ON 127.0.0.1:56923 OK
2018/06/29 17:27:01 socks.go:618: [socks5-udp] 127.0.0.1:65117 <-> 127.0.0.1:56923
2018/06/29 17:27:01 socks.go:606: [socks5-udp] 127.0.0.1:65118 - [::]:56926 BIND ON 127.0.0.1:56926 OK
2018/06/29 17:27:01 socks.go:618: [socks5-udp] 127.0.0.1:65118 <-> 127.0.0.1:56926
2018/06/29 17:27:01 socks.go:606: [socks5-udp] 127.0.0.1:65119 - [::]:56929 BIND ON 127.0.0.1:56929 OK
2018/06/29 17:27:01 socks.go:618: [socks5-udp] 127.0.0.1:65119 <-> 127.0.0.1:56929
2018/06/29 17:27:01 socks.go:606: [socks5-udp] 127.0.0.1:65120 - [::]:56932 BIND ON 127.0.0.1:56932 OK
2018/06/29 17:27:01 socks.go:618: [socks5-udp] 127.0.0.1:65120 <-> 127.0.0.1:56932
2018/06/29 17:27:01 socks.go:606: [socks5-udp] 127.0.0.1:65121 - [::]:56935 BIND ON 127.0.0.1:56935 OK
2018/06/29 17:27:01 socks.go:618: [socks5-udp] 127.0.0.1:65121 <-> 127.0.0.1:56935
2018/06/29 17:27:01 socks.go:606: [socks5-udp] 127.0.0.1:65122 - [::]:56938 BIND ON 127.0.0.1:56938 OK
2018/06/29 17:27:01 socks.go:618: [socks5-udp] 127.0.0.1:65122 <-> 127.0.0.1:56938
2018/06/29 17:27:01 socks.go:606: [socks5-udp] 127.0.0.1:65123 - [::]:56941 BIND ON 127.0.0.1:56941 OK
2018/06/29 17:27:01 socks.go:618: [socks5-udp] 127.0.0.1:65123 <-> 127.0.0.1:56941
2018/06/29 17:27:01 socks.go:606: [socks5-udp] 127.0.0.1:65124 - [::]:56944 BIND ON 127.0.0.1:56944 OK
2018/06/29 17:27:01 socks.go:618: [socks5-udp] 127.0.0.1:65124 <-> 127.0.0.1:56944
2018/06/29 17:27:01 socks.go:606: [socks5-udp] 127.0.0.1:65125 - [::]:56947 BIND ON 127.0.0.1:56947 OK
2018/06/29 17:27:01 socks.go:618: [socks5-udp] 127.0.0.1:65125 <-> 127.0.0.1:56947
2018/06/29 17:27:01 socks.go:620: [socks5-udp] 127.0.0.1:64414 - 127.0.0.1:51194 : read tcp 127.0.0.1:1080->127.0.0.1:64414: wsarecv: An existing connection was forcibly closed by the remote host.
2018/06/29 17:27:01 socks.go:622: [socks5-udp] 127.0.0.1:64414 >-< 127.0.0.1:51194
2018/06/29 17:27:01 socks.go:620: [socks5-udp] 127.0.0.1:64427 - 127.0.0.1:51230 : read tcp 127.0.0.1:1080->127.0.0.1:64427: wsarecv: An existing connection was forcibly closed by the remote host.
2018/06/29 17:27:01 socks.go:622: [socks5-udp] 127.0.0.1:64427 >-< 127.0.0.1:51230
2018/06/29 17:27:01 socks.go:620: [socks5-udp] 127.0.0.1:64426 - 127.0.0.1:51227 : read tcp 127.0.0.1:1080->127.0.0.1:64426: wsarecv: An existing connection was forcibly closed by the remote host.
2018/06/29 17:27:01 socks.go:622: [socks5-udp] 127.0.0.1:64426 >-< 127.0.0.1:51227
2018/06/29 17:27:01 socks.go:620: [socks5-udp] 127.0.0.1:64439 - 127.0.0.1:51266 : read tcp 127.0.0.1:1080->127.0.0.1:64439: wsarecv: An existing connection was forcibly closed by the remote host.
2018/06/29 17:27:01 socks.go:622: [socks5-udp] 127.0.0.1:64439 >-< 127.0.0.1:51266
2018/06/29 17:27:01 socks.go:620: [socks5-udp] 127.0.0.1:64438 - 127.0.0.1:51263 : read tcp 127.0.0.1:1080->127.0.0.1:64438: wsarecv: An existing connection was forcibly closed by the remote host.
2018/06/29 17:27:01 socks.go:622: [socks5-udp] 127.0.0.1:64438 >-< 127.0.0.1:51263
2018/06/29 17:27:01 socks.go:620: [socks5-udp] 127.0.0.1:64465 - 127.0.0.1:54593 : read tcp 127.0.0.1:1080->127.0.0.1:64465: wsarecv: An existing connection was forcibly closed by the remote host.
2018/06/29 17:27:01 socks.go:622: [socks5-udp] 127.0.0.1:64465 >-< 127.0.0.1:54593
2018/06/29 17:27:01 socks.go:620: [socks5-udp] 127.0.0.1:64437 - 127.0.0.1:51260 : read tcp 127.0.0.1:1080->127.0.0.1:64437: wsarecv: An existing connection was forcibly closed by the remote host.
2018/06/29 17:27:01 socks.go:620: [socks5-udp] 127.0.0.1:64463 - 127.0.0.1:54587 : read tcp 127.0.0.1:1080->127.0.0.1:64463: wsarecv: An existing connection was forcibly closed by the remote host.
2018/06/29 17:27:01 socks.go:622: [socks5-udp] 127.0.0.1:64463 >-< 127.0.0.1:54587
2018/06/29 17:27:01 socks.go:620: [socks5-udp] 127.0.0.1:64436 - 127.0.0.1:51257 : read tcp 127.0.0.1:1080->127.0.0.1:64436: wsarecv: An existing connection was forcibly closed by the remote host.

want: Normal use

what is the my_ss_server

What is the my_ss_server ? in command line
sudo route add my_ss_server $origin_gw
Is this command correct ?

sudo ./gotun2socks --local-socks-addr 127.0.0.1:1080

sudo route add -net 0.0.0.0 10.0.0.1 -netmask 128.0.0.0
sudo route add -net 128.0.0.0 10.0.0.1 -netmask 128.0.0.0

orig_gw=$(netstat -nr | grep --color=never '^default' | grep -v 'utun' | sed 's/default ([0-9.]) .*/\1/' | head -1)
sudo route add my_ss_server $origin_gw

windows build

github.com/yinghuocho/gotun2socks

.\gotun2socks.go:97: cannot use int(t2s.dev.Fd()) (type int) as type syscall.Handle in argument to syscall.SetNonblock
what shall i do?

Hello may i ask you a TAP-Windows question?

How to solve the problem that the TAP device cannot write IP packets to or read IP packets from the TAP application layer after reading and writing for a period of time (mostly when downloading a file stream).

Could you please show an usage example on Linux/Ubuntu?

I try to follow the guide in the page https://code.google.com/archive/p/badvpn/wikis/tun2socks.wiki.

I get lost at the step Now start the program (on Linux, run it as <someuser>): badvpn-tun2socks --tundev <tun_spec> --netif-ipaddr 10.0.0.2 --netif-netmask 255.255.255.0 --socks-server-addr 127.0.0.1:1080

Because I do NOT have badvpn-tun2socks command, and I did not get the meaning of NOTE: --netif-ipaddr 10.0.0.2 is not a typo. It specifies the IP address of the virtual router inside the TUN device, and must be different than the IP of the TUN interface itself.

So could you please show an example?

Thanks.

A problem occurred while processing udp packets

I found that the UDP connection will be closed immediately when there is a UDP packet to receive, it happened here:
udp.go line 311 .... case <-ut.socksClosed: ...

it closed because there is a method called:
udp.go line 235 go gosocks.ConnMonitor(ut.socksConn, ut.socksClosed)
I don't understand what this method is for, so I commented it out, and then udp packets will receive normally, okay
This problem causes DNS authentication to fail

UDP loopback IP transport problems

Listen to loopback IP:127.0.0.1
TCP and UDP work properly

but Listen to loopback IP:127.0.0.2 or 2-255
TCP is working properly, UDP can not be transport

send
Application.UDP------>gotun2socks------>server------>target
recv
Application.UDP--x---<gotun2socks------<server------<target

The packet passes through the server and returns
But there is no return from the gotun2socks to the Application

icmp support

ping baidu.com

not support icmp

2016/12/07 22:48:41 Unsupported packet: protocol 1
2016/12/07 22:48:42 Unsupported packet: protocol 1
2016/12/07 22:48:43 Unsupported packet: protocol 1
2016/12/07 22:48:44 Unsupported packet: protocol 1
2016/12/07 22:48:45 Unsupported packet: protocol 1
2016/12/07 22:48:46 Unsupported packet: protocol 1
2016/12/07 22:48:47 Unsupported packet: protocol 1
2016/12/07 22:48:48 Unsupported packet: protocol 1
2016/12/07 22:48:49 Unsupported packet: protocol 1
2016/12/07 22:48:50 Unsupported packet: protocol 1
2016/12/07 22:48:51 Unsupported packet: protocol 1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.