Skip to content

Commit

Permalink
Refactored stage listener
Browse files Browse the repository at this point in the history
  • Loading branch information
moloch-- committed Jul 3, 2021
1 parent 993996b commit 71c921b
Show file tree
Hide file tree
Showing 11 changed files with 665 additions and 573 deletions.
884 changes: 444 additions & 440 deletions client/command/commands.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/command/generate/profiles-generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func ProfilesGenerateCmd(ctx *grumble.Context, con *console.SliverConsoleClient)
if save == "" {
save, _ = os.Getwd()
}
profile := getImplantProfileByName(con, name)
profile := GetImplantProfileByName(name, con)
if profile != nil {
implantFile, err := compile(profile.Config, save, con)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion client/command/generate/profiles-rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/desertbit/grumble"
)

func ProfileRmCmd(ctx *grumble.Context, con *console.SliverConsoleClient) {
func ProfilesRmCmd(ctx *grumble.Context, con *console.SliverConsoleClient) {
_, err := con.Rpc.DeleteImplantProfile(context.Background(), &clientpb.DeleteReq{
Name: ctx.Args.String("profile-name"),
})
Expand Down
2 changes: 1 addition & 1 deletion client/command/generate/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func getImplantProfiles(con *console.SliverConsoleClient) []*clientpb.ImplantPro
return pbProfiles.Profiles
}

func getImplantProfileByName(con *console.SliverConsoleClient, name string) *clientpb.ImplantProfile {
func GetImplantProfileByName(name string, con *console.SliverConsoleClient) *clientpb.ImplantProfile {
pbProfiles, err := con.Rpc.ImplantProfiles(context.Background(), &commonpb.Empty{})
if err != nil {
con.PrintErrorf("Error %s", err)
Expand Down
18 changes: 18 additions & 0 deletions client/command/jobs/dns.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
package jobs

/*
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"
"strings"
Expand Down
18 changes: 18 additions & 0 deletions client/command/jobs/http.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
package jobs

/*
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"

Expand Down
18 changes: 18 additions & 0 deletions client/command/jobs/https.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
package jobs

/*
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"
"io/ioutil"
Expand Down
18 changes: 18 additions & 0 deletions client/command/jobs/mtls.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
package jobs

/*
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"

Expand Down
128 changes: 128 additions & 0 deletions client/command/jobs/stage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package jobs

/*
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"
"net/url"
"strconv"

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

// StageListenerCmd --url [tcp://ip:port | http://ip:port ] --profile name
func StageListenerCmd(ctx *grumble.Context, con *console.SliverConsoleClient) {
profileName := ctx.Flags.String("profile")
listenerURL := ctx.Flags.String("url")

if profileName == "" || listenerURL == "" {
con.PrintErrorf("Missing required flags, see `help stage-listener` for more info\n")
return
}

// parse listener url
stagingURL, err := url.Parse(listenerURL)
if err != nil {
con.PrintErrorf("Listener-url format not supported")
return
}
stagingPort, err := strconv.ParseUint(stagingURL.Port(), 10, 32)
if err != nil {
con.PrintErrorf("error parsing staging port: %v\n", err)
return
}

profile := generate.GetImplantProfileByName(profileName, con)
if profile != nil {
con.PrintErrorf("Profile not found\n")
return
}
stage2, err := generate.GetSliverBinary(profile, con)
if err != nil {
con.PrintErrorf("%s\n", err)
return
}

switch stagingURL.Scheme {
case "http":
ctrl := make(chan bool)
con.SpinUntil("Starting HTTP staging listener...", ctrl)
stageListener, err := con.Rpc.StartHTTPStagerListener(context.Background(), &clientpb.StagerListenerReq{
Protocol: clientpb.StageProtocol_HTTP,
Data: stage2,
Host: stagingURL.Hostname(),
Port: uint32(stagingPort),
})
ctrl <- true
<-ctrl
if err != nil {
con.PrintErrorf("Error starting HTTP staging listener: %s\n", err)
return
}
con.PrintInfof("Job %d (http) started\n", stageListener.GetJobID())
case "https":
cert, key, err := getLocalCertificatePair(ctx)
if err != nil {
con.Println()
con.PrintErrorf("Failed to load local certificate %s\n", err)
return
}
ctrl := make(chan bool)
con.SpinUntil("Starting HTTPS staging listener...", ctrl)
stageListener, err := con.Rpc.StartHTTPStagerListener(context.Background(), &clientpb.StagerListenerReq{
Protocol: clientpb.StageProtocol_HTTPS,
Data: stage2,
Host: stagingURL.Hostname(),
Port: uint32(stagingPort),
Cert: cert,
Key: key,
ACME: ctx.Flags.Bool("lets-encrypt"),
})
ctrl <- true
<-ctrl
if err != nil {
con.PrintErrorf("Error starting HTTPS staging listener: %v\n", err)
return
}
con.PrintInfof("Job %d (https) started\n", stageListener.GetJobID())
case "tcp":
ctrl := make(chan bool)
con.SpinUntil("Starting TCP staging listener...", ctrl)
stageListener, err := con.Rpc.StartTCPStagerListener(context.Background(), &clientpb.StagerListenerReq{
Protocol: clientpb.StageProtocol_TCP,
Data: stage2,
Host: stagingURL.Hostname(),
Port: uint32(stagingPort),
})
ctrl <- true
<-ctrl
if err != nil {
con.PrintErrorf("Error starting TCP staging listener: %v\n", err)
return
}
con.PrintInfof("Job %d (tcp) started\n", stageListener.GetJobID())

default:
con.PrintErrorf("Unsupported staging protocol: %s\n", stagingURL.Scheme)
return
}
}
18 changes: 18 additions & 0 deletions client/command/jobs/wg.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
package jobs

/*
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"

Expand Down
Loading

0 comments on commit 71c921b

Please sign in to comment.