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

Added exception handling & email param in cloudflare DNS module #53

Merged
merged 5 commits into from
Oct 16, 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
1 change: 1 addition & 0 deletions mantis/models/args_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ class ArgsModel(BaseModel):
subdomain: str = Field(None)
list_: bool = False
list_orgs: bool = False
in_scope: bool = False

45 changes: 33 additions & 12 deletions mantis/modules/dns/Cloudflare.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import logging
from mantis.utils.tool_utils import get_assets_grouped_by_type
from mantis.config_parsers.config_client import ConfigProvider
from mantis.tool_base_classes.baseScanner import BaseScanner
from mantis.models.args_model import ArgsModel
Expand All @@ -19,6 +20,7 @@ class Cloudflare(BaseScanner):

async def init(self, args: ArgsModel):
self.args = args
self.db_assets = await get_assets_grouped_by_type(self, args, ASSET_TYPE_TLD)
return [(self, "Cloudflare")]

async def execute(self, tooltuple):
Expand All @@ -32,17 +34,22 @@ async def main(self):
Prerequisite for this script - A CLoudflare DNS Zone Read only API key \n

"""
token = None

cf = CloudFlare.CloudFlare(token, raw=True)
token = None #Edit the value with actual token
per_page = 100

zones = cf.zones.get(params={'per_page': per_page, 'page': 0})
output_dict_list = []
results = {}
results["success"] = 0
results["failure"] = 0
try:
try:
cf = CloudFlare.CloudFlare("", token, raw=True)
zones = cf.zones.get(params={'per_page': per_page, 'page': 0})
results["success"] += 1
except Exception as e:
results["failure"] += 1
results["exception"] = str(e)
logging.error("[!] Error - {}".format(str(e)))

for zone_page in range(zones['result_info']['total_pages']):
zones = cf.zones.get(params={'per_page': per_page, 'page': zone_page})
for zone in zones['result']:
Expand All @@ -53,14 +60,28 @@ async def main(self):
records = cf.zones.dns_records.get(zone['id'], params={'per_page': per_page, 'page': record_page})['result']
for record in records:
domain_dict = {}
domain_dict['_id'] = record['name']
domain_dict['asset'] = record['name']
if AssetType.check_tld(record['name']):
domain_dict['asset_type'] = ASSET_TYPE_TLD
if(self.args.in_scope == True):
print(self.db_assets)
for asset in self.db_assets:
if(asset in record['name']):
domain_dict['_id'] = record['name']
domain_dict['asset'] = record['name']
if AssetType.check_tld(record['name']):
domain_dict['asset_type'] = ASSET_TYPE_TLD
else:
domain_dict['asset_type'] = ASSET_TYPE_SUBDOMAIN
domain_dict['org'] = self.args.org
output_dict_list.append(domain_dict)
break
else:
domain_dict['asset_type'] = ASSET_TYPE_SUBDOMAIN
domain_dict['org'] = self.args.org
output_dict_list.append(domain_dict)
domain_dict['_id'] = record['name']
domain_dict['asset'] = record['name']
if AssetType.check_tld(record['name']):
domain_dict['asset_type'] = ASSET_TYPE_TLD
else:
domain_dict['asset_type'] = ASSET_TYPE_SUBDOMAIN
domain_dict['org'] = self.args.org
output_dict_list.append(domain_dict)
await CrudUtils.insert_assets(output_dict_list, source='internal')
results["success"] = 1
return results
Expand Down
6 changes: 6 additions & 0 deletions mantis/utils/args_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ def args_parse() -> ArgsModel:
scan_parser.add_argument('--sub',
dest = 'subdomain',
help='Subdomain to scan')

scan_parser.add_argument('-is', '--in_scope',
dest = 'in_scope',
help = 'List only the records from nameserver that are in scope',
action = 'store_true'
)


list_parser = subparser.add_parser("list", help="List entities present in db", usage=ArgsParse.list_msg())
Expand Down
Loading