这次依然是以黎明大学的教务管理系统为例,因为之前我认为他的POST是很简单的,可是后来发现,他进行了加密,而且用其他的信息来加密另一个信息,所以我这次重新分析一遍,这里涉及到javascript,我都不会,但是通过百度都能查到,下面看我是怎么一步步挤牙膏的。
我们先来读表单的内容,选取可能被加密的
<input class="tx1" id="txt_pewerwedsdfsdff"
style="WIDTH:134px;HEIGHT:20px"
type="password" maxLength="25"
name="txt_pewerwedsdfsdff"
value="" onblur="chkpwd(this)"
onkeyup="chkpwd(this)">
<input class="tx1" id="txt_sdertfgsadscxcadsads"
name="txt_sdertfgsadscxcadsads"
style="WIDTH:134px;HEIGHT:20px"
onblur="chkyzm(this)" onkeyup="chkyzm(this)"
maxlength="4">
这里我们可以看到,有涉及到两个有关javascript的。
通过查阅资料:
onkeyup 事件会在键盘按键被松开时发生。(瞬间执行)
onblur 事件会在对象失去焦点时发生。(移出输入框点击随机位置后后执行)
我们跳到这里他涉及到的两个chkpwd()和chkyzm()
原来的代码很乱,我给他整理了
function chkpwd(obj) {
if(obj.value!='') {
var s=md5(document.all.txt_asmcdefsddsd.value+md5(obj.value).substring(0,30).toUpperCase()+'11317').substring(0,30).toUpperCase();
document.all.dsdsdsdsdxcxdfgfg.value=s;
}
else {
document.all.dsdsdsdsdxcxdfgfg.value=obj.value;
}
}
function chkyzm(obj) {
if(obj.value!='') {
var s=md5(md5(obj.value.toUpperCase()).substring(0,30).toUpperCase()+'11317').substring(0,30).toUpperCase();
document.all.fgfggfdgtyuuyyuuckjg.value=s;
}else {
document.all.fgfggfdgtyuuyyuuckjg.value=obj.value.toUpperCase();
}
}
其实我看不懂这些代码,但是我可以查,我先从参数开始看起
把this传给obj,这里的this我们要知道他是谁
没有找到详细的回答,但我从下面的代码猜测
obj.value
这个this代替的就是传递过来的参数的那个对象本身,而这个value就是他的值。
我们再接着读代码,
toUpperCase() 方法用于把字符串转换为大写。
substring() 方法用于提取字符串中介于两个指定下标之间的字符。
比如substring(0:30)就是取前30个字符。
这里就是繁琐的大写,取30位,还有一个就是MD5加密,用的是hash算法。
md5()这个函数可以在他导入的js看到
<script type="text/javascript" src="../js/md5.js">script>
这里我们就不打开了,代码太长,而且MD5加密可以通过python的库函数加密。
# -*- coding: utf-8 -*-
import urllib2
import urllib
import cookielib
import cStringIO
import re
import os
import hashlib
#避免编码出错#
import sys
reload(sys)
sys.setdefaultencoding( "utf-8" )
##########################################################
#cookie部分#
#cookie对象#
cookieJar = cookielib.MozillaCookieJar()
#绑定cookie对象和cookie处理器#
cookieSupport = urllib2.HTTPCookieProcessor(cookieJar)
#用于调试的两个httpHandler#
httpHandler = urllib2.HTTPHandler(debuglevel=1)
httpsHandler = urllib2.HTTPSHandler(debuglevel=1)
#创建opener,把httpHandler和HTTP处理器绑定#
opener = urllib2.build_opener(cookieSupport, httpHandler)
#安装opener#
urllib2.install_opener(opener)
##########################################################
#一些变量的定义#
#登陆页面地址#
loginpage = "http://jwmis.lmu.cn/_data/index_LOGIN.aspx"
#处理POST信息的页面#
postURL = "http://jwmis.lmu.cn/_data/index_LOGIN.aspx"
##########################################################
#测试部分,测试cookie是否获取成功#
'''
LoginCookies = urllib2.urlopen(loginpage)
#打印cookies,成功打印,说明cookie获取成功#
print cookieJar
'''
##########################################################
#编写要发送的信息#
#其他变量处理#
userid = raw_input("userid:\n")
password = raw_input("password:\n")
m = hashlib.md5()
m.update(password)
psw = m.hexdigest()
s1 = userid + psw[0:30].upper() + '11317'
m1 = hashlib.md5()
m1.update(s1)
s2 = m1.hexdigest()
s3 = s2[0:30].upper()
dsdsdsdsdxcxdfgfg = s3
#验证码的处理#
im_url = 'http://jwmis.lmu.cn/sys/ValidateCode.aspx'
im_data = urllib2.urlopen(im_url).read()
f=open('Code.png','wb')
f.write(im_data)
f.close()
validateCode = raw_input("Code:\n")
code = validateCode.upper()
m2 = hashlib.md5()
m2.update(code)
s4 = m2.hexdigest()
s5 = s4[0:30].upper() + '11317'
m3 = hashlib.md5()
m3.update(s5)
s6 = m3.hexdigest()
s7 = s6[0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gfg' : dsdsdsdsdxcxdfgfg,
'fgfggfdgtyuuyyuuckjg' : fgfggfdgtyuuyyuuckjg,
'Sel_Type' : 'STU',
'txt_asmcdefsddsd' : userid,
'txt_pewerwedsdfsdff' : password,
'txt_sdertfgsadscxcadsads' : validateCode,
'sbtState' : ''
}
#设置cookies的值#
cookies = ''
#这里要从
for index, cookie in enumerate(cookieJar):
#print '[',index, ']';
#print cookie.name;
#print cookie.value;
#print "###########################"
cookies = cookies+cookie.name+"="+cookie.value+";";
cookie = cookies[:-1]
#post请求头#
headers = {
'Host' : 'jwmis.lmu.cn',
'User-Agent' : 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0',
'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language' : 'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
'Accept-Encoding' : 'gzip, deflate',
'Cookie' : cookie,
'Connection' : 'keep-alive',
'Content-Type' : 'application/x-www-form-urlencoded',
'Content-Length' : '5587'
}
#合成post数据
data = urllib.urlencode(PostData)
print "data:###############"
print data
#创建request
#构造request请求
request = urllib2.Request( postURL,data,headers )
try:
#访问页面
response = urllib2.urlopen(request)
#cur_url = response.geturl()
#print "cur_url:",cur_url
status = response.getcode()
print "yes"
except urllib2.HTTPError, e:
print "error"
#访问该链接#
result = opener.open(request)
#打印返回的内容#
print result.read()
#print dsdsdsdsdxcxdfgfg