2022-05-23 01:05:50 +00:00
|
|
|
package prox5
|
2021-09-30 19:19:09 +00:00
|
|
|
|
|
|
|
import (
|
2022-07-25 06:23:12 +00:00
|
|
|
"strings"
|
2022-07-25 07:14:26 +00:00
|
|
|
|
|
|
|
"git.tcp.direct/kayos/go-socks5"
|
2021-09-30 19:19:09 +00:00
|
|
|
|
2022-08-28 13:12:48 +00:00
|
|
|
"git.tcp.direct/kayos/prox5/internal/pools"
|
|
|
|
)
|
2021-09-30 19:19:09 +00:00
|
|
|
|
2021-10-09 20:45:30 +00:00
|
|
|
type socksCreds struct {
|
2021-09-30 19:19:09 +00:00
|
|
|
username string
|
|
|
|
password string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Valid implements the socks5.CredentialStore interface.
|
|
|
|
func (s socksCreds) Valid(username, password string) bool {
|
|
|
|
if s.username == username && s.password == password {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// StartSOCKS5Server starts our rotating proxy SOCKS5 server.
|
|
|
|
// listen is standard Go listen string, e.g: "127.0.0.1:1080".
|
|
|
|
// username and password are used for authenticatig to the SOCKS5 server.
|
2022-09-22 23:48:08 +00:00
|
|
|
func (p5 *Swamp) StartSOCKS5Server(listen, username, password string) error {
|
2021-09-30 19:19:09 +00:00
|
|
|
|
|
|
|
conf := &socks5.Config{
|
2022-08-28 13:12:48 +00:00
|
|
|
Credentials: socksCreds{username: username, password: password},
|
2022-09-22 23:48:08 +00:00
|
|
|
Logger: p5.DebugLogger,
|
|
|
|
Dial: p5.MysteryDialer,
|
2022-08-28 13:12:48 +00:00
|
|
|
// Resolver: pe.MysteryResolver,
|
2021-09-30 19:19:09 +00:00
|
|
|
}
|
|
|
|
|
2022-08-28 13:12:48 +00:00
|
|
|
buf := pools.CopABuffer.Get().(*strings.Builder)
|
2022-07-25 06:23:12 +00:00
|
|
|
buf.WriteString("listening for SOCKS5 connections on ")
|
|
|
|
buf.WriteString(listen)
|
2022-09-22 23:48:08 +00:00
|
|
|
p5.dbgPrint(buf)
|
2021-09-30 19:19:09 +00:00
|
|
|
|
|
|
|
server, err := socks5.New(conf)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return server.ListenAndServe("tcp", listen)
|
|
|
|
}
|