zoukankan      html  css  js  c++  java
  • 今日头条加密参数的识别

    今日头条有三个加密参数

    先找一个作者的主页,列如:https://www.toutiao.com/c/user/108888017311/#mid=1619989289127939

    然后进去抓包找文章的地址发现:https://www.toutiao.com/c/user/article/?page_type=1&user_id=108888017311&max_behot_time=0&count=20&as=A1459CB8348BDE5&cp=5C849BAD7E75AE1&_signature=9vG.bhAcqn9-xE62aCEsyvbxv3

    里面一共有7个参数,其中 page_type: 1这个不需要变,user_id=108888017311这个是作者的id,count=20,还有这个数量一般不用变。

    剩下的咋们一个个来看,首先max_behot_time=0 咋们可以发现

    这里的第一次参数是0,但是我们也能发现在第一次请求数据成功返回的响应里面

    里面的这个max_behot_time其实是在下次请求的时候使用,这样我们可以一直请求作者之前的文章,每次请求把上一次获得的参数带上就行。

    这是我们下拉获取的第二个数据包,可以看的max_behot_time参数的值就是上一次获取到的响应参数

    然后现在看剩下的as,cp,_signature参数。

    打开全局搜索as可以找到

    其中as,cp的来源来自ascp.getHoney()函数,点击进去

    可以看的这里是生成as和cp参数的地方,他们的生成和当前时间有关。写成python就是

    def getHoney():  
        t = int(time.time())  
        # t=1551971117
        e = str('%X' % t)  
        m1 = hashlib.md5()  
        m1.update(str(t).encode(encoding='utf-8'))  
        i = str(m1.hexdigest()).upper() 
        print(i)
        o = i[0:5]  
        n = i[-5:]  
        a = ''
        r = ''
        for s in range(0, 5):  
            a += o[s] + e[s]
            r += e[s + 3] + n[s]
        eas = 'A1' + a + e[-3:]
        ecp = e[0:3] + r + 'E1'
        print(eas)
        print(ecp)
        return eas, ecp

    接下来我们来看看_signature参数

    来自这个  TAC.sign(userInfo.id + "" + d.params.max_behot_time)

    这个参数加密很繁琐,跟ua指纹有关。

    我想到的破解方法是使用无头的selenium来进入网站然后获取这个参数。

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    class selenium_nign():
        def __init__(self,url=''):
            self.url = url
            driver = webdriver.FirefoxOptions()
            driver.add_argument('-headless')
            self.driver = webdriver.Firefox(firefox_options=driver)
            # driver = webdriver.Firefox()
            self.driver.get(self.url)
        def nign(self,time=0):
            nign = self.driver.execute_script('''return TAC.sign(108888017311+''+'''+str(time)+''')''')
         #通过这里来获取,第一个参数为作者id,第二个参数就是前面讲的max_behot_time参数
    return nign def cookie(self,blok=0):
        #这里获取cookie,头条对id也有加密,正常的session获取的会话似乎没办法通过
    if blok: self.driver.get(self.url) cookies = self.driver.get_cookies() cookie = [item['name'] + "=" + item['value'] for item in cookies] cookiestr = '; '.join(item for item in cookie) return cookiestr def sclock(self): self.driver.close()

    现在我们就可以运行了,运行结果好像头条会随机才能成功,会甩出一些错误来,这个还没找到,希望有大佬知道能告诉我。

  • 相关阅读:
    leetcode--Search for a Range
    leetcode--Valid Palindrome
    leetcode--Validate Binary Search Tree
    leetcode--Count and Say
    leetcode--Partition List
    C语言atof()函数:将字符串转换为double(双精度浮点数)
    程序员与科学家的区别
    mingw编译rtmp库
    使用printf输出各种格式的字符串( 转载)
    c++使用stdint.h和inttypes.h
  • 原文地址:https://www.cnblogs.com/dayouzi/p/10505649.html
Copyright © 2011-2022 走看看