Repository navigation
fix: NameError job_message_buffer not defined in background python jobs - #844
Closed
satanonsteroids2024-zzz wants to merge 1 commit into
Closed
satanonsteroids2024-zzz wants to merge 1 commit into
satanonsteroids2024-zzz wants to merge 1 commit into
Conversation
python_job_func (task 112) execs module-supplied scripts inside a purpose-built globals dict containing only 'print'. Several built-in modules (e.g. python/collection/linux/xkeylogger, python/collection/linux/sniffer) call job_message_buffer(msg) as a bare name from inside that script to stream output, which is unresolved in that scope and raises: [!] Error executing script: name 'job_message_buffer' is not defined Separately, MainAgent has both a string instance attribute self.job_message_buffer (the accumulating buffer, set in __init__) and a like-named method def job_message_buffer(self, message). The instance attribute shadows the method, so even self.job_message_buffer(message) would raise 'str' object is not callable - that pre-existing tangle is left alone here. Inject a small closure named job_message_buffer into script_globals that appends straight to the self.job_message_buffer string attribute, bypassing the shadowed method entirely. Only python_job_func is touched; get_job_message_buffer's flush-and-reset behavior on checkin is unchanged. Fixes BC-SECURITY#827. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 task done
Member
|
Thanks @satanonsteroids2024-zzz! Your commit was cherry-picked (authorship preserved) into our development branch, then refined to bind the shadowed method and mirrored to the IronPython agent. It will ship here with the next release. Closing as superseded. |
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.
Describe your changes
Fixes #827.
python_job_func(task 112) execs module-supplied scripts inside a purpose-built globals dict containing onlyprint:Several built-in modules stream output by calling
job_message_buffer(msg)as a bare name from inside the script body they hand to the agent —python/collection/linux/xkeylogger,python/collection/linux/sniffer,python/collection/linux/port_scanner, and any custom module doing the same. Under the exec scope above the name is unresolved, so the script raisesNameError, surfaced to the operator as:Separately (and this is what shapes the fix):
MainAgenthas both a string instance attributeself.job_message_buffer = ""(the accumulating buffer, set in__init__) and a methoddef job_message_buffer(self, message)with the same name. The instance attribute shadows the method, so evenself.job_message_buffer(message)would raise'str' object is not callable. That's a pre-existing tangle independent of this bug — left alone here rather than bundled into this fix.Fix
Inject a small closure named
job_message_bufferintoscript_globalsthat appends directly to theself.job_message_bufferstring attribute, bypassing the shadowed method entirely:Only
python_job_funcis touched.get_job_message_buffer's existing flush-and-reset behavior on checkin is unchanged.dynamic_code_execute_wait_nosave(task 110) anddynamic_code_execution_wait_save(task 111) — the immediate-execute paths — don't run modules that stream viajob_message_buffer, so they're untouched too.Also added a
CHANGELOG.mdentry per the contribution checklist.Verification
python3 -m py_compile empire/server/data/agent/agent.py— compiles cleanly.FakeAgentmirroringpython_job_func's structure) with a script that callsjob_message_buffer(msg)as a bare name, exactly likexkeylogger.yamldoes: confirmed it previously raisedNameError, and with the fix it correctly appends to the agent's realjob_message_bufferstring attribute with no exception.Checklist before requesting a review
MainAgentcovers the surrounding paths.)CHANGELOG.mddocs/(not applicable — no user-facing behavior/interface change, just makes existing documented module behavior work)Prepared with the assistance of Claude (Anthropic) for investigation and drafting; root cause and fix verified locally by me before submission.