client

package
v0.0.0-...-9e7e4f5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2019 License: MPL-2.0 Imports: 23 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientPassphrase

func ClientPassphrase(s string)

ClientPassphrase sets the GPG passphrase to be used by the client for secret key operations, this can be used to cache a passphrase to avoid being prompted.

func FindHomedir

func FindHomedir() (ret string, err error)

FindHomedir attempts to locate the home directory for the current user

func MakeConfiguration

func MakeConfiguration(file string) (err error)

MakeConfiguration generates a new configuration file for the current user

func PrintCommandResults

func PrintCommandResults(cmd mig.Command, onlyFound, showAgent bool) (err error)

PrintCommandResults prints the results of mig.Command cmd.

func ValueToAction

func ValueToAction(v interface{}) (a mig.Action, err error)

ValueToAction converts JSON data in interface v into a mig.Action

func ValueToAgent

func ValueToAgent(v interface{}) (agt mig.Agent, err error)

ValueToAgent converts JSON data in interface v into a mig.Agent

func ValueToCommand

func ValueToCommand(v interface{}) (cmd mig.Command, err error)

ValueToCommand converts JSON data in interface v into a mig.Command

func ValueToInvestigator

func ValueToInvestigator(v interface{}) (inv mig.Investigator, err error)

ValueToInvestigator converts JSON data in interface v into a mig.Investigator

func ValueToLoaderEntry

func ValueToLoaderEntry(v interface{}) (l mig.LoaderEntry, err error)

ValueToLoaderEntry converts JSON data in interface v into a mig.LoaderEntry

func ValueToManifestRecord

func ValueToManifestRecord(v interface{}) (m mig.ManifestRecord, err error)

ValueToManifestRecord converts JSON data in interface v into a mig.ManifestRecord

Types

type APIConf

type APIConf struct {
	URL            string
	SkipVerifyCert bool
}

APIConf stores configuration values related to the API connectivity.

type Client

type Client struct {
	API     *http.Client
	Token   string
	Conf    Configuration
	Version string
	// contains filtered or unexported fields
}

Client is a type used to interact with the MIG API.

func NewClient

func NewClient(conf Configuration, version string) (cli Client, err error)

NewClient initiates a new instance of a Client

func (Client) CompressAction

func (cli Client) CompressAction(a mig.Action) (compAction mig.Action, err error)

CompressAction takens a MIG action, and applies compression to any operations within the action for which compression is requested.

This function should be called on the action prior to signing it for submission to the API.

func (*Client) DisableDebug

func (cli *Client) DisableDebug()

DisableDebug disables debugging mode in the client

func (Client) Do

func (cli Client) Do(r *http.Request) (resp *http.Response, err error)

Do is a thin wrapper around http.Client.Do() that inserts an authentication header to the outgoing request

func (*Client) EnableDebug

func (cli *Client) EnableDebug()

EnableDebug enables debugging mode in the client

func (Client) EvaluateAgentTarget

func (cli Client) EvaluateAgentTarget(target string) (agents []mig.Agent, err error)

EvaluateAgentTarget runs a search against the api to find all agents that match an action target string

func (Client) FetchActionResults

func (cli Client) FetchActionResults(a mig.Action) (ret []mig.Command, err error)

FetchActionResults retrieves mig command results associated with a particular action. This function differs from PrintActionResults in that it returns a slice of mig.Command structs, rather then printing results to stdout.

XXX Note in the future it may be worth refactoring the action print functions to make use of this, but it would require additional work.

func (Client) FollowAction

func (cli Client) FollowAction(a mig.Action, total int, stop chan bool) (err error)

FollowAction continuously loops over an action and prints its completion status in os.Stderr. When the action reaches its expiration date, FollowAction prints its final status and returns.

a represents the action being followed, and total indicates the total number of agents the action was submitted to and is used to initialize the progress meter.

stop is of type chan bool, and passing a value to this channel will cause the routine to return immediately.

func (Client) GetAPIResource

func (cli Client) GetAPIResource(target string) (resource *cljs.Resource, err error)

GetAPIResource retrieves a cljs resource from a target endpoint. The target must be the relative to the API URL passed in the configuration. For example, if the API URL is `http://localhost:12345/api/v1/` then target could only be set to `dashboard` to retrieve `http://localhost:12345/api/v1/dashboard`

func (Client) GetAction

func (cli Client) GetAction(aid float64) (a mig.Action, links []cljs.Link, err error)

GetAction retrieves a MIG Action from the API using its Action ID

func (Client) GetAgent

func (cli Client) GetAgent(agtid float64) (agt mig.Agent, err error)

GetAgent fetches the specified agent ID from the API and returns it

func (Client) GetCommand

func (cli Client) GetCommand(cmdid float64) (cmd mig.Command, err error)

GetCommand fetches the specified command ID from the API and returns it

func (Client) GetInvestigator

func (cli Client) GetInvestigator(iid float64) (inv mig.Investigator, err error)

GetInvestigator fetches the specified investigator ID from the API and returns it

func (Client) GetLoaderEntry

func (cli Client) GetLoaderEntry(lid float64) (le mig.LoaderEntry, err error)

GetLoaderEntry retrieves a MIG loader entry from the API using the record ID

func (Client) GetManifestLoaders

func (cli Client) GetManifestLoaders(mid float64) (ldrs []mig.LoaderEntry, err error)

GetManifestLoaders retrieves list of known loader entries that will match manifest mid

func (Client) GetManifestRecord

func (cli Client) GetManifestRecord(mid float64) (mr mig.ManifestRecord, err error)

GetManifestRecord retrieves a MIG manifest record from the API using the record ID

func (Client) LoaderEntryExpect

func (cli Client) LoaderEntryExpect(le mig.LoaderEntry, eval string) (err error)

LoaderEntryExpect changes the expect fields of an existing loader entry

func (Client) LoaderEntryKey

func (cli Client) LoaderEntryKey(le mig.LoaderEntry) (newle mig.LoaderEntry, err error)

LoaderEntryKey changes the key on an existing loader entry

func (Client) LoaderEntryStatus

func (cli Client) LoaderEntryStatus(le mig.LoaderEntry, status bool) (err error)

LoaderEntryStatus changes the status of an existing loader entry

func (Client) MakeSignedToken

func (cli Client) MakeSignedToken() (token string, err error)

MakeSignedToken encrypts a timestamp and a random number with the users GPG key to use as an auth token with the API

func (Client) ManifestRecordStatus

func (cli Client) ManifestRecordStatus(mr mig.ManifestRecord, status string) (err error)

ManifestRecordStatus changes the status of an existing manifest record

func (Client) PostAction

func (cli Client) PostAction(a mig.Action) (a2 mig.Action, err error)

PostAction submits a MIG Action to the API and returns the reflected action with API ID

func (Client) PostInvestigator

func (cli Client) PostInvestigator(name string, pubkey []byte, pset mig.InvestigatorPerms) (inv mig.Investigator, err error)

PostInvestigator creates an Investigator and returns the reflected investigator. If pubkey is zero-length, the investigator will be created without a PGP public key.

func (Client) PostInvestigatorAPIKeyStatus

func (cli Client) PostInvestigatorAPIKeyStatus(iid float64, newstatus string) (inv mig.Investigator, err error)

PostInvestigatorAPIKeyStatus is used to either enable or disable API key based access to the MIG API for an investigator. API key based access to the API can be used in place of X-PGPAUTHORIZATION API authentication.

If an API key is being set, the returned investigator APIKey value will contain the assigned key. newstatus should be set to either 'active' or 'disabled'. If a key already exists for an investigator, calling this with a status of 'active' will cause the existing key to be replaced.

func (Client) PostInvestigatorPerms

func (cli Client) PostInvestigatorPerms(iid float64, perm mig.InvestigatorPerms) (err error)

PostInvestigatorPerms sets permission on an investigator

func (Client) PostInvestigatorStatus

func (cli Client) PostInvestigatorStatus(iid float64, newstatus string) (err error)

PostInvestigatorStatus updates the status of an Investigator

func (Client) PostManifestSignature

func (cli Client) PostManifestSignature(mr mig.ManifestRecord, sig string) (err error)

PostManifestSignature adds a new signature to an existing manifest known to the API

func (Client) PostNewLoader

func (cli Client) PostNewLoader(le mig.LoaderEntry) (newle mig.LoaderEntry, err error)

PostNewLoader posts a new loader entry for storage through the API

func (Client) PostNewManifest

func (cli Client) PostNewManifest(mr mig.ManifestRecord) (err error)

PostNewManifest posts a new manifest record for storage through the API

func (Client) PrintActionResults

func (cli Client) PrintActionResults(a mig.Action, show string) (err error)

PrintActionResults fetches the results of action a from the API and prints the results on stdout.

show can either be found, notfound, or all and can be used to control which results are fetched and displayed for a given action.

func (Client) ResolveTargetMacro

func (cli Client) ResolveTargetMacro(target string) string

ResolveTargetMacro resolves macros specified by a client; clients should pass the action target string here, and this function will return the resolved target if it is a valid macro, otherwise it just returns the passed target string

func (Client) SignAction

func (cli Client) SignAction(a mig.Action) (signedAction mig.Action, err error)

SignAction takes a MIG Action, signs it with the key identified in the configuration and returns the signed action

func (Client) SignManifest

func (cli Client) SignManifest(m mig.ManifestRecord) (ret string, err error)

SignManifest takes a MIG manifest record, signs it with the key identified in the configuration and returns the signature

type Configuration

type Configuration struct {
	API     APIConf    // location of the MIG API
	Homedir string     // location of the user's home directory
	GPG     GpgConf    // location of the user's secring
	Targets TargetConf // Target macro specification
}

Configuration stores the live configuration and global parameters of a client

func ReadConfiguration

func ReadConfiguration(file string) (conf Configuration, err error)

ReadConfiguration loads a client configuration from a local configuration file and verifies that GnuPG's secring is available

func ReadEnvConfiguration

func ReadEnvConfiguration(inconf Configuration) (conf Configuration, err error)

ReadEnvConfiguration reads any possible configuration values from the environment; currently we only load a passphrase here if provided, but conf is passed/returned for any future requirements to override file based configuration using environment options.

type GpgConf

type GpgConf struct {
	Home          string // Path to GPG keyrings
	KeyID         string // GPG key ID to use for X-PGPAUTHORIZATION and action signing
	Keyserver     string // Key server to fetch keys from if needed in mig-console
	UseAPIKeyAuth string // Prefer X-MIGAPIKEY authentication for API access, set to API key
}

GpgConf stores configuration values related to client keyring access.

type TargetConf

type TargetConf struct {
	Macro []string
	// contains filtered or unexported fields
}

TargetConf stores macros present in the configuration file that can be used as short form targeting strings.

Directories

Path Synopsis
mig is the command line tool that investigators can use to launch actions for execution by agents to retrieve/display the results of the actions.
mig is the command line tool that investigators can use to launch actions for execution by agents to retrieve/display the results of the actions.
This Source Code Form is subject to the terms of the Mozilla Public License, v.
This Source Code Form is subject to the terms of the Mozilla Public License, v.
This Source Code Form is subject to the terms of the Mozilla Public License, v.
This Source Code Form is subject to the terms of the Mozilla Public License, v.
This Source Code Form is subject to the terms of the Mozilla Public License, v.
This Source Code Form is subject to the terms of the Mozilla Public License, v.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL