fix: mitmdump process leaked and respawned on every dynamic analysis run - #2658
Open
alanhasn wants to merge 1 commit into
Open
fix: mitmdump process leaked and respawned on every dynamic analysis run#2658alanhasn wants to merge 1 commit into
alanhasn wants to merge 1 commit into
Conversation
mobsf_agents_setup() called create_ca() unconditionally on every dynamic analysis session, spawning a new detached mitmdump process even when the CA cert already existed. The spawned process was also never stopped, so it stayed running indefinitely after the session ended. create_ca() now waits for the CA cert file to appear and terminates mitmdump once it's done, and the redundant unconditional call in mobsf_agents_setup() is removed in favor of the existing get_ca_file() check (already used by install_mobsf_ca()). Co-authored-by: alanhasn
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.
Closes #2543
Root cause
mobsf_agents_setup()inenvironment.pycalledcreate_ca()unconditionally on every dynamic analysis session.create_ca()spawns a detachedmitmdump -nprocess to generate the CA cert, but:mitmdumpprocess on every single run.close_fds=True, no stdin/stdout/stderr), so it stayed running forever after the session ended.This matches the reported behavior: a new
mitmdumpprocess appears every time Dynamic Analysis starts, and it never exits after stopping the analysis.Fix
create_ca()now waits (polling, up to ~15s) for the CA cert file to actually appear, then callsproc.terminate()on themitmdumpprocess it started, since it's only needed transiently to generate the cert.create_ca()call inmobsf_agents_setup().install_mobsf_ca('install'), called right after, already goes throughget_ca_file(), which only generates the CA if it doesn't already exist. The unconditional call was redundant and was the source of the "new process every run" behavior.Testing
python -m py_compileon both changed files.flake8on both changed files — clean.create_ca()/get_ca_file()to confirm no other code path relies on the old unconditional-spawn behavior.