login done, but don't detects servers

This commit is contained in:
loveyousomuch 2021-10-27 19:42:41 +03:00
parent d00762ae9e
commit 671a71d5cd
4 changed files with 211 additions and 108 deletions

11
connect_test.py Normal file
View file

@ -0,0 +1,11 @@
from python_aternos import Client as AternosClient
aternos = AternosClient('', password='')
srvs = aternos.servers
print(srvs)
s = srvs[0]
s.start()

View file

@ -8,141 +8,187 @@ from typing import Optional, Union
from . import aterrors from . import aterrors
#TEST
from py_mini_racer import MiniRacer
import base64
presettings = """
let window = {1: null, 2: null, AJAX_TOKEN: null};
let i = 1;
function __log() { return {win_var: window["AJAX_TOKEN"], 1: window[1], 2: window[2]} };
function atob(arg) {window[i++] = arg;};
"""
postsettings = """__log();"""
REQGET = 0 REQGET = 0
REQPOST = 1 REQPOST = 1
REQUA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Goanna/4.8 Firefox/68.0 PaleMoon/29.4.0.2' REQUA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Goanna/4.8 Firefox/68.0 PaleMoon/29.4.0.2'
class AternosConnect: class AternosConnect:
def __init__(self) -> None: def __init__(self) -> None:
pass pass
def parse_token(self, response:Optional[Union[str,bytes]]=None) -> str: def parse_token(self, response:Optional[Union[str,bytes]]=None) -> str:
if response == None: if response == None:
loginpage = self.request_cloudflare( loginpage = self.request_cloudflare(
f'https://aternos.org/go/', REQGET f'https://aternos.org/go/', REQGET
).content ).content
pagetree = lxml.html.fromstring(loginpage) pagetree = lxml.html.fromstring(loginpage)
else: else:
pagetree = lxml.html.fromstring(response) pagetree = lxml.html.fromstring(response)
try: try:
pagehead = pagetree.head # fetch text
self.token = re.search( pagehead = pagetree.head
r'const\s+AJAX_TOKEN\s*=\s*["\'](\w+)["\']', text = pagehead.text_content()
pagehead.text_content() #print(text)
)[1]
except (IndexError, TypeError):
raise aterrors.AternosCredentialsError(
'Unable to parse TOKEN from the page'
)
return self.token #search
token_js_func = text[
text.index("const COOKIE_PREFIX = \"ATERNOS\";") +
len("const COOKIE_PREFIX = \"ATERNOS\";") :
text.index("(function(i,s,o,g,r,a,m)")
].strip()
print(token_js_func)
def generate_sec(self) -> str:
randkey = self.generate_aternos_rand() # run js
randval = self.generate_aternos_rand() ctx = MiniRacer()
self.sec = f'{randkey}:{randval}' result = ctx.eval(presettings + token_js_func)
self.session.cookies.set( result = ctx.call('__log')
f'ATERNOS_SEC_{randkey}', randval,
domain='aternos.org' print(result)
)
if 'win_var' in result and result['win_var']:
result = result['win_var']
elif '1' in result and ('2' in result and not result['2']):
result = base64.standard_b64decode(result['1'])
else:
result = base64.standard_b64decode(result['2'])
return self.sec
def generate_aternos_rand(self, randlen:int=16) -> str: print(result)
self.token = result
"""
self.token = re.search(
r'const\s+AJAX_TOKEN\s*=\s*["\'](\w+)["\']',
text
)[1]
"""
except (IndexError, TypeError):
raise aterrors.AternosCredentialsError(
'Unable to parse TOKEN from the page'
)
rand_arr = [] return self.token
for i in range(randlen+1):
rand_arr.append('')
rand_alphanum = \ def generate_sec(self) -> str:
self.convert_num(random.random(),36) + \
'00000000000000000'
return (rand_alphanum[2:18].join(rand_arr)[:randlen])
def convert_num(self, num:Union[int,float], base:int) -> str: randkey = self.generate_aternos_rand()
randval = self.generate_aternos_rand()
self.sec = f'{randkey}:{randval}'
self.session.cookies.set(
f'ATERNOS_SEC_{randkey}', randval,
domain='aternos.org'
)
result = '' return self.sec
while num > 0:
result = str(num % base) + result
num //= base
return result
def request_cloudflare( def generate_aternos_rand(self, randlen:int=16) -> str:
self, url:str, method:int,
retries:int=10,
params:Optional[dict]=None,
data:Optional[dict]=None,
headers:Optional[dict]=None,
reqcookies:Optional[dict]=None,
sendtoken:bool=False) -> Response:
cftitle = '<title>Please Wait... | Cloudflare</title>' rand_arr = []
for i in range(randlen+1):
rand_arr.append('')
if sendtoken: rand_alphanum = \
if params == None: self.convert_num(random.random(),36) + \
params = {} '00000000000000000'
params['SEC'] = self.sec return (rand_alphanum[2:18].join(rand_arr)[:randlen])
params['TOKEN'] = self.token
if headers == None: def convert_num(self, num:Union[int,float], base:int) -> str:
headers = {}
headers['User-Agent'] = REQUA
try: result = ''
cookies = self.session.cookies while num > 0:
except AttributeError: result = str(num % base) + result
cookies = None num //= base
return result
self.session = CloudScraper() def request_cloudflare(
if cookies != None: self, url:str, method:int,
self.session.cookies = cookies retries:int=10,
params:Optional[dict]=None,
data:Optional[dict]=None,
headers:Optional[dict]=None,
reqcookies:Optional[dict]=None,
sendtoken:bool=False) -> Response:
if method == REQPOST: cftitle = '<title>Please Wait... | Cloudflare</title>'
req = self.session.post(
url,
data=data,
headers=headers,
cookies=reqcookies
)
else:
req = self.session.get(
url,
params=params,
headers=headers,
cookies=reqcookies
)
countdown = retries if sendtoken:
while cftitle in req.text \ if params == None:
and (countdown > 0): params = {}
params['SEC'] = self.sec
params['TOKEN'] = self.token
self.session = CloudScraper() if headers == None:
if cookies != None: headers = {}
self.session.cookies = cookies headers['User-Agent'] = REQUA
if reqcookies != None:
for cookiekey in reqcookies:
self.session.cookies.set(cookiekey, reqcookies[cookiekey])
time.sleep(1) try:
if method == REQPOST: cookies = self.session.cookies
req = self.session.post( except AttributeError:
url, cookies = None
data=data,
headers=headers,
cookies=reqcookies
)
else:
req = self.session.get(
url,
params=params,
headers=headers,
cookies=reqcookies
)
countdown -= 1
return req self.session = CloudScraper()
if cookies != None:
self.session.cookies = cookies
if method == REQPOST:
req = self.session.post(
url,
data=data,
headers=headers,
cookies=reqcookies
)
else:
req = self.session.get(
url,
params=params,
headers=headers,
cookies=reqcookies
)
countdown = retries
while cftitle in req.text \
and (countdown > 0):
self.session = CloudScraper()
if cookies != None:
self.session.cookies = cookies
if reqcookies != None:
for cookiekey in reqcookies:
self.session.cookies.set(cookiekey, reqcookies[cookiekey])
time.sleep(1)
if method == REQPOST:
req = self.session.post(
url,
data=data,
headers=headers,
cookies=reqcookies
)
else:
req = self.session.get(
url,
params=params,
headers=headers,
cookies=reqcookies
)
countdown -= 1
return req

45
racer_test.py Executable file
View file

@ -0,0 +1,45 @@
#!/usr/bin/env python3
from py_mini_racer import MiniRacer
import base64
# Set function for manage global vars
presettings = """
let window = {1: null, 2: null, AJAX_TOKEN: null};
let i = 1;
function __log() { return {win_var: window["AJAX_TOKEN"], 1: window[1], 2: window[2]} };
function atob(arg) {window[i++] = arg;};
"""
# Test cases
tests = [
"""(() => {window[("A" + "J" + "AX_T" + "OKE" + "N")]=("2iXh5W5u" + "EYq" + "5fWJIa" + "zQ6");})();""",
""" (() => {window[["N","TOKE","AJAX_"].reverse().join('')]=["IazQ6","fWJ","h5W5uEYq5","2iX"].reverse().join('');})();""",
"""(() => {window["AJAX_TOKEN"] = atob("SGVsbG8sIHdvcmxk")})();""",
"""(() => {window[atob('QUpBWF9UT0tFTg==')]=atob('MmlYaDVXNXVFWXE1ZldKSWF6UTY=');})();""",
"""(() => {window["AJAX_TOKEN"] = "1234" })();""",
"""(() => {window[atob('QUpBWF9UT0tFTg==')]="2iXh5W5uEYq5fWJIazQ6";})();""",
]
# Emulate 'atob' function
#print(base64.standard_b64decode('MmlYaDVXNXVFWXE1ZldKSWF6UTY='))
for js in tests:
ctx = MiniRacer()
result = ctx.eval(presettings + js)
result = ctx.call('__log')
print(result)
'''
if 'win_var' in result and result['win_var']:
result = result['win_var']
elif '1' in result and ('2' in result and not result['2']):
result = base64.standard_b64decode(result['1'])
else:
result = base64.standard_b64decode(result['2'])
'''
print('Case:\n', js, '\n')
print('Result: \n', result, '\n')
print('-' * 30, '\n')

View file

@ -1,3 +1,4 @@
lxml==4.6.2 lxml==4.6.2
requests==2.25.1 requests==2.25.1
cloudscraper==1.2.58 cloudscraper==1.2.58
py-mini-racer==0.6.0