Skip to content

Instantly share code, notes, and snippets.

@abhi-io
Created February 28, 2025 05:13
Show Gist options
  • Save abhi-io/e38696192134eaa817ac3b17ad9b10f1 to your computer and use it in GitHub Desktop.
Save abhi-io/e38696192134eaa817ac3b17ad9b10f1 to your computer and use it in GitHub Desktop.
Cloudflare Widget Data Extraction
import requests
import json
account_id = "1ed--61e"
url = f"https://api.cloudflare.com/client/v4/accounts/{account_id}/challenges/widgets"
headers = {
"X-Auth-Email": "[email protected]",
"X-Auth-Key": "504--1e6" #not API token
}
def get_secret(sitekey:str):
url = f"https://api.cloudflare.com/client/v4/accounts/{account_id}/challenges/widgets/{sitekey}"
response = requests.get(url, headers=headers)
data = response.json()
widgets = data["result"]
return widgets["secret"]
response = requests.get(url, headers=headers)
if response.status_code == 200:
data = response.json()
if data["success"]:
widgets = data["result"]
widget_data = []
for widget in widgets:
widget_info = {
"name": widget["name"],
"sitekey": widget["sitekey"],
"secret": get_secret(sitekey=widget["sitekey"]),
# "mode": widget["mode"],
"domains": widget["domains"],
# "created_on": widget["created_on"],
# "modified_on": widget["modified_on"],
# "bot_fight_mode": widget["bot_fight_mode"],
# "region": widget["region"],
# "offlabel": widget["offlabel"],
# "ephemeral_id": widget["ephemeral_id"],
# "clearance_level": widget["clearance_level"]
}
widget_data.append(widget_info)
print(widget_data)
with open("widgets.json", "w") as f:
json.dump(widget_data, f, indent=4)
else:
print("API request failed:", data["errors"])
else:
print(f"Error: {response.status_code} - {response.text}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment