Skip to content
This repository was archived by the owner on Feb 15, 2024. It is now read-only.

Commit a5ef80d

Browse files
committed
Important bugfix in javascript parser
1 parent 490a689 commit a5ef80d

File tree

4 files changed

+56
-10
lines changed

4 files changed

+56
-10
lines changed

python_aternos/atconnect.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
import lxml.html
55
from requests import Response
66
from cloudscraper import CloudScraper
7-
from typing import Optional, Union
7+
from typing import Optional, Union, Dict
88

99
from . import atjsparse
1010
from .aterrors import CredentialsError, CloudflareError
1111

12-
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'
12+
REQUA = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.84 Safari/537.36 OPR/85.0.4341.47'
1313

1414
class AternosConnect:
1515

@@ -86,13 +86,29 @@ def convert_num(
8686
num //= base
8787
return result
8888

89+
def add_headers(self, headers:Optional[Dict[str,str]]=None):
90+
91+
headers = headers or {}
92+
headers.update({
93+
'host': 'aternos.org',
94+
'user-agent': REQUA,
95+
'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="100", "Opera";v="86"',
96+
'sec-ch-ua-mobile': '?0',
97+
'sec-ch-ua-platform': '"Linux"',
98+
'sec-fetch-dest': 'document',
99+
'sec-fetch-mode': 'navigate',
100+
'sec-fetch-site': 'same-origin',
101+
'sec-fetch-user': '?1',
102+
'upgrade-insecure-requests': '1'
103+
})
104+
89105
def request_cloudflare(
90106
self, url:str, method:str,
91107
params:Optional[dict]=None, data:Optional[dict]=None,
92108
headers:Optional[dict]=None, reqcookies:Optional[dict]=None,
93109
sendtoken:bool=False, redirect:bool=True, retry:int=0) -> Response:
94110

95-
if retry > 2:
111+
if retry > 3:
96112
raise CloudflareError('Unable to bypass Cloudflare protection')
97113

98114
try:
@@ -105,9 +121,8 @@ def request_cloudflare(
105121

106122
params = params or {}
107123
data = data or {}
108-
headers = headers or {}
109124
reqcookies = reqcookies or {}
110-
headers['User-Agent'] = REQUA
125+
self.add_headers(headers)
111126

112127
if sendtoken:
113128
params['TOKEN'] = self.token
@@ -143,7 +158,8 @@ def request_cloudflare(
143158
url, method,
144159
params, data,
145160
headers, reqcookies,
146-
sendtoken, redirect
161+
sendtoken, redirect,
162+
retry - 1
147163
)
148164

149165
logging.info(

python_aternos/atjsparse.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,10 @@ def atob(s:str) -> str:
2020

2121
def exec(f:str) -> Any:
2222
ctx = js2py.EvalJs({'atob': atob})
23+
ctx.execute('window.document = { };')
24+
ctx.execute('window.Map = function(_i){ };')
25+
ctx.execute('window.setTimeout = function(_f,_t){ };')
26+
ctx.execute('window.setInterval = function(_f,_t){ };')
27+
ctx.execute('window.encodeURIComponent = function(_s){ };')
2328
ctx.execute(to_ecma5_function(f))
2429
return ctx

tests/js2py_test.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ def setUp(self) -> None:
2727
'CuUcmZ27Fb8bVBNw12Vj',
2828
'YPPe8Ph7vzYaZ9PF9oQP',
2929
'UfLlemvKEE16ltk0hZNM',
30-
'q6pYdP6r7xiVHhbotvlN',
31-
'q6pYdP6r7xiVHhbotvlN',
32-
'XAIbksgkVX9JYboMDI7D',
33-
'sBImgVg6RL98W1khPYMl'
30+
'S1Oban9UGRXVIepREw9q',
31+
'S1Oban9UGRXVIepREw9q',
32+
'KYDDyT1DWOJTZpNtJWhM',
33+
'lZPFwRqIGIf8JKk1LG02',
34+
'KbxzYCJUrFjWzbeZcAmE',
35+
'KbxzYCJUrFjWzbeZcAmE'
3436
]
3537

3638
def test_base64(self) -> None:
@@ -45,6 +47,27 @@ def test_conv(self) -> None:
4547
f = atjsparse.to_ecma5_function(token)
4648
self.assertEqual(f, '(function(){window["AJAX_TOKEN"]=("2r" + "KO" + "A1" + "IFdBcHhEM" + "61" + "6cb");})()')
4749

50+
def test_ecma6parse(self) -> None:
51+
52+
code = '''
53+
window.t0 =
54+
window['document']&&
55+
!window[["p","Ma"].reverse().join('')]||
56+
!window[["ut","meo","i","etT","s"].reverse().join('')];'''
57+
58+
part1 = '''window.t1 = Boolean(window['document']);'''
59+
part2 = '''window.t2 = Boolean(!window[["p","Ma"].reverse().join('')]);'''
60+
part3 = '''window.t3 = Boolean(!window[["ut","meo","i","etT","s"].reverse().join('')]);'''
61+
62+
ctx0 = atjsparse.exec(code)
63+
ctx1 = atjsparse.exec(part1)
64+
ctx2 = atjsparse.exec(part2)
65+
ctx3 = atjsparse.exec(part3)
66+
67+
self.assertEqual(ctx1.window['t1'], True)
68+
self.assertEqual(ctx2.window['t2'], False)
69+
self.assertEqual(ctx3.window['t3'], False)
70+
4871
def test_exec(self) -> None:
4972

5073
for i, f in enumerate(self.tests):

token.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@
1515
(() => {window["AJAX_TOKEN"]=window['document']&&window["Map"]&&window[["out","e","Tim","et","s"].reverse().join('')]?["pREw9q","XVIe","UGR","S1Oban9"].reverse().join(''):["dYp6q","Vix7r6P","tobhH","Nlv"].map(s => s.split('').reverse().join('')).join('');})();
1616
(() => {window[["OKEN", "T", "_", "AJAX"].reverse().join("")] = window["document"] && window["Map"] && window["set" + "T" + "im" + "e" + "o" + "u" + "t"] ? ["DYK", "OWD1TyD", "TJ", "JtNpZ", "MhW"].map((s) => s.split("").reverse().join("")).join("") : "XAIbksgkVX9JYboMDI7D";})();
1717
(() => {window[["XAJA","T_","NEKO"].map(s => s.split('').reverse().join('')).join('')]=window['document']&&window[["ap","M"].reverse().join('')]&&window[["es","iTt","oem","u","t"].map(s => s.split('').reverse().join('')).join('')]?["Kk1LG02","If8J","lZPFwRqIG"].reverse().join(''):("sBI" + "mgV" + "g6RL98W1" + "khPY" + "Ml");})();
18+
(() => {window[["N","KE","_TO","X","JA","A"].reverse().join('')]=window['document']&&!window[["p","Ma"].reverse().join('')]||!window[["ut","meo","i","etT","s"].reverse().join('')]?("1UY5" + "1inS" + "kzlSO" + "QmKU0mK"):"KbxzYCJUrFjWzbeZcAmE";})();
19+
(() => {window[["EN", "TOK", "AJAX_"].reverse().join('')] = window['document'] && window["Map"] && window[("s" + "et" + "Tim" + "e" + "o" + "ut")] ? "KbxzYCJUrFjWzbeZcAmE" : ["mK", "SOQmKU0", "zl", "1inSk", "1UY5"].reverse().join('');})();

0 commit comments

Comments
 (0)