-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: container entity panel * docs: add 404 to container entity
- Loading branch information
Showing
7 changed files
with
220 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2023 Specter Ops, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package v2 | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/specterops/bloodhound/src/api" | ||
adAnalysis "github.com/specterops/bloodhound/analysis/ad" | ||
"github.com/specterops/bloodhound/dawgs/graph" | ||
"github.com/specterops/bloodhound/graphschema/ad" | ||
) | ||
|
||
var containerQueries = map[string]any{ | ||
"controllers": adAnalysis.FetchInboundADEntityControllers, | ||
} | ||
|
||
func (s *Resources) GetContainerEntityInfo(response http.ResponseWriter, request *http.Request) { | ||
if hydrateCounts, err := api.ParseOptionalBool(request.URL.Query().Get(api.QueryParameterHydrateCounts), true); err != nil { | ||
api.WriteErrorResponse(request.Context(), api.BuildErrorResponse(http.StatusBadRequest, api.ErrorResponseDetailsBadQueryParameterFilters, request), response) | ||
} else if objectId, err := GetEntityObjectIDFromRequestPath(request); err != nil { | ||
api.WriteErrorResponse(request.Context(), api.BuildErrorResponse(http.StatusBadRequest, fmt.Sprintf("error reading objectid: %v", err), request), response) | ||
} else if node, err := s.GraphQuery.GetEntityByObjectId(request.Context(), objectId, ad.Container); err != nil { | ||
if graph.IsErrNotFound(err) { | ||
api.WriteErrorResponse(request.Context(), api.BuildErrorResponse(http.StatusNotFound, "node not found", request), response) | ||
} else { | ||
api.WriteErrorResponse(request.Context(), api.BuildErrorResponse(http.StatusInternalServerError, fmt.Sprintf("error getting node: %v", err), request), response) | ||
} | ||
} else if hydrateCounts { | ||
results := s.GraphQuery.GetEntityCountResults(request.Context(), node, containerQueries) | ||
api.WriteBasicResponse(request.Context(), results, http.StatusOK, response) | ||
} else { | ||
results := map[string]any{"props": node.Properties.Map} | ||
api.WriteBasicResponse(request.Context(), results, http.StatusOK, response) | ||
} | ||
} |
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,110 @@ | ||
{ | ||
"/api/v2/containers/{object_id}": { | ||
"parameters": [ | ||
{ | ||
"type": "string", | ||
"description": "Container Object ID", | ||
"name": "object_id", | ||
"in": "path", | ||
"required": true | ||
} | ||
], | ||
"get": { | ||
"description": "Get basic info and counts for this Container", | ||
"tags": [ | ||
"Container Entity API", | ||
"Community", | ||
"Enterprise" | ||
], | ||
"summary": "Get container entity info", | ||
"parameters": [ | ||
{ | ||
"$ref": "#/definitions/parameters.PreferHeader" | ||
} | ||
], | ||
"responses": { | ||
"200": { | ||
"description": "OK", | ||
"schema": { | ||
"$ref": "#/definitions/api.BasicResponse" | ||
} | ||
}, | ||
"400": { | ||
"description": "Bad Request", | ||
"schema": { | ||
"$ref": "#/definitions/api.ErrorWrapper" | ||
} | ||
}, | ||
"404": { | ||
"description": "Not Found", | ||
"schema": { | ||
"$ref": "#/definitions/api.ErrorWrapper" | ||
} | ||
}, | ||
"504": { | ||
"description": "Gateway Timeout", | ||
"schema": { | ||
"$ref": "#/definitions/api.ErrorWrapper" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"/api/v2/containers/{object_id}/controllers": { | ||
"parameters": [ | ||
{ | ||
"type": "string", | ||
"description": "Container Object ID", | ||
"name": "object_id", | ||
"in": "path", | ||
"required": true | ||
} | ||
], | ||
"get": { | ||
"description": "List the principals that can control this Container through ACLs", | ||
"tags": [ | ||
"Container Entity API", | ||
"Community", | ||
"Enterprise" | ||
], | ||
"summary": "List container controllers", | ||
"parameters": [ | ||
{ | ||
"$ref": "#/definitions/parameters.PreferHeader" | ||
}, | ||
{ | ||
"type": "integer", | ||
"description": "Paging Skip", | ||
"name": "skip", | ||
"in": "query" | ||
}, | ||
{ | ||
"type": "integer", | ||
"description": "Paging Limit", | ||
"name": "limit", | ||
"in": "query" | ||
} | ||
], | ||
"responses": { | ||
"200": { | ||
"description": "OK", | ||
"schema": { | ||
"$ref": "#/definitions/api.ResponseWrapper" | ||
} | ||
}, | ||
"400": { | ||
"description": "Bad Request", | ||
"schema": { | ||
"$ref": "#/definitions/api.ErrorWrapper" | ||
} | ||
}, | ||
"504": { | ||
"description": "Gateway Timeout", | ||
"schema": { | ||
"$ref": "#/definitions/api.ErrorWrapper" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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