Skip to content

Commit

Permalink
Remove starkiller submodule (#595)
Browse files Browse the repository at this point in the history
* remove starkiller submodule

* ignore starkiller dir

* Remove starkiller as a submodule

* fix auto update

* update sync script
  • Loading branch information
vinnybod authored May 22, 2023
1 parent 4f7cde0 commit eb9fa6f
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 64 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ empire/server/data/generated-stagers/*
empire/server/downloads/*
empire/server/api/static/*
empire/server/api/v2/starkiller-temp
empire/server/api/v2/starkiller

# client
empire/client/generated-stagers/*
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@
[submodule "empire/server/csharp/Covenant/Data/ReferenceSourceLibraries/DotNetStratumMiner"]
path = empire/server/csharp/Covenant/Data/ReferenceSourceLibraries/DotNetStratumMiner
url = https://github.com/BC-SECURITY/DotNetStratumMiner.git
[submodule "empire/server/api/v2/starkiller"]
path = empire/server/api/v2/starkiller
url = [email protected]:BC-SECURITY/Starkiller-Sponsors.git
[submodule "empire/server/csharp/Covenant/Data/ReferenceSourceLibraries/RunOF"]
path = empire/server/csharp/Covenant/Data/ReferenceSourceLibraries/RunOF
url = https://github.com/BC-SECURITY/RunOF.git
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Remove Starkiller as a submodule, treat it as a normal directory (@Vinnybod)
- Everything should 'just work', but if you have issues after pulling these latest changes, try deleting the Starkiller directory before running the server `rm -r empire/server/api/v2/starkiller`.

## [5.3.0] - 2023-05-17

- Add the ability to specify a module option as a file (@Vinnybod)
Expand Down
63 changes: 24 additions & 39 deletions empire/scripts/sync_starkiller.py
Original file line number Diff line number Diff line change
@@ -1,60 +1,45 @@
import logging
import os
import subprocess
from pathlib import Path
from typing import Dict

log = logging.getLogger(__name__)


def sync_starkiller(empire_config):
"""
Syncs the starkiller submodule with what is in the config.
Using dict acccess because this script should be able to run with minimal packages, not just within empire.
Syncs the starkiller directory with what is in the config.
Using dict access because this script should be able to run with minimal packages,
not just within empire server.
"""
starkiller_config = empire_config["starkiller"]
starkiller_submodule_dir = "empire/server/api/v2/starkiller"
starkiller_temp_dir = "empire/server/api/v2/starkiller-temp"
starkiller_dir = starkiller_config["directory"]

subprocess.run(["git", "submodule", "update", "--init", "--recursive"], check=True)
if not Path(starkiller_dir).exists():
log.info("Starkiller: directory not found. Cloning Starkiller")
_clone_starkiller(starkiller_config, starkiller_dir)

if not starkiller_config["use_temp_dir"]:
log.info("Syncing starkiller submodule to match config.yaml")
subprocess.run(
[
"git",
"submodule",
"set-url",
"--",
starkiller_submodule_dir,
starkiller_config["repo"],
],
check=True,
if starkiller_config.get("auto_update"):
log.info("Starkiller: Autoupdate on. Pulling latest ref.")
_fetch_checkout_pull(
starkiller_config["repo"], starkiller_config["ref"], starkiller_dir
)
subprocess.run(
["git", "submodule", "sync", "--", starkiller_submodule_dir], check=True
)

_fetch_checkout_pull(starkiller_config["ref"], starkiller_submodule_dir)

else:
if not os.path.exists(starkiller_temp_dir):
log.info("Cloning starkiller to temp dir")
subprocess.run(
["git", "clone", starkiller_config["repo"], starkiller_temp_dir],
check=True,
)

else:
log.info("Updating starkiller temp dir")
subprocess.run(
["git", "remote", "set-url", "origin", starkiller_config["repo"]],
cwd=starkiller_temp_dir,
check=True,
)
def _clone_starkiller(starkiller_config: Dict, starkiller_dir: str):
subprocess.run(
["git", "clone", starkiller_config["repo"], starkiller_dir],
check=True,
)

_fetch_checkout_pull(starkiller_config["ref"], starkiller_temp_dir)

def _fetch_checkout_pull(remote_repo, ref, cwd):
subprocess.run(
["git", "remote", "set-url", "origin", remote_repo],
cwd=cwd,
check=True,
)

def _fetch_checkout_pull(ref, cwd):
subprocess.run(["git", "fetch"], cwd=cwd, check=True)
subprocess.run(
["git", "checkout", ref],
Expand Down
18 changes: 3 additions & 15 deletions empire/server/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import os
from datetime import datetime
from json import JSONEncoder
from pathlib import Path

import socketio
import uvicorn
Expand Down Expand Up @@ -44,22 +43,11 @@ def default(self, o):


def load_starkiller(v2App):
use_temp = empire_config.starkiller.use_temp_dir
starkiller_submodule_dir = "empire/server/api/v2/starkiller"
starkiller_temp_dir = "empire/server/api/v2/starkiller-temp"

if (
Path(starkiller_submodule_dir) / ".git"
).exists() and empire_config.starkiller.auto_update:
sync_starkiller(empire_config.dict())
sync_starkiller(empire_config.dict())

v2App.mount(
"/",
StaticFiles(
directory=f"{starkiller_temp_dir}/dist"
if use_temp
else f"{starkiller_submodule_dir}/dist"
),
StaticFiles(directory=f"{empire_config.starkiller.directory}/dist"),
name="static",
)

Expand Down Expand Up @@ -147,7 +135,7 @@ def shutdown_event():
load_starkiller(v2App)
log.info(f"Starkiller served at http://localhost:{port}/index.html")
except Exception as e:
log.warning("Failed to load Starkiller: %s", e)
log.warning("Failed to load Starkiller: %s", e, exc_info=True)
pass

cert_path = os.path.abspath("./empire/server/data/")
Expand Down
1 change: 0 additions & 1 deletion empire/server/api/v2/starkiller
Submodule starkiller deleted from d7ecad
5 changes: 1 addition & 4 deletions empire/server/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,9 @@ database:
ip-blacklist: ""
starkiller:
repo: [email protected]:BC-SECURITY/Starkiller-Sponsors.git
directory: empire/server/api/v2/starkiller
# Can be a branch, tag, or commit hash
ref: sponsors-main
# for private-main, instead of updating the submodule, just work out of a local copy.
# So devs can work off the latest changes and not worry about accidentally updating the submodule
# for the downstream main branches.
use_temp_dir: false
auto_update: true
plugins:
# Auto-load plugin with defined settings
Expand Down
2 changes: 1 addition & 1 deletion empire/server/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

class StarkillerConfig(BaseModel):
repo: str = "bc-security/starkiller"
directory: str = "empire/server/api/v2/starkiller"
ref: str = "main"
use_temp_dir: bool = False
auto_update: bool = True


Expand Down
2 changes: 1 addition & 1 deletion empire/server/core/plugin_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def execute_plugin(
return plugin.execute(cleaned_options, db=db, user=user), None
except TypeError:
log.warning(
"Plugin does not support db session or user_id, falling back to old method"
f"Plugin {plugin.info.get('Name')} does not support db session or user_id, falling back to old method"
)

try:
Expand Down

0 comments on commit eb9fa6f

Please sign in to comment.