写爬虫的时候,只能需要模拟登录。有些网站可以直接用POST明文密码登录,但有价值的网站通常会加密密码,然后发送。理解JS加密是必要的。
今天,我们先来看看优酷的登录加密。需要的工具:开发人员工具所在的浏览器、JS调试工具。我用360浏览器和鬼JS调试工具7.0。是的,首先打开优酷,然后打开开发者工具。
用户名随意丢失手机号码的话,密码是123456。接受吧
你看。倒数第二个是登录请求。点击是get请求。拖到底部可以看到这个。
很明显,密码是加密的。然后我们搜索了密码这个关键词。
点击确认是否有有效信息,前两个发现没有有用信息,打开第三个。
直接Ctrl F搜索password关键字,发现有79个。愚蠢的方法是逐个降低断点或分析内容。
有Loginsubmit。命名上是提交登录的意思。这里应该就是这里。可以在这里下断点。
我们回到优酷登录界面点击登录
网页被断下来了,我们看到出现了阴影部分t=””这是变量t的值,我们按下F10继续下一步,
被加密的密码出现了,那么这一行就是加密的过程。我们现在打开JS调试工具,
提示这个,那我们就来找一下I,把鼠标放在上面:
点开这个function I(e),把相关的代码复制进去,运行得到
与结果是一样的。
Js代码:
function G(e) {
return Z(Q(X(e)))
}
function Q(e) {
return ee(ie(J(e), 8 * e.length))
}
var ii = 0
function Z(e) {
for (var i, o = ii ? "0123456789ABCDEF" : "0123456789abcdef", t = "", r = 0; r < e.length; r++)
i = e.charCodeAt(r),
t += o.charAt(i >>> 4 & 15) + o.charAt(15 & i);
return t
}
function X(e) {
for (var i, o, t = "", r = -1; ++r < e.length; )
i = e.charCodeAt(r),
o = r + 1 < e.length ? e.charCodeAt(r + 1) : 0,
55296 <= i && i <= 56319 && 56320 <= o && o <= 57343 && (i = 65536 + ((1023 & i) << 10) + (1023 & o),
r++),
i <= 127 ? t += S(i) : i <= 2047 ? t += S(192 | i >>> 6 & 31, 128 | 63 & i) : i <= 65535 ? t += S(224 | i >>> 12 & 15, 128 | i >>> 6 & 63, 128 | 63 & i) : i <= 2097151 && (t += S(240 | i >>> 18 & 7, 128 | i >>> 12 & 63, 128 | i >>> 6 & 63, 128 | 63 & i));
return t
}
function J(e) {
for (var i = Array >> 2), o = 0; o < i.length; o++)
i[o] = 0;
for (var o = 0; o < 8 * e.length; o += 8)
i[o >> 5] |= (255 & e.charCodeAt(o / 8)) << o % 32;
return i
}
function ee(e) {
for (var i = "", o = 0; o < 32 * e.length; o += 8)
i += S(e[o >> 5] >>> o % 32 & 255);
return i
}
function ie(e, i) {
e[i >> 5] |= 128 << i % 32,
e[14 + (i + 64 >>> 9 << 4)] = i;
for (var o = 1732584193, t = -271733879, r = -1732584194, n = 271733878, s = 0; s < e.length; s += 16) {
var a = o
, l = t
, c = r
, d = n;
o = te(o, t, r, n, e[s + 0], 7, -680876936),
n = te(n, o, t, r, e[s + 1], 12, -389564586),
r = te(r, n, o, t, e[s + 2], 17, 606105819),
t = te(t, r, n, o, e[s + 3], 22, -1044525330),
o = te(o, t, r, n, e[s + 4], 7, -176418897),
n = te(n, o, t, r, e[s + 5], 12, 1200080426),
r = te(r, n, o, t, e[s + 6], 17, -1473231341),
t = te(t, r, n, o, e[s + 7], 22, -45705983),
o = te(o, t, r, n, e[s + 8], 7, 1770035416),
n = te(n, o, t, r, e[s + 9], 12, -1958414417),
r = te(r, n, o, t, e[s + 10], 17, -42063),
t = te(t, r, n, o, e[s + 11], 22, -1990404162),
o = te(o, t, r, n, e[s + 12], 7, 1804603682),
n = te(n, o, t, r, e[s + 13], 12, -40341101),
r = te(r, n, o, t, e[s + 14], 17, -1502002290),
t = te(t, r, n, o, e[s + 15], 22, 1236535329),
o = re(o, t, r, n, e[s + 1], 5, -165796510),
n = re(n, o, t, r, e[s + 6], 9, -1069501632),
r = re(r, n, o, t, e[s + 11], 14, 643717713),
t = re(t, r, n, o, e[s + 0], 20, -373897302),
o = re(o, t, r, n, e[s + 5], 5, -701558691),
n = re(n, o, t, r, e[s + 10], 9, 38016083),
r = re(r, n, o, t, e[s + 15], 14, -660478335),
t = re(t, r, n, o, e[s + 4], 20, -405537848),
o = re(o, t, r, n, e[s + 9], 5, 568446438),
n = re(n, o, t, r, e[s + 14], 9, -1019803690),
r = re(r, n, o, t, e[s + 3], 14, -187363961),
t = re(t, r, n, o, e[s + 8], 20, 1163531501),
o = re(o, t, r, n, e[s + 13], 5, -1444681467),
n = re(n, o, t, r, e[s + 2], 9, -51403784),
r = re(r, n, o, t, e[s + 7], 14, 1735328473),
t = re(t, r, n, o, e[s + 12], 20, -1926607734),
o = ne(o, t, r, n, e[s + 5], 4, -378558),
n = ne(n, o, t, r, e[s + 8], 11, -2022574463),
r = ne(r, n, o, t, e[s + 11], 16, 1839030562),
t = ne(t, r, n, o, e[s + 14], 23, -35309556),
o = ne(o, t, r, n, e[s + 1], 4, -1530992060),
n = ne(n, o, t, r, e[s + 4], 11, 1272893353),
r = ne(r, n, o, t, e[s + 7], 16, -155497632),
t = ne(t, r, n, o, e[s + 10], 23, -1094730640),
o = ne(o, t, r, n, e[s + 13], 4, 681279174),
n = ne(n, o, t, r, e[s + 0], 11, -358537222),
r = ne(r, n, o, t, e[s + 3], 16, -722521979),
t = ne(t, r, n, o, e[s + 6], 23, 76029189),
o = ne(o, t, r, n, e[s + 9], 4, -640364487),
n = ne(n, o, t, r, e[s + 12], 11, -421815835),
r = ne(r, n, o, t, e[s + 15], 16, 530742520),
t = ne(t, r, n, o, e[s + 2], 23, -995338651),
o = se(o, t, r, n, e[s + 0], 6, -198630844),
n = se(n, o, t, r, e[s + 7], 10, 1126891415),
r = se(r, n, o, t, e[s + 14], 15, -1416354905),
t = se(t, r, n, o, e[s + 5], 21, -57434055),
o = se(o, t, r, n, e[s + 12], 6, 1700485571),
n = se(n, o, t, r, e[s + 3], 10, -1894986606),
r = se(r, n, o, t, e[s + 10], 15, -1051523),
t = se(t, r, n, o, e[s + 1], 21, -2054922799),
o = se(o, t, r, n, e[s + 8], 6, 1873313359),
n = se(n, o, t, r, e[s + 15], 10, -30611744),
r = se(r, n, o, t, e[s + 6], 15, -1560198380),
t = se(t, r, n, o, e[s + 13], 21, 1309151649),
o = se(o, t, r, n, e[s + 4], 6, -145523070),
n = se(n, o, t, r, e[s + 11], 10, -1120210379),
r = se(r, n, o, t, e[s + 2], 15, 718787259),
t = se(t, r, n, o, e[s + 9], 21, -343485551),
o = ae(o, a),
t = ae(t, l),
r = ae(r, c),
n = ae(n, d)
}
return Array(o, t, r, n)
}
function oe(e, i, o, t, r, n) {
return ae(le(ae(ae(i, e), ae(t, n)), r), o)
}
function te(e, i, o, t, r, n, s) {
return oe(i & o | ~i & t, e, i, r, n, s)
}
function re(e, i, o, t, r, n, s) {
return oe(i & t | o & ~t, e, i, r, n, s)
}
function ne(e, i, o, t, r, n, s) {
return oe(i ^ o ^ t, e, i, r, n, s)
}
function se(e, i, o, t, r, n, s) {
return oe(o ^ (i | ~t), e, i, r, n, s)
}
function ae(e, i) {
var o = (65535 & e) + (65535 & i);
return (e >> 16) + (i >> 16) + (o >> 16) << 16 | 65535 & o
}
function le(e, i) {
return e << i | e >>> 32 - i
}
function test(aa){
return G(aa);
}
1.《优酷登录加密JS分析》援引自互联网,旨在传递更多网络信息知识,仅代表作者本人观点,与本网站无关,侵删请联系页脚下方联系方式。
2.《优酷登录加密JS分析》仅供读者参考,本网站未对该内容进行证实,对其原创性、真实性、完整性、及时性不作任何保证。
3.文章转载时请保留本站内容来源地址,https://www.lu-xu.com/gl/3140990.html