-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* scoutsuite integration * refactor: Update AWS ScoutSuite report generation process * refactor: Update AWS ScoutSuite command construction * refactor: Update AWS ScoutSuite command construction * refactor: Update AWS ScoutSuite command construction * refactor: Delete ScoutSuite report and associated files * refactor: Update AWS ScoutSuite command construction * added cloud-security-assessment * updated overview page breakpoints * added cloudSecurityAssessment api/types * added AvailableReportsItem component * refactor: Remove unnecessary code in create_customer_provisioning_default_settings * refactor: modify admin password creation to fix bug with special characters * refactor: Update admin password generation to use longer length * bug: update ProvisioningDefaultSettings * provision ha proxy bug fix * refactor * update: AvailableReportsList component * refactor: Update available report generation options in ScoutSuite API to only include aws for now * added azure and gcp back to scoutsuite * add CreationReportForm component * fix: getBaseUrl function * precommit fixes --------- Co-authored-by: Davide Di Modica <[email protected]>
- Loading branch information
1 parent
8de81ec
commit 6f75c39
Showing
32 changed files
with
811 additions
and
40 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
122 changes: 122 additions & 0 deletions
122
backend/app/integrations/scoutsuite/routes/scoutsuite.py
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 os | ||
|
||
from fastapi import APIRouter | ||
from fastapi import BackgroundTasks | ||
from fastapi import HTTPException | ||
from loguru import logger | ||
|
||
from app.integrations.scoutsuite.schema.scoutsuite import ( | ||
AvailableScoutSuiteReportsResponse, | ||
) | ||
from app.integrations.scoutsuite.schema.scoutsuite import AWSScoutSuiteReportRequest | ||
from app.integrations.scoutsuite.schema.scoutsuite import ScoutSuiteReportOptions | ||
from app.integrations.scoutsuite.schema.scoutsuite import ( | ||
ScoutSuiteReportOptionsResponse, | ||
) | ||
from app.integrations.scoutsuite.schema.scoutsuite import ScoutSuiteReportResponse | ||
from app.integrations.scoutsuite.services.scoutsuite import ( | ||
generate_aws_report_background, | ||
) | ||
|
||
integration_scoutsuite_router = APIRouter() | ||
|
||
|
||
@integration_scoutsuite_router.get( | ||
"/report-generation-options", | ||
response_model=ScoutSuiteReportOptionsResponse, | ||
description="Get the available report generation options.", | ||
) | ||
async def get_report_generation_options(): | ||
""" | ||
Retrieves the available report generation options for ScoutSuite. | ||
Returns: | ||
ScoutSuiteReportOptionsResponse: The response containing the available report generation options. | ||
""" | ||
return ScoutSuiteReportOptionsResponse( | ||
options=[ScoutSuiteReportOptions.aws, ScoutSuiteReportOptions.azure, ScoutSuiteReportOptions.gcp], | ||
success=True, | ||
message="ScoutSuite Report generation options retrieved successfully", | ||
) | ||
|
||
|
||
@integration_scoutsuite_router.get( | ||
"/available-reports", | ||
response_model=AvailableScoutSuiteReportsResponse, | ||
description="Get the available ScoutSuite reports.", | ||
) | ||
async def get_available_reports(): | ||
""" | ||
List all the `.html` files from the `scoutsuite-report` directory | ||
Returns: | ||
AvailableScoutSuiteReportsResponse: The response containing the list of available ScoutSuite reports. | ||
Raises: | ||
HTTPException: If the directory does not exist. | ||
""" | ||
directory = "scoutsuite-report" | ||
full_path = os.path.abspath(directory) | ||
|
||
logger.info(f"Checking directory: {full_path}") | ||
|
||
if not os.path.exists(directory): | ||
raise HTTPException(status_code=404, detail="Directory does not exist") | ||
|
||
files = os.listdir(directory) | ||
html_files = [file for file in files if file.endswith(".html")] | ||
|
||
return AvailableScoutSuiteReportsResponse( | ||
available_reports=html_files, | ||
success=True, | ||
message="Available ScoutSuite reports retrieved successfully", | ||
) | ||
|
||
|
||
@integration_scoutsuite_router.post( | ||
"/generate-aws-report", | ||
response_model=ScoutSuiteReportResponse, | ||
) | ||
async def generate_aws_report( | ||
background_tasks: BackgroundTasks, | ||
request: AWSScoutSuiteReportRequest, | ||
): | ||
""" | ||
Endpoint to generate an AWS ScoutSuite report. | ||
Args: | ||
background_tasks (BackgroundTasks): The background tasks object. | ||
request (AWSScoutSuiteReportRequest): The request object. | ||
session (AsyncSession): The async session object for database operations. | ||
""" | ||
background_tasks.add_task(generate_aws_report_background, request) | ||
return ScoutSuiteReportResponse( | ||
success=True, | ||
message="AWS ScoutSuite report generation started successfully. This will take a few minutes to complete. Check back in shortly.", | ||
) | ||
|
||
|
||
@integration_scoutsuite_router.delete( | ||
"/delete-report/{report_name}", | ||
response_model=ScoutSuiteReportResponse, | ||
) | ||
async def delete_report( | ||
report_name: str, | ||
): | ||
""" | ||
Endpoint to delete a ScoutSuite report. | ||
Args: | ||
report_name (str): The name of the report to delete. | ||
""" | ||
report_base_name = os.path.splitext(report_name)[0] | ||
report_file_path = f"scoutsuite-report/{report_name}" | ||
exceptions_file_path = f"scoutsuite-report/scoutsuite-results/scoutsuite_exceptions_{report_base_name}.js" | ||
results_file_path = f"scoutsuite-report/scoutsuite-results/scoutsuite_results_{report_base_name}.js" | ||
|
||
files_to_delete = [report_file_path, exceptions_file_path, results_file_path] | ||
|
||
for file_path in files_to_delete: | ||
if os.path.exists(file_path): | ||
os.remove(file_path) | ||
|
||
return ScoutSuiteReportResponse(success=True, message=f"Report {report_name} and associated files deleted successfully") |
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,48 @@ | ||
from enum import Enum | ||
from typing import List | ||
|
||
from fastapi import HTTPException | ||
from pydantic import BaseModel | ||
from pydantic import Field | ||
from pydantic import root_validator | ||
|
||
|
||
class ScoutSuiteReportOptions(str, Enum): | ||
aws = "aws" | ||
azure = "azure" | ||
gcp = "gcp" | ||
|
||
|
||
class ScoutSuiteReportOptionsResponse(BaseModel): | ||
options: List[ScoutSuiteReportOptions] = Field( | ||
..., | ||
description="The available report generation options", | ||
example=["aws", "azure", "gcp"], | ||
) | ||
success: bool | ||
message: str | ||
|
||
|
||
class AWSScoutSuiteReportRequest(BaseModel): | ||
report_type: str = Field(..., description="The type of report to generate", example="aws") | ||
access_key_id: str = Field(..., description="The AWS access key ID", example="AKIAIOSFODNN7EXAMPLE") | ||
secret_access_key: str = Field(..., description="The AWS secret access key", example="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY") | ||
report_name: str = Field(..., description="The name of the report", example="aws-report") | ||
|
||
@root_validator | ||
def validate_report_type(cls, values): | ||
report_type = values.get("report_type") | ||
if report_type != ScoutSuiteReportOptions.aws: | ||
raise HTTPException(status_code=400, detail="Invalid report type.") | ||
return values | ||
|
||
|
||
class ScoutSuiteReportResponse(BaseModel): | ||
success: bool | ||
message: str | ||
|
||
|
||
class AvailableScoutSuiteReportsResponse(BaseModel): | ||
success: bool | ||
message: str | ||
available_reports: List[str] |
50 changes: 50 additions & 0 deletions
50
backend/app/integrations/scoutsuite/services/scoutsuite.py
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,50 @@ | ||
import asyncio | ||
import subprocess | ||
from concurrent.futures import ThreadPoolExecutor | ||
|
||
from loguru import logger | ||
|
||
from app.integrations.scoutsuite.schema.scoutsuite import AWSScoutSuiteReportRequest | ||
|
||
|
||
async def generate_aws_report_background(request: AWSScoutSuiteReportRequest): | ||
logger.info("Generating AWS ScoutSuite report in the background") | ||
|
||
command = construct_aws_command(request) | ||
await run_command_in_background(command) | ||
|
||
|
||
def construct_aws_command(request: AWSScoutSuiteReportRequest): | ||
"""Construct the scout command.""" | ||
return [ | ||
"scout", | ||
"aws", | ||
"--access-key-id", | ||
request.access_key_id, | ||
"--secret-access-key", | ||
request.secret_access_key, | ||
"--report-name", | ||
request.report_name, | ||
"--force", | ||
"--no-browser", | ||
] | ||
|
||
|
||
def run_command(command): | ||
"""Run the command and handle the output.""" | ||
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
stdout, stderr = process.communicate() | ||
|
||
if process.returncode != 0: | ||
logger.error(f"ScoutSuite report generation failed: {stderr.decode()}") | ||
return None | ||
|
||
logger.info("ScoutSuite report generated successfully") | ||
return None | ||
|
||
|
||
async def run_command_in_background(command): | ||
"""Run the command in a separate thread.""" | ||
with ThreadPoolExecutor() as executor: | ||
loop = asyncio.get_event_loop() | ||
await loop.run_in_executor(executor, lambda: run_command(command)) |
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,13 @@ | ||
from fastapi import APIRouter | ||
|
||
from app.integrations.scoutsuite.routes.scoutsuite import integration_scoutsuite_router | ||
|
||
# Instantiate the APIRouter | ||
router = APIRouter() | ||
|
||
# Include the ScoutSuite related routes | ||
router.include_router( | ||
integration_scoutsuite_router, | ||
prefix="/scoutsuite", | ||
tags=["ScoutSuite"], | ||
) |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.