From 0847b677bc8491b16e63633e337b4cc8640f1b30 Mon Sep 17 00:00:00 2001 From: Vomitblood Date: Fri, 24 Jan 2025 11:17:20 +0800 Subject: [PATCH] updated prompt logic --- internal/listener/listener.go | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/internal/listener/listener.go b/internal/listener/listener.go index f9d2ebb..4ffa7c1 100644 --- a/internal/listener/listener.go +++ b/internal/listener/listener.go @@ -1,6 +1,7 @@ package listener import ( + "bufio" "fmt" "io" "net" @@ -13,18 +14,26 @@ func handleConnection(conn net.Conn) { fmt.Println("Connection established. Interacting with reverse shell...") fmt.Println("Press enter once if prompt does not show up.") - for { - var cmd string - fmt.Scanln(&cmd) + // Use bufio.NewReader for more interactive input handling + reader := bufio.NewReader(os.Stdin) - // send the command to the reverse shell - _, err := conn.Write([]byte(cmd + "\n")) + for { + // Read command input interactively from the user + fmt.Print("Shell> ") + cmd, err := reader.ReadString('\n') // Read until Enter is pressed + if err != nil { + fmt.Println("Error reading command:", err) + return + } + + // Send the command to the reverse shell + _, err = conn.Write([]byte(cmd)) if err != nil { fmt.Println("Error sending command:", err) return } - // read the response from the reverse shell + // Read the response from the reverse shell buf := make([]byte, 1024) n, err := conn.Read(buf) if err != nil && err != io.EOF { @@ -32,7 +41,7 @@ func handleConnection(conn net.Conn) { return } - // print the reverse shell output + // Print the reverse shell output fmt.Print(string(buf[:n])) } } @@ -48,7 +57,7 @@ func startListener(lhost, lport string) { fmt.Printf("Listening for reverse shell on %s:%s...\n", lhost, lport) - // accept incoming connections and handle them + // Accept incoming connections and handle them for { conn, err := listener.Accept() if err != nil { @@ -56,13 +65,13 @@ func startListener(lhost, lport string) { continue } - // handle the connection in a new goroutine + // Handle the connection in a new goroutine go handleConnection(conn) } } func Listen(lport string) { - // listen on everything, lazy + // Listen on everything, lazy lhost := "0.0.0.0" startListener(lhost, lport)