Fork me on GitHub

爬虫笔记之Google镜像导航链接JS加密破解(http://ac.scmor.com/)

这是个非常非常简单的js加密链接。

 

这是一个导航网站,实际链接到的网站的url被加密了,并没有直接显示在页面上,首先开发者模式选中链接元素:

发现这个链接有一个onclick事件,是调用了visit方法传入了一个很长的看上去像是base64的字符串,猜测实际的url应该就是根据这个字符串生成的,但是怎么跟进去visit方法呢,这个方法能够在html中直接访问到,说明其作用域是全局的,那么切换到console面板,输入刚才那个函数的名称visit回车将其打印:

单击输出,跳转到函数所在的代码:

 可以看到这部分关键的代码在strdecode函数中,如法炮制,跳转到strdecode所在的代码:

 

单击跳转:

 

 

这部分用到了两个全局变量,Gword和hn,通过搜索请求找到这两个变量都在页面doc里声明的:

 

 hn就是域名的主机名部分转为小写,即“ac.scmor.com”,然后就是Gword貌似是作者的邮箱,这样写在页面代码中还不得被各种爬虫发的小广告给烦死啊。。。

 

搞清楚了这两个变量,再回到之前的js:

 默认情况下每个链接都会有一串看上去像是base64的字符串,这里strdecode传入的参数就是那个字符串,传进来的字符串首先进行base64解码,然后基于Gword和hn转换为一个新的base64编码的字符串,然后继续对其base64解码,就得到了最终的url。

根据上面的逻辑编写出代码:

package cc11001100.misc.crawler.js.acscmorcom;

import cc11001100.misc.crawler.utils.HttpUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.jsoup.Connection;

import java.util.ArrayList;
import java.util.Base64;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * http://ac.scmor.com/
 *
 * @author CC11001100
 */
@Slf4j
public class AcscmorcomCrawler {

	public static List<String> getMirrorSiteLink() {
		String responseBody = HttpUtil.request("http://ac.scmor.com/", null, Connection.Response::body);
		if (StringUtils.isBlank(responseBody)) {
			log.error("response empty");
			return Collections.emptyList();
		}
		Matcher matcher = Pattern.compile("autourl\\[\\d+] = \"(.+?)\"").matcher(responseBody);
		List<String> result = new ArrayList<>();
		while (matcher.find()) {
			result.add(decodeToLink(matcher.group(1)));
		}
		return result;
	}

	/**
	 * <pre>
	 * function strdecode(string) {
	 *     string = base64decode(string);
	 *     key = Gword + hn;
	 *     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);
	 * }
	 * </pre>
	 *
	 * @param likeBase64
	 * @return
	 */
	private static String decodeToLink(String likeBase64) {
		String hn = "ac.scmor.com";
		String gword = "author: link@scmor.com.";
		String s1 = base64DecodeToString(likeBase64);
		String key = gword + hn;
		StringBuilder result = new StringBuilder();
		for (int i = 0; i < s1.length(); i++) {
			char c = (char) (s1.charAt(i) ^ key.charAt(i % key.length()));
			result.append(c);
		}
		return base64DecodeToString(result.toString());
	}

	private static String base64DecodeToString(String raw) {
		return new String(Base64.getDecoder().decode(raw));
	}

	public static void main(String[] args) {

//		System.out.println(decodeToLink("AD0mWAw2VVYgWiAdDB4LHQwqaxY2XxcVL0M9FiEYTxM="));

		List<String> list = getMirrorSiteLink();
		System.out.println("count: " + list.size());
		list.forEach(System.out::println);
//		count: 16
//		http://so.hiqq.com.cn/
//		https://sci-hub.org.cn/
//		https://xueshu.soogle.top
//		http://www.ndtsg.com/
//		https://www.80xueshu.com/
//		https://xs.glgoo.top/scholar
//		https://scholar.123admin.com/
//		https://g3.luciaz.me/scholar
//		http://nav.hiqq.com.cn/twy/
//		https://a.g456.top
//		https://g.sudo.gq/
//		https://q.g456.top
//		https://ice.g456.top
//		http://206.189.135.241/
//		https://www.kuaimen.bid/
//		https://gg.chn.moe/

	}

}

 输出:

 

.

 

posted @ 2020-02-20 20:07  CC11001100  阅读(3304)  评论(0编辑  收藏  举报