-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.py
142 lines (107 loc) · 4.88 KB
/
main.py
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
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import configparser
from colorama import Fore
from httpx import Client
import re
from utils.captcha import capsolver_solver
from utils.utils import print_colored
config = configparser.ConfigParser()
config.read('config.ini')
CAPSOLVER = config.get('API', 'CAPSOLVER_API')
class Account:
def __init__(self, cookies:dict, proxy:str) -> None:
self.cookies = cookies
self.url = "https://twitter.com/account/access"
self.client = Client(timeout=30, follow_redirects=True, proxies=proxy)
self.headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:123.0) Gecko/20100101 Firefox/123.0",
"Accept": "*/*",
"Accept-Language": "en-GB,en;q=0.5",
"Accept-Encoding": "gzip, deflate, br",
"DNT": "1",
"Sec-GPC": "1",
"Connection": "keep-alive",
"Sec-Fetch-Dest": "script",
"Sec-Fetch-Mode": "no-cors",
"Sec-Fetch-Site": "same-origin",
"Pragma": "no-cache",
"Cache-Control": "no-cache",
"TE": "trailers"
}
self._tokens = {}
def __extract_tokens_from_access_html_page(self, html:str):
pattern = re.compile(r'name="authenticity_token" value="([^"]+)"|name="assignment_token" value="([^"]+)"')
if matches := pattern.findall(html):
authenticity_token = matches[0][0] if matches[0][0] else matches[0][1]
assignment_token = matches[1][0] if matches[1][0] else matches[1][1]
self._tokens = {"authenticity_token": authenticity_token,
"assignment_token": assignment_token}
def __js_inst(self):
js_script = self.client.get(
url="https://twitter.com/i/js_inst?c_name=ui_metrics"
).text
pattern = re.compile(r'return\s*({.*?});', re.DOTALL)
js_instr = pattern.search(js_script)
return js_instr.group(1)
def __get_access_page(self):
res = self.client.get(self.url, headers=self.headers, cookies=self.cookies)
self.cookies.update(dict(res.cookies))
self.__extract_tokens_from_access_html_page(html=res.text)
def __post_to_accces_page(self, data:dict):
headers = self.headers
headers["Host"] = "twitter.com"
headers["Origin"] = "https://twitter.com"
headers["Referer"] = "https://twitter.com/account/access"
res = self.client.post(f"{self.url}?lang=en", data=data, headers=headers, cookies=self.cookies)
self.cookies.update(dict(res.cookies))
self.__extract_tokens_from_access_html_page(html=res.text)
def __data_with_js_inst(self, tokens:dict) -> dict:
return {
"authenticity_token": tokens["authenticity_token"],
"assignment_token": tokens["assignment_token"],
"lang": "en",
"flow": "",
"ui_metrics": self.__js_inst()
}
def __data_with_funcaptcha(self, tokens:dict, fun_captcha_token:str) -> dict:
return {
"authenticity_token": tokens["authenticity_token"],
"assignment_token": tokens["assignment_token"],
'lang': 'en',
'flow': '',
'verification_string': fun_captcha_token,
'language_code': 'en'
}
def __post_data_with_token(self, fun_captcha_token:str):
data = self.__data_with_funcaptcha(tokens=self._tokens, fun_captcha_token=fun_captcha_token)
self.__post_to_accces_page(data=data)
def __post_data_with_js_inst(self):
data = self.__data_with_js_inst(tokens=self._tokens)
self.__post_to_accces_page(data=data)
def unlock(self):
print_colored(text="UNLOCKING ACCOUNT...", color=Fore.GREEN)
self.__get_access_page()
self.__post_data_with_js_inst()
fun_captcha_token = capsolver_solver(api_key=CAPSOLVER,
websitePublicKey="0152B4EB-D2DC-460A-89A1-629838B529C9",
websiteURL="https://twitter.com")
self.__post_data_with_token(fun_captcha_token=fun_captcha_token)
fun_captcha_token = capsolver_solver(api_key=CAPSOLVER,
websitePublicKey="0152B4EB-D2DC-460A-89A1-629838B529C9",
websiteURL="https://twitter.com")
self.__post_data_with_token(fun_captcha_token=fun_captcha_token)
self.__post_data_with_js_inst()
print_colored(text="ACCOUNT UNLOCKED...", color=Fore.GREEN)
"""
Example usage
"""
client = Account(
# Fill in the auth token and ct0 cookies of the account you wanna unlock
cookies={
"auth_token": "",
"ct0": ""
},
# the proxy is a must it shout be in "http://ip:port" or "http://username:password@ip:port"
# Get the best proxy from the best provider => https://iproyal.com/?r=SeasonedCode
proxy=""
)
client.unlock()