Skip to content

Commit

Permalink
Refactor randomString to randomFileName
Browse files Browse the repository at this point in the history
  • Loading branch information
moloch-- committed Oct 1, 2022
1 parent 338b622 commit 794db93
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions client/command/exec/psexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@ package exec
import (
"context"
"fmt"
insecureRand "math/rand"
"os"
"strings"
"time"

insecureRand "math/rand"

"github.com/bishopfox/sliver/client/command/generate"
"github.com/bishopfox/sliver/client/command/settings"
"github.com/bishopfox/sliver/client/console"
"github.com/bishopfox/sliver/protobuf/clientpb"
"github.com/bishopfox/sliver/protobuf/commonpb"
"github.com/bishopfox/sliver/protobuf/sliverpb"
"github.com/bishopfox/sliver/server/codenames"
"github.com/bishopfox/sliver/util/encoders"
"github.com/desertbit/grumble"
)
Expand Down Expand Up @@ -101,7 +103,7 @@ func PsExecCmd(ctx *grumble.Context, con *console.SliverConsoleClient) {
serviceBinary = fileBytes
}

filename := randomString(10)
filename := randomFileName()
filePath := fmt.Sprintf("%s\\%s.exe", uploadPath, filename)
uploadGzip := new(encoders.Gzip).Encode(serviceBinary)
// upload to remote target
Expand Down Expand Up @@ -172,11 +174,28 @@ func PsExecCmd(ctx *grumble.Context, con *console.SliverConsoleClient) {
con.PrintInfof("Successfully removed service %s on %s\n", serviceName, hostname)
}

func randomString(length int) string {
var charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
b := make([]byte, length)
for i := range b {
b[i] = charset[insecureRand.Intn(len(charset))]
func randomFileName() string {
noun, _ := codenames.RandomNoun()
noun = strings.ToLower(noun)
switch insecureRand.Intn(3) {
case 0:
noun = strings.ToUpper(noun)
case 1:
noun = strings.ToTitle(noun)
}

separators := []string{"", "", "", "", "", ".", "-", "_", "--", "__"}
sep := separators[insecureRand.Intn(len(separators))]

alphanumeric := "abcdefghijklmnopqrstuvwxyz0123456789"
prefix := ""
for index := 0; index < insecureRand.Intn(3); index++ {
prefix += string(alphanumeric[insecureRand.Intn(len(alphanumeric))])
}
return string(b)
suffix := ""
for index := 0; index < insecureRand.Intn(6); index++ {
suffix += string(alphanumeric[insecureRand.Intn(len(alphanumeric))])
}

return fmt.Sprintf("%s%s%s%s%s", prefix, sep, noun, sep, suffix)
}

0 comments on commit 794db93

Please sign in to comment.