For simplicity, let’s break down the structure of a challenge notebook with the coolest one around, “test”. This is an example to validate your API key. Think of this like a tutorial in a video game when you have to look up and jump.
The notebook first contains a code cell to execute the storing of your Crucible API key and some other variables for you to authenticate to the Crucible API and structure your later requests to the correct challenge.
Copy
Ask AI
DREADNODE_API_KEY = "YOUR_API_KEY" # Replace with your actual API keyCHALLENGE = "test"CRUCIBLE_URL = "https://platform.dreadnode.io"CHALLENGE_URL = "https://test.platform.dreadnode.io"
Challenges will always come shipped with dependencies so ensure to install them via pip:
Copy
Ask AI
%pip install requests --quiet
Now we have our environment loaded, we can interact with the challenge API. This is a simple request using python to make transmit a HTTP POST request to the endpoint.
Copy
Ask AI
import requestsdef query(input_data): response = requests.post( f"{CHALLENGE_URL}/score", headers={"X-API-Key": DREADNODE_API_KEY}, json={"data": input_data} ) return response.json()query("send your text inputs here")
Yargh mateys! Flags for everyone!
Since we have our unique flag for this challenge, let’s submit it to the endpoint for some sweet kudos:
Copy
Ask AI
import requestsdef submit_flag(flag): url = f"{CRUCIBLE_URL}/api/challenges/{CHALLENGE}/submit-flag" headers = {"X-API-Key": DREADNODE_API_KEY} payload = {"challenge": CHALLENGE, "flag": flag} response = requests.post(url, headers=headers, json=payload) if response.status_code == 200: if response.json().get("correct") is True: print("The flag was correct. Congrats!") else: print("The flag was incorrect. Keep trying!") else: print("There was an error submitting your flag") print(response.text)flag = "gAAAAABnJreQ5YYJ9x9m4oFdFMXUsbmH0_FmG5trWTGzVXI-TIvB9APjquiIdv8HJzRWP56Qkm1L3ef8qXf5J6Q0s3D_-d21N2r_FMjlTbtYdXwLl4IM5wD60ut5kstqsD4k0NgNzJqxVJb7Llm1QrIAHXkL54jxgcmORWlNw9t-fKvTxoQGy0g=" # Replace with the flag once you find itsubmit_flag(flag)
Assistant
Responses are generated using AI and may contain mistakes.