add reverse portfwd function
This commit is contained in:
+35
-4
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/armon/go-socks5"
|
||||
"github.com/hashicorp/yamux"
|
||||
"github.com/sirupsen/logrus"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -95,11 +96,12 @@ func DialTcpBySocks5Proxy(proxyHost string, dstAddr string, auth *ProxyAuth) (c
|
||||
}
|
||||
|
||||
func main() {
|
||||
relayServer := flag.String("s", "", "The ligolo server (the connect-back address)(e.g. example.com:443)")
|
||||
relayServer := flag.String("s", "", "The ligolo server ip:port (e.g. example.com:443)")
|
||||
targetServer := flag.String("t", "", "The destination server ip:port (e.g. 192.168.1.3:3389, 192.168.1.3:22, etc.) - when not specified, Ligolo starts a socks5 proxy server")
|
||||
proxyStr := flag.String("proxy", "", "Use proxy to connect ligolo server(e.g. http://user:[email protected]:8080 socks5://user:[email protected]:1080)")
|
||||
flag.Parse()
|
||||
for {
|
||||
err := StartLigolo(*relayServer, *proxyStr)
|
||||
err := StartLigolo(*relayServer, *targetServer, *proxyStr)
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
@@ -108,7 +110,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func StartLigolo(relayServer string, proxyStr string) error {
|
||||
func StartLigolo(relayServer string, targetServer string, proxyStr string) error {
|
||||
var socks *socks5.Server
|
||||
logrus.Infoln("Connecting to ligolo server...")
|
||||
config := &tls.Config{InsecureSkipVerify: true}
|
||||
@@ -149,7 +151,16 @@ func StartLigolo(relayServer string, proxyStr string) error {
|
||||
}
|
||||
logrus.WithFields(logrus.Fields{"active_sessions": session.NumStreams()}).Println("Accepted new connection !")
|
||||
// When no targetServer are specified, starts a socks5 proxy
|
||||
go socks.ServeConn(stream)
|
||||
if targetServer == "" {
|
||||
go socks.ServeConn(stream)
|
||||
} else {
|
||||
proxyConn, err := net.Dial("tcp", targetServer)
|
||||
if err != nil {
|
||||
logrus.Errorf("Error creating Proxy TCP connection ! Error : %s\n", err)
|
||||
return err
|
||||
}
|
||||
go handleRelay(stream, proxyConn)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -163,3 +174,23 @@ func startSocksProxy() (*socks5.Server, error) {
|
||||
}
|
||||
return socks, nil
|
||||
}
|
||||
|
||||
func handleRelay(src net.Conn, dst net.Conn) {
|
||||
stop := make(chan bool, 2)
|
||||
|
||||
go relay(src, dst, stop)
|
||||
go relay(dst, src, stop)
|
||||
|
||||
select {
|
||||
case <-stop:
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func relay(src net.Conn, dst net.Conn, stop chan bool) {
|
||||
io.Copy(dst, src)
|
||||
dst.Close()
|
||||
src.Close()
|
||||
stop <- true
|
||||
return
|
||||
}
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
localServer := flag.String("s5", "127.0.0.1:1080", "The local socks5 server address (your proxychains parameter)")
|
||||
localServer := flag.String("p", "127.0.0.1:1080", "The local socks5 server address or ip:port to connect")
|
||||
relayServer := flag.String("l", "0.0.0.0:443", "The relay server listening address (the connect-back address)")
|
||||
certFile := flag.String("cert", "cert.pem", "The TLS server certificate,Unnecessary")
|
||||
keyFile := flag.String("key", "key.pem", "The TLS server key,Unnecessary")
|
||||
|
||||
Reference in New Issue
Block a user