-
-
Notifications
You must be signed in to change notification settings - Fork 580
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
Support Empire for system-wide deployment #757
base: main
Are you sure you want to change the base?
Conversation
The reason the
Can you explain this in a bit more detail? You shouldn't need sudo to update the starkiller submodule. |
Hey. |
@vinnybod any clue about my last comment? |
The current assumption Empire makes is that it is:
I'd approve a PR that adds your admin install use case as long as it still supports the above assumptions too. |
I need to do with you a deeper analysis to properly work on the code. Problem statementEmpire cannot work at system-level, for example when on my host I have 10 user accounts (i.e., in a school), I cannot install one single Empire instance for everyone but I need to install N instances for each user by consuming a lot of resources. Your requirements
not installed as admin
run as admin for opening portsSo, opening ports on the local network, and admin is needed.
doesn't write files as admin
run_as_user() scopeCurrently
So, currently, My proposalI don't see relevant risks to install Empire at system-level (so as root) and to pull updates and submodules. If you want to be compliant with the minimum privilege principles, what we can do is to allow Empire to be installed as root at system-level (as occurs for any tools/packages in Linux), but we can identify all those files, resources, elements that must be dealt as current user instead of root, and manage them in the user HOME folder. In this context |
It's more of a convenience factor for us at maintainers. There have been a lot of issues opened in the past due to file permissions issues. So enforcing installs and the file writes to be user-level decreases that. For example:
We handle this automatically with the ps-empire command
Sort of got into this above, but ideally all the files in the application directory would have uniform access permissions. It is less about risks and more about alleviating inbound requests related to issues stemming from people installing in different ways. My intention is that for 90%+ of users, the standard install that we enforce "just works". |
I try to split the problem in small problems because involving all users could be complex but still possible. If we want to try to "unblock" the minority of users, and to not impact the current 90+% users, I would start to manage from the raising issues when Empire is installed system-wide BUT with non-root run. I will edit the PR code. 1. Issue: Permission denied on directories specified in config files
Solution: code will check This approach is compliant to Linux specs (XDG Base Directory Specification that standardizes where application files, including logs, should be stored within the user’s home directory.) Advantages:
2. Add check on fetch_submodules()Added: def fetch_submodules():
if not os.path.exists(Path(".git")):
log.info("No .git directory found. Skipping submodule fetch.")
return
command = ["git", "submodule", "update", "--init", "--recursive"]
run_as_user(command) to run this function only if 3. config.yaml must be copied in HOME user folderIn Linux/Windows, configuration files must be copied from the default one to HOME folder, in order to allow it to manage according XDG standard specification. It allows to cover both user-level and system-level approach. Furthermore, the definition of config file path must be managed centrally. 4. Manage dirs specified in config.yaml to fallback to $HOME directory - WIP
directories:
downloads: empire/server/downloads/
module_source: empire/server/data/module_source/
obfuscated_module_source: empire/server/data/obfuscated_module_source/
|
c8bf478
to
6b001e5
Compare
@D3vil0p3r thanks for iterating on this with me 😅 . I'm still learning the best practices around Linux. |
Yes I am aware but I cannot write directly it because yaml file cannot expand env variables in case of Linux or Windows systems. So my approach is "first, copy config.yaml to home dir |
1st Questionwhat is the difference between Why in These two folders are changed/written at runtime during the usage of Empire? If not, what is the reason to have directories:
module_source: empire/server/data/module_source/
obfuscated_module_source: empire/server/data/obfuscated_module_source/ in 2nd QuestionOne additional note: since you don't want users use sudo for running Empire, INVOKE_OBFS_DST_DIR_BASE = "/usr/local/share/powershell/Modules/Invoke-Obfuscation"
...
...
# invoke obfuscation
if os.path.exists(f"{INVOKE_OBFS_DST_DIR_BASE}"):
shutil.rmtree(INVOKE_OBFS_DST_DIR_BASE)
pathlib.Path(pathlib.Path(INVOKE_OBFS_SRC_DIR_BASE).parent).mkdir(
parents=True, exist_ok=True
)
shutil.copytree(
INVOKE_OBFS_SRC_DIR_BASE, INVOKE_OBFS_DST_DIR_BASE, dirs_exist_ok=True
) this copy will always fail due to missing permission. Still, here I would suggest to write in 3rd QuestionWhen Empire is run the first time (for example on a Linux system), why is it running building/compilation by MSBuild? Usually compilation must not run at runtime. Best practices suggest to do it at "building time". Is it possible you build them offline and upload the output files directly on the Empire repository so this build process code can be removed? |
e523bbe
to
d2e7f90
Compare
The
Not every module has a 1 to 1 mapping with source code in
I don't recall the exact reason that these are in the
I am fine moving
This is coming from compiling the csharp compiler https://github.com/BC-SECURITY/Empire/blob/main/empire/server/plugins/csharpserver/csharpserver.py#L98-L100 We have actually already addressed this point in the upcoming 6.0 release which is due in a few months, so you shouldn't bother changing that. The 6.0 release will download a binary in the install script instead of compiling it at runtime. |
Oh ok... So... at this point, the PR is ready to be reviewed and merged. I tested on my Arch Linux and it works for both system-level and user-level deployment. without impacting your implementation with |
@vinnybod did you get the chance to review my changes? |
Describe your changes
Refactored code to make Empire to be deployed at system-level (multi-user) with no impact on the current approach based on working only in a case Empire is cloned in a user-granted directory.
This PR makes Empire working also in case it is installed in a system directory without changing the current grants. It is possible by refactoring code by following XDG Base Dir specifications.
Issue ticket number and link (if there is one)
#756
Checklist before requesting a review
CHANGELOG.md
docs/
(if applicable)