MythicAgents / Apollo

A .NET Framework 4.0 Windows Agent
BSD 3-Clause "New" or "Revised" License
432 stars 90 forks source link

Proposed fix for TCP profile unlink bug #106

Closed thespicybyte closed 2 years ago

thespicybyte commented 2 years ago

This pull request addresses issue #105 where established connections were not being properly closed when the unlink command was executed. The issue appears to be in TCPPeer.cs in Stop() where the CancelationTokenSource is cancelled but _sendTask.Wait() never returns which is causing the hang.

This solution is fairly simple and does the following:

  1. Grabs the handle from OnConnect() when a new TCP link is established and stores the value in a new _socketHandle property
  2. When unlink is issued, after the CancelationTokenSource is cancelled, CloseHandle() is called on that handle
  3. Connection is closed, the function returns, and the link is removed

There might be a more eloquent solution by figuring out why the sendTask never returns but figured this is a good starting place for discussion.

djhohnstein commented 2 years ago

I'll go through the PRs this week and get things resolved. Thank you!