Skip to content

Commit

Permalink
Socks can listen on specific interface, closes #56
Browse files Browse the repository at this point in the history
  • Loading branch information
ph4ntonn committed Mar 29, 2024
1 parent 75942c3 commit b183e10
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
8 changes: 7 additions & 1 deletion admin/cli/interactive.go
@@ -1,3 +1,4 @@
//go:build !windows
// +build !windows

package cli
Expand Down Expand Up @@ -781,7 +782,12 @@ func (console *Console) handleNodePanelCommand(uuidNum int) {
socks.Password = fCommand[3]
}

printer.Warning("\r\n[*] Trying to listen on 0.0.0.0:%s......", fCommand[1])
if socks.Addr != "" {
printer.Warning("\r\n[*] Trying to listen on %s:%s......", socks.Addr, socks.Port)
} else {
printer.Warning("\r\n[*] Trying to listen on 0.0.0.0:%s......", socks.Port)
}

printer.Warning("\r\n[*] Waiting for agent's response......")

err := socks.LetSocks(console.mgr, route, uuid)
Expand Down
24 changes: 21 additions & 3 deletions admin/handler/socks.go
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"net"
"strings"

"Stowaway/admin/manager"
"Stowaway/admin/topology"
Expand All @@ -14,17 +15,34 @@ import (
type Socks struct {
Username string
Password string
Addr string
Port string
}

func NewSocks(port string) *Socks {
func NewSocks(param string) *Socks {
socks := new(Socks)
socks.Port = port

slice := strings.SplitN(param, ":", 2)

if len(slice) < 2 {
socks.Port = param
} else {
socks.Addr = slice[0]
socks.Port = slice[1]
}

return socks
}

func (socks *Socks) LetSocks(mgr *manager.Manager, route string, uuid string) error {
addr := fmt.Sprintf("0.0.0.0:%s", socks.Port)
var addr string

if socks.Addr != "" {
addr = fmt.Sprintf("%s:%s", socks.Addr, socks.Port)
} else {
addr = fmt.Sprintf("0.0.0.0:%s", socks.Port)
}

listener, err := net.Listen("tcp", addr)
if err != nil {
return err
Expand Down

0 comments on commit b183e10

Please sign in to comment.