mirror of
https://github.com/BishopFox/sliver.git
synced 2026-11-08 08:04:14 -10:00
Compare commits
14
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c90e674f25 | ||
|
|
679b8d0c51 | ||
|
|
0a42a03052 | ||
|
|
73852e5bf2 | ||
|
|
5bcf59e1b3 | ||
|
|
935c737c35 | ||
|
|
5c04e61235 | ||
|
|
cff7a8ce53 | ||
|
|
e6f452ea2e | ||
|
|
c5f533bc80 | ||
|
|
bc08760320 | ||
|
|
9b37bee391 | ||
|
|
709085238d | ||
|
|
6e4240f0d9 |
No files matched your search
@@ -12,7 +12,7 @@ jobs:
|
||||
tag-check:
|
||||
name: Check Release Tag
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 10
|
||||
timeout-minutes: 30
|
||||
outputs:
|
||||
tag: ${{ steps.tag.outputs.tag }}
|
||||
steps:
|
||||
@@ -48,21 +48,23 @@ jobs:
|
||||
run: sudo apt-get update --fix-missing && sudo apt-get -y install minisign
|
||||
|
||||
- name: Build Clients
|
||||
run: make clients
|
||||
run: |
|
||||
make clients
|
||||
mkdir -p artifacts
|
||||
mv sliver-client_* artifacts/
|
||||
|
||||
- name: Build Servers
|
||||
run: make servers
|
||||
|
||||
- name: Collect Artifacts
|
||||
run: |
|
||||
mkdir -p artifacts
|
||||
cp sliver-server_* sliver-client_* artifacts/
|
||||
make servers
|
||||
mv sliver-server_* artifacts/
|
||||
|
||||
- name: Sign Artifacts
|
||||
env:
|
||||
MINISIGN_KEY: ${{ secrets.MINISIGN_SLIVER_RELEASE_KEY }}
|
||||
run: |
|
||||
printf '%s' "$MINISIGN_KEY" > minisign.key
|
||||
echo "$MINISIGN_KEY" | base64 -d > minisign.key
|
||||
echo "minisign.key bytes: $(wc -c < minisign.key | tr -d ' ')"
|
||||
echo "minisign.key sha256: $(sha256sum minisign.key | awk '{print $1}')"
|
||||
chmod 600 minisign.key
|
||||
for file in artifacts/sliver-*; do
|
||||
[ -f "$file" ] || continue
|
||||
|
||||
@@ -46,3 +46,4 @@ Please take a moment and fill out [our survey](https://forms.gle/SwVsHFNh24ChG58
|
||||
### License - GPLv3
|
||||
|
||||
Sliver is licensed under [GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html), some sub-components may have separate licenses. See their respective subdirectories in this project for details.
|
||||
|
||||
@@ -14,16 +14,15 @@ fi
|
||||
if command -v apt-get &> /dev/null; then
|
||||
echo "Installing dependencies using apt..."
|
||||
DEBIAN_FRONTEND=noninteractive apt-get install -yqq \
|
||||
minisign curl build-essential git \
|
||||
mingw-w64 binutils-mingw-w64 g++-mingw-w64
|
||||
minisign curl build-essential git
|
||||
INSTALLER=(apt-get install -yqq)
|
||||
elif command -v yum &> /dev/null; then # Redhat-based OS (Fedora, CentOS, RHEL)
|
||||
echo "Installing dependencies using yum..."
|
||||
yum -y install minisign curl gcc gcc-c++ make mingw64-gcc git
|
||||
yum -y install minisign curl make git
|
||||
INSTALLER=(yum -y)
|
||||
elif command -v pacman &>/dev/null; then # Arch-based (Manjaro, Garuda, Blackarch)
|
||||
echo "Installing dependencies using pacman..."
|
||||
pacman --noconfirm -S minisign mingw-w64-gcc mingw-w64-binutils mingw-w64-headers
|
||||
pacman --noconfirm -S minisign
|
||||
INSTALLER=(pacman --noconfirm -S)
|
||||
else
|
||||
echo "Unsupported OS, exiting"
|
||||
@@ -47,7 +46,7 @@ echo "Using Minisign public key..."
|
||||
ARCH="$(uname -m)"
|
||||
case "$ARCH" in
|
||||
x86_64|amd64)
|
||||
SLIVER_PLATFORM="linux"
|
||||
SLIVER_PLATFORM="linux-amd64"
|
||||
;;
|
||||
aarch64|arm64)
|
||||
SLIVER_PLATFORM="linux-arm64"
|
||||
@@ -138,7 +137,7 @@ echo "Generating local configs ..."
|
||||
# Generate local configs
|
||||
echo "Generating operator configs ..."
|
||||
mkdir -p /root/.sliver-client/configs
|
||||
/root/sliver-server operator --name root --lhost localhost --save /root/.sliver-client/configs
|
||||
/root/sliver-server operator --name root --lhost localhost --permissions all --save /root/.sliver-client/configs
|
||||
chown -R root:root /root/.sliver-client/
|
||||
|
||||
USER_DIRS=(/home/*)
|
||||
@@ -147,7 +146,7 @@ for USER_DIR in "${USER_DIRS[@]}"; do
|
||||
if id -u "$USER" >/dev/null 2>&1; then
|
||||
echo "Generating operator configs for user $USER..."
|
||||
mkdir -p "$USER_DIR/.sliver-client/configs"
|
||||
/root/sliver-server operator --name "$USER" --lhost localhost --save "$USER_DIR/.sliver-client/configs"
|
||||
/root/sliver-server operator --name "$USER" --lhost localhost --permissions all --save "$USER_DIR/.sliver-client/configs"
|
||||
chown -R "$USER":"$(id -gn "$USER")" "$USER_DIR/.sliver-client/"
|
||||
fi
|
||||
done
|
||||
@@ -19,8 +19,13 @@ package rpc
|
||||
*/
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/bishopfox/sliver/server/core"
|
||||
"github.com/bishopfox/sliver/server/db"
|
||||
"github.com/bishopfox/sliver/server/db/models"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
@@ -49,3 +54,38 @@ var (
|
||||
|
||||
ErrInvalidBeaconTaskCancelState = status.Error(codes.InvalidArgument, fmt.Sprintf("Invalid task state, must be '%s' to cancel", models.PENDING))
|
||||
)
|
||||
|
||||
func rpcError(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if st, ok := status.FromError(err); ok && st.Code() != codes.Unknown {
|
||||
return err
|
||||
}
|
||||
|
||||
switch {
|
||||
case errors.Is(err, context.Canceled):
|
||||
return status.Error(codes.Canceled, err.Error())
|
||||
case errors.Is(err, context.DeadlineExceeded):
|
||||
return status.Error(codes.DeadlineExceeded, err.Error())
|
||||
case errors.Is(err, core.ErrImplantTimeout):
|
||||
return status.Error(codes.DeadlineExceeded, err.Error())
|
||||
case errors.Is(err, core.ErrUnknownMessageType):
|
||||
return status.Error(codes.Unimplemented, err.Error())
|
||||
case errors.Is(err, core.ErrInvalidTunnelID):
|
||||
return status.Error(codes.InvalidArgument, err.Error())
|
||||
case errors.Is(err, core.ErrDuplicateHosts):
|
||||
return status.Error(codes.AlreadyExists, err.Error())
|
||||
case errors.Is(err, core.ErrDuplicateExternalBuilderName):
|
||||
return status.Error(codes.AlreadyExists, err.Error())
|
||||
case errors.Is(err, db.ErrRecordNotFound):
|
||||
return status.Error(codes.NotFound, err.Error())
|
||||
case os.IsNotExist(err):
|
||||
return status.Error(codes.NotFound, err.Error())
|
||||
case os.IsPermission(err):
|
||||
return status.Error(codes.PermissionDenied, err.Error())
|
||||
default:
|
||||
return status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
}
|
||||
+14
-14
@@ -47,10 +47,10 @@ func (rpc *Server) Backdoor(ctx context.Context, req *clientpb.BackdoorReq) (*cl
|
||||
if req.Name == "" {
|
||||
name, err = codenames.GetCodename()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
} else if err := util.AllowedName(name); err != nil {
|
||||
return nil, err
|
||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||
} else {
|
||||
name = req.Name
|
||||
}
|
||||
@@ -68,18 +68,18 @@ func (rpc *Server) Backdoor(ctx context.Context, req *clientpb.BackdoorReq) (*cl
|
||||
Path: req.FilePath,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
if download.Encoder == "gzip" {
|
||||
download.Data, err = new(encoders.Gzip).Decode(download.Data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
}
|
||||
|
||||
profiles, err := rpc.ImplantProfiles(context.Background(), &commonpb.Empty{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
var p *clientpb.ImplantProfile
|
||||
for _, prof := range profiles.Profiles {
|
||||
@@ -88,38 +88,38 @@ func (rpc *Server) Backdoor(ctx context.Context, req *clientpb.BackdoorReq) (*cl
|
||||
}
|
||||
}
|
||||
if p.GetName() == "" {
|
||||
return nil, fmt.Errorf("no profile found for name %s", req.ProfileName)
|
||||
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("no profile found for name %s", req.ProfileName))
|
||||
}
|
||||
|
||||
if p.Config.Format != clientpb.OutputFormat_SHELLCODE {
|
||||
return nil, fmt.Errorf("please select a profile targeting a shellcode format")
|
||||
return nil, status.Error(codes.InvalidArgument, "please select a profile targeting a shellcode format")
|
||||
}
|
||||
|
||||
build, err := generate.GenerateConfig(name, p.Config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
// retrieve http c2 implant config
|
||||
httpC2Config, err := db.LoadHTTPC2ConfigByName(p.Config.HTTPC2ConfigName)
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
fPath, err := generate.SliverShellcode(name, build, p.Config, httpC2Config.ImplantConfig)
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
shellcode, err := os.ReadFile(fPath)
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
bjConfig := &bj.BinjectConfig{
|
||||
CodeCaveMode: true,
|
||||
}
|
||||
newFile, err := bj.Binject(download.Data, shellcode, bjConfig)
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
uploadGzip, _ := new(encoders.Gzip).Encode(newFile)
|
||||
// upload to remote target
|
||||
@@ -133,11 +133,11 @@ func (rpc *Server) Backdoor(ctx context.Context, req *clientpb.BackdoorReq) (*cl
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
if upload.Response != nil && upload.Response.Err != "" {
|
||||
return nil, fmt.Errorf("%s", upload.Response.Err)
|
||||
return nil, status.Error(codes.FailedPrecondition, upload.Response.Err)
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
|
||||
@@ -90,7 +90,10 @@ func (rpc *Server) GetBeaconTasks(ctx context.Context, req *clientpb.Beacon) (*c
|
||||
return nil, ErrInvalidBeaconID
|
||||
}
|
||||
tasks, err := db.BeaconTasksByBeaconID(beacon.ID.String())
|
||||
return &clientpb.BeaconTasks{Tasks: tasks}, err
|
||||
if err != nil {
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
return &clientpb.BeaconTasks{Tasks: tasks}, nil
|
||||
}
|
||||
|
||||
// GetBeaconTaskContent - Get the content of a specific task
|
||||
@@ -138,7 +141,7 @@ func (rpc *Server) UpdateBeaconIntegrityInformation(ctx context.Context, req *cl
|
||||
beacon.Integrity = req.Integrity
|
||||
err = db.Session().Save(beacon).Error
|
||||
if err != nil {
|
||||
return resp, err
|
||||
return resp, rpcError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
@@ -27,6 +27,8 @@ import (
|
||||
"github.com/bishopfox/sliver/protobuf/commonpb"
|
||||
"github.com/bishopfox/sliver/server/configs"
|
||||
"github.com/bishopfox/sliver/server/db"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// GetC2Profiles - Retrieve C2 Profile names and id's
|
||||
@@ -34,7 +36,7 @@ func (rpc *Server) GetHTTPC2Profiles(ctx context.Context, req *commonpb.Empty) (
|
||||
c2Configs := clientpb.HTTPC2Configs{}
|
||||
httpC2Config, err := db.LoadHTTPC2s()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
c2Configs.Configs = httpC2Config
|
||||
@@ -46,7 +48,7 @@ func (rpc *Server) GetHTTPC2Profiles(ctx context.Context, req *commonpb.Empty) (
|
||||
func (rpc *Server) GetHTTPC2ProfileByName(ctx context.Context, req *clientpb.C2ProfileReq) (*clientpb.HTTPC2Config, error) {
|
||||
httpC2Config, err := db.LoadHTTPC2ConfigByName(req.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
return httpC2Config, nil
|
||||
@@ -56,24 +58,24 @@ func (rpc *Server) GetHTTPC2ProfileByName(ctx context.Context, req *clientpb.C2P
|
||||
func (rpc *Server) SaveHTTPC2Profile(ctx context.Context, req *clientpb.HTTPC2ConfigReq) (*commonpb.Empty, error) {
|
||||
err := configs.CheckHTTPC2ConfigErrors(req.C2Config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||
}
|
||||
|
||||
if req.Overwrite && req.C2Config.Name == "" {
|
||||
return nil, configs.ErrMissingC2ProfileName
|
||||
return nil, status.Error(codes.InvalidArgument, configs.ErrMissingC2ProfileName.Error())
|
||||
}
|
||||
|
||||
httpC2Config, err := db.LoadHTTPC2ConfigByName(req.C2Config.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
if httpC2Config.Name != "" && req.Overwrite == false {
|
||||
return nil, configs.ErrDuplicateC2ProfileName
|
||||
return nil, status.Error(codes.AlreadyExists, configs.ErrDuplicateC2ProfileName.Error())
|
||||
}
|
||||
|
||||
if req.Overwrite {
|
||||
if httpC2Config.Name == "" {
|
||||
return nil, configs.ErrC2ProfileNotFound
|
||||
return nil, status.Error(codes.NotFound, configs.ErrC2ProfileNotFound.Error())
|
||||
}
|
||||
err = db.HTTPC2ConfigUpdate(req.C2Config, httpC2Config)
|
||||
if err != nil {
|
||||
|
||||
@@ -89,7 +89,7 @@ func (rpc *Server) GetCertificateInfo(ctx context.Context, req *clientpb.Certifi
|
||||
|
||||
certInfoDB, err := db.GetCertificateInfo(req.CategoryFilters, req.CN)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
certInfo.Info = make([]*clientpb.CertificateData, len(certInfoDB))
|
||||
|
||||
@@ -88,7 +88,7 @@ func (rpc *Server) ClientLog(stream rpcpb.SliverRPC_ClientLogServer) error {
|
||||
logsDir, err := getClientLogsDir(commonName)
|
||||
if err != nil {
|
||||
rpcClientLogs.Errorf("Failed to get client console log directory: %s", err)
|
||||
return err
|
||||
return rpcError(err)
|
||||
}
|
||||
streams := make(map[string]*LogStream)
|
||||
defer func() {
|
||||
@@ -104,14 +104,14 @@ func (rpc *Server) ClientLog(stream rpcpb.SliverRPC_ClientLogServer) error {
|
||||
}
|
||||
if err != nil {
|
||||
rpcClientLogs.Errorf("Failed to receive client console log data: %s", err)
|
||||
return err
|
||||
return rpcError(err)
|
||||
}
|
||||
streamName := fromClient.GetStream()
|
||||
if _, ok := streams[streamName]; !ok {
|
||||
streams[streamName], err = openNewLogStream(logsDir, streamName)
|
||||
if err != nil {
|
||||
rpcClientLogs.Errorf("Failed to open client console log file: %s", err)
|
||||
return err
|
||||
return rpcError(err)
|
||||
}
|
||||
}
|
||||
rpcClientLogs.Debugf("Received %d bytes of client console log data for stream %s", len(fromClient.GetData()), streamName)
|
||||
|
||||
@@ -133,10 +133,10 @@ func (rpc *Server) CrackstationRegister(req *clientpb.Crackstation, stream rpcpb
|
||||
crackStation := core.NewCrackstation(req)
|
||||
err := core.AddCrackstation(crackStation)
|
||||
if err == core.ErrDuplicateHosts {
|
||||
status.Error(codes.AlreadyExists, "crackstation already running on host")
|
||||
return status.Error(codes.AlreadyExists, "crackstation already running on host")
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
return rpcError(err)
|
||||
}
|
||||
|
||||
dbCrackstation, err := db.CrackstationByHostUUID(req.HostUUID)
|
||||
@@ -180,7 +180,7 @@ func (rpc *Server) CrackstationRegister(req *clientpb.Crackstation, stream rpcpb
|
||||
err := stream.Send(msg)
|
||||
if err != nil {
|
||||
crackRpcLog.Warnf(err.Error())
|
||||
return err
|
||||
return rpcError(err)
|
||||
}
|
||||
case event := <-events: // All server-side events
|
||||
if !util.Contains(crackingEvents, event.EventType) {
|
||||
@@ -207,7 +207,7 @@ func (rpc *Server) CrackstationRegister(req *clientpb.Crackstation, stream rpcpb
|
||||
err := stream.Send(pbEvent)
|
||||
if err != nil {
|
||||
crackRpcLog.Warnf(err.Error())
|
||||
return err
|
||||
return rpcError(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ func (rpc *Server) Creds(ctx context.Context, req *commonpb.Empty) (*clientpb.Cr
|
||||
dbCreds := []*models.Credential{}
|
||||
err := db.Session().Where(&models.Credential{}).Find(&dbCreds).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
credentials := []*clientpb.Credential{}
|
||||
for _, dbCred := range dbCreds {
|
||||
|
||||
@@ -51,7 +51,7 @@ func (rpc *Server) Events(_ *commonpb.Empty, stream rpcpb.SliverRPC_EventsServer
|
||||
err := stream.Send(pbEvent)
|
||||
if err != nil {
|
||||
rpcEventsLog.Warnf(err.Error())
|
||||
return err
|
||||
return rpcError(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+53
-44
@@ -66,10 +66,10 @@ func (rpc *Server) Generate(ctx context.Context, req *clientpb.GenerateReq) (*cl
|
||||
if req.Name == "" {
|
||||
name, err = codenames.GetCodename()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
} else if err := util.AllowedName(req.Name); err != nil {
|
||||
return nil, err
|
||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||
} else {
|
||||
name = req.Name
|
||||
}
|
||||
@@ -78,7 +78,7 @@ func (rpc *Server) Generate(ctx context.Context, req *clientpb.GenerateReq) (*cl
|
||||
// if this is a profile reuse existing configuration
|
||||
config, err = db.ImplantConfigByID(req.Config.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
} else {
|
||||
// configure c2 channels to enable
|
||||
@@ -98,13 +98,13 @@ func (rpc *Server) Generate(ctx context.Context, req *clientpb.GenerateReq) (*cl
|
||||
// generate config
|
||||
build, err := generate.GenerateConfig(name, config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
// retrieve http c2 implant config
|
||||
httpC2Config, err := db.LoadHTTPC2ConfigByName(req.Config.HTTPC2ConfigName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
var fPath string
|
||||
@@ -118,22 +118,22 @@ func (rpc *Server) Generate(ctx context.Context, req *clientpb.GenerateReq) (*cl
|
||||
case clientpb.OutputFormat_SHELLCODE:
|
||||
fPath, err = generate.SliverShellcode(name, build, config, httpC2Config.ImplantConfig)
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid output format: %s", req.Config.Format)
|
||||
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid output format: %s", req.Config.Format))
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
fileName := filepath.Base(fPath)
|
||||
fileData, err := os.ReadFile(fPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
err = generate.ImplantBuildSave(build, config, fPath)
|
||||
if err != nil {
|
||||
rpcLog.Errorf("Failed to save external build: %s", err)
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
core.EventBroker.Publish(core.Event{
|
||||
@@ -160,12 +160,12 @@ func (rpc *Server) Regenerate(ctx context.Context, req *clientpb.RegenerateReq)
|
||||
|
||||
config, err := db.ImplantConfigByID(build.ImplantConfigID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
fileData, err := generate.ImplantFileFromBuild(build)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
return &clientpb.Generate{
|
||||
@@ -180,7 +180,7 @@ func (rpc *Server) Regenerate(ctx context.Context, req *clientpb.RegenerateReq)
|
||||
func (rpc *Server) ImplantBuilds(ctx context.Context, _ *commonpb.Empty) (*clientpb.ImplantBuilds, error) {
|
||||
builds, err := db.ImplantBuilds()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
return builds, nil
|
||||
}
|
||||
@@ -189,12 +189,12 @@ func (rpc *Server) ImplantBuilds(ctx context.Context, _ *commonpb.Empty) (*clien
|
||||
func (rpc *Server) StageImplantBuild(ctx context.Context, req *clientpb.ImplantStageReq) (*commonpb.Empty, error) {
|
||||
err := db.Session().Model(&models.ImplantBuild{}).Where("Stage = ?", true).Update("Stage", false).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
for _, name := range req.Build {
|
||||
err = db.Session().Model(&models.ImplantBuild{}).Where(&models.ImplantBuild{Name: name}).Update("Stage", true).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ func (rpc *Server) StageImplantBuild(ctx context.Context, req *clientpb.ImplantS
|
||||
func (rpc *Server) Canaries(ctx context.Context, _ *commonpb.Empty) (*clientpb.Canaries, error) {
|
||||
dbCanaries, err := db.ListCanaries()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
rpcLog.Infof("Found %d canaries", len(dbCanaries))
|
||||
@@ -225,7 +225,7 @@ func (rpc *Server) GenerateUniqueIP(ctx context.Context, _ *commonpb.Empty) (*cl
|
||||
|
||||
if err != nil {
|
||||
rpcLog.Infof("Failed to generate unique wg peer ip: %s\n", err)
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
return &clientpb.UniqueWGIP{
|
||||
@@ -237,7 +237,7 @@ func (rpc *Server) GenerateUniqueIP(ctx context.Context, _ *commonpb.Empty) (*cl
|
||||
func (rpc *Server) ImplantProfiles(ctx context.Context, _ *commonpb.Empty) (*clientpb.ImplantProfiles, error) {
|
||||
implantProfiles, err := db.ImplantProfiles()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
return &clientpb.ImplantProfiles{Profiles: implantProfiles}, nil
|
||||
@@ -250,7 +250,7 @@ func (rpc *Server) SaveImplantProfile(ctx context.Context, profile *clientpb.Imp
|
||||
rpcLog.Infof("Saving new profile with name %#v", profile.Name)
|
||||
profile, err := generate.SaveImplantProfile(profile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
core.EventBroker.Publish(core.Event{
|
||||
EventType: consts.ProfileEvent,
|
||||
@@ -258,29 +258,35 @@ func (rpc *Server) SaveImplantProfile(ctx context.Context, profile *clientpb.Imp
|
||||
})
|
||||
return profile, nil
|
||||
}
|
||||
return nil, errors.New("invalid profile name")
|
||||
return nil, status.Error(codes.InvalidArgument, "invalid profile name")
|
||||
}
|
||||
|
||||
// DeleteImplantProfile - Delete an implant profile
|
||||
func (rpc *Server) DeleteImplantProfile(ctx context.Context, req *clientpb.DeleteReq) (*commonpb.Empty, error) {
|
||||
profile, err := db.ProfileByName(req.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
for _, build := range profile.Config.ImplantBuilds {
|
||||
err = RemoveBuildByName(build.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
}
|
||||
err = db.DeleteProfile(req.Name)
|
||||
return &commonpb.Empty{}, err
|
||||
if err != nil {
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
return &commonpb.Empty{}, nil
|
||||
}
|
||||
|
||||
// DeleteImplantBuild - Delete an implant build
|
||||
func (rpc *Server) DeleteImplantBuild(ctx context.Context, req *clientpb.DeleteReq) (*commonpb.Empty, error) {
|
||||
err := RemoveBuildByName(req.Name)
|
||||
return &commonpb.Empty{}, err
|
||||
if err != nil {
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
return &commonpb.Empty{}, nil
|
||||
}
|
||||
|
||||
// Remove Implant build given the build name
|
||||
@@ -319,7 +325,10 @@ func RemoveBuildByName(name string) error {
|
||||
// ShellcodeRDI - Generates a RDI shellcode from a given DLL
|
||||
func (rpc *Server) ShellcodeRDI(ctx context.Context, req *clientpb.ShellcodeRDIReq) (*clientpb.ShellcodeRDI, error) {
|
||||
shellcode, err := generate.ShellcodeRDIFromBytes(req.GetData(), req.GetFunctionName(), req.GetArguments())
|
||||
return &clientpb.ShellcodeRDI{Data: shellcode}, err
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||
}
|
||||
return &clientpb.ShellcodeRDI{Data: shellcode}, nil
|
||||
}
|
||||
|
||||
// GetCompiler - Get information about the internal Go compiler and its configuration
|
||||
@@ -347,19 +356,19 @@ func (rpc *Server) GenerateExternal(ctx context.Context, req *clientpb.ExternalG
|
||||
if req.Name == "" {
|
||||
name, err = codenames.GetCodename()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
} else if err := util.AllowedName(req.Name); err != nil {
|
||||
return nil, err
|
||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||
} else {
|
||||
name = req.Name
|
||||
}
|
||||
if config == nil {
|
||||
return nil, errors.New("invalid implant config")
|
||||
return nil, status.Error(codes.InvalidArgument, "invalid implant config")
|
||||
}
|
||||
externalConfig, err := generate.SliverExternal(name, config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
core.EventBroker.Publish(core.Event{
|
||||
@@ -398,7 +407,7 @@ func (rpc *Server) GenerateExternalSaveBuild(ctx context.Context, req *clientpb.
|
||||
err = generate.ImplantBuildSave(implantBuild, implantConfig, tmpFile.Name())
|
||||
if err != nil {
|
||||
rpcLog.Errorf("Failed to save external build: %s", err)
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
core.EventBroker.Publish(core.Event{
|
||||
@@ -424,7 +433,7 @@ func (rpc *Server) GenerateExternalGetBuildConfig(ctx context.Context, req *clie
|
||||
// retrieve http c2 implant config
|
||||
httpC2Config, err := db.LoadHTTPC2ConfigByName(implantConfig.HTTPC2ConfigName)
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, fmt.Sprintf("Unable to load HTTP C2 Configuration: %s", err))
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
encoders := map[string]uint64{
|
||||
@@ -500,7 +509,7 @@ func (rpc *Server) BuilderRegister(req *clientpb.Builder, stream rpcpb.SliverRPC
|
||||
err := stream.Send(pbEvent)
|
||||
if err != nil {
|
||||
rpcEventsLog.Warnf(err.Error())
|
||||
return err
|
||||
return rpcError(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -557,7 +566,7 @@ func (rpc *Server) TrafficEncoderAdd(ctx context.Context, req *clientpb.TrafficE
|
||||
tests, err := testTrafficEncoder(ctx, req, progress)
|
||||
close(progress)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
return tests, nil
|
||||
}
|
||||
@@ -591,7 +600,7 @@ func testTrafficEncoder(ctx context.Context, req *clientpb.TrafficEncoder, progr
|
||||
})
|
||||
if err != nil {
|
||||
rpcLog.Errorf("Failed to create traffic encoder: %s", err.Error())
|
||||
return nil, err
|
||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||
}
|
||||
|
||||
// Test Suite for Traffic Encoders
|
||||
@@ -689,16 +698,16 @@ func (rpc *Server) GenerateStage(ctx context.Context, req *clientpb.GenerateStag
|
||||
|
||||
profile, err := db.ImplantProfileByName(req.Profile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
if req.Name == "" {
|
||||
name, err = codenames.GetCodename()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
} else if err := util.AllowedName(name); err != nil {
|
||||
return nil, err
|
||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||
} else {
|
||||
name = req.Name
|
||||
}
|
||||
@@ -706,7 +715,7 @@ func (rpc *Server) GenerateStage(ctx context.Context, req *clientpb.GenerateStag
|
||||
// retrieve http c2 implant config
|
||||
httpC2Config, err := db.LoadHTTPC2ConfigByName(profile.Config.HTTPC2ConfigName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
if len(profile.Config.Exports) == 0 {
|
||||
@@ -716,7 +725,7 @@ func (rpc *Server) GenerateStage(ctx context.Context, req *clientpb.GenerateStag
|
||||
// generate config
|
||||
build, err := generate.GenerateConfig(name, profile.Config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
var fPath string
|
||||
@@ -730,16 +739,16 @@ func (rpc *Server) GenerateStage(ctx context.Context, req *clientpb.GenerateStag
|
||||
case clientpb.OutputFormat_SHELLCODE:
|
||||
fPath, err = generate.SliverShellcode(name, build, profile.Config, httpC2Config.ImplantConfig)
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid output format: %s", profile.Config.Format)
|
||||
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid output format: %s", profile.Config.Format))
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
fileName := filepath.Base(fPath)
|
||||
fileData, err := os.ReadFile(fPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
core.EventBroker.Publish(core.Event{
|
||||
@@ -761,7 +770,7 @@ func (rpc *Server) GenerateStage(ctx context.Context, req *clientpb.GenerateStag
|
||||
stageType = req.Compress + " - "
|
||||
stage2, err = Compress(stage2, req.Compress)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -774,14 +783,14 @@ func (rpc *Server) GenerateStage(ctx context.Context, req *clientpb.GenerateStag
|
||||
|
||||
stage2, err = Encrypt(stage2, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
err = generate.SaveStage(build, profile.Config, stage2, stageType)
|
||||
if err != nil {
|
||||
rpcLog.Errorf("Failed to save external build: %s", err)
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
core.EventBroker.Publish(core.Event{
|
||||
|
||||
+13
-13
@@ -79,7 +79,7 @@ func (rpc *Server) HijackDLL(ctx context.Context, req *clientpb.DllHijackReq) (*
|
||||
if download.Encoder == "gzip" {
|
||||
download.Data, err = new(encoders.Gzip).Decode(download.Data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
}
|
||||
refDLL = download.Data
|
||||
@@ -89,7 +89,7 @@ func (rpc *Server) HijackDLL(ctx context.Context, req *clientpb.DllHijackReq) (*
|
||||
if req.ProfileName != "" {
|
||||
profiles, err := rpc.ImplantProfiles(context.Background(), &commonpb.Empty{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
var p *clientpb.ImplantProfile
|
||||
for _, prof := range profiles.Profiles {
|
||||
@@ -113,47 +113,47 @@ func (rpc *Server) HijackDLL(ctx context.Context, req *clientpb.DllHijackReq) (*
|
||||
if req.Name == "" {
|
||||
name, err = codenames.GetCodename()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
} else if err := util.AllowedName(name); err != nil {
|
||||
return nil, err
|
||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||
} else {
|
||||
name = req.Name
|
||||
}
|
||||
build, err := generate.GenerateConfig(name, config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
// retrieve http c2 implant config
|
||||
httpC2Config, err := db.LoadHTTPC2ConfigByName(p.Config.HTTPC2ConfigName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
fPath, err := generate.SliverSharedLibrary(name, build, config, httpC2Config.ImplantConfig)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
targetDLLData, err = os.ReadFile(fPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
} else {
|
||||
if len(req.TargetDLL) == 0 {
|
||||
return nil, errors.New("missing target DLL")
|
||||
return nil, status.Error(codes.InvalidArgument, "missing target DLL")
|
||||
}
|
||||
targetDLLData = req.TargetDLL
|
||||
}
|
||||
// call clone
|
||||
result, err := cloneExports(targetDLLData, refDLL, req.ReferenceDLLPath)
|
||||
if err != nil {
|
||||
return resp, fmt.Errorf("failed to clone exports: %s", err)
|
||||
return resp, status.Error(codes.InvalidArgument, fmt.Sprintf("failed to clone exports: %s", err))
|
||||
}
|
||||
targetBytes, err := result.Bytes()
|
||||
if err != nil {
|
||||
return resp, fmt.Errorf("failed to convert PE to bytes: %s", err)
|
||||
return resp, status.Error(codes.Internal, fmt.Sprintf("failed to convert PE to bytes: %s", err))
|
||||
}
|
||||
// upload new dll
|
||||
uploadGzip, _ := new(encoders.Gzip).Encode(targetBytes)
|
||||
@@ -169,11 +169,11 @@ func (rpc *Server) HijackDLL(ctx context.Context, req *clientpb.DllHijackReq) (*
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
if upload.Response != nil && upload.Response.Err != "" {
|
||||
return nil, fmt.Errorf("%s", upload.Response.Err)
|
||||
return nil, status.Error(codes.FailedPrecondition, upload.Response.Err)
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
|
||||
@@ -34,7 +34,7 @@ import (
|
||||
func (rpc *Server) Hosts(ctx context.Context, _ *commonpb.Empty) (*clientpb.AllHosts, error) {
|
||||
dbHosts, err := db.ListHosts()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
hosts := []*clientpb.Host{}
|
||||
for _, dbHost := range dbHosts {
|
||||
@@ -47,7 +47,7 @@ func (rpc *Server) Hosts(ctx context.Context, _ *commonpb.Empty) (*clientpb.AllH
|
||||
func (rpc *Server) Host(ctx context.Context, req *clientpb.Host) (*clientpb.Host, error) {
|
||||
dbHost, err := db.HostByHostUUID(req.HostUUID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
return dbHost.ToProtobuf(), nil
|
||||
}
|
||||
@@ -56,11 +56,11 @@ func (rpc *Server) Host(ctx context.Context, req *clientpb.Host) (*clientpb.Host
|
||||
func (rpc *Server) HostRm(ctx context.Context, req *clientpb.Host) (*commonpb.Empty, error) {
|
||||
dbHost, err := db.HostByHostUUID(req.HostUUID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
err = db.Session().Delete(*dbHost).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
return &commonpb.Empty{}, nil
|
||||
}
|
||||
@@ -69,11 +69,11 @@ func (rpc *Server) HostRm(ctx context.Context, req *clientpb.Host) (*commonpb.Em
|
||||
func (rpc *Server) HostIOCRm(ctx context.Context, req *clientpb.IOC) (*commonpb.Empty, error) {
|
||||
dbIOC, err := db.IOCByID(req.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
err = db.Session().Delete(dbIOC).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
return &commonpb.Empty{}, nil
|
||||
}
|
||||
+27
-26
@@ -20,7 +20,6 @@ package rpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/bishopfox/sliver/client/constants"
|
||||
@@ -29,6 +28,8 @@ import (
|
||||
"github.com/bishopfox/sliver/server/c2"
|
||||
"github.com/bishopfox/sliver/server/core"
|
||||
"github.com/bishopfox/sliver/server/db"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -43,7 +44,7 @@ const (
|
||||
|
||||
var (
|
||||
// ErrInvalidPort - Invalid TCP port number
|
||||
ErrInvalidPort = errors.New("invalid listener port")
|
||||
ErrInvalidPort = status.Error(codes.InvalidArgument, "invalid listener port")
|
||||
)
|
||||
|
||||
// GetJobs - List jobs
|
||||
@@ -72,12 +73,12 @@ func (rpc *Server) RestartJobs(ctx context.Context, restartJobReq *clientpb.Rest
|
||||
job := core.Jobs.Get(int(jobID))
|
||||
listenerJob, err := db.ListenerByJobID(jobID)
|
||||
if err != nil {
|
||||
return &commonpb.Empty{}, err
|
||||
return &commonpb.Empty{}, rpcError(err)
|
||||
}
|
||||
job.JobCtrl <- true
|
||||
job, err = c2.StartHTTPListenerJob(listenerJob.HTTPConf)
|
||||
if err != nil {
|
||||
return &commonpb.Empty{}, err
|
||||
return &commonpb.Empty{}, rpcError(err)
|
||||
}
|
||||
listenerJob.JobID = uint32(job.ID)
|
||||
db.UpdateHTTPC2Listener(listenerJob)
|
||||
@@ -96,11 +97,11 @@ func (rpc *Server) KillJob(ctx context.Context, kill *clientpb.KillJobReq) (*cli
|
||||
killJob.Success = true
|
||||
err = db.DeleteListener(killJob.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
} else {
|
||||
killJob.Success = false
|
||||
err = errors.New("invalid Job ID")
|
||||
err = status.Error(codes.NotFound, "invalid job ID")
|
||||
}
|
||||
return killJob, err
|
||||
}
|
||||
@@ -116,12 +117,12 @@ func (rpc *Server) StartMTLSListener(ctx context.Context, req *clientpb.MTLSList
|
||||
|
||||
err := PortInUse(req.Port)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
job, err := c2.StartMTLSListenerJob(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
listenerJob := &clientpb.ListenerJob{
|
||||
@@ -131,7 +132,7 @@ func (rpc *Server) StartMTLSListener(ctx context.Context, req *clientpb.MTLSList
|
||||
}
|
||||
err = db.SaveC2Listener(listenerJob)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
return &clientpb.ListenerJob{JobID: uint32(job.ID)}, nil
|
||||
@@ -157,22 +158,22 @@ func (rpc *Server) StartWGListener(ctx context.Context, req *clientpb.WGListener
|
||||
|
||||
err := PortInUse(req.Port)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
err = PortInUse(req.NPort)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
err = PortInUse(req.KeyPort)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
job, err := c2.StartWGListenerJob(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
listenerJob := &clientpb.ListenerJob{
|
||||
@@ -182,7 +183,7 @@ func (rpc *Server) StartWGListener(ctx context.Context, req *clientpb.WGListener
|
||||
}
|
||||
err = db.SaveC2Listener(listenerJob)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
return &clientpb.ListenerJob{JobID: uint32(job.ID)}, nil
|
||||
@@ -192,12 +193,12 @@ func (rpc *Server) StartWGListener(ctx context.Context, req *clientpb.WGListener
|
||||
func (rpc *Server) StartDNSListener(ctx context.Context, req *clientpb.DNSListenerReq) (*clientpb.ListenerJob, error) {
|
||||
err := PortInUse(req.Port)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
job, err := c2.StartDNSListenerJob(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
listenerJob := &clientpb.ListenerJob{
|
||||
@@ -207,7 +208,7 @@ func (rpc *Server) StartDNSListener(ctx context.Context, req *clientpb.DNSListen
|
||||
}
|
||||
err = db.SaveC2Listener(listenerJob)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
return &clientpb.ListenerJob{JobID: uint32(job.ID)}, nil
|
||||
@@ -224,12 +225,12 @@ func (rpc *Server) StartHTTPSListener(ctx context.Context, req *clientpb.HTTPLis
|
||||
|
||||
err := PortInUse(req.Port)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
job, err := c2.StartHTTPListenerJob(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
listenerJob := &clientpb.ListenerJob{
|
||||
@@ -239,7 +240,7 @@ func (rpc *Server) StartHTTPSListener(ctx context.Context, req *clientpb.HTTPLis
|
||||
}
|
||||
err = db.SaveC2Listener(listenerJob)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
return &clientpb.ListenerJob{JobID: uint32(job.ID)}, nil
|
||||
@@ -256,12 +257,12 @@ func (rpc *Server) StartHTTPListener(ctx context.Context, req *clientpb.HTTPList
|
||||
|
||||
err := PortInUse(req.Port)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
job, err := c2.StartHTTPListenerJob(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
listenerJob := &clientpb.ListenerJob{
|
||||
@@ -271,7 +272,7 @@ func (rpc *Server) StartHTTPListener(ctx context.Context, req *clientpb.HTTPList
|
||||
}
|
||||
err = db.SaveC2Listener(listenerJob)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
return &clientpb.ListenerJob{JobID: uint32(job.ID)}, nil
|
||||
@@ -280,13 +281,13 @@ func (rpc *Server) StartHTTPListener(ctx context.Context, req *clientpb.HTTPList
|
||||
func PortInUse(newPort uint32) error {
|
||||
listenerJobs, err := db.ListenerJobs()
|
||||
if err != nil {
|
||||
return err
|
||||
return rpcError(err)
|
||||
}
|
||||
var port uint32
|
||||
for _, job := range listenerJobs {
|
||||
listener, err := db.ListenerByJobID(job.JobID)
|
||||
if err != nil {
|
||||
return err
|
||||
return rpcError(err)
|
||||
}
|
||||
switch job.Type {
|
||||
case "http":
|
||||
@@ -304,7 +305,7 @@ func PortInUse(newPort uint32) error {
|
||||
}
|
||||
|
||||
if port == newPort {
|
||||
return errors.New(fmt.Sprintf("port %d is in use", port))
|
||||
return status.Error(codes.AlreadyExists, fmt.Sprintf("port %d is in use", port))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -52,7 +52,7 @@ func (rpc *Server) Kill(ctx context.Context, kill *sliverpb.KillReq) (*commonpb.
|
||||
func (rpc *Server) killSession(kill *sliverpb.KillReq, session *core.Session) (*commonpb.Empty, error) {
|
||||
data, err := proto.Marshal(kill)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
timeout := time.Duration(kill.Request.GetTimeout())
|
||||
// Do not block waiting for the msg send, the implant connection may already be dead
|
||||
@@ -69,19 +69,22 @@ func (rpc *Server) killBeacon(kill *sliverpb.KillReq, beacon *models.Beacon) (*c
|
||||
request.BeaconID = beacon.ID.String()
|
||||
reqData, err := proto.Marshal(request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
task, err := beacon.Task(&sliverpb.Envelope{
|
||||
Type: sliverpb.MsgKillSessionReq,
|
||||
Data: reqData,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
parts := strings.Split(string(kill.ProtoReflect().Descriptor().FullName().Name()), ".")
|
||||
name := parts[len(parts)-1]
|
||||
task.Description = name
|
||||
// Update db
|
||||
err = db.Session().Save(task).Error
|
||||
return resp, err
|
||||
if err != nil {
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
@@ -32,7 +32,7 @@ import (
|
||||
func (rpc *Server) LootAdd(ctx context.Context, lootReq *clientpb.Loot) (*clientpb.Loot, error) {
|
||||
loot, err := loot.GetLootStore().Add(lootReq)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
core.EventBroker.Publish(core.Event{
|
||||
EventType: consts.LootAddedEvent,
|
||||
@@ -45,7 +45,7 @@ func (rpc *Server) LootAdd(ctx context.Context, lootReq *clientpb.Loot) (*client
|
||||
func (rpc *Server) LootRm(ctx context.Context, lootReq *clientpb.Loot) (*commonpb.Empty, error) {
|
||||
err := loot.GetLootStore().Rm(lootReq.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
core.EventBroker.Publish(core.Event{
|
||||
EventType: consts.LootRemovedEvent,
|
||||
@@ -57,7 +57,7 @@ func (rpc *Server) LootRm(ctx context.Context, lootReq *clientpb.Loot) (*commonp
|
||||
func (rpc *Server) LootUpdate(ctx context.Context, lootReq *clientpb.Loot) (*clientpb.Loot, error) {
|
||||
loot, err := loot.GetLootStore().Update(lootReq)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
core.EventBroker.Publish(core.Event{
|
||||
EventType: consts.LootAddedEvent,
|
||||
@@ -67,7 +67,11 @@ func (rpc *Server) LootUpdate(ctx context.Context, lootReq *clientpb.Loot) (*cli
|
||||
|
||||
// LootContent - Get a list of all loot of a specific type
|
||||
func (rpc *Server) LootContent(ctx context.Context, lootReq *clientpb.Loot) (*clientpb.Loot, error) {
|
||||
return loot.GetLootStore().GetContent(lootReq.ID, true)
|
||||
result, err := loot.GetLootStore().GetContent(lootReq.ID, true)
|
||||
if err != nil {
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// LootAll - Get a list of all loot
|
||||
|
||||
@@ -15,7 +15,7 @@ func (rpc *Server) MonitorStart(ctx context.Context, _ *commonpb.Empty) (*common
|
||||
if err != nil {
|
||||
resp.Err = err.Error()
|
||||
}
|
||||
return resp, err
|
||||
return resp, rpcError(err)
|
||||
}
|
||||
|
||||
func (rpc *Server) MonitorStop(ctx context.Context, _ *commonpb.Empty) (*commonpb.Empty, error) {
|
||||
@@ -27,7 +27,7 @@ func (rpc *Server) MonitorStop(ctx context.Context, _ *commonpb.Empty) (*commonp
|
||||
func (rpc *Server) MonitorListConfig(ctx context.Context, _ *commonpb.Empty) (*clientpb.MonitoringProviders, error) {
|
||||
resp, err := watchtower.ListConfig()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ func (rpc *Server) Msf(ctx context.Context, req *clientpb.MSFReq) (*sliverpb.Tas
|
||||
})
|
||||
if err != nil {
|
||||
rpcLog.Warnf("Error while generating msf payload: %v\n", err)
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
taskReq := &sliverpb.TaskReq{
|
||||
Encoder: "raw",
|
||||
@@ -81,7 +81,7 @@ func (rpc *Server) Msf(ctx context.Context, req *clientpb.MSFReq) (*sliverpb.Tas
|
||||
resp := &sliverpb.Task{Response: &commonpb.Response{}}
|
||||
err = rpc.GenericHandler(taskReq, resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
@@ -121,7 +121,7 @@ func (rpc *Server) MsfRemote(ctx context.Context, req *clientpb.MSFRemoteReq) (*
|
||||
Format: "raw",
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
taskReq := &sliverpb.TaskReq{
|
||||
Pid: req.PID,
|
||||
@@ -133,7 +133,7 @@ func (rpc *Server) MsfRemote(ctx context.Context, req *clientpb.MSFRemoteReq) (*
|
||||
resp := &sliverpb.Task{Response: &commonpb.Response{}}
|
||||
err = rpc.GenericHandler(taskReq, resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
@@ -34,17 +34,20 @@ func (s *Server) Portfwd(ctx context.Context, req *sliverpb.PortfwdReq) (*sliver
|
||||
}
|
||||
tunnel := core.Tunnels.Get(req.TunnelID)
|
||||
if tunnel == nil {
|
||||
return nil, core.ErrInvalidTunnelID
|
||||
return nil, rpcError(core.ErrInvalidTunnelID)
|
||||
}
|
||||
reqData, err := proto.Marshal(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
data, err := session.Request(sliverpb.MsgNumber(req), s.getTimeout(req), reqData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
portfwd := &sliverpb.Portfwd{}
|
||||
err = proto.Unmarshal(data, portfwd)
|
||||
return portfwd, err
|
||||
if err != nil {
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
return portfwd, nil
|
||||
}
|
||||
+10
-8
@@ -31,6 +31,8 @@ import (
|
||||
"github.com/bishopfox/sliver/server/generate"
|
||||
"github.com/bishopfox/sliver/util"
|
||||
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
@@ -89,16 +91,16 @@ func (rpc *Server) GetSystem(ctx context.Context, req *clientpb.GetSystemReq) (*
|
||||
// retrieve http c2 implant config
|
||||
httpC2Config, err := db.LoadHTTPC2ConfigByName(req.Config.HTTPC2ConfigName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
if req.Name == "" {
|
||||
name, err = codenames.GetCodename()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
} else if err := util.AllowedName(name); err != nil {
|
||||
return nil, err
|
||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||
} else {
|
||||
name = req.Name
|
||||
}
|
||||
@@ -109,11 +111,11 @@ func (rpc *Server) GetSystem(ctx context.Context, req *clientpb.GetSystemReq) (*
|
||||
req.Config.ObfuscateSymbols = false
|
||||
build, err := generate.GenerateConfig(name, req.Config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
shellcodePath, err := generate.SliverShellcode(name, build, req.Config, httpC2Config.ImplantConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
shellcode, _ = os.ReadFile(shellcodePath)
|
||||
}
|
||||
@@ -123,18 +125,18 @@ func (rpc *Server) GetSystem(ctx context.Context, req *clientpb.GetSystemReq) (*
|
||||
Request: req.GetRequest(),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
timeout := rpc.getTimeout(req)
|
||||
data, err = session.Request(sliverpb.MsgInvokeGetSystemReq, timeout, data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
getSystem := &sliverpb.GetSystem{}
|
||||
err = proto.Unmarshal(data, getSystem)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
return getSystem, nil
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ func (rpc *Server) Reconfigure(ctx context.Context, req *sliverpb.ReconfigureReq
|
||||
}
|
||||
err = db.Session().Save(beacon).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
} else {
|
||||
return nil, ErrMissingRequestField
|
||||
@@ -98,7 +98,7 @@ func (rpc *Server) Rename(ctx context.Context, req *clientpb.RenameReq) (*common
|
||||
}
|
||||
err = db.RenameBeacon(beacon.ID.String(), req.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
} else {
|
||||
return nil, ErrMissingRequestField
|
||||
|
||||
@@ -56,7 +56,7 @@ func (rpc *Server) KillSession(ctx context.Context, kill *sliverpb.KillReq) (*co
|
||||
core.Sessions.Remove(session.ID)
|
||||
data, err := proto.Marshal(kill)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
timeout := time.Duration(kill.Request.GetTimeout())
|
||||
session.Request(sliverpb.MsgNumber(kill), timeout, data)
|
||||
|
||||
@@ -42,19 +42,22 @@ func (rpc *Server) Shell(ctx context.Context, req *sliverpb.ShellReq) (*sliverpb
|
||||
}
|
||||
tunnel := core.Tunnels.Get(req.TunnelID)
|
||||
if tunnel == nil {
|
||||
return nil, core.ErrInvalidTunnelID
|
||||
return nil, rpcError(core.ErrInvalidTunnelID)
|
||||
}
|
||||
reqData, err := proto.Marshal(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
data, err := session.Request(sliverpb.MsgNumber(req), rpc.getTimeout(req), reqData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
shell := &sliverpb.Shell{}
|
||||
err = proto.Unmarshal(data, shell)
|
||||
return shell, err
|
||||
if err != nil {
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
return shell, nil
|
||||
}
|
||||
|
||||
// RunSSHCommand runs a SSH command using the client built into the implant
|
||||
|
||||
@@ -95,7 +95,7 @@ func (s *Server) SocksProxy(stream rpcpb.SliverRPC_SocksProxyServer) error {
|
||||
//fmt.Println("Send Agent 1 ",fromClient.TunnelID,len(fromClient.Data))
|
||||
if err != nil {
|
||||
rpcLog.Warnf("Error on stream recv %s", err)
|
||||
return err
|
||||
return rpcError(err)
|
||||
}
|
||||
tunnelLog.Debugf("Tunnel %d: From client %d byte(s)",
|
||||
fromClient.TunnelID, len(fromClient.Data))
|
||||
@@ -173,7 +173,7 @@ func (s *Server) CloseSocks(ctx context.Context, req *sliverpb.Socks) (*commonpb
|
||||
toImplantCacheSocks.DeleteTun(req.TunnelID)
|
||||
fromImplantCacheSocks.DeleteTun(req.TunnelID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
return &commonpb.Empty{}, nil
|
||||
}
|
||||
@@ -36,7 +36,7 @@ func (rpc *Server) StartTCPStagerListener(ctx context.Context, req *clientpb.Sta
|
||||
}
|
||||
job, err := c2.StartTCPStagerListenerJob(host, uint16(req.GetPort()), req.ProfileName, req.GetData())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
listenerJob := &clientpb.ListenerJob{
|
||||
@@ -46,7 +46,7 @@ func (rpc *Server) StartTCPStagerListener(ctx context.Context, req *clientpb.Sta
|
||||
}
|
||||
err = db.SaveC2Listener(listenerJob)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
return &clientpb.StagerListener{JobID: uint32(job.ID)}, nil
|
||||
|
||||
+16
-16
@@ -54,7 +54,7 @@ func (rpc *Server) Task(ctx context.Context, req *sliverpb.TaskReq) (*sliverpb.T
|
||||
resp := &sliverpb.Task{Response: &commonpb.Response{}}
|
||||
err := rpc.GenericHandler(req, resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
@@ -91,10 +91,10 @@ func (rpc *Server) Migrate(ctx context.Context, req *clientpb.MigrateReq) (*sliv
|
||||
if req.Name == "" {
|
||||
name, err = codenames.GetCodename()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
} else if err := util.AllowedName(name); err != nil {
|
||||
return nil, err
|
||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||
} else {
|
||||
name = req.Name
|
||||
}
|
||||
@@ -106,25 +106,25 @@ func (rpc *Server) Migrate(ctx context.Context, req *clientpb.MigrateReq) (*sliv
|
||||
config.ObfuscateSymbols = true
|
||||
build, err := generate.GenerateConfig(name, config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
// retrieve http c2 implant config
|
||||
httpC2Config, err := db.LoadHTTPC2ConfigByName(req.Config.HTTPC2ConfigName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
shellcodePath, err := generate.SliverShellcode(name, build, config, httpC2Config.ImplantConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
shellcode, _ = os.ReadFile(shellcodePath)
|
||||
// Save the implant config in the database so that the server recognizes it when it tries to connect
|
||||
config.ID = ""
|
||||
savedConfig, err := db.SaveImplantConfig(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
build.ImplantConfigID = savedConfig.ID
|
||||
|
||||
@@ -135,7 +135,7 @@ func (rpc *Server) Migrate(ctx context.Context, req *clientpb.MigrateReq) (*sliv
|
||||
build.Name = fmt.Sprintf("%s_%d", build.Name, time.Now().Unix())
|
||||
_, err = db.SaveImplantBuild(build)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -149,7 +149,7 @@ func (rpc *Server) Migrate(ctx context.Context, req *clientpb.MigrateReq) (*sliv
|
||||
case clientpb.ShellcodeEncoder_SHIKATA_GA_NAI:
|
||||
shellcode, err = sgn.EncodeShellcode(shellcode, arch, 1, []byte{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -165,7 +165,7 @@ func (rpc *Server) Migrate(ctx context.Context, req *clientpb.MigrateReq) (*sliv
|
||||
err = rpc.GenericHandler(migrateReq, resp)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
@@ -205,7 +205,7 @@ func (rpc *Server) ExecuteAssembly(ctx context.Context, req *sliverpb.ExecuteAss
|
||||
)
|
||||
if err != nil {
|
||||
tasksLog.Errorf("Execute assembly failed: %s", err)
|
||||
return nil, err
|
||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||
}
|
||||
|
||||
resp := &sliverpb.ExecuteAssembly{Response: &commonpb.Response{}}
|
||||
@@ -232,7 +232,7 @@ func (rpc *Server) ExecuteAssembly(ctx context.Context, req *sliverpb.ExecuteAss
|
||||
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
@@ -269,7 +269,7 @@ func (rpc *Server) Sideload(ctx context.Context, req *sliverpb.SideloadReq) (*sl
|
||||
shellcode, err := generate.DonutShellcodeFromPE(req.Data, arch, false, strings.Join(req.Args, " "), "", req.EntryPoint, req.IsDLL, req.IsUnicode, false)
|
||||
if err != nil {
|
||||
tasksLog.Errorf("Sideload failed: %s", err)
|
||||
return nil, err
|
||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||
}
|
||||
req = &sliverpb.SideloadReq{
|
||||
Request: req.Request,
|
||||
@@ -283,7 +283,7 @@ func (rpc *Server) Sideload(ctx context.Context, req *sliverpb.SideloadReq) (*sl
|
||||
resp := &sliverpb.Sideload{Response: &commonpb.Response{}}
|
||||
err = rpc.GenericHandler(req, resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
@@ -314,7 +314,7 @@ func (rpc *Server) SpawnDll(ctx context.Context, req *sliverpb.InvokeSpawnDllReq
|
||||
resp := &sliverpb.SpawnDll{Response: &commonpb.Response{}}
|
||||
offset, err := getExportOffsetFromMemory(req.Data, req.EntryPoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||
}
|
||||
spawnDLLReq := &sliverpb.SpawnDllReq{
|
||||
Data: req.Data,
|
||||
@@ -328,7 +328,7 @@ func (rpc *Server) SpawnDll(ctx context.Context, req *sliverpb.InvokeSpawnDllReq
|
||||
}
|
||||
err = rpc.GenericHandler(spawnDLLReq, resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -89,8 +89,9 @@ func (c *dataCache) DeleteSeq(tunnelID uint64, sequence uint64) {
|
||||
}
|
||||
|
||||
// CreateTunnel - Create a new tunnel on the server, however based on only this request there's
|
||||
// no way to associate the tunnel with the correct client, so the client must send
|
||||
// a zero-byte message over TunnelData to bind itself to the newly created tunnel.
|
||||
//
|
||||
// no way to associate the tunnel with the correct client, so the client must send
|
||||
// a zero-byte message over TunnelData to bind itself to the newly created tunnel.
|
||||
func (s *Server) CreateTunnel(ctx context.Context, req *sliverpb.Tunnel) (*sliverpb.Tunnel, error) {
|
||||
session := core.Sessions.Get(req.SessionID)
|
||||
if session == nil {
|
||||
@@ -124,14 +125,14 @@ func (s *Server) TunnelData(stream rpcpb.SliverRPC_TunnelDataServer) error {
|
||||
}
|
||||
if err != nil {
|
||||
rpcLog.Warnf("Error on stream recv %s", err)
|
||||
return err
|
||||
return rpcError(err)
|
||||
}
|
||||
tunnelLog.Debugf("Tunnel %d: From client %d byte(s)",
|
||||
fromClient.TunnelID, len(fromClient.Data))
|
||||
|
||||
tunnel := core.Tunnels.Get(fromClient.TunnelID)
|
||||
if tunnel == nil {
|
||||
return core.ErrInvalidTunnelID
|
||||
return rpcError(core.ErrInvalidTunnelID)
|
||||
}
|
||||
if tunnel.Client == nil {
|
||||
tunnel.Client = stream // Bind client to tunnel
|
||||
|
||||
+14
-10
@@ -42,7 +42,7 @@ func (rpc *Server) Websites(ctx context.Context, _ *commonpb.Empty) (*clientpb.W
|
||||
websiteNames, err := website.Names()
|
||||
if err != nil {
|
||||
rpcWebsiteLog.Warnf("Failed to find website %s", err)
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
websites := &clientpb.Websites{Websites: []*clientpb.Website{}}
|
||||
for _, name := range websiteNames {
|
||||
@@ -60,24 +60,24 @@ func (rpc *Server) Websites(ctx context.Context, _ *commonpb.Empty) (*clientpb.W
|
||||
func (rpc *Server) WebsiteRemove(ctx context.Context, req *clientpb.Website) (*commonpb.Empty, error) {
|
||||
web, err := website.MapContent(req.Name, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
for path := range web.Contents {
|
||||
err := website.RemoveContent(req.Name, path)
|
||||
if err != nil {
|
||||
rpcWebsiteLog.Errorf("Failed to remove content %s", err)
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
}
|
||||
|
||||
dbWebsite, err := website.WebsiteByName(req.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
err = db.RemoveWebSite(dbWebsite.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
|
||||
core.EventBroker.Publish(core.Event{
|
||||
@@ -90,7 +90,11 @@ func (rpc *Server) WebsiteRemove(ctx context.Context, req *clientpb.Website) (*c
|
||||
|
||||
// Website - Get one website
|
||||
func (rpc *Server) Website(ctx context.Context, req *clientpb.Website) (*clientpb.Website, error) {
|
||||
return website.MapContent(req.Name, false)
|
||||
site, err := website.MapContent(req.Name, false)
|
||||
if err != nil {
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
return site, nil
|
||||
}
|
||||
|
||||
// WebsiteAddContent - Add content to a website, the website is created if `name` does not exist
|
||||
@@ -111,13 +115,13 @@ func (rpc *Server) WebsiteAddContent(ctx context.Context, req *clientpb.WebsiteA
|
||||
err := website.AddContent(req.Name, content)
|
||||
if err != nil {
|
||||
rpcWebsiteLog.Errorf("Failed to add content %s", err)
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_, err := website.AddWebsite(req.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,7 +137,7 @@ func (rpc *Server) WebsiteAddContent(ctx context.Context, req *clientpb.WebsiteA
|
||||
func (rpc *Server) WebsiteUpdateContent(ctx context.Context, req *clientpb.WebsiteAddContent) (*clientpb.Website, error) {
|
||||
dbWebsite, err := website.WebsiteByName(req.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
for _, content := range req.Contents {
|
||||
website.AddContent(dbWebsite.Name, content)
|
||||
@@ -153,7 +157,7 @@ func (rpc *Server) WebsiteRemoveContent(ctx context.Context, req *clientpb.Websi
|
||||
err := website.RemoveContent(req.Name, path)
|
||||
if err != nil {
|
||||
rpcWebsiteLog.Errorf("Failed to remove content %s", err)
|
||||
return nil, err
|
||||
return nil, rpcError(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+9
-8
@@ -20,7 +20,6 @@ package rpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -33,8 +32,10 @@ import (
|
||||
"github.com/bishopfox/sliver/server/db"
|
||||
"github.com/bishopfox/sliver/server/log"
|
||||
"github.com/bishopfox/sliver/server/version"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/credentials"
|
||||
"google.golang.org/grpc/peer"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
)
|
||||
@@ -106,7 +107,7 @@ func (rpc *Server) GenericHandler(req GenericRequest, resp GenericResponse) erro
|
||||
}
|
||||
if request.Async {
|
||||
err = rpc.asyncGenericHandler(req, resp)
|
||||
return err
|
||||
return rpcError(err)
|
||||
}
|
||||
|
||||
// Sync request
|
||||
@@ -117,18 +118,18 @@ func (rpc *Server) GenericHandler(req GenericRequest, resp GenericResponse) erro
|
||||
|
||||
reqData, err := proto.Marshal(req)
|
||||
if err != nil {
|
||||
return err
|
||||
return rpcError(err)
|
||||
}
|
||||
|
||||
data, err := session.Request(sliverpb.MsgNumber(req), rpc.getTimeout(req), reqData)
|
||||
if err != nil {
|
||||
return err
|
||||
return rpcError(err)
|
||||
}
|
||||
err = proto.Unmarshal(data, resp)
|
||||
if err != nil {
|
||||
return err
|
||||
return rpcError(err)
|
||||
}
|
||||
return rpc.getError(resp)
|
||||
return rpcError(rpc.getError(resp))
|
||||
}
|
||||
|
||||
// asyncGenericHandler - Generic handler for async request/response's for beacon tasks
|
||||
@@ -151,7 +152,7 @@ func (rpc *Server) asyncGenericHandler(req GenericRequest, resp GenericResponse)
|
||||
request.BeaconID = ""
|
||||
reqData, err := proto.Marshal(req)
|
||||
if err != nil {
|
||||
return err
|
||||
return rpcError(err)
|
||||
}
|
||||
taskResponse := resp.GetResponse()
|
||||
taskResponse.Async = true
|
||||
@@ -208,7 +209,7 @@ func (rpc *Server) getTimeout(req GenericRequest) time.Duration {
|
||||
func (rpc *Server) getError(resp GenericResponse) error {
|
||||
respHeader := resp.GetResponse()
|
||||
if respHeader != nil && respHeader.Err != "" {
|
||||
return errors.New(respHeader.Err)
|
||||
return status.Error(codes.FailedPrecondition, respHeader.Err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user