Improve error handling in tcp channels #7770
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This makes some minor idiomatic changes to channel handling code, but also fixes some areas where Meterpreter payloads actually send failure responses to opening sockets, but Metasploit does not handle these as expected. Rather than raising an exception or returning a nil socket, often a nil object is instead dereferenced, throwing an entirely different exception, and as a result, a lot of things sort of work only by luck.
Verification
Run various exploits and modules that use TCP sockets through a pivot. For example, I have been running this RC script for testing mettle's network channel support:
Your mileage may vary. This is certainly up for discussion, and I suspect I may have gotten intent vs what the code was actually doing mixed up. It does seem to help a bit with handling sudden unexpected socket closes.