學校垃圾系統的登陸器

隨手看了看學校的破系統,除了發現登陸按鈕是使用的內建的 form 的 submit 功能提交表單。而後還發現了一個大問題,密碼居然是明文傳輸的。而後抓包後正式驗證了本身的想法,真的是明文傳送密碼。html

相比之下,高考報名系統至少也會用 rsa.js 對鏈接進行加密。gitlab 也是提交表單的,可人家建議,也確實用了 SSL 證書。
可咱們學校就很垃圾了,http,表單明文傳送密碼,這或許能夠解釋隔三岔五就有人被盜號。git

登陸是一個表單,發送到 /default2.aspx,正文中的 TextBox2 就是密碼。其中有個隱藏的表單項 __VIEWSTATE ,用正則從網頁中提取出來就行。而驗證碼,這個只能手動填寫了。。。多是經過 __VIEWSTATE 以及 Cookie 中的 ASP.NET-SessionId 來表示一個會話。編程

下面就是一個登陸器的實現。緩存

  1 # 登陸器2
  2 
  3 import requests
  4 import re
  5 from PIL import Image
  6 from io import BytesIO
  7 
  8 # 系統網址
  9 homepage_url    = 'http://jwgl.xxxx.edu.cn'
 10 check_code_url  = 'http://jwgl.xxxx.edu.cn/CheckCode.aspx'
 11 login_url       = 'http://jwgl.xxxx.edu.cn/default2.aspx'
 12 
 13 user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win32; x32) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/64.0.3282.140'
 14 
 15 # session 會話 保持一個會話
 16 s = requests.Session()
 17 
 18 # homepage
 19 
 20 homepage_headers = {
 21 'Accept': '*/*',
 22 'Accept-Encoding':'deflate',
 23 'Accept-Language': 'zh-Hans-CN, zh-Hans; q=0.8, en-US; q=0.5, en; q=0.3',
 24 'Cache-Control': 'no-cache',
 25 'Connection': 'Keep-Alive',
 26 'Host': 'jwgl.xxxx.edu.cn',
 27 'User-Agent': user_agent
 28 }
 29 
 30 # HTTP GET!
 31 homepage_res = s.get(homepage_url, headers=homepage_headers)
 32 
 33 print('homepage cookie ->', homepage_res.cookies)
 34 
 35 # check_code
 36 
 37 check_code_headers = {
 38 'Accept': 'image/png, image/svg+xml, image/*; q=0.8, */*; q=0.5',
 39 'Accept-Encoding':'deflate',
 40 'Accept-Language': 'zh-Hans-CN, zh-Hans; q=0.8, en-US; q=0.5, en; q=0.3',
 41 'Cache-Control': 'max-age=0',
 42 'Connection': 'Keep-Alive',
 43 'Host': 'jwgl.xxxx.edu.cn',
 44 'Referer': 'http://jwgl.xxxx.edu.cn/',
 45 'User-Agent': user_agent
 46 }
 47 
 48 # HTTP GET!
 49 check_code_res = s.get(check_code_url, headers=check_code_headers)
 50 
 51 # 原本以爲要緩存一下
 52 #with open('check_code.gif', 'wb') as f:
 53 #    f.write(check_code_res.content)
 54 # 感謝requests官網的直接打開例子
 55 
 56 i = Image.open(BytesIO(check_code_res.content))
 57 
 58 print('check_code_res ->', check_code_res.status_code)
 59 
 60 # login
 61 
 62 studentid = '學號'
 63 passwd = '密碼'
 64 # check_code = 'hehe' 成爲歷史吧!!!
 65 # 顯示驗證碼
 66 i.show()
 67 # 手動輸入驗證碼
 68 check_code = input('input check_code>>>>>')
 69 
 70 login_headers = {
 71 'Accept': 'text/html, application/xhtml+xml, application/xml; q=0.9, */*; q=0.8',
 72 'Accept-Encoding': 'deflate',
 73 'Accept-Language': 'zh-Hans-CN, zh-Hans; q=0.8, en-US; q=0.5, en; q=0.3',
 74 'Cache-Control': 'max-age=0',
 75 'Connection': 'Keep-Alive',
 76 'Content-Type': 'application/x-www-form-urlencoded',
 77 'User-Agent': user_agent,
 78 'Host': 'jwgl.xxxx.edu.cn',
 79 'Referer': 'http://jwgl.xxxx.edu.cn/',
 80 'Upgrade-Insecure-Requests': '1'
 81 }
 82 
 83 login_data_VIEWSTATE = re.findall(r'name="__VIEWSTATE" value="(\S+)"', homepage_res.text)[0]
 84 print('login_data_VIEWSTATE ->', login_data_VIEWSTATE)
 85 
 86 payload = {
 87 '__VIEWSTATE': login_data_VIEWSTATE,
 88 'txtUserName': studentid,
 89 'Textbox1': '',
 90 'TextBox2': passwd,
 91 'txtSecretCode': check_code,
 92 'RadioButtonList1': b'\xd1\xa7\xc9\xfa',
 93 'Button1': '',
 94 'lbLanguage': '',
 95 'hidPdrs': '',
 96 'hidsc': ''
 97 }
 98 
 99 # HTTP POST
100 login_res = s.post(login_url, data=payload, headers=login_headers)
101 
102 print('login_res ->', login_res.status_code)
103 print('--------------------')
104 print(login_res.text)

 對於搶課,還得等下次獲得相關信息後進行編程(笑)。cookie

相關文章
相關標籤/搜索