From bfa23efee8bba88a170d93149dbaaca5b99952c0 Mon Sep 17 00:00:00 2001 From: Josh Mudge Date: Mon, 11 Nov 2019 18:10:00 -0700 Subject: [PATCH] Add some of the files, new docs. --- All/Sign Using OV Cert.md | 77 +++++++++++++++++++++------------------ All/b0x.json | 58 +++++++++++++++++++++++++++++ All/serve.go | 30 +++++++++++++++ All/setup.exe.manifest | 10 +++++ All/setup.go | 55 ++++++++++++++++++++++++++++ todo111119.txt | 5 +++ 6 files changed, 200 insertions(+), 35 deletions(-) create mode 100644 All/b0x.json create mode 100644 All/serve.go create mode 100644 All/setup.exe.manifest create mode 100644 All/setup.go create mode 100644 todo111119.txt diff --git a/All/Sign Using OV Cert.md b/All/Sign Using OV Cert.md index 9e7da28..d31ad27 100644 --- a/All/Sign Using OV Cert.md +++ b/All/Sign Using OV Cert.md @@ -65,7 +65,7 @@ Lastly, you can give your application a name, like "Go Web Server" under the `Pr ``` # Next, build your server app. -go build +go build -o server.exe -ldflags "-s -w -H=windowsgui" ``` You will want to sign your application, the next section will show you how. @@ -108,29 +108,22 @@ Now we're going to create the setup file that will create the firewall rule we n ## Firewall Rule -We are using Powershell to create the firewall rule, so we're going to install `go-powershell`. - -``` -# Install go-powershell -go get github.com/aquasecurity/go-powershell -``` - Create a file named `setup.go` and include the following: ``` //go:generate goversioninfo -manifest=setup.exe.manifest -//Add a new firewall rule in Go. +//Add new firewall rule in Go. package main import ( "os" + "os/exec" + "io/ioutil" + "syscall" "fmt" "log" - "static" // Create fileb0x before this will work. - "io/ioutil" - ps "github.com/aquasecurity/go-powershell" - "github.com/aquasecurity/go-powershell/backend" + "static" // Your fileb0x. ) func main() { @@ -156,31 +149,22 @@ func main() { return } - // choose a backend - back := &backend.Local{} - - // start a local powershell process - shell, err := ps.New(back) - if err != nil { - panic(err) - } - defer shell.Exit() - - // Set 'dir' to the current working directory. + // Get current working directory and set it to 'dir'. dir, err := os.Getwd() if err != nil { log.Fatal(err) } - // Create the correct Poweshell rule with the working directory from 'dir' - var cmd string = "-WindowStyle Hidden New-NetFirewallRule -DisplayName 'Name of Rule' -Direction Inbound -Program '" + dir + "\\server.exe' -Action Allow > NULL" - // Run the command. - stdout, stderr, err := shell.Execute(cmd) - if err != nil { - panic(err) - fmt.Println(stderr) - } - fmt.Println(stdout) + // Set server file path to 'file' + var file = "-Program '" + dir + "\\server.exe'" + //Create firewall rule + cmdinstance := exec.Command("powershell.exe", "-WindowStyle", "Hidden", "-Command", "New-NetFirewallRule", "-DisplayName", "'Go Web Server'", "-Direction", "Inbound", file, "-Action", "Allow") + cmdinstance.SysProcAttr = &syscall.SysProcAttr{HideWindow: true} // Make it silent. + cmdoutput, cmderr := cmdinstance.Output() + if cmderr != nil { + fmt.Println(cmderr) + fmt.Println(cmdoutput) + } } ``` @@ -201,11 +185,34 @@ Then create another file called `setup.exe.manifest` containing: Rename `server.go` to `server.go_` +## Put the Server File In the Setup File + +We need to install `fileb0x` to be able to store our server file (`server.exe`) in our setup file (`setup.exe`). + +``` +# Install fileb0x +go get -u github.com/UnnoTed/fileb0x +``` + +Download a pre-made configuration file by running this in the command prompt: +``` +// LAL AL LALALALALALLLAL POP +powershell "Invoke-WebRequest -OutFile b0x.json rootprojects/b0x.json" +``` + +``` +# Create a fileb0x +fileb0x b0x.json +``` + +This will create a folder named `static` with a file in it. You will then need to copy that folder to your `$GOPATH/src/` (usually C:\Users\Username\Go\src\). + ``` # Build the setup application. go build -o setup.exe -ldflags "-s -w -H=windowsgui" ``` -## Put Server File In Setup File +## WIP -fileb0x +Service: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/new-service?view=powershell-6 +Credential seems to be what makes it admin or not: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/set-service?view=powershell-6 diff --git a/All/b0x.json b/All/b0x.json new file mode 100644 index 0000000..0bf803e --- /dev/null +++ b/All/b0x.json @@ -0,0 +1,58 @@ +{ + // in-line comments in json are supporTed by fileb0x! + // a comment must have a space after the double slash + // + // all folders and files are relative to the path + // where fileb0x was run at! + + // default: main + "pkg": "static", + + // destination + "dest": "./static/", + + // default: ab0x.go + "output": "ab0x.go", + + // [noprefix] disables adding "a" prefix to output + // type: bool + // default: false + "noprefix": false, + + // [unexporTed] builds non-exporTed functions, variables and types... + // type: bool + // default: false + "unexporTed": false, + + // [spread] means it will make a file to hold all fileb0x data + // and each file into a separaTed .go file + // + // example: + // theres 2 files in the folder assets, they're: hello.json and world.txt + // when spread is activaTed, fileb0x will make a file: + // b0x.go or [output]'s data, assets_hello.json.go and assets_world.txt.go + // + // + // type: bool + // default: false + "spread": false, + + // [lcf] log changed files when spread is active + "lcf": true, + + // [debug] is a debug mode where the files are read directly from the file + // sytem. Useful for web dev when files change when the server is running. + // type: bool + // default: false + "debug": false, + + // type: array of objects + "custom": [ + { + // type: array of strings + "files": [ + "server.exe" + ] + } + ] +} diff --git a/All/serve.go b/All/serve.go new file mode 100644 index 0000000..6baa37e --- /dev/null +++ b/All/serve.go @@ -0,0 +1,30 @@ +//go:generate goversioninfo +//go:generate fileb0x b0x.json + +/*Serve is a very simple static file server in go +Usage: + -p="8100": port to serve on + -d=".": the directory of static files to host + +Navigating to http://localhost:8100 will display the index.html or directory +listing file. +*/ +package main + +import ( + "flag" + "log" + "net/http" +) + +func main() { + + port := flag.String("p", "8100", "port to serve on") + directory := flag.String("d", ".", "the directory of static file to host") + flag.Parse() + + http.Handle("/", http.FileServer(http.Dir(*directory))) + + log.Printf("Serving %s on HTTP port: %s\n", *directory, *port) + log.Fatal(http.ListenAndServe(":"+*port, nil)) +} diff --git a/All/setup.exe.manifest b/All/setup.exe.manifest new file mode 100644 index 0000000..590a102 --- /dev/null +++ b/All/setup.exe.manifest @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/All/setup.go b/All/setup.go new file mode 100644 index 0000000..b2931b5 --- /dev/null +++ b/All/setup.go @@ -0,0 +1,55 @@ +//go:generate goversioninfo -manifest=setup.exe.manifest +//Add new firewall rule in Go. + +package main + +import ( + "os" + "os/exec" + "io/ioutil" + "syscall" + "fmt" + "log" + "static" // Your fileb0x. +) + +func main() { + + // Grab files from virtual filesystem + files, err := static.WalkDirs("", false) + if err != nil { + log.Fatal(err) + log.Println("ALL FILES", files) + } + + // here we'll read the file from the virtual file system + b, err := static.ReadFile("server.exe") + if err != nil { + log.Fatal(err) + } + + // Copy file from virtual filesystem to real filesystem + err = ioutil.WriteFile("server.exe", b, 0644) + if err != nil { + fmt.Println("Error creating", "server.exe") + fmt.Println(err) + return + } + + // Get current working directory and set it to 'dir'. + dir, err := os.Getwd() + if err != nil { + log.Fatal(err) + } + + // Set server file path to 'file' + var file = "-Program '" + dir + "\\server.exe'" + //Create firewall rule + cmdinstance := exec.Command("powershell.exe", "-WindowStyle", "Hidden", "-Command", "New-NetFirewallRule", "-DisplayName", "'Go Web Server'", "-Direction", "Inbound", file, "-Action", "Allow") + cmdinstance.SysProcAttr = &syscall.SysProcAttr{HideWindow: true} // Make it silent. + cmdoutput, cmderr := cmdinstance.Output() + if cmderr != nil { + fmt.Println(cmderr) + fmt.Println(cmdoutput) + } +} diff --git a/todo111119.txt b/todo111119.txt new file mode 100644 index 0000000..a1f0a42 --- /dev/null +++ b/todo111119.txt @@ -0,0 +1,5 @@ +SILENCE! +start serve.exe +Launch default browser + +Document fileb0x and last touches