Add some of the files, new docs.

This commit is contained in:
Josh Mudge 2019-11-11 18:10:00 -07:00
parent ca1e8b730a
commit bfa23efee8
6 changed files with 200 additions and 35 deletions

View File

@ -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)
// 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)
}
fmt.Println(stdout)
}
```
@ -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

58
All/b0x.json Normal file
View File

@ -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"
]
}
]
}

30
All/serve.go Normal file
View File

@ -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))
}

10
All/setup.exe.manifest Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>

55
All/setup.go Normal file
View File

@ -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)
}
}

5
todo111119.txt Normal file
View File

@ -0,0 +1,5 @@
SILENCE!
start serve.exe
Launch default browser
Document fileb0x and last touches