Skip to content

Commit

Permalink
Refactored jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
moloch-- committed Jul 3, 2021
1 parent b01376d commit 1c81b2b
Show file tree
Hide file tree
Showing 15 changed files with 460 additions and 342 deletions.
1 change: 1 addition & 0 deletions client/command/README.md
Expand Up @@ -10,4 +10,5 @@ General guidance on the structure of this package:
* The root command, and reused code should go into the file named after the command
* For example, code shared between the `generate` and the `regenerate` command should go in `generate.go`, and any `regenerate` specific code should go in `regenerate.go`
* Command entrypoint functions should have the suffix `Cmd` e.g., `GenerateCmd` is the entrypoint for `generate`
* Command entrypoints should always a function signature of `func (ctx *grumble.Context, con *console.SliverConsoleClient)`
* Functions that are only ever exported for other commands to use should go in a `helpers.go`, if the function is used internally and exported follow the guidance above on shared code.
111 changes: 0 additions & 111 deletions client/command/env.go

This file was deleted.

4 changes: 4 additions & 0 deletions client/command/environment/README.md
@@ -0,0 +1,4 @@
Environment
===========

Contains command implementations for manipulating remote environment variables.
49 changes: 49 additions & 0 deletions client/command/environment/get.go
@@ -0,0 +1,49 @@
package environment

/*
Sliver Implant Framework
Copyright (C) 2019 Bishop Fox
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import (
"context"

"github.com/bishopfox/sliver/client/console"
"github.com/bishopfox/sliver/protobuf/sliverpb"
"github.com/desertbit/grumble"
)

func EnvGetCmd(ctx *grumble.Context, con *console.SliverConsoleClient) {
session := con.ActiveSession.Get()
if session == nil {
return
}

name := ctx.Args.String("name")
envInfo, err := con.Rpc.GetEnv(context.Background(), &sliverpb.EnvReq{
Name: name,
Request: con.ActiveSession.Request(ctx),
})

if err != nil {
con.PrintErrorf("%s\n", err)
return
}

for _, envVar := range envInfo.Variables {
con.Printf("%s=%s\n", envVar.Key, envVar.Value)
}
}
59 changes: 59 additions & 0 deletions client/command/environment/set.go
@@ -0,0 +1,59 @@
package environment

/*
Sliver Implant Framework
Copyright (C) 2019 Bishop Fox
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import (
"context"

"github.com/bishopfox/sliver/client/console"
"github.com/bishopfox/sliver/protobuf/commonpb"
"github.com/bishopfox/sliver/protobuf/sliverpb"
"github.com/desertbit/grumble"
)

func EnvSetCmd(ctx *grumble.Context, con *console.SliverConsoleClient) {
session := con.ActiveSession.Get()
if session == nil {
return
}

name := ctx.Args.String("name")
value := ctx.Args.String("value")
if name == "" || value == "" {
con.PrintErrorf("Usage: setenv KEY VALUE\n")
return
}

envInfo, err := con.Rpc.SetEnv(context.Background(), &sliverpb.SetEnvReq{
Variable: &commonpb.EnvVar{
Key: name,
Value: value,
},
Request: con.ActiveSession.Request(ctx),
})
if err != nil {
con.PrintErrorf("%s\n", err)
return
}
if envInfo.Response != nil && envInfo.Response.Err != "" {
con.PrintErrorf("%s\n", envInfo.Response.Err)
return
}
con.PrintInfof("Set %s to %s\n", name, value)
}
56 changes: 56 additions & 0 deletions client/command/environment/unset.go
@@ -0,0 +1,56 @@
package environment

/*
Sliver Implant Framework
Copyright (C) 2019 Bishop Fox
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import (
"context"

"github.com/bishopfox/sliver/client/console"
"github.com/bishopfox/sliver/protobuf/sliverpb"
"github.com/desertbit/grumble"
)

func EnvUnsetCmd(ctx *grumble.Context, con *console.SliverConsoleClient) {
session := con.ActiveSession.Get()
if session == nil {
return
}

name := ctx.Args.String("name")
if name == "" {
con.PrintErrorf("Usage: setenv NAME\n")
return
}

unsetResp, err := con.Rpc.UnsetEnv(context.Background(), &sliverpb.UnsetEnvReq{
Name: name,
Request: con.ActiveSession.Request(ctx),
})

if err != nil {
con.PrintErrorf("%s\n", err)
return
}

if unsetResp.Response != nil && unsetResp.Response.Err != "" {
con.PrintErrorf("%s\n", unsetResp.Response.Err)
return
}
con.PrintInfof("Successfully unset %s\n", name)
}
4 changes: 4 additions & 0 deletions client/command/jobs/README.md
@@ -0,0 +1,4 @@
Jobs
=====

Implements commands related to starting/killing jobs like `jobs` and starting C2 listeners (`mtls`, `http`, etc.)
36 changes: 36 additions & 0 deletions client/command/jobs/dns.go
@@ -0,0 +1,36 @@
package jobs

import (
"context"
"strings"

"github.com/bishopfox/sliver/client/console"
"github.com/bishopfox/sliver/protobuf/clientpb"
"github.com/desertbit/grumble"
)

func DNSListenerCmd(ctx *grumble.Context, con *console.SliverConsoleClient) {

domains := strings.Split(ctx.Flags.String("domains"), ",")
for _, domain := range domains {
if !strings.HasSuffix(domain, ".") {
domain += "."
}
}

lport := uint16(ctx.Flags.Int("lport"))

con.PrintInfof("Starting DNS listener with parent domain(s) %v ...\n", domains)
dns, err := con.Rpc.StartDNSListener(context.Background(), &clientpb.DNSListenerReq{
Domains: domains,
Port: uint32(lport),
Canaries: !ctx.Flags.Bool("no-canaries"),
Persistent: ctx.Flags.Bool("persistent"),
})
con.Println()
if err != nil {
con.PrintErrorf("%s\n", err)
} else {
con.PrintInfof("Successfully started job #%d\n", dns.JobID)
}
}
28 changes: 28 additions & 0 deletions client/command/jobs/http.go
@@ -0,0 +1,28 @@
package jobs

import (
"context"

"github.com/bishopfox/sliver/client/console"
"github.com/bishopfox/sliver/protobuf/clientpb"
"github.com/desertbit/grumble"
)

func HTTPListenerCmd(ctx *grumble.Context, con *console.SliverConsoleClient) {
domain := ctx.Flags.String("domain")
lport := uint16(ctx.Flags.Int("lport"))

con.PrintInfof("Starting HTTP %s:%d listener ...\n", domain, lport)
http, err := con.Rpc.StartHTTPListener(context.Background(), &clientpb.HTTPListenerReq{
Domain: domain,
Website: ctx.Flags.String("website"),
Port: uint32(lport),
Secure: false,
Persistent: ctx.Flags.Bool("persistent"),
})
if err != nil {
con.PrintErrorf("%s\n", err)
} else {
con.PrintInfof("Successfully started job #%d\n", http.JobID)
}
}

0 comments on commit 1c81b2b

Please sign in to comment.