Pandaaaa906

szu

Nov 15th, 2020
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.37 KB | None | 0 0
  1. from base64 import b64encode
  2. from random import choices
  3.  
  4. from Crypto.Cipher import AES
  5. from more_itertools import first
  6. from requests_html import HTMLSession
  7.  
  8. url_login = 'https://webvpn.ujs.edu.cn/https/77726476706e69737468656265737421e0f6528f69256243300d8db9d6562d/cas/login'
  9.  
  10. username = 'asdf'
  11. pwd = '123456'
  12.  
  13. def pad(m):
  14.     return m+chr(16-len(m)%16)*(16-len(m)%16)
  15.  
  16. def unpad(ct):
  17.     return ct[:-ord(ct[-1])]
  18.  
  19. def rds(n):
  20.     return ''.join(choices('ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678', k=n))
  21.  
  22. # getting initial variable
  23. s = HTMLSession()
  24. r = s.get(url_login)
  25. html = r.html
  26. salt = first(html.xpath('//input[@id="pwdDefaultEncryptSalt"]/@value'), None)
  27. lt = first(html.xpath('//input[@name="lt"]/@value'), None)
  28. dllt = first(html.xpath('//input[@name="dllt"]/@value'), None)
  29. execution = first(html.xpath('//input[@name="execution"]/@value'), None)
  30. rmShown = first(html.xpath('//input[@name="rmShown"]/@value'), None)
  31.  
  32. # encrypt password
  33. key = salt.encode()
  34. cipher = AES.new(key, AES.MODE_CBC, iv=rds(16).encode())
  35. encrypted_pwd = b64encode(cipher.encrypt((pad(rds(64)+pwd)).encode()))
  36.  
  37.  
  38. d = {
  39.     'username': username,
  40.     'password': encrypted_pwd,
  41.     'lt': lt,
  42.     'dllt': dllt,
  43.     'execution': execution,
  44.     '_eventId': 'submit',
  45.     'rmShown': rmShown,
  46. }
  47.  
  48. r = s.post(url_login, d)
  49.  
  50.  
  51. if __name__ == '__main__':
  52.     pass
  53.  
Add Comment
Please, Sign In to add comment