-
Notifications
You must be signed in to change notification settings - Fork 5
feat(bloodhound): add Active Directory attack-path injector (#316) #326
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
Open
Samuel Hassine (SamuelHassine)
wants to merge
7
commits into
main
Choose a base branch
from
feat/injector-bloodhound
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4c004b1
feat(bloodhound): add Active Directory attack-path injector (#316)
SamuelHassine 7900442
style(bloodhound): sort imports for repo-root isort check (#316)
SamuelHassine 752b9a4
test(bloodhound): cover injector lifecycle and collector (#316)
SamuelHassine 911facd
fix(bloodhound): surface collector failures and harden secret handlin…
SamuelHassine 653f22d
fix(bloodhound): address review comments and harden runtime (#316)
SamuelHassine 3427c95
fix(bloodhound): guard null Properties and share name fallback (#316)
SamuelHassine bd9938c
fix(bloodhound): parse loose collector output and log inject failures…
SamuelHassine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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,2 @@ | ||
| config.yml | ||
| **/__pycache__ |
This file contains hidden or 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,13 @@ | ||
| # OPENAEV Environment Variables | ||
| # base URL to reach the OpenAEV server | ||
| # note this URL must be routable from inside the container | ||
| # so `localhost` will most likely not work | ||
| OPENAEV_URL=ChangeMe | ||
| # admin account API token from the OpenAEV server | ||
| OPENAEV_TOKEN=ChangeMe | ||
| OPENAEV_TENANT_ID=ChangeMe | ||
|
|
||
| # INJECTOR Environment Variables | ||
| INJECTOR_ID=bloodhound--ChangeMe | ||
| INJECTOR_NAME=BloodHound AD | ||
| INJECTOR_LOG_LEVEL=error |
This file contains hidden or 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,52 @@ | ||
| FROM python:3.13-alpine AS builder | ||
|
|
||
| ENV PIP_VERSION=25.0.1 | ||
|
|
||
| RUN apk update && apk upgrade && apk add git curl | ||
|
|
||
| WORKDIR /opt/injector_common | ||
| COPY --from=injector_common ./ ./ | ||
|
|
||
| WORKDIR / | ||
| RUN git clone https://github.com/OpenAEV-Platform/client-python | ||
|
|
||
| RUN curl -sS https://bootstrap.pypa.io/get-pip.py -o get-pip.py && \ | ||
| python3 get-pip.py pip==${PIP_VERSION} && \ | ||
| rm get-pip.py | ||
|
|
||
| RUN python3 -m pip install poetry==2.3.2 \ | ||
| && poetry config installer.re-resolve false \ | ||
| && poetry config virtualenvs.create false | ||
|
|
||
| ARG installdir=/opt/injector | ||
| ADD . ${installdir} | ||
| WORKDIR ${installdir} | ||
| RUN poetry install && \ | ||
| python3 -m pip install --no-cache-dir pip==${PIP_VERSION} | ||
|
|
||
| FROM python:3.13-alpine AS runner | ||
|
|
||
| ENV PIP_VERSION=25.0.1 | ||
|
|
||
| WORKDIR /opt/injector_common | ||
| COPY --from=injector_common ./ ./ | ||
|
|
||
| ARG installdir=/opt/injector | ||
| WORKDIR ${installdir} | ||
| COPY --from=builder ${installdir} ${installdir} | ||
| COPY --from=builder /usr/local/lib/python3.13/site-packages /usr/local/lib/python3.13/site-packages | ||
|
|
||
| ARG PYOAEV_GIT_BRANCH_OVERRIDE | ||
|
|
||
| RUN if [[ ${PYOAEV_GIT_BRANCH_OVERRIDE} ]] ; then \ | ||
| echo "Forcing specific version of client-python" && \ | ||
| apk add --no-cache git curl && \ | ||
| curl -sS https://bootstrap.pypa.io/get-pip.py -o get-pip.py && \ | ||
| python3 get-pip.py pip==${PIP_VERSION} && \ | ||
| rm get-pip.py && \ | ||
| pip install pip3-autoremove && \ | ||
| pip-autoremove pyoaev -y && \ | ||
| pip install git+https://github.com/OpenAEV-Platform/client-python@${PYOAEV_GIT_BRANCH_OVERRIDE} ; \ | ||
| fi | ||
|
|
||
| CMD ["python3", "-m", "bloodhound_injector.openaev_bloodhound"] | ||
This file contains hidden or 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,30 @@ | ||
| # OpenAEV BloodHound AD Injector | ||
|
|
||
| Runs the [BloodHound.py](https://github.com/dirkjanm/BloodHound.py) Active | ||
| Directory collector (SharpHound-compatible) and surfaces users, computers and | ||
| privilege-escalation attack paths (Kerberoastable, AS-REP roastable) as | ||
| findings. | ||
|
|
||
| ## Contract | ||
|
|
||
| - BloodHound - Collect AD attack paths: fields for domain, username, password | ||
| and domain controller. Produces VULNERABILITY (attack paths exist) and | ||
| DETECTION (enumeration detected) expectations. | ||
|
|
||
| ## Credentials | ||
|
|
||
| The AD credentials are provided per inject through the contract fields and are | ||
| never logged (the password argument is redacted in logs). | ||
|
|
||
|
SamuelHassine marked this conversation as resolved.
|
||
| ## Development | ||
|
|
||
| ```bash | ||
| poetry install | ||
| poetry run python -m unittest | ||
| ``` | ||
|
|
||
| ## Icon | ||
|
|
||
| `bloodhound_injector/img/icon-bloodhound.png` must follow the injector icon | ||
| standard (square 1:1, 512x512 PNG, solid opaque background, genuine BloodHound | ||
| artwork) - see OpenAEV-Platform/injectors#305. | ||
This file contains hidden or 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,2 @@ | ||
| # OpenAEV BloodHound AD Attack-Path Injector | ||
| __version__ = "1.0.0" |
Empty file.
27 changes: 27 additions & 0 deletions
27
bloodhound/bloodhound_injector/configuration/config_loader.py
This file contains hidden or 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,27 @@ | ||
| from bloodhound_injector.configuration.injector_config_override import ( | ||
| InjectorConfigOverride, | ||
| ) | ||
| from bloodhound_injector.contracts_bloodhound import BloodhoundContracts | ||
| from pydantic import Field | ||
| from pyoaev.configuration import ConfigLoaderOAEV, Configuration, SettingsLoader | ||
|
Comment on lines
+1
to
+6
|
||
|
|
||
|
|
||
| class ConfigLoader(SettingsLoader): | ||
| openaev: ConfigLoaderOAEV = Field(default_factory=ConfigLoaderOAEV) | ||
| injector: InjectorConfigOverride = Field(default_factory=InjectorConfigOverride) | ||
|
|
||
| def to_daemon_config(self) -> Configuration: | ||
| return Configuration( | ||
| config_hints={ | ||
| "openaev_url": {"data": str(self.openaev.url)}, | ||
| "openaev_token": {"data": self.openaev.token}, | ||
| "openaev_tenant_id": {"data": self.openaev.tenant_id}, | ||
| "injector_id": {"data": self.injector.id}, | ||
| "injector_name": {"data": self.injector.name}, | ||
| "injector_type": {"data": "openaev_bloodhound"}, | ||
| "injector_contracts": {"data": BloodhoundContracts.build_contract()}, | ||
| "injector_log_level": {"data": self.injector.log_level}, | ||
| "injector_icon_filepath": {"data": self.injector.icon_filepath}, | ||
| }, | ||
| config_base_model=self, | ||
| ) | ||
16 changes: 16 additions & 0 deletions
16
bloodhound/bloodhound_injector/configuration/injector_config_override.py
This file contains hidden or 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,16 @@ | ||
| from pydantic import Field | ||
| from pyoaev.configuration import ConfigLoaderCollector | ||
|
|
||
|
|
||
| class InjectorConfigOverride(ConfigLoaderCollector): | ||
| id: str = Field( | ||
| description="A unique UUIDv4 identifier for this injector instance.", | ||
| ) | ||
| name: str = Field( | ||
| default="BloodHound AD", | ||
| description="Name of the injector.", | ||
| ) | ||
| icon_filepath: str | None = Field( | ||
| default="bloodhound_injector/img/icon-bloodhound.png", | ||
| description="Path to the icon file", | ||
| ) |
This file contains hidden or 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,114 @@ | ||
| from typing import List | ||
|
|
||
| from pyoaev.contracts import ContractBuilder | ||
| from pyoaev.contracts.contract_config import ( | ||
| Contract, | ||
| ContractCardinality, | ||
| ContractConfig, | ||
| ContractElement, | ||
| ContractExpectations, | ||
| ContractOutputElement, | ||
| ContractOutputType, | ||
| ContractText, | ||
| Expectation, | ||
| ExpectationType, | ||
| SupportedLanguage, | ||
| prepare_contracts, | ||
| ) | ||
| from pyoaev.security_domain.types import SecurityDomains | ||
|
|
||
| TYPE = "openaev_bloodhound" | ||
|
|
||
| AD_COLLECTION_CONTRACT = "a7d8e9f0-abbb-4ac8-8fd6-bc2d3e4f5a67" | ||
|
|
||
|
|
||
| class BloodhoundContracts: | ||
| @staticmethod | ||
| def build_contract(): | ||
| contract_config = ContractConfig( | ||
| type=TYPE, | ||
| label={ | ||
| SupportedLanguage.en: "BloodHound AD", | ||
| SupportedLanguage.fr: "BloodHound AD", | ||
| }, | ||
| color_dark="#b00020", | ||
| color_light="#b00020", | ||
| expose=True, | ||
| ) | ||
|
|
||
| domain = ContractText(key="domain", label="AD domain (FQDN)", mandatory=True) | ||
| username = ContractText(key="username", label="Username", mandatory=True) | ||
| password = ContractText(key="password", label="Password", mandatory=True) | ||
| domain_controller = ContractText( | ||
| key="domain_controller", | ||
| label="Domain controller (host or IP)", | ||
| mandatory=True, | ||
| ) | ||
|
|
||
| expectations = ContractExpectations( | ||
| key="expectations", | ||
| label="Expectations", | ||
| mandatory=False, | ||
| cardinality=ContractCardinality.Multiple, | ||
| predefinedExpectations=[ | ||
| Expectation( | ||
| expectation_type=ExpectationType.vulnerability, | ||
| expectation_name="Vulnerability", | ||
| expectation_description="Privilege-escalation attack paths exist.", | ||
| expectation_score=100, | ||
| expectation_expectation_group=False, | ||
| ), | ||
| Expectation( | ||
| expectation_type=ExpectationType.detection, | ||
| expectation_name="Detection", | ||
| expectation_description="The AD enumeration is detected.", | ||
| expectation_score=100, | ||
| expectation_expectation_group=False, | ||
| ), | ||
| ], | ||
| ) | ||
|
|
||
| output_users = ContractOutputElement( | ||
| type=ContractOutputType.Username, | ||
| field="users", | ||
| isMultiple=True, | ||
| isFindingCompatible=True, | ||
| labels=["bloodhound", "ad", "user"], | ||
| ) | ||
| output_computers = ContractOutputElement( | ||
| type=ContractOutputType.Computer, | ||
| field="computers", | ||
| isMultiple=True, | ||
| isFindingCompatible=True, | ||
| labels=["bloodhound", "ad", "computer"], | ||
| ) | ||
| output_paths = ContractOutputElement( | ||
| type=ContractOutputType.Vulnerability, | ||
| field="attack_paths", | ||
| isMultiple=True, | ||
| isFindingCompatible=True, | ||
| labels=["bloodhound", "ad", "attack_path"], | ||
| ) | ||
|
|
||
| fields: List[ContractElement] = ( | ||
| ContractBuilder() | ||
| .add_fields([domain, username, password, domain_controller, expectations]) | ||
| .build_fields() | ||
| ) | ||
|
|
||
| contract = Contract( | ||
| contract_id=AD_COLLECTION_CONTRACT, | ||
| config=contract_config, | ||
| label={ | ||
| SupportedLanguage.en: "BloodHound - Collect AD attack paths", | ||
| SupportedLanguage.fr: "BloodHound - Collecter les chemins d'attaque AD", | ||
| }, | ||
| fields=fields, | ||
| outputs=ContractBuilder() | ||
| .add_outputs([output_users, output_computers, output_paths]) | ||
| .build_outputs(), | ||
| manual=False, | ||
| domains=[SecurityDomains.ENDPOINT.value], | ||
| ) | ||
|
|
||
| return prepare_contracts([contract]) |
Empty file.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.