Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Delay/Jitter adjustment broken in python agent #764

Closed
1 task done
janit0rjoe opened this issue Dec 17, 2024 · 0 comments · Fixed by #765
Closed
1 task done

[BUG] Delay/Jitter adjustment broken in python agent #764

janit0rjoe opened this issue Dec 17, 2024 · 0 comments · Fixed by #765
Labels
bug Something isn't working confirmed

Comments

@janit0rjoe
Copy link

janit0rjoe commented Dec 17, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Empire Version

5.12.0

Python Version

3.12.7

Operating System

Kali Linux

Database

MariaDB

Current Behavior

The python agent does not change its delay/jitter settings upon receiving a new configuration.

As you see in the screenshots, the delay has been set to 2 sec in the first example and 30 sec in the last example. In both cases the agent checks still checks in every 5 sec.

agent_sleep2_defunct

agent_sleep30_defunct

Expected Behavior

The agent should check in corresponding to the delay/jitter set.

Steps To Reproduce

  1. Spawn a python agent
  2. Set sleep 30 0.0

Agent will still check in every 5 sec.

Anything else?

There is a python scope bug located in empire/server/data/agent/agent.py.

The task to change the delay/jitter is a ID=100 task that is handled by dynamic_code_execute_wait_nosave().
This method compiles python code received from the server and executes it:

    def dynamic_code_execute_wait_nosave(self, data, result_id):
    [snip]
            code_obj = compile(data, "<string>", "exec")
            exec(code_obj, globals())
            sys.stdout = sys.__stdout__
            results = buffer.getvalue()
            self.packet_handler.send_message(self.packet_handler.build_response_packet(100, str(results), result_id))
    [snip]

In case of delay/jitter setting the python code send by the server is defined in empire/server/core/agent_task_service.py:

 f"global delay; global jitter; delay={delay}; jitter={jitter}; print('delay/jitter set to {delay}/{jitter}')",

This string gets compiled and executed by the method above. This may set a global variable delay and jitter to the new value. But these not used anywhere. The delay and jitter is stored in the delay and jitter attributes of the MainAgent object. These never get adjusted, because they are not accessible within the executed statement.

The problem can be illustrated with this little script:

class Agent(object):

    def __init__(self, delay):
        self.delay = delay

    def pd(self):
        print(f'current delay: {self.delay}')

    def update(self, data):
        code_obj = compile(data, "<string>", "exec")
        exec(code_obj,globals())


t = Agent(1)

t.pd()
t.update(f"global delay; delay=2; print('delay set to 2')")
t.pd()
@janit0rjoe janit0rjoe added the bug Something isn't working label Dec 17, 2024
janit0rjoe added a commit to janit0rjoe/Empire that referenced this issue Dec 17, 2024
@Cx01N Cx01N linked a pull request Jan 12, 2025 that will close this issue
4 tasks
vinnybod added a commit that referenced this issue Jan 12, 2025
Fixing delay/jitter adjustment in python agent (#764) (#765)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working confirmed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants