forked from EmpireProject/Empire
-
-
Notifications
You must be signed in to change notification settings - Fork 584
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bypass language, stale processes, keyword length (#452)
* add minimum requirements for keyword dto * add language to bypass endpoints. Update ps hook to mark processes stale. add requirements to keyword dto * add stale process to endpoint, fix int comparison * delete hostprocesses after hook test
- Loading branch information
Showing
9 changed files
with
174 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import json | ||
|
||
import pytest | ||
|
||
from empire.server.core.db.models import TaskingStatus | ||
from empire.server.core.hooks import hooks | ||
|
||
|
||
@pytest.fixture(scope="module", autouse=True) | ||
def agent(db, models, main): | ||
hosts = db.query(models.Host).all() | ||
if len(hosts) == 0: | ||
host = models.Host(name="default_host", internal_ip="127.0.0.1") | ||
db.add(host) | ||
else: | ||
host = hosts[0] | ||
|
||
name = f'agent_{__name__.split(".")[-1]}' | ||
|
||
agent = db.query(models.Agent).filter(models.Agent.session_id == name).first() | ||
if not agent: | ||
agent = models.Agent( | ||
name=name, | ||
session_id=name, | ||
delay=1, | ||
jitter=0.1, | ||
external_ip="1.1.1.1", | ||
session_key="qwerty", | ||
nonce="nonce", | ||
profile="profile", | ||
kill_date="killDate", | ||
working_hours="workingHours", | ||
lost_limit=60, | ||
listener="http", | ||
language="powershell", | ||
language_version="5", | ||
high_integrity=True, | ||
process_name="abc", | ||
process_id=123, | ||
hostname=host.name, | ||
host_id=host.id, | ||
archived=False, | ||
) | ||
db.add(agent) | ||
else: | ||
agent.archived = False | ||
|
||
db.flush() | ||
|
||
main.agents.agents[name] = { | ||
"sessionKey": agent.session_key, | ||
"functions": agent.functions, | ||
} | ||
|
||
yield agent | ||
|
||
db.query(models.HostProcess).delete() | ||
db.delete(agent) | ||
db.delete(host) | ||
db.commit() | ||
|
||
|
||
def test_ps_hook(client, db, models, agent): | ||
existing_processes = [ | ||
models.HostProcess( | ||
host_id=agent.host_id, | ||
process_id=1, | ||
process_name="should_be_stale", | ||
architecture="x86", | ||
user="test_user", | ||
), | ||
models.HostProcess( | ||
host_id=agent.host_id, | ||
process_id=2, | ||
process_name="should_be_updated", | ||
architecture="x86", | ||
user="test_user", | ||
), | ||
models.HostProcess( | ||
host_id=agent.host_id, | ||
process_id=3, | ||
process_name="should_be_same", | ||
architecture="x86", | ||
user="test_user", | ||
), | ||
] | ||
db.add_all(existing_processes) | ||
|
||
output = json.dumps( | ||
[ | ||
{ | ||
"CMD": "has_been_updated", | ||
"PID": 2, | ||
"Arch": "x86_64", | ||
"UserName": "test_user", | ||
}, | ||
{"CMD": "should_be_same", "PID": 3, "Arch": "x86", "UserName": "test_user"}, | ||
{"CMD": "should_be_new", "PID": 4, "Arch": "x86", "UserName": "test_user"}, | ||
] | ||
) | ||
tasking = models.Tasking( | ||
id=1, | ||
agent_id=agent.session_id, | ||
agent=agent, | ||
input="ps", | ||
status=TaskingStatus.pulled, | ||
output=output, | ||
original_output=output, | ||
) | ||
hooks.run_hooks(hooks.BEFORE_TASKING_RESULT_HOOK, db, tasking) | ||
db.flush() | ||
processes = db.query(models.HostProcess).all() | ||
|
||
assert len(processes) == 4 | ||
assert processes[0].process_name == "should_be_stale" | ||
assert processes[0].stale is True | ||
assert processes[1].process_name == "has_been_updated" | ||
assert processes[1].stale is False | ||
assert processes[2].process_name == "should_be_same" | ||
assert processes[2].stale is False | ||
assert processes[3].process_name == "should_be_new" | ||
assert processes[3].stale is False |
This file contains 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