2022-05-23 01:05:50 +00:00
|
|
|
package prox5
|
2021-09-14 07:28:10 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
2021-09-23 07:38:00 +00:00
|
|
|
"fmt"
|
2021-10-25 09:57:38 +00:00
|
|
|
"io"
|
2021-09-14 07:28:10 +00:00
|
|
|
"os"
|
2021-09-18 08:33:40 +00:00
|
|
|
"strconv"
|
2021-09-14 07:28:10 +00:00
|
|
|
"strings"
|
2021-10-25 10:32:59 +00:00
|
|
|
"time"
|
2021-09-18 10:38:22 +00:00
|
|
|
|
2021-10-23 17:25:28 +00:00
|
|
|
"github.com/miekg/dns"
|
2021-09-18 10:38:22 +00:00
|
|
|
ipa "inet.af/netaddr"
|
2021-09-14 07:28:10 +00:00
|
|
|
)
|
|
|
|
|
2021-09-20 01:23:18 +00:00
|
|
|
// throw shit proxies here, get map
|
2021-09-21 12:24:30 +00:00
|
|
|
// see daemons.go
|
2021-09-20 01:23:18 +00:00
|
|
|
var inChan chan string
|
|
|
|
|
|
|
|
func init() {
|
2021-10-23 17:25:28 +00:00
|
|
|
inChan = make(chan string, 100000)
|
2021-09-20 01:23:18 +00:00
|
|
|
}
|
|
|
|
|
2021-10-25 04:15:06 +00:00
|
|
|
func checkV6(in string) (filtered string, ok bool) {
|
|
|
|
split := strings.Split(in, "]:")
|
|
|
|
if len(split) != 2 {
|
2021-09-23 07:38:00 +00:00
|
|
|
return in, false
|
2021-09-20 01:23:18 +00:00
|
|
|
}
|
2021-10-23 14:26:23 +00:00
|
|
|
|
2021-10-25 04:15:06 +00:00
|
|
|
combo, err := ipa.ParseIPPort(split[0] + "]:" + split[1])
|
|
|
|
if err != nil {
|
|
|
|
return in, false
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(split[1], ":") {
|
|
|
|
return combo.String(), true
|
|
|
|
}
|
|
|
|
|
|
|
|
split6 := strings.Split(split[1], ":")
|
|
|
|
if len(split6) != 2 {
|
|
|
|
return in, false
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Sprintf("%s:%s@%s", split6[0], split6[1], combo.String()), true
|
|
|
|
}
|
|
|
|
|
2022-06-26 02:51:42 +00:00
|
|
|
func (pe *ProxyEngine) filter(in string) (filtered string, ok bool) {
|
2021-10-25 04:15:06 +00:00
|
|
|
if !strings.Contains(in, ":") {
|
|
|
|
return in, false
|
|
|
|
}
|
2021-09-20 01:23:18 +00:00
|
|
|
split := strings.Split(in, ":")
|
2021-10-25 04:15:06 +00:00
|
|
|
|
|
|
|
if len(split) < 2 {
|
|
|
|
return in, false
|
|
|
|
}
|
2021-10-27 02:13:52 +00:00
|
|
|
|
2021-10-25 04:15:06 +00:00
|
|
|
if _, err := strconv.Atoi(split[1]); err != nil {
|
2021-09-23 07:38:00 +00:00
|
|
|
return in, false
|
2021-10-25 04:15:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch len(split) {
|
2021-10-23 14:26:23 +00:00
|
|
|
case 2:
|
2021-10-24 20:30:15 +00:00
|
|
|
if _, ok := dns.IsDomainName(split[0]); ok {
|
|
|
|
return in, true
|
|
|
|
}
|
2021-10-23 14:26:23 +00:00
|
|
|
combo, err := ipa.ParseIPPort(in)
|
|
|
|
if err != nil {
|
|
|
|
return in, false
|
|
|
|
}
|
|
|
|
return combo.String(), true
|
2021-10-23 17:25:28 +00:00
|
|
|
case 4:
|
|
|
|
if _, ok := dns.IsDomainName(split[0]); ok {
|
|
|
|
return fmt.Sprintf("%s:%s@%s:%s", split[2], split[3], split[0], split[1]), true
|
|
|
|
}
|
2021-10-23 14:26:23 +00:00
|
|
|
combo, err := ipa.ParseIPPort(split[0] + ":" + split[1])
|
|
|
|
if err != nil {
|
|
|
|
return in, false
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("%s:%s@%s", split[2], split[3], combo.String()), true
|
|
|
|
default:
|
2021-10-25 04:15:06 +00:00
|
|
|
if !strings.Contains(split[0], "[") || !strings.Contains(split[0], "]:") {
|
2021-10-23 14:26:23 +00:00
|
|
|
return in, false
|
|
|
|
}
|
2021-09-20 01:23:18 +00:00
|
|
|
}
|
2021-10-25 04:15:06 +00:00
|
|
|
return checkV6(in)
|
2021-09-20 01:23:18 +00:00
|
|
|
}
|
|
|
|
|
2021-09-21 12:24:30 +00:00
|
|
|
// LoadProxyTXT loads proxies from a given seed file and feeds them to the mapBuilder to be later queued automatically for validation.
|
2021-10-25 04:15:06 +00:00
|
|
|
// Expects the following formats:
|
|
|
|
// * 127.0.0.1:1080
|
|
|
|
// * 127.0.0.1:1080:user:pass
|
|
|
|
// * yeet.com:1080
|
|
|
|
// * yeet.com:1080:user:pass
|
|
|
|
// * [fe80::2ef0:5dff:fe7f:c299]:1080
|
|
|
|
// * [fe80::2ef0:5dff:fe7f:c299]:1080:user:pass
|
2022-06-28 02:27:52 +00:00
|
|
|
func (pe *ProxyEngine) LoadProxyTXT(seedFile string) (count int) {
|
2021-10-25 10:32:59 +00:00
|
|
|
f, err := os.Open(seedFile)
|
|
|
|
if err != nil {
|
2022-06-26 02:51:42 +00:00
|
|
|
pe.dbgPrint(err.Error())
|
2021-10-25 10:32:59 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2021-10-23 17:25:28 +00:00
|
|
|
defer func() {
|
2021-10-25 10:32:59 +00:00
|
|
|
if err := f.Close(); err != nil {
|
2022-06-26 02:51:42 +00:00
|
|
|
pe.dbgPrint(err.Error())
|
2021-10-25 10:32:59 +00:00
|
|
|
}
|
2021-10-23 17:25:28 +00:00
|
|
|
}()
|
2021-09-14 07:28:10 +00:00
|
|
|
|
2021-10-25 10:32:59 +00:00
|
|
|
bs, err := io.ReadAll(f)
|
2021-09-14 07:28:10 +00:00
|
|
|
if err != nil {
|
2022-06-26 02:51:42 +00:00
|
|
|
pe.dbgPrint(err.Error())
|
2021-09-20 01:23:18 +00:00
|
|
|
return 0
|
2021-09-14 07:28:10 +00:00
|
|
|
}
|
2021-10-25 09:57:38 +00:00
|
|
|
sockstr := string(bs)
|
2021-09-14 07:28:10 +00:00
|
|
|
|
2022-06-28 02:27:52 +00:00
|
|
|
return pe.LoadMultiLineString(sockstr)
|
2021-09-14 07:28:10 +00:00
|
|
|
}
|
2021-09-18 03:47:11 +00:00
|
|
|
|
2021-09-21 12:24:30 +00:00
|
|
|
// LoadSingleProxy loads a SOCKS proxy into our map. Uses the format: 127.0.0.1:1080 (host:port).
|
2022-06-26 02:51:42 +00:00
|
|
|
func (pe *ProxyEngine) LoadSingleProxy(sock string) (ok bool) {
|
|
|
|
if sock, ok = pe.filter(sock); !ok {
|
2021-10-25 04:15:06 +00:00
|
|
|
return
|
|
|
|
}
|
2022-06-26 02:51:42 +00:00
|
|
|
go pe.loadSingleProxy(sock)
|
2021-10-25 04:15:06 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-06-26 02:51:42 +00:00
|
|
|
func (pe *ProxyEngine) loadSingleProxy(sock string) {
|
2021-10-25 10:32:59 +00:00
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case inChan <- sock:
|
|
|
|
return
|
|
|
|
default:
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
}
|
|
|
|
}
|
2021-09-14 07:28:10 +00:00
|
|
|
}
|
2021-09-18 03:47:11 +00:00
|
|
|
|
2021-09-21 12:24:30 +00:00
|
|
|
// LoadMultiLineString loads a multiine string object with one (host:port) SOCKS proxy per line.
|
2022-06-26 02:51:42 +00:00
|
|
|
func (pe *ProxyEngine) LoadMultiLineString(socks string) int {
|
2021-09-18 08:33:40 +00:00
|
|
|
var count int
|
2021-09-14 07:28:10 +00:00
|
|
|
scan := bufio.NewScanner(strings.NewReader(socks))
|
|
|
|
for scan.Scan() {
|
2022-06-26 02:51:42 +00:00
|
|
|
if pe.LoadSingleProxy(scan.Text()) {
|
2021-10-25 09:57:38 +00:00
|
|
|
count++
|
|
|
|
}
|
2021-09-18 08:33:40 +00:00
|
|
|
}
|
2021-09-20 01:23:18 +00:00
|
|
|
return count
|
2021-09-14 07:28:10 +00:00
|
|
|
}
|
2021-09-18 03:47:11 +00:00
|
|
|
|
2021-09-21 12:24:30 +00:00
|
|
|
// ClearSOCKSList clears the map of proxies that we have on record.
|
2021-10-23 14:26:23 +00:00
|
|
|
// Other operations (proxies that are still in buffered channels) will continue.
|
2022-06-26 02:51:42 +00:00
|
|
|
func (pe *ProxyEngine) ClearSOCKSList() {
|
|
|
|
pe.swampmap.clear()
|
2021-09-14 07:28:10 +00:00
|
|
|
}
|