import base64 import requests from xml.etree import ElementTree as ET import urllib.parse # SAML request in URL-encoded base64 format saml_request_url_encoded = 'rVNdb5swFH3Pr0C8g23CR7CSSLTRtqhpEhE6bXuJjLmsXsFmtunafz%2Bg29pOWp%2FGm88995x7jsTSsLbpaNbbW5nD9x6MnTnOQ9tIQ6fRyu21pIoZYahkLRhqOT1l1zsa%2BJh2WlnFVeO%2BWnp7hxkD2golx6XtZuVubg7nBEgIdRngoMR1HWIeJGGUJDgOSZosohBIGfNFkAbRvJxjnrKy5kkU8ZpEUcA5jFofQZtBduUOLpO2MT1spbFM2gHEQejh1CPzAmMaBXQ%2B%2FzKyNkNkIZmdNm%2Bt7QxFqB4QyQVraqU5%2BOrOMp%2BrFrGu%2B2t2rnplgPda2Mcx%2B5kgeLgLbbhIJGZp9m1%2FTeI0QcYoNM5Hy%2BOv1i6ErIT8%2BnZd5RPJ0A9FcfSOh1MxSmS%2FS7xU0vQt6BPoe8HhJt89pxg8PV6WJInJwh8e%2FotbpzjjQQESVYfybZ5v9odPV1efswv8Po%2FjXYEYN%2B56MHOc5cikU6F6%2Fb%2FkW7CsYpYt0Uv1Z7%2BO7oc2tpujagR%2FnPDxe6d0y%2By%2FSyM%2BmRBRefVEpb00HXBRC6jcPzJZ06gflxqYhZVrdQ%2Bug9az2dMxr%2F%2BI9U8%3D' # Decode the URL encoding saml_request_base64 = urllib.parse.unquote(saml_request_url_encoded) # Convert URL-safe base64 encoding to standard base64 encoding saml_request_base64 = saml_request_base64.replace('-', '+').replace('_', '/') # Function to fix base64 padding (missing = characters) def fix_base64_padding(data): return data + '=' * (-len(data) % 4) saml_request_base64 = fix_base64_padding(saml_request_base64) # Decode the base64-encoded SAML request try: decoded_saml_request = base64.b64decode(saml_request_base64) except Exception as e: print(f"Base64 decoding error: {e}") exit() # Assuming the data is valid XML, convert bytes to string try: decoded_saml_request_str = decoded_saml_request.decode('utf-8') except UnicodeDecodeError as e: print(f"UTF-8 decoding error: {e}") exit() # Parse the XML and access the root element try: root = ET.fromstring(decoded_saml_request_str) except ET.ParseError as e: print(f"XML parsing error: {e}") exit() # Modify the XML content (e.g., change ID and IssueInstant) root.set('ID', 'NEW_TEST_ID') root.set('IssueInstant', '2024-09-13T01:00:00Z') # Convert the modified XML to a string modified_saml_request = ET.tostring(root, encoding='utf-8', method='xml').decode('utf-8') # Encode with base64 encoded_saml_request = base64.b64encode(modified_saml_request.encode('utf-8')).decode('utf-8') # Convert to URL-safe base64 encoding encoded_saml_request = encoded_saml_request.replace('+', '-').replace('/', '_').replace('=', '') # Construct the GET request target_url = 'https://financialforce.okta.com/app/financialforce_duosecuritysaml_1/exk4t487n0a9AjNM1697/sso/saml' get_url = f"{target_url}?SAMLRequest={encoded_saml_request}" # Send the GET request to the server try: response = requests.get(get_url) if response.status_code == 200: print("Test successful: Server responded.") else: print(f"Test failed: The server did not respond or an error occurred. Response code: {response.status_code}") except requests.RequestException as e: print(f"Request error: {e}")