|
楼主 |
发表于 2014-10-29 16:27
|
显示全部楼层
本帖最后由 moon2778 于 2014-11-17 13:41 编辑
复杂登录二:58同城登录
网站:https://passport.58.com/login
代码运行时可能会跳出信任错误,请事先在internet选项中进行设置:
Internet选项----高级----安全,去掉“检查服务器证书吊销*”前面的勾。
登录并抓包。
找到登录网页,查看参数:
搜索各参数名:
上面的这几个是明码(值在网页里能找到)。
这几个是加密数据,由javascript函数计算所得。
把参数来源列张表更清晰:
接下来查找包含加密算法函数的JS文件:
找到:
1、h t t ps://passport.58.com/js/v6/source/828ef34c77a2cbed693ba874ce570dfe.js?version=0.0.2
这个文件是由h t t ps://passport.58.com/static/ppt/js/5_1/comm_js/boot_passport_version.js里的函数产生的,所以我们需要先GET 后面那个js文件,以获取前面那个js文件名;
2、h t t ps://passport.58.com/rsa/ppt_security.js
这个文件里面包含了JQuery代码,所以同时还必须加载h t t ps://passport.58.com/static/js/5_1/jquery1.3.2.js
和上一次登录的例子不同,这次的JS函数包含了操作html的代码(JQuery大部分都是这种),不能在ScriptControl控件里运行了,必须在Html里运行。把js文件名写入DOM的script节点的src属性里,然后DOM的parentwindow就可以执行JS文件里的各种全局函数了。同前,vba代码编写的时候,最好用callbyname调用这些函数。
完整的代码:- Sub Main()
- Const strHost As String = "https://passport.58.com"
- Const Username As String = "vbatest"
- Const Password As String = "12341234"
- Dim strText As String, SendData
- Dim objDom As Object, objWin As Object, objXML As Object
- Dim arrJSFile(), i As Integer, strJS As String
- Dim path, pts, ptk, cd, timesign, timespan, p1, p2, p3, key1, key2
-
- '初始化赋值
- Set objDom = CreateObject("htmlfile")
- objDom.write "<script></script>" '添加一个空script节点
- Set objWin = objDom.parentwindow
- Set objXML = CreateObject("MSXML2.XMLHTTP")
- arrJSFile = Array("jquery1.3.2.js", "ppt_security.js", "boot_passport_version.js") '要加载的js文件名
-
- '获取主页面的源代码
- objXML.Open "GET", strHost & "/login", False
- objXML.Send
- strText = objXML.responsetext
-
- '获取各参数的明码值及运算时所需的值
- path = Split(Split(strText, "name=""path"" value=""")(1), """")(0) '获取参数path
- pts = Split(path, "/?pts=")(1) '用于timesign参数的计算
- timespan = pts - CallByName(objWin, "eval", VbMethod, "new Date().getTime()") '用于timesign参数计算
- ptk = Split(Split(strText, "id=""ptk"" value=""")(1), """")(0) '获取参数ptk
- cd = Split(Split(strText, "id=""cd"" value=""")(1), """")(0) '获取参数cd
- key1 = Split(Split(strText, """#password"").val()),""")(1), """")(0) 'encryptString函数的第二参数
- key2 = Split(Split(strText, """#password"").val()),""" & key1 & """,""")(1), """")(0) 'encryptString函数的第三参数
-
- '先下载JS文件到缓存(GET请求一次即可),以提高DOM加载JS文件的速度。(否则加载会有延迟)
- For i = 0 To 2
- '58的js路径有时会变,用下面这个小函数在HTML代码里寻找js文件的完整路径名
- arrJSFile(i) = FindJSFile(strText, arrJSFile(i), strHost)
- objXML.Open "GET", arrJSFile(i), False
- objXML.Send
- Next
-
- '找到所需的第三个JS文件名并GET到缓存
- strText = objXML.responsetext
- arrJSFile(2) = Split(Split(strText, "try{var d=""")(1), """")(0) & Split(Split(strText, "just"":""")(1), """")(0)
- objXML.Open "GET", arrJSFile(2), False
- objXML.Send
-
- '将JS文件加载进HTML
- For i = 0 To 2
- strJS = strJS & "<script src=""" & arrJSFile(i) & """></script>"
- Next
- objDom.write strJS '加载
-
- '执行函数计算各参数的值
- timesign = CStr(CallByName(objWin, "eval", VbMethod, "new Date().getTime()") + timespan)
- p1 = CallByName(objWin, "getm32str", VbMethod, Password, timesign)
- p2 = CallByName(objWin, "getm16str", VbMethod, Password, timesign)
- p3 = CallByName(objWin, "encryptString", VbMethod, timesign & CallByName(objWin, "encodeURIComponent", VbMethod, Password), key1, key2)
-
- '生成POST用的SendData
- SendData = "isweak=0"
- SendData = SendData & "&path=" & path
- SendData = SendData & "&p1=" & p1
- SendData = SendData & "&p2=" & p2
- SendData = SendData & "&p3=" & p3
- SendData = SendData & "×ign=" & timesign
- SendData = SendData & "&ptk=" & ptk
- SendData = SendData & "&cd=" & cd
- SendData = SendData & "&username=" & Username
- SendData = SendData & "&password=password"
- SendData = SendData & "&mcresult=undefined"
-
- '登录
- With objXML
- .Open "POST", "https://passport.58.com/dounionlogin", False
- .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
- .Send SendData
- Debug.Print .getallresponseheaders '包含58cooper和58passport的Set-Cookie即为登录成功
- Debug.Print .responsetext '成功时这里包含location
- End With
-
- Set objXML = Nothing
- Set objWin = Nothing
- Set objDom = Nothing
- End Sub
- Function FindJSFile(Html As String, JSName, Host As String)
- '在HTML代码里找到以JSName为名的JS文件的全路径名。没有Host的添加Host
- With CreateObject("vbscript.regexp")
- .Pattern = "[\s\S]+<script\s+(?:type=""text/javascript""\s+)?src=""([^""]+/" & Replace(JSName, ".", "\.") & ")""[\s\S]+"
- FindJSFile = .Replace(Html, "$1")
- If Not FindJSFile Like "http*" Then FindJSFile = Host & FindJSFile
- End With
- End Function
复制代码 |
评分
-
3
查看全部评分
-
|