Skip to content
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

Adding code to print report dictionary from yaml block #61

Merged
merged 5 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion configs/local.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Do not store sensitive information and check-in code to gitlab

report:
title: "Attack Surface Management Report"
author: "John Doe"
date: "2024-09-30"
header: "Confidential - For Internal Use Only"
footer: "Company XYZ - All Rights Reserved"
format: "pdf"

workflow:
- workflowName: 'default'
schedule: 'daily between 00:00 and 04:00'
Expand Down Expand Up @@ -84,6 +92,14 @@ workflow:
tools: ['Cloudflare']
order: 1

- workflowName: 'testreport'
schedule: 'daily between 00:00 and 04:00'
cmd: []
workflowConfig:
- moduleName : discovery
tools: ['Subfinder']
order: 1

nuclei_template_path:
whitelist:
blacklist:
Expand Down Expand Up @@ -161,4 +177,4 @@ logging_debug:

root:
level: DEBUG
handlers: [console]
handlers: [console]
3 changes: 2 additions & 1 deletion mantis/config_parsers/config_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class NucleiTemplate(BaseModel):
blacklist: str = Field(None)

class AppConfig(BaseModel):
report: dict
workflow: List[Workflow]
dbConfig: DBConfig
logging: dict
Expand All @@ -57,4 +58,4 @@ class AppConfig(BaseModel):
app: dict
nuclei_template_path: NucleiTemplate
aws: AWSConfig


3 changes: 2 additions & 1 deletion mantis/models/args_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ class ArgsModel(BaseModel):
subdomain: str = Field(None)
list_: bool = False
list_orgs: bool = False
report_: bool = False
list_domains: bool = False
orgs_list: list[str] = False
asset_types_list: list[str] = False
after_datetime_filter: str = None
before_datetime_filter: str = None
in_scope: bool = False


20 changes: 18 additions & 2 deletions mantis/utils/args_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ def list_msg(name=None):

\033[0;32mmantis list {subcommand}\033[0m
'''

@staticmethod
def report_msg(name=None):
return '''
\033[1;34mREPORT:\033[0m
\033[0;32mmantis report -o example_org\033[0m
'''

@staticmethod
def args_parse() -> ArgsModel:
Expand Down Expand Up @@ -248,6 +255,13 @@ def args_parse() -> ArgsModel:
list_parser.add_argument("-a","--after", type=str, help="Start date in YYYY-MM-DD format", dest="list_sub_command_ls_subs_after_filter")
list_parser.add_argument("-b","--before", type=str, help="End date in YYYY-MM-DD format", dest="list_sub_command_ls_subs_before_filter")

report_parser = subparser.add_parser("report", help="Generate report", usage=ArgsParse.report_msg())

report_parser.add_argument('-o', '--org',
dest = 'org',
required = True,
help = "name of the organisation")

# display help, if no arguments are passed
args = parser.parse_args(args=None if argv[1:] else ['--help'])
logging.info(f"Arguments Passed - {args}")
Expand All @@ -264,7 +278,7 @@ def args_parse() -> ArgsModel:
parsed_args['input_type'] = "file"
parsed_args['input'] = str(args.file_name)

if args.subcommand != "list":
if args.subcommand != "list" and args.subcommand != "report":

if args.aws_profiles:
parsed_args["aws_profiles"] = args.aws_profiles.split(',')
Expand Down Expand Up @@ -320,6 +334,8 @@ def args_parse() -> ArgsModel:
if args.list_sub_command_ls_orgs:
parsed_args["list_orgs"] = True

if args.subcommand == "report":
parsed_args["report_"] = True
# python launch.py list -d -s -t -o <org> -a 2024-10-04 -b 2024-10-05
if args.list_sub_command_ls_domains:
asset_types = []
Expand All @@ -344,4 +360,4 @@ def args_parse() -> ArgsModel:

return args_pydantic_obj



5 changes: 4 additions & 1 deletion mantis/workflows/mantis_workflow.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from mantis.models.args_model import ArgsModel
from mantis.modules.workflow import Workflow
from mantis.workflows.list_workflow import ListWorkflow
from mantis.workflows.report_workflow import ReportWorkflow
import asyncio

class MantisWorkflow:
Expand All @@ -9,6 +10,8 @@ def select_workflow(args: ArgsModel) -> None:

if args.list_:
asyncio.run(ListWorkflow.executor(args))
elif args.report_:
asyncio.run(ReportWorkflow.executor())
else:
asyncio.run(Workflow.workflow_executor(args))


9 changes: 9 additions & 0 deletions mantis/workflows/report_workflow.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you directly use configprovider to access the config here? Having an util just for this is redundant. If any usecase arrives in future we can move this as an util

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Changes removed from config_utils.py and modified report_workflow to directly use ConfigProvider

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import logging
from mantis.config_parsers.config_client import ConfigProvider

class ReportWorkflow:

@staticmethod
async def executor():
report = ConfigProvider.get_config().report
print(f"Report: {report}")