Skip to content

Commit

Permalink
golint fixes in server/
Browse files Browse the repository at this point in the history
  • Loading branch information
moloch-- committed Jul 4, 2021
1 parent 9a5d694 commit b800448
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 13 deletions.
2 changes: 1 addition & 1 deletion server/configs/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const (
)

var (
// ErrInvalidDialect -
// ErrInvalidDialect - An invalid dialect was specified
ErrInvalidDialect = errors.New("Invalid SQL Dialect")

databaseConfigLog = log.NamedLogger("config", "database")
Expand Down
4 changes: 4 additions & 0 deletions server/configs/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ type WGJobConfig struct {
KeyPort uint16 `json:"key_port"`
JobID string `json:"jobid"`
}

// DNSJobConfig - Persistent DNS job config
type DNSJobConfig struct {
Domains []string `json:"domains"`
Canaries bool `json:"canaries"`
Expand All @@ -91,6 +93,7 @@ type DNSJobConfig struct {
JobID string `json:"jobid"`
}

// HTTPJobConfig - Persistent HTTP job config
type HTTPJobConfig struct {
Domain string `json:"domain"`
Host string `json:"host"`
Expand All @@ -103,6 +106,7 @@ type HTTPJobConfig struct {
JobID string `json:"jobid"`
}

// WatchTowerConfig - Watch Tower job config
type WatchTowerConfig struct {
VTApiKey string `json:"vt_api_key"`
XForceApiKey string `json:"xforce_api_key"`
Expand Down
1 change: 1 addition & 0 deletions server/db/models/wgkeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func (c *WGKeys) BeforeCreate(tx *gorm.DB) (err error) {
return nil
}

// WGPeer- WGPeer database model
type WGPeer struct {
// gorm.Model
ID uuid.UUID `gorm:"primaryKey;->;<-:create;type:uuid;"`
Expand Down
11 changes: 10 additions & 1 deletion server/loot/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,21 @@ import (
)

var (
// ErrInvalidLootID - Invalid Loot ID
ErrInvalidLootID = errors.New("invalid loot id")
ErrLootNotFound = errors.New("loot not found")
// ErrLootNotFound - Loot not found
ErrLootNotFound = errors.New("loot not found")

lootLog = log.NamedLogger("loot", "backend")
)

// LocalBackend - A loot backend that saves files locally to disk
type LocalBackend struct {
LocalFileDir string
LocalCredDir string
}

// Add - Add a piece of loot
func (l *LocalBackend) Add(loot *clientpb.Loot) (*clientpb.Loot, error) {
dbLoot := &models.Loot{
Name: loot.GetName(),
Expand Down Expand Up @@ -90,6 +94,7 @@ func (l *LocalBackend) Add(loot *clientpb.Loot) (*clientpb.Loot, error) {
return loot, err
}

// Update - Update metadata about loot, currently only 'name' can be changed
func (l *LocalBackend) Update(lootReq *clientpb.Loot) (*clientpb.Loot, error) {
dbSession := db.Session()
lootUUID, err := uuid.FromString(lootReq.LootID)
Expand All @@ -112,6 +117,7 @@ func (l *LocalBackend) Update(lootReq *clientpb.Loot) (*clientpb.Loot, error) {
return l.GetContent(lootReq.LootID, false)
}

// Rm - Remove a piece of loot
func (l *LocalBackend) Rm(lootID string) error {
dbSession := db.Session()
lootUUID, err := uuid.FromString(lootID)
Expand Down Expand Up @@ -146,6 +152,7 @@ func (l *LocalBackend) Rm(lootID string) error {
return result.Error
}

// GetContent - Get the content of a piece of loot
func (l *LocalBackend) GetContent(lootID string, eager bool) (*clientpb.Loot, error) {
dbSession := db.Session()
lootUUID, err := uuid.FromString(lootID)
Expand Down Expand Up @@ -198,6 +205,7 @@ func (l *LocalBackend) GetContent(lootID string, eager bool) (*clientpb.Loot, er
return loot, nil
}

// All - Get all loot
func (l *LocalBackend) All() *clientpb.AllLoot {
dbSession := db.Session()
allDBLoot := []*models.Loot{}
Expand All @@ -221,6 +229,7 @@ func (l *LocalBackend) All() *clientpb.AllLoot {
return all
}

// AllOf - Get all loot of a particular loot type
func (l *LocalBackend) AllOf(lootType clientpb.LootType) *clientpb.AllLoot {
dbSession := db.Session()
allDBLoot := []*models.Loot{}
Expand Down
19 changes: 12 additions & 7 deletions server/loot/loot.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const (
MaxLootSize = 2 * 1024 * 1024 * 1024 // 2Gb, shouldn't matter the gRPC message size limit is 2Gb
)

// LootBackend - The interface any loot backend must implement
type LootBackend interface {
Add(*clientpb.Loot) (*clientpb.Loot, error)
Rm(string) error
Expand All @@ -40,11 +41,12 @@ type LootBackend interface {
AllOf(clientpb.LootType) *clientpb.AllLoot
}

// LootStore - The struct that represents the loot store
type LootStore struct {
backend LootBackend
mirrors []LootBackend
}

// Add - Add a piece of loot to the loot store
func (l *LootStore) Add(lootReq *clientpb.Loot) (*clientpb.Loot, error) {
if lootReq.File != nil && MaxLootSize < len(lootReq.File.Data) {
return nil, errors.New("max loot size exceeded")
Expand All @@ -53,12 +55,10 @@ func (l *LootStore) Add(lootReq *clientpb.Loot) (*clientpb.Loot, error) {
if err != nil {
return nil, err
}
for _, mirror := range l.mirrors {
mirror.Add(loot)
}
return loot, nil
}

// Update - Update a piece of loot in the loot store
func (l *LootStore) Update(lootReq *clientpb.Loot) (*clientpb.Loot, error) {
loot, err := l.backend.Update(lootReq)
if err != nil {
Expand All @@ -67,29 +67,31 @@ func (l *LootStore) Update(lootReq *clientpb.Loot) (*clientpb.Loot, error) {
return loot, nil
}

// Remove - Remove a piece of loot from the loot store
func (l *LootStore) Rm(lootID string) error {
err := l.backend.Rm(lootID)
if err != nil {
return err
}
for _, mirror := range l.mirrors {
mirror.Rm(lootID)
}
return nil
}

// GetContent - Get the content of a piece of loot from the loot store
func (l *LootStore) GetContent(lootID string, eager bool) (*clientpb.Loot, error) {
return l.backend.GetContent(lootID, eager)
}

// All - Get all loot from the loot store
func (l *LootStore) All() *clientpb.AllLoot {
return l.backend.All()
}

// AllOf - Get loot of a particular type from the loot store
func (l *LootStore) AllOf(lootType clientpb.LootType) *clientpb.AllLoot {
return l.backend.AllOf(lootType)
}

// GetLootStore - Get an instances of the core LootStore
func GetLootStore() *LootStore {
return &LootStore{
backend: &LocalBackend{
Expand All @@ -99,6 +101,7 @@ func GetLootStore() *LootStore {
}
}

// GetLootDir - Get the directory that contains all loot
func GetLootDir() string {
lootDir := filepath.Join(assets.GetRootAppDir(), "loot")
if _, err := os.Stat(lootDir); os.IsNotExist(err) {
Expand All @@ -110,6 +113,7 @@ func GetLootDir() string {
return lootDir
}

// GetLootFileDir - Get the subdirectory where loot files are stored
func GetLootFileDir() string {
lootFileDir := filepath.Join(GetLootDir(), "files")
if _, err := os.Stat(lootFileDir); os.IsNotExist(err) {
Expand All @@ -121,6 +125,7 @@ func GetLootFileDir() string {
return lootFileDir
}

// GetLootCredentialDir - Get the subdirectory where loot credentials are stored
func GetLootCredentialDir() string {
lootCredDir := filepath.Join(GetLootDir(), "credentials")
if _, err := os.Stat(lootCredDir); os.IsNotExist(err) {
Expand Down
4 changes: 2 additions & 2 deletions server/rpc/rpc-shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var (
)

// Shell - Open an interactive shell
func (s *Server) Shell(ctx context.Context, req *sliverpb.ShellReq) (*sliverpb.Shell, error) {
func (rpc *Server) Shell(ctx context.Context, req *sliverpb.ShellReq) (*sliverpb.Shell, error) {
session := core.Sessions.Get(req.Request.SessionID)
if session == nil {
return nil, ErrInvalidSessionID
Expand All @@ -46,7 +46,7 @@ func (s *Server) Shell(ctx context.Context, req *sliverpb.ShellReq) (*sliverpb.S
if err != nil {
return nil, err
}
data, err := session.Request(sliverpb.MsgNumber(req), s.getTimeout(req), reqData)
data, err := session.Request(sliverpb.MsgNumber(req), rpc.getTimeout(req), reqData)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions server/rpc/rpc-tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (s *Server) TunnelData(stream rpcpb.SliverRPC_TunnelDataServer) error {

go func() {
session := core.Sessions.Get(tunnel.SessionID)
send_cache, _ := toImplantCache[tunnel.ID]
sendCache, _ := toImplantCache[tunnel.ID]
for data := range tunnel.ToImplant {
tunnelLog.Debugf("Tunnel %d: To implant %d byte(s), seq: %d", tunnel.ID, len(data), tunnel.ToImplantSequence)
tunnelData := sliverpb.TunnelData{
Expand All @@ -181,7 +181,7 @@ func (s *Server) TunnelData(stream rpcpb.SliverRPC_TunnelDataServer) error {
Closed: false,
}
// Add tunnel data to cache
send_cache[tunnelData.Sequence] = &tunnelData
sendCache[tunnelData.Sequence] = &tunnelData

data, _ := proto.Marshal(&tunnelData)
tunnel.ToImplantSequence++
Expand Down

0 comments on commit b800448

Please sign in to comment.