Skip to content

Commit

Permalink
Merge pull request #1655 from BishopFox/fix/init-logging
Browse files Browse the repository at this point in the history
Fix/init logging
  • Loading branch information
moloch-- authored Apr 30, 2024
2 parents fa7033f + 0a44fde commit eddfb70
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 16 deletions.
10 changes: 6 additions & 4 deletions client/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
"os"
"path"

"github.com/bishopfox/sliver/client/assets"
"github.com/bishopfox/sliver/client/console"
"github.com/bishopfox/sliver/client/version"
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)
Expand All @@ -34,8 +34,6 @@ const (
logFileName = "sliver-client.log"
)

var sliverServerVersion = fmt.Sprintf("v%s", version.FullVersion())

// Initialize logging.
func initLogging(appDir string) *os.File {
log.SetFlags(log.LstdFlags | log.Lshortfile)
Expand All @@ -48,6 +46,10 @@ func initLogging(appDir string) *os.File {
}

func init() {
appDir := assets.GetRootAppDir()
logFile := initLogging(appDir)
defer logFile.Close()

rootCmd.TraverseChildren = true

// Create the console client, without any RPC or commands bound to it yet.
Expand Down Expand Up @@ -90,7 +92,7 @@ var rootCmd = &cobra.Command{
// Execute - Execute root command.
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
fmt.Printf("root command: %s\n", err)
os.Exit(1)
}
}
22 changes: 18 additions & 4 deletions client/cli/console.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
package cli

/*
Sliver Implant Framework
Copyright (C) 2019 Bishop Fox
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import (
"fmt"

Expand All @@ -20,17 +38,13 @@ func consoleCmd(con *console.SliverClient) *cobra.Command {
}

consoleCmd.RunE, consoleCmd.PersistentPostRunE = consoleRunnerCmd(con, true)

return consoleCmd
}

func consoleRunnerCmd(con *console.SliverClient, run bool) (pre, post func(cmd *cobra.Command, args []string) error) {
var ln *grpc.ClientConn

pre = func(_ *cobra.Command, _ []string) error {
appDir := assets.GetRootAppDir()
logFile := initLogging(appDir)
defer logFile.Close()

configs := assets.GetConfigs()
if len(configs) == 0 {
Expand Down
20 changes: 19 additions & 1 deletion client/cli/implant.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
package cli

/*
Sliver Implant Framework
Copyright (C) 2019 Bishop Fox
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import (
"errors"

Expand All @@ -24,7 +42,7 @@ func implantCmd(con *console.SliverClient) *cobra.Command {
implantFlags.StringP("use", "s", "", "interact with a session")
cmd.Flags().AddFlagSet(implantFlags)

// Prerunners (console setup, connection, etc)
// Pre-runners (console setup, connection, etc)
cmd.PersistentPreRunE, cmd.PersistentPostRunE = makeRunners(cmd, con)

// Completions
Expand Down
2 changes: 1 addition & 1 deletion client/command/alias/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (ec *AliasManifest) getDefaultProcess(targetOS string) (proc string, err er
return
}

func (a *AliasManifest) getFileForTarget(cmdName string, targetOS string, targetArch string) (string, error) {
func (a *AliasManifest) getFileForTarget(_ string, targetOS string, targetArch string) (string, error) {
filePath := ""
for _, extFile := range a.Files {
if targetOS == extFile.OS && targetArch == extFile.Arch {
Expand Down
14 changes: 8 additions & 6 deletions client/command/extensions/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ func (e *ExtCommand) getFileForTarget(targetOS string, targetArch string) (strin
func ExtensionLoadCmd(cmd *cobra.Command, con *console.SliverClient, args []string) {
dirPath := args[0]
// dirPath := ctx.Args.String("dir-path")
manyfest, err := LoadExtensionManifest(filepath.Join(dirPath, ManifestFileName))
manifest, err := LoadExtensionManifest(filepath.Join(dirPath, ManifestFileName))
if err != nil {
return
}
// do not add if the command already exists
sliverMenu := con.App.Menu("implant")
for _, extCmd := range manyfest.ExtCommand {
for _, extCmd := range manifest.ExtCommand {
if CmdExists(extCmd.CommandName, sliverMenu.Command) {
con.PrintErrorf("%s command already exists\n", extCmd.CommandName)
confirm := false
Expand Down Expand Up @@ -184,7 +184,7 @@ func LoadExtensionManifest(manifestPath string) (*ExtensionManifest, error) {

func convertOldManifest(old *ExtensionManifest_) *ExtensionManifest {
ret := &ExtensionManifest{
Name: old.CommandName, //treating old commandname as the manifest name to avoid weird chars mostly
Name: old.CommandName, //treating old command name as the manifest name to avoid weird chars mostly
Version: old.Version,
ExtensionAuthor: old.ExtensionAuthor,
OriginalAuthor: old.OriginalAuthor,
Expand Down Expand Up @@ -215,7 +215,9 @@ func ParseExtensionManifest(data []byte) (*ExtensionManifest, error) {
err := json.Unmarshal(data, &extManifest)
if err != nil || len(extManifest.ExtCommand) == 0 { //extensions must have at least one command to be sensible
//maybe it's an old manifest
log.Println(err)
if err != nil {
log.Printf("extension load error: %s", err)
}
oldmanifest := &ExtensionManifest_{}
err := json.Unmarshal(data, &oldmanifest)
if err != nil {
Expand Down Expand Up @@ -412,7 +414,7 @@ func loadExtension(goos string, goarch string, checkCache bool, ext *ExtCommand,
return nil
}

func registerExtension(goos string, ext *ExtCommand, binData []byte, cmd *cobra.Command, con *console.SliverClient) error {
func registerExtension(goos string, _ *ExtCommand, binData []byte, cmd *cobra.Command, con *console.SliverClient) error {
//set extension name to a hash of the data to avoid loading more than one instance
bd := sha256.Sum256(binData)
name := hex.EncodeToString(bd[:])
Expand Down Expand Up @@ -567,7 +569,7 @@ func PrintExtOutput(extName string, commandName string, callExtension *sliverpb.
}
}

func getExtArgs(cmd *cobra.Command, args []string, binPath string, ext *ExtCommand) ([]byte, error) {
func getExtArgs(_ *cobra.Command, args []string, _ string, ext *ExtCommand) ([]byte, error) {
var err error
argsBuffer := core.BOFArgsBuffer{
Buffer: new(bytes.Buffer),
Expand Down

0 comments on commit eddfb70

Please sign in to comment.