ham-maximo.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/python3
  2. import subprocess
  3. import re
  4. import lxml
  5. from lxml import html
  6. import urllib.request
  7. import urllib3
  8. headers = {}
  9. headers['User-Agent'] = 'Mozilla/5.0'
  10. pool = urllib3.PoolManager()
  11. dummy='google.com'
  12. f1 = pool.request(method='GET', url=dummy, headers=headers)
  13. print("%s" % f1.getheaders())
  14. htmr = f1.data
  15. hdoc = html.document_fromstring(htmr)
  16. inputs = hdoc.xpath('//input')
  17. kvs = [(elt.attrib.get('name'), elt.attrib.get('value')) for elt in inputs if elt.attrib.get('type') == 'hidden']
  18. chk = [(elt.attrib.get('name'), "checked") for elt in inputs if elt.attrib.get('type') == 'checkbox']
  19. forms = hdoc.xpath('//form')
  20. fields = dict(kvs)
  21. href = "https://ham-wifi.maximo-it.de/login"
  22. fields.get('link-login')
  23. print(fields)
  24. print(href)
  25. f3 = pool.request_encode_body(method='POST', url=href, headers=headers, fields=fields)
  26. # print(f3.getheaders())
  27. coox = {}
  28. for cookie1 in f3.getheaders().get_all('Set-Cookie'):
  29. cookies1 = re.findall('([^= ]*)=([^; ]*); ', cookie1)
  30. for (k,v) in cookies1:
  31. coox[k] = v
  32. f3doc = html.document_fromstring(f3.data)
  33. href2 = "https://ham-wifi.maximo-it.de/login"
  34. # print(href2)
  35. headers['Cookie'] = "; ".join(["%s=%s" % (k,v) \
  36. for (k,v) in coox.items()])
  37. fields2 = {'username':'you@example.com', 'visitreason_id':10}
  38. f4 = pool.request_encode_body(method='POST', url=href2, headers=headers, fields=fields2, encode_multipart = False)
  39. # print(f4.getheaders())
  40. f4doc = html.document_fromstring(f4.data)
  41. inputs4 = f4doc.xpath('//input')
  42. kvs4 = [(elt.attrib.get('name'), elt.attrib.get('value')) for elt in inputs4 if elt.attrib.get('type') == 'hidden']
  43. fields4 = dict(kvs4)
  44. href5 = "https://gateway.maximo-it.de/login"
  45. # it is form action indeed, should be able to extract
  46. f5 = pool.request_encode_body(method='POST', url=href5, headers=headers, fields=fields4, encode_multipart = False)
  47. # print(f5.getheaders())
  48. # print(f5.data.split(b"Privacy Policy")[0])