js混淆解密_谷歌镜像的url分析

参考(万分感谢):http://blog.icxun.cn/Python/438.html

刚开始学习爬虫,遇到了一个js加密的网站,技术不够,很无奈,开始了学习js加密解密的路,一个简单的加密网站作为demo。

开始:

 目标网址:http://ac.scmor.com/

想爬取红框内部的url,首先进行分析

F12开发者模式,发现a标签的onclick触发了一个visit()函数,而且里面的参数不可读,不在是一个url地址,断定网页已经进行过加密。

开始分析,a标签调用了函数,而函数在js文件中调用,所有在所有的js文件中搜索visit关键字。

已经找到了visit存在的js文件,双击后,右边response中显示具体函数

分析visit函数得知,函数中使用了Gword变量进行判断是否为空,不为空的时候执行如下代码,执行后继续执行使用lication实现网页跳转

url = strdecode(url)

我们继续搜索Gword变量,开始分析一共又三处,都在和保存visit函数相同js文件内,目前开来Gword是不在js文件中定义的。

那么,我们尝试的去网页中进行寻找,网页->右键->查看网页源代码进行搜索

存在!!,Gword的值是" [email protected]",因为js文件中只有对Gword进行判断和拼接,没有重新赋值,所以说Gword这个变量是一直不为空的,所以js文件的visit函数是会执行如下,返回的结果进行跳转

url = strdecode(url);

以下为strdecode方法和其相关的方法(都在当前的js文件中)

//code
function strdecode(string) {
    string = base64decode(string);
    key = Gword+'ok ';
    len = key.length;
    code = '';
    for (i = 0; i < string.length; i++) {
        var k = i % len;
        code += String.fromCharCode(string.charCodeAt(i) ^ key.charCodeAt(k))
    }
    return base64decode(code)
}
var base64DecodeChars = new Array(-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 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, -1, -1, -1, -1, -1, -1, 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, -1, -1, -1, -1, -1);

function base64decode(str) {
    var c1, c2, c3, c4;
    var i, len, out;
    len = str.length;
    i = 0;
    out = "";
    while (i < len) {
        do {
            c1 = base64DecodeChars[str.charCodeAt(i++) & 0xff]
        } while (i < len && c1 == -1);
        if (c1 == -1) break;
        do {
            c2 = base64DecodeChars[str.charCodeAt(i++) & 0xff]
        } while (i < len && c2 == -1);
        if (c2 == -1) break;
        out += String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4));
        do {
            c3 = str.charCodeAt(i++) & 0xff;
            if (c3 == 61) return out;
            c3 = base64DecodeChars[c3]
        } while (i < len && c3 == -1);
        if (c3 == -1) break;
        out += String.fromCharCode(((c2 & 0XF) << 4) | ((c3 & 0x3C) >> 2));
        do {
            c4 = str.charCodeAt(i++) & 0xff;
            if (c4 == 61) return out;
            c4 = base64DecodeChars[c4]
        } while (i < len && c4 == -1);
        if (c4 == -1) break;
        out += String.fromCharCode(((c3 & 0x03) << 6) | c4)
    }
    return out
}

看样子已经知道了该网页如何进行js加密的,所以在本地新建一个html文件,模拟进行加密,将js文件中visit函数中的字符串作为参数传入,查看最后的返回结果,进行验证

如下是我的html文件代码:

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>js加密验证</title>
</head>
<body>
	<script>
		var Gword = " [email protected]"
		function strdecode(string) {
		    string = base64decode(string);
		    key = Gword+'ok ';
		    len = key.length;
		    code = '';
		    for (i = 0; i < string.length; i++) {
		        var k = i % len;
		        code += String.fromCharCode(string.charCodeAt(i) ^ key.charCodeAt(k))
		    }
		    return base64decode(code)
		}
		var base64DecodeChars = new Array(-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 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, -1, -1, -1, -1, -1, -1, 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, -1, -1, -1, -1, -1);

		function base64decode(str) {
		    var c1, c2, c3, c4;
		    var i, len, out;
		    len = str.length;
		    i = 0;
		    out = "";
		    while (i < len) {
		        do {
		            c1 = base64DecodeChars[str.charCodeAt(i++) & 0xff]
		        } while (i < len && c1 == -1);
		        if (c1 == -1) break;
		        do {
		            c2 = base64DecodeChars[str.charCodeAt(i++) & 0xff]
		        } while (i < len && c2 == -1);
		        if (c2 == -1) break;
		        out += String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4));
		        do {
		            c3 = str.charCodeAt(i++) & 0xff;
		            if (c3 == 61) return out;
		            c3 = base64DecodeChars[c3]
		        } while (i < len && c3 == -1);
		        if (c3 == -1) break;
		        out += String.fromCharCode(((c2 & 0XF) << 4) | ((c3 & 0x3C) >> 2));
		        do {
		            c4 = str.charCodeAt(i++) & 0xff;
		            if (c4 == 61) return out;
		            c4 = base64DecodeChars[c4]
		        } while (i < len && c4 == -1);
		        if (c4 == -1) break;
		        out += String.fromCharCode(((c3 & 0x03) << 6) | c4)
		    }
		    return out
		}

		console.log(strdecode('QSQ7XggEHBUhXUdGBwZYAAp4ZhQlAyU2ETBYBRBHWl8JXABW'))
	</script>
</body>
</html>

运行  F12 console中查看结果:

单击打开网址,和我在原网页中单击打开的网址一样。故解密完毕

网址已经拿到,所以只需将js加密函数转换成python格式,然后从网页中取出visit函数传入的实参传入即可获取真正的url。

猜你喜欢

转载自blog.csdn.net/jss19940414/article/details/85084137
今日推荐