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

Method executeChunks

internal/bridge/module_download.go:176–209  ·  view source on GitHub ↗
(ctx ModuleContext, sessionID string, taskID uint32, shellTool string, sess *sessions.Session, chunks []sessions.DownloadChunk, ch <-chan *sessions.CommandResult)

Source from the content-addressed store, hash-verified

174}
175
176func (m *DownloadModule) executeChunks(ctx ModuleContext, sessionID string, taskID uint32, shellTool string, sess *sessions.Session, chunks []sessions.DownloadChunk, ch <-chan *sessions.CommandResult) {
177 var assembled []byte
178
179 for i, chunk := range chunks {
180 args := sessions.BuildCommandArguments(sess, shellTool, chunk.Command)
181 if _, ok := enqueueToolAction(ctx, sessionID, taskID, shellTool, args); !ok {
182 return
183 }
184 log.Infof("[bridge] enqueued download chunk %d/%d for session %s", i+1, len(chunks), sessionID)
185
186 // Wait for chunk result.
187 result, ok := awaitTaskResult(ch, taskID)
188 if !ok {
189 log.Errorf("[bridge] download chunk %d/%d failed for session %s", i+1, len(chunks), sessionID)
190 ctx.Tasks.Fail(sessionID, taskID, "chunk failed")
191 return
192 }
193
194 decoded, err := sessions.DecodeBase64Output(result.Output)
195 if err != nil {
196 log.Errorf("[bridge] failed to decode download chunk %d/%d for session %s: %v", i+1, len(chunks), sessionID, err)
197 ctx.Tasks.Fail(sessionID, taskID, "decode failed")
198 return
199 }
200
201 assembled = append(assembled, decoded...)
202 log.Infof("[bridge] download chunk %d/%d decoded: %d bytes (total: %d) for session %s",
203 i+1, len(chunks), len(decoded), len(assembled), sessionID)
204 }
205
206 log.Infof("[bridge] all %d download chunks assembled: %d bytes for session %s", len(chunks), len(assembled), sessionID)
207 sendDownloadResp(ctx, sessionID, taskID, assembled)
208 ctx.Tasks.Complete(sessionID, taskID)
209}
210
211// sendDownloadResp sends a DownloadResponse via ModuleContext.
212func sendDownloadResp(ctx ModuleContext, sessionID string, taskID uint32, content []byte) {

Callers 1

probeAndDownloadMethod · 0.95

Calls 7

BuildCommandArgumentsFunction · 0.92
DecodeBase64OutputFunction · 0.92
enqueueToolActionFunction · 0.85
awaitTaskResultFunction · 0.85
sendDownloadRespFunction · 0.85
FailMethod · 0.80
CompleteMethod · 0.45

Tested by

no test coverage detected