Projects STRLCPY reverse_ssh Commits 6d883f29
🤬
  • Make remoteforward way more robust

  • Loading...
  • NHAS committed 11 months ago
    6d883f29
    1 parent e963f920
  • ■ ■ ■ ■ ■ ■
    internal/client/handlers/remoteforward.go
    skipped 78 lines
    79 79   if err != nil {
    80 80   return
    81 81   }
    82  - go handleData(rf, proxyCon, sshConn)
     82 + go handleData(proxyCon, sshConn)
    83 83   }
    84 84   
    85 85  }
    86 86   
    87  -func handleData(rf internal.RemoteForwardRequest, proxyCon net.Conn, sshConn ssh.Conn) error {
     87 +func handleData(proxyCon net.Conn, sshConn ssh.Conn) error {
    88 88   
    89 89   log.Println("Accepted new connection: ", proxyCon.RemoteAddr())
    90 90   
    91  - originatorAddress := proxyCon.LocalAddr().String()
    92  - var originatorPort uint32
     91 + lHost, strPort, err := net.SplitHostPort(proxyCon.LocalAddr().String())
     92 + if err != nil {
     93 + return err
     94 + }
    93 95   
    94  - for i := len(originatorAddress) - 1; i > 0; i-- {
    95  - if originatorAddress[i] == ':' {
     96 + lPort, err := strconv.Atoi(strPort)
     97 + if err != nil {
     98 + return err
     99 + }
    96 100   
    97  - e, err := strconv.Atoi(originatorAddress[i+1:])
    98  - if err != nil {
    99  - return err
    100  - }
     101 + rHost, strPort, err := net.SplitHostPort(proxyCon.RemoteAddr().String())
     102 + if err != nil {
     103 + return err
     104 + }
    101 105   
    102  - originatorPort = uint32(e)
    103  - originatorAddress = originatorAddress[:i]
    104  - break
    105  - }
     106 + rPort, err := strconv.Atoi(strPort)
     107 + if err != nil {
     108 + return err
    106 109   }
    107 110   
    108 111   drtMsg := internal.ChannelOpenDirectMsg{
    109  - Raddr: rf.BindAddr,
    110  - Rport: rf.BindPort,
     112 + Raddr: rHost,
     113 + Rport: uint32(rPort),
    111 114   
    112  - Laddr: originatorAddress,
    113  - Lport: originatorPort,
     115 + Laddr: lHost,
     116 + Lport: uint32(lPort),
    114 117   }
    115 118   
    116 119   b := ssh.Marshal(&drtMsg)
    skipped 26 lines
Please wait...
Page is in error, reload to recover