Skip to content

Commit

Permalink
Various golint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
moloch-- committed Jul 4, 2021
1 parent 7321f62 commit 53d6d14
Show file tree
Hide file tree
Showing 25 changed files with 81 additions and 29 deletions.
2 changes: 1 addition & 1 deletion client/command/exec/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/desertbit/grumble"
)

// Execute - Run a command on the remote system
// ExecuteCmd - Run a command on the remote system
func ExecuteCmd(ctx *grumble.Context, con *console.SliverConsoleClient) {
session := con.ActiveSession.GetInteractive()
if session == nil {
Expand Down
1 change: 1 addition & 0 deletions client/command/filesystem/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func LsCmd(ctx *grumble.Context, con *console.SliverConsoleClient) {
}
}

// PrintLs - Display an sliverpb.Ls object
func PrintLs(stdout io.Writer, ls *sliverpb.Ls) {
fmt.Fprintf(stdout, "%s\n", ls.Path)
fmt.Fprintf(stdout, "%s\n", strings.Repeat("=", len(ls.Path)))
Expand Down
27 changes: 19 additions & 8 deletions client/command/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,28 @@ import (
)

const (
DefaultMTLSLPort = 8888
DefaultWGLPort = 53
DefaultWGNPort = 8888
DefaultWGKeyExPort = 1337
DefaultHTTPLPort = 80
DefaultHTTPSLPort = 443
DefaultDNSLPort = 53
// DefaultMTLSLPort is the default port for mtls
DefaultMTLSLPort = 8888
// DefaultWGPort is the default port for wg
DefaultWGLPort = 53
// DefaultWGNPort is the default n port for wg
DefaultWGNPort = 8888
// DefaultWGKeyExPort is the default port for wg key exchange
DefaultWGKeyExPort = 1337
// DefaultHTTPLPort is the default port for http
DefaultHTTPLPort = 80
// DefaultHTTPSLPort is the default port for https
DefaultHTTPSLPort = 443
// DefaultDNSLPortis the default port for dns
DefaultDNSLPort = 53
// DefaultTCPPivotPort is the default port for tcp pivots
DefaultTCPPivotPort = 9898

// DefaultReconnect is the default reconnect time
DefaultReconnect = 60
DefaultPoll = 1
// DefaultPoll is the default poll interval
DefaultPoll = 1
// DefaultMaxErrors is the default max reconnection errors before giving up
DefaultMaxErrors = 1000
)

Expand Down
5 changes: 4 additions & 1 deletion client/command/loot/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ import (
)

var (
// ErrInvalidFileType - Invalid file type
ErrInvalidFileType = errors.New("invalid file type")
// ErrInvalidLootType - Invalid loot type
ErrInvalidLootType = errors.New("invalid loot type")
ErrNoLootFileData = errors.New("no loot file data")
// ErrNoLootFileData - No loot file data
ErrNoLootFileData = errors.New("no loot file data")
)

// AddLootFile - Add a file as loot
Expand Down
1 change: 1 addition & 0 deletions client/command/loot/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/desertbit/grumble"
)

// LootAddRemoteCmd - Add a file from the remote system to the server as loot
func LootAddRemoteCmd(ctx *grumble.Context, con *console.SliverConsoleClient) {
session := con.ActiveSession.GetInteractive()
if session == nil {
Expand Down
1 change: 1 addition & 0 deletions client/command/loot/rename.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/desertbit/grumble"
)

// LootRenameCmd - Rename a piece of loot
func LootRenameCmd(ctx *grumble.Context, con *console.SliverConsoleClient) {
loot, err := SelectLoot(ctx, con.Rpc)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions client/command/processes/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ func printProcInfo(table *tabwriter.Writer, proc *commonpb.Process, cmdLine bool
return color
}

// GetPIDByName - Get a PID by name from the active session
func GetPIDByName(ctx *grumble.Context, name string, con *console.SliverConsoleClient) int {
ps, err := con.Rpc.Ps(context.Background(), &sliverpb.PsReq{
Request: con.ActiveSession.Request(ctx),
Expand Down
4 changes: 3 additions & 1 deletion client/command/sessions/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ import (
)

var (
ErrNoSessions = errors.New("no sessions")
// ErrNoSessions - No sessions available
ErrNoSessions = errors.New("no sessions")
// ErrNoSelection - No selection made
ErrNoSelection = errors.New("no selection")
)

Expand Down
8 changes: 7 additions & 1 deletion client/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,26 @@ package constants

// Meta
const (
// KeepAliveStr - Keep alive constant
KeepAliveStr = "keepalive"
)

const (
// LastUpdateCheckFileName - Last update check file name
LastUpdateCheckFileName = "last_update_check"
)

// Events
const (
UpdateStr = "update"
// UpdateStr - "update"
UpdateStr = "update"
// VersionStr - "version"
VersionStr = "version"

// EventStr - "event"
EventStr = "event"

// ServersStr - "server-error"
ServerErrorStr = "server-error"

// ConnectedEvent - Sliver Connected
Expand Down
6 changes: 6 additions & 0 deletions implant/sliver/forwarder/forwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,38 @@ var (
socksServers map[int]*WGSocksServer
)

// GetTCPForwarders - Returns a map of WireGuard TCP forwarders
func GetTCPForwarders() map[int]*WGTCPForwarder {
return tcpForwarders
}

// GetSocksServers - Returns a map of WireGuard SOCKS proxies
func GetSocksServers() map[int]*WGSocksServer {
return socksServers
}

// GetTCPForwarder - Returns a WireGuard TCP forwarder by id
func GetTCPForwarder(id int) *WGTCPForwarder {
if f, ok := tcpForwarders[id]; ok {
return f
}
return nil
}

// RemoteTCPForwarder - Remove a TCP forwarder by id
func RemoveTCPForwarder(id int) {
delete(tcpForwarders, id)
}

// GetSocksServer - Returns a WireGuard SOCKS proxy by id
func GetSocksServer(id int) *WGSocksServer {
if s, ok := socksServers[id]; ok {
return s
}
return nil
}

// RemoveSocksServer - Remove a SOCKS proxy by id
func RemoveSocksServer(id int) {
delete(socksServers, id)
}
Expand Down
6 changes: 6 additions & 0 deletions implant/sliver/forwarder/portforward.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

var tcpForwarderID = 0

// WGTCPForwarder - A WireGuard TCP forwarder
type WGTCPForwarder struct {
ID int
tunIP string
Expand All @@ -27,6 +28,7 @@ type WGTCPForwarder struct {
listener net.Listener
}

// NewWGTCPForwarder - Create a new WireGuard TCP forwarder
func NewWGTCPForwarder(targetAddress string, tunIP string, tunPort int, tnet *netstack.Net) *WGTCPForwarder {
tf := &WGTCPForwarder{
tunIP: tunIP,
Expand All @@ -41,14 +43,17 @@ func NewWGTCPForwarder(targetAddress string, tunIP string, tunPort int, tnet *ne
return tf
}

// LocalAddr - The local address
func (f *WGTCPForwarder) LocalAddr() string {
return fmt.Sprintf("%s:%d", f.tunIP, f.tunPort)
}

// RemoteAddr - The remote address
func (f *WGTCPForwarder) RemoteAddr() string {
return f.targetAddress
}

// Start - Start the forwarder
func (f *WGTCPForwarder) Start() error {
// Start wg net listener
var err error
Expand Down Expand Up @@ -80,6 +85,7 @@ func (f *WGTCPForwarder) Start() error {
}
}

// Stop - Stop the forwarder
func (f *WGTCPForwarder) Stop() {
// {{if .Config.Debug}}
log.Printf("Stop called, closing channel\n")
Expand Down
1 change: 1 addition & 0 deletions implant/sliver/hostuuid/uuid_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"io/ioutil"
)

// GetUUID - Get a system specific UUID
func GetUUID() string {
uuid, err := ioutil.ReadFile("/etc/machine-id")
// UUID length is 32 plus newline
Expand Down
2 changes: 1 addition & 1 deletion implant/sliver/proxy/provider_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type providerLinux struct {
}

/*
Create a new Provider which is used to retrieve Proxy configurations.
NewProvider - Create a new Provider which is used to retrieve Proxy configurations.
Params:
configFile: Optional. Path to a configuration file which specifies proxies.
*/
Expand Down
4 changes: 2 additions & 2 deletions implant/sliver/shell/pty/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
"os"
)

// ErrUnsupported is returned if a function is not
// ErrUnsupported - is returned if a function is not
// available on the current platform.
var ErrUnsupported = errors.New("unsupported")

// Opens a pty and its corresponding tty.
// Open - Opens a pty and its corresponding tty.
func Open() (pty, tty *os.File, err error) {
return open()
}
1 change: 1 addition & 0 deletions implant/sliver/shell/ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func getClient(host string, port uint16, username string, password string, privK

}

// RunSSHCommand - SSH to a host and execute a command
func RunSSHCommand(host string, port uint16, username string, password string, privKey []byte, command string) (string, string, error) {
var (
stdout bytes.Buffer
Expand Down
10 changes: 7 additions & 3 deletions server/c2/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var (
jobLog = log.NamedLogger("c2", "jobs")
)

// StartMTLSListenerJob - Start an mTLS listener as a job
func StartMTLSListenerJob(host string, listenPort uint16) (*core.Job, error) {
bind := fmt.Sprintf("%s:%d", host, listenPort)
ln, err := StartMutualTLSListener(host, listenPort)
Expand Down Expand Up @@ -68,6 +69,7 @@ func StartMTLSListenerJob(host string, listenPort uint16) (*core.Job, error) {
return job, nil
}

// StartWGListenerJob - Start a WireGuard listener as a job
func StartWGListenerJob(listenPort uint16, nListenPort uint16, keyExchangeListenPort uint16) (*core.Job, error) {
ln, dev, currenWGConf, err := StartWGListener(listenPort, nListenPort, keyExchangeListenPort)
if err != nil {
Expand Down Expand Up @@ -143,6 +145,7 @@ func StartWGListenerJob(listenPort uint16, nListenPort uint16, keyExchangeListen
return job, nil
}

// StartDNSListenerJob - Start a DNS listener as a job
func StartDNSListenerJob(domains []string, canaries bool, listenPort uint16) (*core.Job, error) {
server := StartDNSListener(domains, canaries)
description := fmt.Sprintf("%s (canaries %v)", strings.Join(domains, " "), canaries)
Expand Down Expand Up @@ -185,6 +188,7 @@ func StartDNSListenerJob(domains []string, canaries bool, listenPort uint16) (*c
return job, nil
}

// StartHTTPListenerJob - Start a HTTP listener as a job
func StartHTTPListenerJob(conf *HTTPServerConfig) (*core.Job, error) {
server, err := StartHTTPSListener(conf)
if err != nil {
Expand Down Expand Up @@ -243,7 +247,7 @@ func StartHTTPListenerJob(conf *HTTPServerConfig) (*core.Job, error) {
return job, nil
}

// Start a TCP staging payload listener
// StartTCPStagerListenerJob - Start a TCP staging payload listener
func StartTCPStagerListenerJob(host string, port uint16, shellcode []byte) (*core.Job, error) {
ln, err := StartTCPListener(host, port, shellcode)
if err != nil {
Expand Down Expand Up @@ -277,7 +281,7 @@ func StartTCPStagerListenerJob(host string, port uint16, shellcode []byte) (*cor
return job, nil
}

// StartHTTPStagerListener - Start an HTTP(S) stager payload listener
// StartHTTPStagerListenerJob - Start an HTTP(S) stager payload listener
func StartHTTPStagerListenerJob(conf *HTTPServerConfig, data []byte) (*core.Job, error) {
server, err := StartHTTPSListener(conf)
if err != nil {
Expand Down Expand Up @@ -335,7 +339,7 @@ func StartHTTPStagerListenerJob(conf *HTTPServerConfig, data []byte) (*core.Job,
return job, nil
}

// Start persistent jobs
// StartPersistentJobs - Start persistent jobs
func StartPersistentJobs(cfg *configs.ServerConfig) error {
if cfg.Jobs == nil {
return nil
Expand Down
4 changes: 2 additions & 2 deletions server/c2/pivot.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,14 @@ func (h *PivotsMap) Session(pivotID uint32) *core.Session {
return (*h.Pivots)[pivotID]
}

// AddSliver - Add a sliver to the hive (atomically)
// AddSession - Add a sliver to the core (atomically)
func (h *PivotsMap) AddSession(pivotID uint32, session *core.Session) {
h.mutex.Lock()
defer h.mutex.Unlock()
(*h.Pivots)[pivotID] = session
}

// RemoveSliver - Remove a session from the hive (atomically)
// RemoveSession - Remove a session from the core (atomically)
func (h *PivotsMap) RemoveSession(pivotID uint32) {
h.mutex.Lock()
defer h.mutex.Unlock()
Expand Down
2 changes: 2 additions & 0 deletions server/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ var (
serverConfig = configs.GetServerConfig()
daemonLog = log.NamedLogger("daemon", "main")

// BlankHost is a blank hostname
BlankHost = "-"
// BlankPort is a blank port number
BlankPort = uint16(0)
)

Expand Down
5 changes: 2 additions & 3 deletions server/generate/binaries.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,10 +487,9 @@ func renderSliverGoCode(name string, config *models.ImplantConfig, goConfig *gog

if err != nil {
return "", fmt.Errorf("Failed to embed implant wg keys: %s", err)
} else {
config.WGImplantPrivKey = implantPrivKey
config.WGServerPubKey = serverPubKey
}
config.WGImplantPrivKey = implantPrivKey
config.WGServerPubKey = serverPubKey
}

// binDir - ~/.sliver/slivers/<os>/<arch>/<name>/bin
Expand Down
1 change: 1 addition & 0 deletions server/gogo/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ func GoVersion(config GoConfig) ([]byte, error) {
return GoCmd(config, wd, goCommand)
}

// GoToolDistList - Get a list of supported GOOS/GOARCH pairs
func GoToolDistList(config GoConfig) []string {
var goCommand = []string{"tool", "dist", "list"}
wd, _ := os.Getwd()
Expand Down
1 change: 1 addition & 0 deletions server/loot/loot.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
)

const (
// MaxLootSize - The maximum size of a loot file in bytes
MaxLootSize = 2 * 1024 * 1024 * 1024 // 2Gb, shouldn't matter the gRPC message size limit is 2Gb
)

Expand Down
3 changes: 2 additions & 1 deletion server/rpc/rpc-generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ func (rpc *Server) ShellcodeRDI(ctx context.Context, req *clientpb.ShellcodeRDIR
return &clientpb.ShellcodeRDI{Data: shellcode}, err
}

// GetCompiler - Get information about the internal Go compiler and its configuration
func (rpc *Server) GetCompiler(ctx context.Context, _ *commonpb.Empty) (*clientpb.Compiler, error) {
compiler := &clientpb.Compiler{
GOOS: runtime.GOOS,
Expand All @@ -244,6 +245,6 @@ func (rpc *Server) GetCompiler(ctx context.Context, _ *commonpb.Empty) (*clientp
UnsupportedTargets: generate.GetUnsupportedTargets(),
CrossCompilers: generate.GetCrossCompilers(),
}
rcpLog.Infof("GetCompiler = %v", compiler)
rcpLog.Debugf("GetCompiler = %v", compiler)
return compiler, nil
}
4 changes: 2 additions & 2 deletions server/rpc/rpc-loot.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (rpc *Server) LootUpdate(ctx context.Context, lootReq *clientpb.Loot) (*cli
return loot, err
}

// LootAll - Get a list of all loot of a specific type
// 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.LootID, true)
}
Expand All @@ -75,7 +75,7 @@ func (rpc *Server) LootAll(ctx context.Context, _ *commonpb.Empty) (*clientpb.Al
return loot.GetLootStore().All(), nil
}

// LootAll - Get a list of all loot of a specific type
// LootAllOf - Get a list of all loot of a specific type
func (rpc *Server) LootAllOf(ctx context.Context, lootReq *clientpb.Loot) (*clientpb.AllLoot, error) {
return loot.GetLootStore().AllOf(lootReq.Type), nil
}
Loading

0 comments on commit 53d6d14

Please sign in to comment.