Skip to content

Commit a468ec8

Browse files
committed
Allow migrate to use process names
1 parent 40aa052 commit a468ec8

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

client/command/commands.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -1205,12 +1205,10 @@ func BindCommands(con *console.SliverConsoleClient) {
12051205
con.Println()
12061206
return nil
12071207
},
1208-
Args: func(a *grumble.Args) {
1209-
a.Uint("pid", "pid")
1210-
},
12111208
Flags: func(f *grumble.Flags) {
12121209
f.Bool("S", "disable-sgn", true, "disable shikata ga nai shellcode encoder")
1213-
1210+
f.Uint("p", "pid", 0, "process id to migrate into")
1211+
f.String("n", "process-name", "", "name of the process to migrate into")
12141212
f.Int("t", "timeout", defaultTimeout, "command timeout in seconds")
12151213
},
12161214
HelpGroup: consts.SliverWinHelpGroup,

client/command/exec/migrate.go

+32-1
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ package exec
2121
import (
2222
"context"
2323
"fmt"
24+
"strings"
2425

2526
"github.com/bishopfox/sliver/client/console"
2627
"github.com/bishopfox/sliver/protobuf/clientpb"
28+
"github.com/bishopfox/sliver/protobuf/sliverpb"
2729
"github.com/desertbit/grumble"
2830
)
2931

@@ -34,7 +36,36 @@ func MigrateCmd(ctx *grumble.Context, con *console.SliverConsoleClient) {
3436
return
3537
}
3638

37-
pid := ctx.Args.Uint("pid")
39+
pid := ctx.Flags.Uint("pid")
40+
procName := ctx.Flags.String("process-name")
41+
if pid == 0 && procName == "" {
42+
con.PrintErrorf("Error: Must specify either a PID or process name\n")
43+
return
44+
}
45+
if procName != "" {
46+
procCtrl := make(chan bool)
47+
con.SpinUntil(fmt.Sprintf("Searching for %s ...", procName), procCtrl)
48+
proc, err := con.Rpc.Ps(context.Background(), &sliverpb.PsReq{
49+
Request: con.ActiveTarget.Request(ctx),
50+
})
51+
if err != nil {
52+
con.PrintErrorf("Error: %v\n", err)
53+
return
54+
}
55+
procCtrl <- true
56+
<-procCtrl
57+
for _, p := range proc.GetProcesses() {
58+
if strings.ToLower(p.Executable) == strings.ToLower(procName) {
59+
pid = uint(p.Pid)
60+
break
61+
}
62+
}
63+
if pid == 0 {
64+
con.PrintErrorf("Error: Could not find process %s\n", procName)
65+
return
66+
}
67+
con.PrintInfof("Process name specified, overriding PID with %d\n", pid)
68+
}
3869
config := con.GetActiveSessionConfig()
3970
encoder := clientpb.ShellcodeEncoder_SHIKATA_GA_NAI
4071
if ctx.Flags.Bool("disable-sgn") {

0 commit comments

Comments
 (0)