Skip to content

Fix: SMB pivot session memory leak causing server OOM kill#340

Open
Cherno-x wants to merge 1 commit into
Adaptix-Framework:mainfrom
Cherno-x:fix/smb-session-memory-leak
Open

Fix: SMB pivot session memory leak causing server OOM kill#340
Cherno-x wants to merge 1 commit into
Adaptix-Framework:mainfrom
Cherno-x:fix/smb-session-memory-leak

Conversation

@Cherno-x

Copy link
Copy Markdown

Summary

  • Fix data starvation-accumulation cycle in extractPivotTasks: ensure a minimum 64KB allocation per pivot child so SMB agent tasks can be extracted instead of accumulating indefinitely
  • Cap Queue capacity at 65536 items: drop oldest/newest items when full instead of unbounded resize(), preventing memory from growing without limit
  • Update LastTick for non-async agents (SMB/TCP) in TsAgentProcessData so the server can track their liveness and detect stale sessions
  • Add bounds check in SMB/TCP InternalHandler before slicing decrypted agent info data

Root Cause

When a parent HTTP agent checks in, extractPivotTasks passes lostSize = availableSize - usedSize to each SMB child. After packing the parent's own tasks, lostSize is often too small or near-zero, causing TsAgentGetHostedAll for the child to return empty. Meanwhile, TsAgentProcessData (triggered by COMMAND_PIVOT_EXEC) keeps generating new response tasks that get queued into the child's HostedTasks. These tasks are never extracted and accumulate indefinitely, causing the Queue to grow without bound until the server is OOM-killed.

Additionally, non-async agents (SMB/TCP) never get their LastTick updated, preventing the server from detecting and cleaning up dead sessions.

Testing

  • Started teamserver with HTTP + SMB listeners
  • Launched HTTP agent, linked 2 SMB pivot sessions
  • Monitored server memory over extended period: stable at ~80MB (0.4% of 15GB)
  • Previously, the same scenario would consume all available memory until OOM kill

Files Changed

File Change
core/server/ts_tasks.go Minimum pivot data allocation (64KB) + skip empty data
core/utils/safe/queue.go Max capacity limit (65536) + bounded Push/PushFront
core/server/ts_agent.go LastTick update for non-async agents
extenders/beacon_listener_smb/pl_main.go Bounds check on decrypted data
extenders/beacon_listener_tcp/pl_main.go Bounds check on decrypted data

🤖 Generated with Claude Code

When SMB pivot sessions are active, the server's memory grows
unboundedly until the OS kills the process. Root cause is a
data starvation-accumulation cycle in extractPivotTasks.

- extractPivotTasks: ensure minimum 64KB allocation per pivot
  child so tasks can be extracted instead of accumulating
- Queue: cap capacity at 65536 items, drop oldest/newest
  when full instead of unbounded resize
- TsAgentProcessData: update LastTick for non-async (SMB/TCP)
  agents so the server can track their liveness
- SMB/TCP InternalHandler: add bounds check before slicing
  decrypted agent info

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant