Fixes calling cleanup method when post/auxiliary modules fail#21036
Open
EclipseAditya wants to merge 1 commit into
Open
Fixes calling cleanup method when post/auxiliary modules fail#21036EclipseAditya wants to merge 1 commit into
EclipseAditya wants to merge 1 commit into
Conversation
msutovsky-r7
reviewed
Mar 2, 2026
191b247 to
c3d91a1
Compare
msutovsky-r7
approved these changes
Apr 13, 2026
Contributor
msutovsky-r7
left a comment
There was a problem hiding this comment.
So the fix here seems odd - it does not take into account some categories of modules, where the bug persists and for some, it removes calling cleanup entirely when module throw some specific error(?). Not really sure, I'll investigate more here.
Contributor
msutovsky-r7
left a comment
There was a problem hiding this comment.
I think this issue requires little bit more testing and more time - I've opened new PR, but I would like to keep the specs from this PR.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #18138
Post and Auxiliary modules were invoking mod.cleanup twice when exiting through error paths (fail_with, Timeout, Interrupt, or unhandled exceptions). Cleanup was first triggered inside the rescue blocks of job_run_proc and then executed again by job_cleanup_proc, which run_simple calls unconditionally.
Root cause: job_run_proc explicitly called mod.cleanup in each rescue clause, while run_simple always invoked job_cleanup_proc afterward, resulting in duplicate cleanup.
Resolution: Removed direct mod.cleanup calls from all rescue blocks in job_run_proc for Msf::Simple::Post and Msf::Simple::Auxiliary. The synchronous execution path is now wrapped in begin/ensure so job_cleanup_proc runs exactly once regardless of how execution exits. Applied the same fix in ExploitDriver, where an Interrupt rescue caused duplicate cleanup during multi-target runs.
Verification: Executed the updated test suite (24 examples), all passing:
bundle exec rspec spec/lib/msf/base/simple/