抖音X-Gorgon,X-Khronos生成源码java层

抓包抖音请求时,大家都知道抖音的接口数据请求,都需要用到x-gorgon、X-Khronos参数,用于服务器验证,不然都无法请求到数据,通过工具逆向了抖音app的源码,发现下列这个位于类com.ss.sys.ces.gg.tt中,有这样一个函数用于生成x-gorgon的值。

    public static void init_gorgon() {
        e.a((a) new a() {
            public final Map<String, String> a(String str, Map<String, List<String>> map) {
                HashMap hashMap = new HashMap();
                try {
                    if (!str.toLowerCase().contains(HttpConstant.HTTP) && !str.toLowerCase().contains(HttpConstant.HTTPS)) {
                        throw new NullPointerException("nein http/https");
                    } else if (str.toLowerCase().contains("X-Khronos") && str.toLowerCase().contains("X-Gorgon")) {
                        throw new NullPointerException("it was");
                    } else if (tt.filter_url(str)) {
                        throw new NullPointerException(tt.FILTER_TAG);
                    } else {
                        int currentTimeMillis = (int) (System.currentTimeMillis() / 1000);
                        String format_url = tt.format_url(str);
                        String str2 = null;
                        String a2 = (format_url == null || format_url.length() <= 0) ? null : d.a(format_url);
                        String str3 = null;
                        String str4 = null;
                        for (Entry entry : map.entrySet()) {
                            if (((String) entry.getKey()).toUpperCase().contains("X-SS-STUB")) {
                                str2 = (String) ((List) entry.getValue()).get(0);
                            }
                            if (((String) entry.getKey()).toUpperCase().contains("COOKIE")) {
                                String str5 = (String) ((List) entry.getValue()).get(0);
                                if (str5 != null && str5.length() > 0) {
                                    str3 = d.a(str5);
                                    String format_session_id = tt.format_session_id(str5);
                                    if (format_session_id != null && format_session_id.length() > 0) {
                                        str4 = d.a(format_session_id);
                                    }
                                }
                            }
                        }
                        hashMap.put("X-Khronos", String.valueOf(currentTimeMillis));
                        if (a2 == null || a2.length() == 0) {
                            a2 = tt.NULL_MD5_STRING;
                        }
                        if (str2 == null || str2.length() == 0) {
                            str2 = tt.NULL_MD5_STRING;
                        }
                        if (str3 == null || str3.length() == 0) {
                            str3 = tt.NULL_MD5_STRING;
                        }
                        if (str4 == null || str4.length() == 0) {
                            str4 = tt.NULL_MD5_STRING;
                        }
                        StringBuilder sb = new StringBuilder();
                        sb.append(a2);
                        sb.append(str2);
                        sb.append(str3);
                        sb.append(str4);
                        hashMap.put("X-Gorgon", l.a(com.ss.sys.ces.a.leviathan(currentTimeMillis, l.a(sb.toString()))));
                        hashMap.put("X-Pods", com.ss.sys.ces.e.a.b());
                        return hashMap;
                    }
                } catch (Throwable th) {
                    if (!th.getMessage().contains(tt.FILTER_TAG)) {
                        com.google.b.a.a.a.a.a.a(th);
                    }
                    return hashMap;
                }
            }
        });
    }

通过分析知道,最终的x-gorgon的生成,是调用com.ss.sys.ces.a.leviathan函数,所以我们只要利用这个函数就能帮我们解决x-gorgon的生成,他里面的参数有两个

public static native byte[] leviathan(int i, byte[] bArr);

第一个是当前的时间戳,也就是X-Khronos
第二个字节组就一串字符串,由md5(Url)+md5(postdata)+md5(cookies)+md5(sesseionid)组成的字串,做的二次请求。

所以也就发现了X-SS-STUB的值是将要post的数据做md5计算的值,如果是要做post的话,那这个值就需要带上。就能正常请求到数据了
在这里插入图片描述

关于抖音相关技术交流,可加Q:507917719一起探讨。

发布了2 篇原创文章 · 获赞 0 · 访问量 363

猜你喜欢

转载自blog.csdn.net/idisnull/article/details/104173555