BC-SECURITY / Empire

Empire is a post-exploitation and adversary emulation framework that is used to aid Red Teams and Penetration Testers.
https://bc-security.gitbook.io/empire-wiki/
BSD 3-Clause "New" or "Revised" License
4.06k stars 564 forks source link

corrected "selected" field assignment in InteractMenu.py #704

Open tamasbakos opened 8 months ago

tamasbakos commented 8 months ago

The "selected" field in the InteractMenu was not assigned correctly before. I changed it to assign the agent_name to the "selected" field, similarly as in other menus. Without this correction if you rename an agent, interact with its new name, and issue the "shell" command, the client will crash because it will try to find the agent in "state.agents" by session ID, even though it should search by name. Exception that occurs in this case without my correction:

(Empire: web05) > shell Traceback (most recent call last): File "/home/tamas/repos/Empire/empire.py", line 26, in client.start(args) File "/home/tamas/repos/Empire/empire/client/client.py", line 508, in start empire.main() File "/home/tamas/repos/Empire/empire/client/client.py", line 261, in main self.parse_command_line(text, cmd_line) File "/home/tamas/repos/Empire/empire/client/client.py", line 363, in parse_command_line menu_state.push( File "/home/tamas/repos/Empire/empire/client/src/MenuState.py", line 22, in push if menu.on_enter(**kwargs): ^^^^^^^^^^^^^^^^^^^^^^^ File "/home/tamas/repos/Empire/empire/client/src/menus/ShellMenu.py", line 31, in on_enter self.use(kwargs["selected"]) File "/home/tamas/repos/Empire/empire/client/src/menus/ShellMenu.py", line 50, in use self.session_id = state.agents[self.selected]["session_id"]


KeyError: 'F7EZCSH9'
vinnybod commented 7 months ago

Thanks. works for me.

Probably would be better (but more work to fix) to have the state key be the session_id and just use name for display interaction purposes, but I'm fine with this soution.

Can you run the linting? Looks like its failing there. poetry run black . https://github.com/BC-SECURITY/Empire/blob/main/.github/CONTRIBUTING.md#code-formatting-and-linting