-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alex Levinson
committed
Feb 27, 2018
1 parent
e758c4d
commit ba76553
Showing
5 changed files
with
260 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
package engine | ||
|
||
import ( | ||
services "github.com/gen0cide/service-go" | ||
"github.com/robertkrimen/otto" | ||
) | ||
|
||
func (e *Engine) InstallSystemService(path, name, displayName, description string) error { | ||
c := &services.Config{ | ||
Path: path, | ||
Name: name, | ||
DisplayName: displayName, | ||
Description: description, | ||
} | ||
|
||
s, err := services.NewServiceConfig(c) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = s.Install() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (e *Engine) StartServiceByName(name string) error { | ||
c := &services.Config{ | ||
Name: name, | ||
} | ||
|
||
s, err := services.NewServiceConfig(c) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = s.Start() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (e *Engine) StopServiceByName(name string) error { | ||
c := &services.Config{ | ||
Name: name, | ||
} | ||
|
||
s, err := services.NewServiceConfig(c) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = s.Stop() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (e *Engine) RemoveServiceByName(name string) error { | ||
c := &services.Config{ | ||
Name: name, | ||
} | ||
|
||
s, err := services.NewServiceConfig(c) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = s.Remove() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (e *Engine) VMInstallSystemService(call otto.FunctionCall) otto.Value { | ||
if len(call.ArgumentList) != 4 { | ||
e.Logger.Errorf("Not enough arguments provided.") | ||
return otto.FalseValue() | ||
} | ||
|
||
path, err := call.Argument(0).ToString() | ||
if err != nil { | ||
e.Logger.Errorf("Error converting path to string: %s", err.Error()) | ||
return otto.FalseValue() | ||
} | ||
|
||
name, err := call.Argument(1).ToString() | ||
if err != nil { | ||
e.Logger.Errorf("Error converting name to string: %s", err.Error()) | ||
return otto.FalseValue() | ||
} | ||
|
||
displayName, err := call.Argument(2).ToString() | ||
if err != nil { | ||
e.Logger.Errorf("Error converting displayName to string: %s", err.Error()) | ||
return otto.FalseValue() | ||
} | ||
|
||
description, err := call.Argument(3).ToString() | ||
if err != nil { | ||
e.Logger.Errorf("Error converting description to string: %s", err.Error()) | ||
return otto.FalseValue() | ||
} | ||
|
||
err = e.InstallSystemService(path, name, displayName, description) | ||
if err != nil { | ||
e.Logger.Errorf("Error installing system service: %s", err.Error()) | ||
return otto.FalseValue() | ||
} | ||
|
||
return otto.TrueValue() | ||
} | ||
|
||
func (e *Engine) VMStartServiceByName(call otto.FunctionCall) otto.Value { | ||
if len(call.ArgumentList) != 1 { | ||
e.Logger.Errorf("Not enough arguments provided.") | ||
return otto.FalseValue() | ||
} | ||
|
||
name, err := call.Argument(0).ToString() | ||
if err != nil { | ||
e.Logger.Errorf("Error converting name to string: %s", err.Error()) | ||
return otto.FalseValue() | ||
} | ||
|
||
err = e.StartServiceByName(name) | ||
if err != nil { | ||
e.Logger.Errorf("Error starting system service: %s", err.Error()) | ||
return otto.FalseValue() | ||
} | ||
|
||
return otto.TrueValue() | ||
} | ||
|
||
func (e *Engine) VMStopServiceByName(call otto.FunctionCall) otto.Value { | ||
if len(call.ArgumentList) != 1 { | ||
e.Logger.Errorf("Not enough arguments provided.") | ||
return otto.FalseValue() | ||
} | ||
|
||
name, err := call.Argument(0).ToString() | ||
if err != nil { | ||
e.Logger.Errorf("Error converting name to string: %s", err.Error()) | ||
return otto.FalseValue() | ||
} | ||
|
||
err = e.StopServiceByName(name) | ||
if err != nil { | ||
e.Logger.Errorf("Error starting system service: %s", err.Error()) | ||
return otto.FalseValue() | ||
} | ||
|
||
return otto.TrueValue() | ||
} | ||
|
||
func (e *Engine) VMRemoveServiceByName(call otto.FunctionCall) otto.Value { | ||
if len(call.ArgumentList) != 1 { | ||
e.Logger.Errorf("Not enough arguments provided.") | ||
return otto.FalseValue() | ||
} | ||
|
||
name, err := call.Argument(0).ToString() | ||
if err != nil { | ||
e.Logger.Errorf("Error converting name to string: %s", err.Error()) | ||
return otto.FalseValue() | ||
} | ||
|
||
err = e.RemoveServiceByName(name) | ||
if err != nil { | ||
e.Logger.Errorf("Error starting system service: %s", err.Error()) | ||
return otto.FalseValue() | ||
} | ||
|
||
return otto.TrueValue() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// ----------------------------------------------------- | ||
// GENESIS Script Engine | ||
// https://github.com/gen0cide/gscript | ||
// | ||
// Example Script | ||
// | ||
// *Note: .gs files are just javascript! Enjoy! | ||
// ----------------------------------------------------- | ||
|
||
// ----------------------------------------------------- | ||
// COMPILER MACROS (Remove comment and modify to use) | ||
// //priority:100 (lower will execute first) | ||
// //timeout:30 (time in seconds) | ||
// //import:/path/to/local/file.exe | ||
// //import_url:https://website.com/with/local/file.exe | ||
// In both of those examples, you can retrieve the asset | ||
// by using Asset("file.exe") (returns byte array). | ||
|
||
// ----------------------------------------------------- | ||
// GLOBALS | ||
var test_var = "hello, world"; | ||
var test_num = 5; | ||
|
||
// ----------------------------------------------------- | ||
// HOOKS | ||
// Your final script must implement these methods. | ||
// If any method returns false, the VM will cease | ||
// execution and not continue to the subsequent | ||
// functions. | ||
|
||
// ----------------------------------------------------- | ||
// BeforeDeploy() is meant to allow you the opportunity | ||
// to investigate the target system to determine if you | ||
// even want to proceed to the Deploy() step. You might: | ||
// - Check to see if you have the right architecture. | ||
// - Check to see if apache is installed. | ||
// - Check to see if your payload has already been dropped. | ||
function BeforeDeploy() { | ||
LogInfo("This is an example of a debug command."); | ||
LogWarn("This will only show when you use the \"run\" subcommand."); | ||
LogError("It will *not* print when run from a compiled binary."); | ||
return true; | ||
} | ||
|
||
// ----------------------------------------------------- | ||
// Deploy() is where you actually deploy your payload. | ||
// Remember to return true if it deploys successfully. | ||
function Deploy() { | ||
InstallSystemService("/usr/local/bin/testsvc", "gscriptdaemon", "Gscript Daemon", "this is a test daemon.") | ||
LogInfo("service installed"); | ||
StartServiceByName("gscriptdaemon"); | ||
LogInfo("service started"); | ||
return true; | ||
} | ||
|
||
// ----------------------------------------------------- | ||
// AfterDeploy() allows you to clean up or validate deployment. | ||
function AfterDeploy() { | ||
Sleep(10); | ||
StopServiceByName("gscriptdaemon"); | ||
LogInfo("service stopped"); | ||
Sleep(5) | ||
RemoveServiceByName("gscriptdaemon"); | ||
LogInfo("service removed"); | ||
return true; | ||
} | ||
|
||
|
||
|