Projects STRLCPY reverse_ssh Commits 96ba7cf5
🤬
  • Make remote forwarding threadsafe

  • Loading...
  • NHAS committed 11 months ago
    96ba7cf5
    1 parent ad8e3b82
  • ■ ■ ■ ■ ■
    internal/client/handlers/remoteforward.go
    skipped 5 lines
    6 6   "log"
    7 7   "net"
    8 8   "strconv"
     9 + "sync"
    9 10   
    10 11   "github.com/NHAS/reverse_ssh/internal"
    11 12   "golang.org/x/crypto/ssh"
    12 13  )
    13 14   
    14  -var currentRemoteForwards = map[internal.RemoteForwardRequest]net.Listener{}
     15 +var (
     16 + currentRemoteForwardsLck sync.RWMutex
     17 + currentRemoteForwards = map[internal.RemoteForwardRequest]net.Listener{}
     18 +)
    15 19   
    16 20  func StopRemoteForward(rf internal.RemoteForwardRequest) error {
     21 + currentRemoteForwardsLck.Lock()
     22 + defer currentRemoteForwardsLck.Unlock()
    17 23   
    18 24   if _, ok := currentRemoteForwards[rf]; !ok {
    19 25   return fmt.Errorf("Unable to find remote forward request")
    skipped 35 lines
    55 61   
    56 62   log.Println("Started listening on: ", l.Addr())
    57 63   
    58  - currentRemoteForwards[rf] = l
     64 + currentRemoteForwardsLck.Lock()
    59 65   
     66 + currentRemoteForwards[rf] = l
     67 + currentRemoteForwardsLck.Unlock()
    60 68   for {
    61 69   
    62 70   proxyCon, err := l.Accept()
    skipped 64 lines
Please wait...
Page is in error, reload to recover