mirror of
https://github.com/whyvl/wireproxy.git
synced 2025-04-29 19:01:42 +02:00
commit
0ac02beb7d
1 changed files with 23 additions and 4 deletions
27
main.go
27
main.go
|
@ -2,17 +2,17 @@ package main
|
|||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"math/rand"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
"strconv"
|
||||
"context"
|
||||
"math/rand"
|
||||
"strings"
|
||||
|
||||
"github.com/armon/go-socks5"
|
||||
|
||||
|
@ -39,6 +39,11 @@ type NetstackDNSResolver struct {
|
|||
|
||||
type Configuration []ConfigSection
|
||||
|
||||
type CredentialValidator struct {
|
||||
username string
|
||||
password string
|
||||
}
|
||||
|
||||
func (d NetstackDNSResolver) Resolve(ctx context.Context, name string) (context.Context, net.IP, error) {
|
||||
addrs, err := d.tnet.LookupContextHost(ctx, name)
|
||||
if err != nil {
|
||||
|
@ -232,7 +237,16 @@ func socks5Routine(config map[string]string) (func(*netstack.Net), error) {
|
|||
}
|
||||
|
||||
routine := func(tnet *netstack.Net) {
|
||||
conf := &socks5.Config{ Dial: tnet.DialContext, Resolver: NetstackDNSResolver{ tnet: tnet } }
|
||||
conf := &socks5.Config{Dial: tnet.DialContext, Resolver: NetstackDNSResolver{tnet: tnet}}
|
||||
if username, ok := config["username"]; ok {
|
||||
validator := CredentialValidator{username: username}
|
||||
password, ok := config["password"]
|
||||
if ok {
|
||||
validator.password = password
|
||||
}
|
||||
|
||||
conf.Credentials = validator
|
||||
}
|
||||
server, err := socks5.New(conf)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
|
@ -246,6 +260,11 @@ func socks5Routine(config map[string]string) (func(*netstack.Net), error) {
|
|||
return routine, nil
|
||||
}
|
||||
|
||||
func (c CredentialValidator) Valid(username, password string) bool {
|
||||
return c.username == username && c.password == password
|
||||
}
|
||||
|
||||
|
||||
func connForward(bufSize int, from, to net.Conn) {
|
||||
buf := make([]byte, bufSize)
|
||||
for {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue