Skip to content

Instantly share code, notes, and snippets.

@exy02
Last active October 5, 2021 19:48
Show Gist options
  • Save exy02/7543b8f74acb23e198a63d1a64ed9700 to your computer and use it in GitHub Desktop.
Save exy02/7543b8f74acb23e198a63d1a64ed9700 to your computer and use it in GitHub Desktop.
xml_interpreter_converter
import pandas as pd
import requests
import pickle
import base64
import getpass
import boto3
import json
def get_access_token():
user_successful_login = False
while user_successful_login == False:
cog_username = input("Username: ")
cog_password = getpass.getpass(prompt="Password: ")
cognito_login = boto3.client('cognito-idp', region_name='us-west-1')
try:
access_response = cognito_login.initiate_auth(
ClientId=base64.b64decode('Z2lqbGE3NHNvaWNxYWFtMmlwcWdzcG9iaQ=='.encode('utf-8')).decode('utf-8'),
AuthFlow='USER_PASSWORD_AUTH',
AuthParameters={'USERNAME': cog_username,'PASSWORD': cog_password})
id_token = access_response['AuthenticationResult']['IdToken']
access_token = access_response['AuthenticationResult']['AccessToken']
refresh_token = access_response['AuthenticationResult']['RefreshToken']
user_successful_login = True
print("=== LOGIN SUCCESSFUL ===")
return id_token, access_token, refresh_token
except Exception as e:
print("< ! > LOGIN FAILED < ! >")
print(str(e))
def convert_xml_to_df(xml_file_path):
id_token, access_token, refresh_token = get_access_token()
xml_string = open(xml_file_path).read()
xml_b64 = base64.urlsafe_b64encode(xml_string.encode('utf-8')).decode('utf-8')
xml_api = base64.b64decode('aHR0cHM6Ly93dnFpNjkwYzE5LmV4ZWN1dGUtYXBpLnVzLXdlc3QtMS5hbWF6b25hd3MuY29tL3Rlc3QveG1sLWludGVycHJldGVy'.encode('utf-8')).decode('utf-8')
api_response = requests.get(f"{xml_api}?xml={xml_b64}&access_token={access_token}", headers={"Content-type":"text/plain","Authorization":f"{id_token}"})
api_txt_response = json.loads(api_response.text)
if str(api_response) == "<Response [200]>":
if api_txt_response['check_response'] in ["VULNERABLE","ERROR","LIMIT"]:
print(str(api_response), "{message}: Request Pushback")
print(api_txt_response['response'])
return pd.DataFrame()
else:
print(str(api_response), "{message}: Request Successful")
return pickle.loads(base64.urlsafe_b64decode(api_txt_response['response'].encode('utf-8')))
else:
print(str(api_response), api_txt_response)
return pd.DataFrame()
df = convert_xml_to_df("/PATH/TO/XML.xml")
df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment