@@ -21,9 +21,11 @@ package exec
21
21
import (
22
22
"context"
23
23
"fmt"
24
+ "strings"
24
25
25
26
"github.com/bishopfox/sliver/client/console"
26
27
"github.com/bishopfox/sliver/protobuf/clientpb"
28
+ "github.com/bishopfox/sliver/protobuf/sliverpb"
27
29
"github.com/desertbit/grumble"
28
30
)
29
31
@@ -34,7 +36,36 @@ func MigrateCmd(ctx *grumble.Context, con *console.SliverConsoleClient) {
34
36
return
35
37
}
36
38
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
+ }
38
69
config := con .GetActiveSessionConfig ()
39
70
encoder := clientpb .ShellcodeEncoder_SHIKATA_GA_NAI
40
71
if ctx .Flags .Bool ("disable-sgn" ) {
0 commit comments