audibleblink / holeysocks

Cross-Platform Reverse Socks Proxy in Go
GNU General Public License v3.0
25 stars 11 forks source link

socks5 proxy service dies after 1 request #4

Open ghost-ng opened 3 years ago

ghost-ng commented 3 years ago
.\socksproxy.exe
2021/06/30 11:58:00 [ERR] socks: Failed to handle request: Connect to 10.0.0.4:80 failed: dial tcp 10.0.0.4:80: connectex: No connection could be made because the target machine actively refused it.

my program:

func main() {
    //error handling removed for brevity

    mainConfig := holeysocks.MainConfig{}
    //configBytes, _ := os.ReadFile("ssh.json")
    //configBytes, _ := os.ReadFile(jsonConfig)
    //json.Unmarshal(configBytes, &config)

    f, _ := os.Create("key")
    f.WriteString(sshKey)
    f.Close()

    s, _ := os.Create("config")
    s.WriteString(jsonConfig)
    s.Close()

    key, _ := os.ReadFile("key")
    config, _ := os.ReadFile("config")

    json.Unmarshal(config, &mainConfig)
    //json.Unmarshal([]byte(jsonConfig), &mainConfig)
    mainConfig.SSH.SetKey(key)
    //mainConfig.SSH.SetKey([]byte(sshKey))

    os.Remove("key")
    os.Remove("config")

    holeysocks.ForwardService(mainConfig)
    // #DarnSocks runs two goroutines then returns so we have to keep main from returning
    select {}
}

On connection:

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:1080          0.0.0.0:*               LISTEN      -                                    
tcp        0      0 0.0.0.0:2202            0.0.0.0:*               LISTEN      -        `

Proxychains Error (the port should be open)

└─$ proxychains4 -f proxychains5.msf nmap 10.0.0.4 -p 2202
[proxychains] config file found: proxychains5.msf
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4
[proxychains] DLL init: proxychains-ng 4.14
Starting Nmap 7.91 ( https://nmap.org ) at 2021-06-30 12:02 EDT
[proxychains] Dynamic chain  ...  0.0.0.0:1080  ...  10.0.0.4:80 <--socket error or timeout!
[proxychains] Dynamic chain  ...  0.0.0.0:1080  ...  timeout

the exe then quits. This happens with and without the "select {}"

Update 1: seems to work with netcat, but not with nmap - either way though, it closes after the first connection (regardless of error); my initial thought is that nmap scans dont work because of the immediate close, see update 2

└─$ proxychains -f proxychains.conf nc -vz 10.0.0.4 2202 
[proxychains] config file found: proxychains.conf
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4
[proxychains] DLL init: proxychains-ng 4.14
[proxychains] Strict chain  ...  127.0.0.1:1080  ...  10.0.0.4:2202  ...  OK
10.0.0.4 [10.0.0.4] 2202 (?) open : Operation now in progress

└─$ proxychains -f proxychains.conf nc -vz 10.0.0.4 2203
[proxychains] config file found: proxychains.conf
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4
[proxychains] DLL init: proxychains-ng 4.14
[proxychains] Strict chain  ...  127.0.0.1:1080  ...  10.0.0.4:2203 <--socket error or timeout!
10.0.0.4 [10.0.0.4] 2203 (?) : Connection refused

Update 2:

└─$ proxychains -f proxychains.conf nmap 10.0.0.4 -p 2202 -Pn -sT                                                 1 ⨯
[proxychains] config file found: proxychains.conf
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4
[proxychains] DLL init: proxychains-ng 4.14
Host discovery disabled (-Pn). All addresses will be marked 'up' and scan times will be slower.
Starting Nmap 7.91 ( https://nmap.org ) at 2021-07-04 17:51 EDT
[proxychains] Strict chain  ...  127.0.0.1:1080  ...  10.0.0.4:2202  ...  OK
Nmap scan report for 10.0.0.4
Host is up (0.0026s latency).

PORT     STATE SERVICE
2202/tcp open  imtc-map

Nmap done: 1 IP address (1 host up) scanned in 0.04 seconds

I used the code in the front page readme

package main

import (
    "encoding/json"
    "os"

    "github.com/audibleblink/holeysocks/pkg/holeysocks"
)

func main() {
    //error handling removed for brevity
    config := holeysocks.MainConfig{}
    configBytes, _ := os.ReadFile("configs/ssh.json")
    json.Unmarshal(configBytes, &config)

    sshKey, _ := os.ReadFile("configs/key")
    config.SSH.SetKey(sshKey)
    holeysocks.ForwardService(config)
}
ghost-ng commented 3 years ago

im fairly certain this is not the best way to do this, but i solved the problem with a loop:

for {
        socksClient, err := remoteListener.Accept()
        if err != nil {
            return fmt.Errorf("could not handle incoming socks client request: %s", err)
        }

        conf := &socks5.Config{}

        server, err := socks5.New(conf)
        if err != nil {
            return fmt.Errorf("failed creating new Socks server: %s", err)
        }
        server.ServeConn(socksClient)
    }
    //return server.ServeConn(socksClient)
}