-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Specify out local address. Fix whitelist validation.
- Loading branch information
Showing
7 changed files
with
121 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
accounts: | ||
- username: "test" | ||
password: "test123456" | ||
bind_address: "0.0.0.0:8080" | ||
req_address: "" | ||
tcp_timeout: 60 | ||
udp_timeout: 60 | ||
whitelist: | ||
- username: "test" # auth username | ||
password: "test123456" # auth password | ||
bind_address: "0.0.0.0:8080" # listen bind address + port | ||
udp_bind_ip: "127.0.0.1" # udp bind ip | ||
out_address: "192.168.100.165" # specify out local address | ||
tcp_timeout: 60 # tcp timeout | ||
udp_timeout: 60 # udp timeout | ||
whitelist: # whitelist | ||
- "192.168.100.1" | ||
- "127.0.0.1" | ||
- bind_address: "0.0.0.0:8081" | ||
- bind_address: "0.0.0.0:8081" # bind 2 | ||
out_address: "" # auto out address |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package s5 | ||
|
||
import ( | ||
"io" | ||
"log" | ||
"net" | ||
|
||
"github.com/txthinking/socks5" | ||
) | ||
|
||
// Connect remote conn which u want to connect with your dialer | ||
// Error or OK both replied. | ||
func Connect(w io.Writer, r *socks5.Request, outAddress string) (*net.TCPConn, error) { | ||
if socks5.Debug { | ||
log.Println("Call:", r.Address()) | ||
} | ||
var tmp *net.TCPConn | ||
var err error | ||
|
||
tcpaddr, err := net.ResolveTCPAddr("tcp", r.Address()) | ||
if err != nil { | ||
var p *socks5.Reply | ||
if r.Atyp == socks5.ATYPIPv4 || r.Atyp == socks5.ATYPDomain { | ||
p = socks5.NewReply(socks5.RepHostUnreachable, socks5.ATYPIPv4, []byte{0x00, 0x00, 0x00, 0x00}, []byte{0x00, 0x00}) | ||
} else { | ||
p = socks5.NewReply(socks5.RepHostUnreachable, socks5.ATYPIPv6, []byte(net.IPv6zero), []byte{0x00, 0x00}) | ||
} | ||
if _, err := p.WriteTo(w); err != nil { | ||
return nil, err | ||
} | ||
return nil, err | ||
} | ||
if outAddress != "" { | ||
localAddr, _ := net.ResolveTCPAddr("tcp", outAddress+":0") | ||
|
||
tmp, err = socks5.Dial.DialTCP("tcp", localAddr, tcpaddr) | ||
|
||
} else { | ||
tmp, err = socks5.Dial.DialTCP("tcp", nil, tcpaddr) | ||
} | ||
if err != nil { | ||
var p *socks5.Reply | ||
if r.Atyp == socks5.ATYPIPv4 || r.Atyp == socks5.ATYPDomain { | ||
p = socks5.NewReply(socks5.RepHostUnreachable, socks5.ATYPIPv4, []byte{0x00, 0x00, 0x00, 0x00}, []byte{0x00, 0x00}) | ||
} else { | ||
p = socks5.NewReply(socks5.RepHostUnreachable, socks5.ATYPIPv6, []byte(net.IPv6zero), []byte{0x00, 0x00}) | ||
} | ||
if _, err := p.WriteTo(w); err != nil { | ||
return nil, err | ||
} | ||
return nil, err | ||
} | ||
rc := tmp | ||
a, addr, port, err := socks5.ParseAddress(rc.LocalAddr().String()) | ||
if err != nil { | ||
var p *socks5.Reply | ||
if r.Atyp == socks5.ATYPIPv4 || r.Atyp == socks5.ATYPDomain { | ||
p = socks5.NewReply(socks5.RepHostUnreachable, socks5.ATYPIPv4, []byte{0x00, 0x00, 0x00, 0x00}, []byte{0x00, 0x00}) | ||
} else { | ||
p = socks5.NewReply(socks5.RepHostUnreachable, socks5.ATYPIPv6, []byte(net.IPv6zero), []byte{0x00, 0x00}) | ||
} | ||
if _, err := p.WriteTo(w); err != nil { | ||
return nil, err | ||
} | ||
return nil, err | ||
} | ||
p := socks5.NewReply(socks5.RepSuccess, a, addr, port) | ||
if _, err := p.WriteTo(w); err != nil { | ||
return nil, err | ||
} | ||
|
||
return rc, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package server | ||
|
||
import ( | ||
"net" | ||
) | ||
|
||
func checkIsWhitelisted(address string, whitelistMap WhitelistMapType) bool { | ||
//log.Printf("client come in: %s", address) | ||
w_map := whitelistMap | ||
if len(w_map) == 0 { | ||
return true | ||
} | ||
var ok bool | ||
addr, _, err := net.SplitHostPort(address) | ||
if err != nil { | ||
addr = address | ||
} | ||
_, ok = w_map[addr] | ||
return ok | ||
} |