安装好环境可以直接运行测试。
抖音方面有需要交流的可以加我q/v 779226574
# coding:utf-8
import random
import urllib.parse
from time import time
from hashlib import md5
from copy import deepcopy
from random import choice
def check_log(temp_list):
tmp = []
for item in temp_list:
tmp.append(hex(item))
print('长度:{} 内容:{}\n'.format(len(tmp), tmp))
def hex_string(num):
tmp_string = hex(num)[2:]
if len(tmp_string) < 2:
tmp_string = '0' + tmp_string
return tmp_string
def reverse(num):
tmp_string = hex(num)[2:]
if len(tmp_string) < 2:
tmp_string = '0' + tmp_string
return int(tmp_string[1:] + tmp_string[:1], 16)
def RBIT(num):
result = ''
tmp_string = bin(num)[2:]
while len(tmp_string) < 8:
tmp_string = '0' + tmp_string
for i in range(0, 8):
result = result + tmp_string[7 - i]
return int(result, 2)
class XG:
def __init__(self, debug):
self.length = 0x14
self.debug = debug
self.hex_510 = [0x55, 0x00, 0x50, choice(range(0, 0xFF)), 0x32, 0xFA, 0x00, 8 * choice(range(0, 0x1F))]
def addr_3F4(self):
tmp = ''
hex_3F4 = []
for i in range(0x0, 0x100):
hex_3F4.append(i)
for i in range(0, 0x100):
if i == 0:
A = 0
elif tmp:
A = tmp
else:
A = hex_3F4[i - 1]
B = self.hex_510[i % 0x8]
if A == 0x55:
if i != 1:
if tmp != 0x55:
A = 0
C = A + i + B
while C >= 0x100:
C = C - 0x100
if C < i:
tmp = C
else:
tmp = ''
D = hex_3F4[C]
hex_3F4[i] = D
return hex_3F4
def initial(self, debug, hex_3F4):
tmp_add = []
tmp_hex = deepcopy(hex_3F4)
for i in range(self.length):
A = debug[i]
if not tmp_add:
B = 0
else:
B = tmp_add[-1]
C = hex_3F4[i + 1] + B
while C >= 0x100:
C = C - 0x100
tmp_add.append(C)
D = tmp_hex[C]
tmp_hex[i + 1] = D
E = D + D
while E >= 0x100:
E = E - 0x100
F = tmp_hex[E]
G = A ^ F
debug[i] = G
return debug
def calculate(self, debug):
for i in range(self.length):
A = debug[i]
B = reverse(A)
C = debug[(i + 1) % self.length]
D = B ^ C
E = RBIT(D)
F = E ^ self.length
G = ~F
while G < 0:
G += 0x100000000
H = int(hex(G)[-2:], 16)
debug[i] = H
return debug
def main(self):
result = ''
for item in self.calculate(self.initial(self.debug, self.addr_3F4())):
result = result + hex_string(item)
return '0300{}{}0000{}'.format(hex_string(self.hex_510[7]), hex_string(self.hex_510[3]), result)
def X_Gorgon(url, data, cookie, model='utf-8'):
gorgon = []
Khronos = hex(int(time()))[2:]
url_md5 = md5(bytearray(url, 'utf-8')).hexdigest()
for i in range(0, 4):
gorgon.append(int(url_md5[2 * i: 2 * i + 2], 16))
if data:
if model == 'utf-8':
data_md5 = md5(bytearray(data, 'utf-8')).hexdigest()
for i in range(0, 4):
gorgon.append(int(data_md5[2 * i: 2 * i + 2], 16))
elif model == 'octet':
data_md5 = md5(data).hexdigest()
for i in range(0, 4):
gorgon.append(int(data_md5[2 * i: 2 * i + 2], 16))
else:
for i in range(0, 4):
gorgon.append(0x0)
if cookie:
cookie_md5 = md5(bytearray(cookie, 'utf-8')).hexdigest()
for i in range(0, 4):
gorgon.append(int(cookie_md5[2 * i: 2 * i + 2], 16))
else:
for i in range(0, 4):
gorgon.append(0x0)
for i in range(0, 4):
gorgon.append(0x0)
for i in range(0, 4):
gorgon.append(int(Khronos[2 * i: 2 * i + 2], 16))
return {'X-Gorgon': XG(gorgon).main(), 'X-Khronos': str(int(Khronos, 16))}
def get_post_xg(url,data,cookie=''):
index = url.find('?') + 1
params = url[index:]
data_encode = urllib.parse.urlencode(data)
x = X_Gorgon(params, data_encode,cookie)
ck = cookie if cookie else f"install_id={int(random.randrange(10 ** 11, 10 ** 12))}"
headers = {
"Cookie":ck ,
"X-Khronos": x['X-Khronos'],
"sdk-version": "1",
"X-SS-REQ-TICKET": f"{x['X-Khronos']}233",
"X-Gorgon": x['X-Gorgon'],
"User-Agent": "com.ss.android.ugc.aweme/750 (Linux; U; Android 8.0.0; zh_CN; MIX 2; Build/OPR1.170623.027; Cronet/58.0.2991.0)",
# "User-Agent": "ttnet okhttp/3.10.0.2",
"Connection": "Keep-Alive",
}
return {
'url':url,
'data':data,
'headers':headers
}
def get_get_xg(url,data='',cookie=''):
index = url.find('?') + 1
params = url[index:]
x = X_Gorgon(params, data,cookie)
ck = cookie if cookie else f"install_id={int(random.randrange(10 ** 11, 10 ** 12))}"
headers = {
"Cookie": ck,
"X-Khronos": x['X-Khronos'],
"sdk-version": "1",
"X-SS-REQ-TICKET": f"{x['X-Khronos']}322",
"X-Gorgon": x['X-Gorgon'],
"User-Agent": "com.ss.android.ugc.aweme/690 (Linux; U; Android 5.1.1; zh_CN; HUAWEI MLA-AL10; Build/HUAWEIMLA-AL10; Cronet/58.0.2991.0)",
# "User-Agent": "ttnet okhttp/3.10.0.2",
# "Connection": "Keep-Alive",
}
return {
'url':url,
'data':data,
'headers':headers
}