随手看了看学校的破系统,除了发现登陆按钮是使用的内建的 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