-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import requests | ||
from azure.identity import DefaultAzureCredential | ||
|
||
from subdomain_takeover_tools.helper.main import bootstrap, settings | ||
from subdomain_takeover_tools.helper.prepare import resolve_cname | ||
|
||
EDGE_CDN = '.azure-api.net' | ||
|
||
credential = DefaultAzureCredential() | ||
|
||
session = requests.Session() | ||
(token, _) = credential.get_token('https://management.azure.com/.default') | ||
session.headers['Authorization'] = "Bearer " + token | ||
url = "https://management.azure.com/api/invoke" | ||
|
||
|
||
def is_valid(hostname, cname): | ||
if hostname == cname: | ||
cname = resolve_cname(hostname) | ||
|
||
if cname is None: | ||
return False | ||
|
||
return confirm_azure_edge_cdn(cname) | ||
|
||
|
||
def confirm_azure_edge_cdn(cname): | ||
try: | ||
if cname.count('.') == 2 and EDGE_CDN in cname: | ||
dns_prefix = cname.replace(EDGE_CDN, '') | ||
result = session.post(url, json={'name': dns_prefix, 'type': 'Microsoft.ApiManagement/service'}, headers={ | ||
"X-Ms-Path-Query": | ||
"/subscriptions/" + settings['azure']['subscription_id'] | ||
+ "/providers/Microsoft.ApiManagement/checkNameAvailability?api-version=2022-09-01-preview" | ||
}) | ||
return result.json()['nameAvailable'] | ||
except KeyError: | ||
pass | ||
return False | ||
|
||
|
||
def main(): | ||
bootstrap(is_valid) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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