Security implications of a socket race when tunnelling a sub-command -


i want tunnel sub-command through connection listening port, running sub-command (to connect port), , forwarding data through connection:

package main  import (     "fmt"     "net"     "os"     "os/exec" )  func main() {     ln, err := net.listentcp("tcp4", &net.tcpaddr{ip: localhost})     if err != nil {         fmt.fprintln(os.stderr, err)         os.exit(1)     }     defer ln.close()      port := ln.addr().(*net.tcpaddr).port      cmd := exec.command(         "git",         "clone",         fmt.sprintf("git://127.0.0.1:%d/project.git", port),     )      cmd.stdout = os.stdout     cmd.stderr = os.stderr      if err := cmd.start(); err != nil {         fmt.fprintln(os.stderr, err)         os.exit(1)     }     defer cmd.process.kill()      errs := make(chan error, 1)     go func() {         errs <- cmd.wait()     }()      conns := make(chan net.conn, 1)     go func() {         conn, err := ln.accept()         if err == nil {             conns <- conn         } else {             fmt.println(err)             errs <- err         }     }()      select {     case err := <-errs:         fmt.fprintln(os.stderr, err)         os.exit(1)     case conn := <-conns:         defer conn.close()         // todo tunnel data `conn` through connection.     }      fmt.println("done.") }  var localhost = net.ipv4(127, 0, 0, 1) 

however, there's race here between time start listening , time when sub-command connects listener, process can connect listener. believe race exploited attacker communicate process @ other end of connection , achieve results otherwise require privilege escalation perform (example attacks require special permissions replacing git command malicious program or reading contents of cloned directory, in instance).

should concern? if so, there way can prevented? though question asked using go example, answers , comments in language welcome.

yes concern. can prevented using form of authentication server allows connections legitimate clients.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -