Skip to content

Commit

Permalink
Merge branch 'master' into ssh
Browse files Browse the repository at this point in the history
  • Loading branch information
rkervella committed Jul 1, 2021
2 parents dedcb42 + f6f68dc commit d213728
Show file tree
Hide file tree
Showing 9 changed files with 596 additions and 472 deletions.
15 changes: 15 additions & 0 deletions client/command/bind-commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -1947,6 +1947,21 @@ func BindCommands(app *grumble.App, rpc rpcpb.SliverRPCClient) {
},
HelpGroup: consts.GenericHelpGroup,
})
lootCmd.AddCommand(&grumble.Command{
Name: consts.RenameStr,
Help: "Re-name a piece of existing loot",
LongHelp: help.GetHelpFor([]string{consts.LootStr, consts.RenameStr}),
Flags: func(f *grumble.Flags) {
f.Int("t", "timeout", defaultTimeout, "command timeout in seconds")
},
Run: func(ctx *grumble.Context) error {
fmt.Println()
lootRename(ctx, rpc)
fmt.Println()
return nil
},
HelpGroup: consts.GenericHelpGroup,
})
lootCmd.AddCommand(&grumble.Command{
Name: consts.LootFetchStr,
Help: "Fetch a piece of loot from the server's loot store",
Expand Down
22 changes: 22 additions & 0 deletions client/command/loot.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,28 @@ func lootAddRemote(ctx *grumble.Context, rpc rpcpb.SliverRPCClient) {
fmt.Printf(Info+"Successfully added loot to server (%s)\n", loot.LootID)
}

func lootRename(ctx *grumble.Context, rpc rpcpb.SliverRPCClient) {
loot, err := selectLoot(ctx, rpc)
if err != nil {
fmt.Printf(Warn+"%s\n", err)
return
}
oldName := loot.Name
newName := ""
prompt := &survey.Input{Message: "Enter new name: "}
survey.AskOne(prompt, &newName)

loot, err = rpc.LootUpdate(context.Background(), &clientpb.Loot{
LootID: loot.LootID,
Name: newName,
})
if err != nil {
fmt.Printf(Warn+"%s\n", err)
return
}
fmt.Printf(Info+"Renamed %s -> %s\n", oldName, loot.Name)
}

func lootRm(ctx *grumble.Context, rpc rpcpb.SliverRPCClient) {
loot, err := selectLoot(ctx, rpc)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions client/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ const (
LootFetchStr = "fetch"
LootCredsStr = "creds"

RenameStr = "rename"

ImplantBuildsStr = "implants"
ListCanariesStr = "canaries"

Expand Down
875 changes: 440 additions & 435 deletions protobuf/rpcpb/services.pb.go

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion protobuf/rpcpb/services.proto
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ service SliverRPC {
// *** Loot ***
rpc LootAdd(clientpb.Loot) returns(clientpb.Loot);
rpc LootRm(clientpb.Loot) returns(commonpb.Empty);
rpc LootUpdate(clientpb.Loot) returns(clientpb.Loot);
rpc LootContent(clientpb.Loot) returns(clientpb.Loot);
rpc LootAll(commonpb.Empty) returns(clientpb.AllLoot);
rpc LootAllOf(clientpb.Loot) returns(clientpb.AllLoot);
rpc LootContent(clientpb.Loot) returns(clientpb.Loot);

// *** Implants ***
rpc Generate(clientpb.GenerateReq) returns (clientpb.Generate);
Expand Down
96 changes: 66 additions & 30 deletions protobuf/rpcpb/services_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions server/loot/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,28 @@ func (l *LocalBackend) Add(loot *clientpb.Loot) (*clientpb.Loot, error) {
return loot, err
}

func (l *LocalBackend) Update(lootReq *clientpb.Loot) (*clientpb.Loot, error) {
dbSession := db.Session()
lootUUID, err := uuid.FromString(lootReq.LootID)
if err != nil {
return nil, ErrInvalidLootID
}
dbLoot := &models.Loot{}
result := dbSession.Where(&models.Loot{ID: lootUUID}).First(dbLoot)
if errors.Is(result.Error, db.ErrRecordNotFound) {
return nil, ErrLootNotFound
}

if dbLoot.Name != lootReq.Name {
err = dbSession.Model(&dbLoot).Update("Name", lootReq.Name).Error
if err != nil {
return nil, err
}
}

return l.GetContent(lootReq.LootID, false)
}

func (l *LocalBackend) Rm(lootID string) error {
dbSession := db.Session()
lootUUID, err := uuid.FromString(lootID)
Expand Down
11 changes: 10 additions & 1 deletion server/loot/loot.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ const (
type LootBackend interface {
Add(*clientpb.Loot) (*clientpb.Loot, error)
Rm(string) error
Update(*clientpb.Loot) (*clientpb.Loot, error)
GetContent(string, bool) (*clientpb.Loot, error)
All() *clientpb.AllLoot
AllOf(clientpb.LootType) *clientpb.AllLoot
GetContent(string, bool) (*clientpb.Loot, error)
}

type LootStore struct {
Expand All @@ -58,6 +59,14 @@ func (l *LootStore) Add(lootReq *clientpb.Loot) (*clientpb.Loot, error) {
return loot, nil
}

func (l *LootStore) Update(lootReq *clientpb.Loot) (*clientpb.Loot, error) {
loot, err := l.backend.Update(lootReq)
if err != nil {
return nil, err
}
return loot, nil
}

func (l *LootStore) Rm(lootID string) error {
err := l.backend.Rm(lootID)
if err != nil {
Expand Down
22 changes: 17 additions & 5 deletions server/rpc/rpc-loot.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,23 @@ func (rpc *Server) LootRm(ctx context.Context, lootReq *clientpb.Loot) (*commonp
return &commonpb.Empty{}, err
}

// LootUpdate - Update loot metadata
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
}
core.EventBroker.Publish(core.Event{
EventType: consts.LootAddedEvent,
})
return loot, err
}

// LootAll - 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.LootID, true)
}

// LootAll - Get a list of all loot
func (rpc *Server) LootAll(ctx context.Context, _ *commonpb.Empty) (*clientpb.AllLoot, error) {
return loot.GetLootStore().All(), nil
Expand All @@ -62,8 +79,3 @@ func (rpc *Server) LootAll(ctx context.Context, _ *commonpb.Empty) (*clientpb.Al
func (rpc *Server) LootAllOf(ctx context.Context, lootReq *clientpb.Loot) (*clientpb.AllLoot, error) {
return loot.GetLootStore().AllOf(lootReq.Type), nil
}

// LootAll - 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.LootID, true)
}

0 comments on commit d213728

Please sign in to comment.