hyper-sdk 4.3.1__tar.gz → 4.3.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/PKG-INFO +1 -1
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/akamai/sec_cpt.py +133 -129
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/datadome/parse.py +17 -14
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk.egg-info/PKG-INFO +1 -1
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk.egg-info/SOURCES.txt +1 -0
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/pyproject.toml +1 -1
- hyper_sdk-4.3.2/tests/test_challenge_script_url.py +68 -0
- hyper_sdk-4.3.2/tests/test_sec_cpt.py +69 -0
- hyper_sdk-4.3.1/tests/test_challenge_script_url.py +0 -35
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/LICENSE +0 -0
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/README.md +0 -0
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/__init__.py +0 -0
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/akamai/__init__.py +0 -0
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/akamai/pixel.py +0 -0
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/akamai/script_path.py +0 -0
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/akamai/stop_signal.py +0 -0
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/akamai_input.py +0 -0
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/datadome/__init__.py +0 -0
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/datadome_input.py +0 -0
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/incapsula/__init__.py +0 -0
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/incapsula/dynamic.py +0 -0
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/incapsula/utmvc.py +0 -0
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/incapsula_input.py +0 -0
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/kasada/__init__.py +0 -0
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/kasada/dv.py +0 -0
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/kasada/parse.py +0 -0
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/kasada/user_agent.py +0 -0
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/kasada_input.py +0 -0
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/payloads.py +0 -0
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/results.py +0 -0
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/session.py +0 -0
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/session_async.py +0 -0
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/shared.py +0 -0
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/trustdecision_input.py +0 -0
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk.egg-info/dependency_links.txt +0 -0
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk.egg-info/requires.txt +0 -0
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk.egg-info/top_level.txt +0 -0
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/setup.cfg +0 -0
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/tests/test_dv.py +0 -0
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/tests/test_results.py +0 -0
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/tests/test_script_hash.py +0 -0
- {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/tests/test_user_agent.py +0 -0
|
@@ -1,130 +1,134 @@
|
|
|
1
|
-
import base64
|
|
2
|
-
import hashlib
|
|
3
|
-
import json
|
|
4
|
-
import os
|
|
5
|
-
import re
|
|
6
|
-
import time
|
|
7
|
-
from collections import OrderedDict
|
|
8
|
-
from typing import List
|
|
9
|
-
|
|
10
|
-
sec_duration_expr = re.compile(r'data-duration=(\d+)')
|
|
11
|
-
sec_challenge_expr = re.compile(r'challenge="(.*?)"')
|
|
12
|
-
sec_page_expr = re.compile(r'data-duration=\d+\s+src="([^"]+)"')
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
class SecCptChallengeData:
|
|
16
|
-
def __init__(self, token: str, timestamp: int, nonce: str, difficulty: int, count: int):
|
|
17
|
-
self.token = token
|
|
18
|
-
self.timestamp = timestamp
|
|
19
|
-
self.nonce = nonce
|
|
20
|
-
self.difficulty = difficulty
|
|
21
|
-
self.count = count
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
class SecCptChallenge:
|
|
25
|
-
def __init__(self, duration: int, challenge_path: str, challenge_data: SecCptChallengeData):
|
|
26
|
-
self.duration = duration
|
|
27
|
-
self.challenge_path = challenge_path
|
|
28
|
-
self.challenge_data = challenge_data
|
|
29
|
-
|
|
30
|
-
@staticmethod
|
|
31
|
-
def parse(html: str) -> 'SecCptChallenge':
|
|
32
|
-
challenge_data = SecCptChallenge._parse_challenge_data(html)
|
|
33
|
-
duration = SecCptChallenge._parse_duration(html)
|
|
34
|
-
challenge_path = SecCptChallenge._parse_challenge_path(html)
|
|
35
|
-
|
|
36
|
-
return SecCptChallenge(duration, challenge_path, challenge_data)
|
|
37
|
-
|
|
38
|
-
@staticmethod
|
|
39
|
-
def parse_from_json(json_payload: str) -> 'SecCptChallenge':
|
|
40
|
-
api_response = json.loads(json_payload)
|
|
41
|
-
|
|
42
|
-
challenge_data = SecCptChallengeData(
|
|
43
|
-
api_response.get('token', ''),
|
|
44
|
-
api_response.get('timestamp', 0),
|
|
45
|
-
api_response.get('nonce', ''),
|
|
46
|
-
api_response.get('difficulty', 0)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
challenge_data.get('
|
|
66
|
-
challenge_data.get('
|
|
67
|
-
challenge_data.get('
|
|
68
|
-
challenge_data.get('
|
|
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
|
-
|
|
1
|
+
import base64
|
|
2
|
+
import hashlib
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
import re
|
|
6
|
+
import time
|
|
7
|
+
from collections import OrderedDict
|
|
8
|
+
from typing import List
|
|
9
|
+
|
|
10
|
+
sec_duration_expr = re.compile(r'data-duration=(\d+)')
|
|
11
|
+
sec_challenge_expr = re.compile(r'challenge="(.*?)"')
|
|
12
|
+
sec_page_expr = re.compile(r'data-duration=\d+\s+src="([^"]+)"')
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class SecCptChallengeData:
|
|
16
|
+
def __init__(self, token: str, timestamp: int, nonce: str, difficulty: int, count: int):
|
|
17
|
+
self.token = token
|
|
18
|
+
self.timestamp = timestamp
|
|
19
|
+
self.nonce = nonce
|
|
20
|
+
self.difficulty = difficulty
|
|
21
|
+
self.count = count
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class SecCptChallenge:
|
|
25
|
+
def __init__(self, duration: int, challenge_path: str, challenge_data: SecCptChallengeData):
|
|
26
|
+
self.duration = duration
|
|
27
|
+
self.challenge_path = challenge_path
|
|
28
|
+
self.challenge_data = challenge_data
|
|
29
|
+
|
|
30
|
+
@staticmethod
|
|
31
|
+
def parse(html: str) -> 'SecCptChallenge':
|
|
32
|
+
challenge_data = SecCptChallenge._parse_challenge_data(html)
|
|
33
|
+
duration = SecCptChallenge._parse_duration(html)
|
|
34
|
+
challenge_path = SecCptChallenge._parse_challenge_path(html)
|
|
35
|
+
|
|
36
|
+
return SecCptChallenge(duration, challenge_path, challenge_data)
|
|
37
|
+
|
|
38
|
+
@staticmethod
|
|
39
|
+
def parse_from_json(json_payload: str) -> 'SecCptChallenge':
|
|
40
|
+
api_response = json.loads(json_payload)
|
|
41
|
+
|
|
42
|
+
challenge_data = SecCptChallengeData(
|
|
43
|
+
api_response.get('token', ''),
|
|
44
|
+
api_response.get('timestamp', 0),
|
|
45
|
+
api_response.get('nonce', ''),
|
|
46
|
+
api_response.get('difficulty', 0),
|
|
47
|
+
api_response.get('count', 0)
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
duration = api_response.get('chlg_duration', 0)
|
|
51
|
+
challenge_path = api_response.get('branding_url_content', '')
|
|
52
|
+
|
|
53
|
+
return SecCptChallenge(duration, challenge_path, challenge_data)
|
|
54
|
+
|
|
55
|
+
@staticmethod
|
|
56
|
+
def _parse_challenge_data(src: str) -> SecCptChallengeData:
|
|
57
|
+
challenge_match = sec_challenge_expr.search(src)
|
|
58
|
+
if not challenge_match:
|
|
59
|
+
raise Exception("hyper-sdk: Challenge data not found.")
|
|
60
|
+
|
|
61
|
+
decoded_challenge = base64.b64decode(challenge_match.group(1))
|
|
62
|
+
challenge_data = json.loads(decoded_challenge)
|
|
63
|
+
|
|
64
|
+
return SecCptChallengeData(
|
|
65
|
+
challenge_data.get('token', ''),
|
|
66
|
+
challenge_data.get('timestamp', 0),
|
|
67
|
+
challenge_data.get('nonce', ''),
|
|
68
|
+
challenge_data.get('difficulty', 0),
|
|
69
|
+
challenge_data.get('count', 0)
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
@staticmethod
|
|
73
|
+
def _parse_duration(src: str) -> int:
|
|
74
|
+
duration_match = sec_duration_expr.search(src)
|
|
75
|
+
if not duration_match:
|
|
76
|
+
raise Exception("hyper-sdk: Duration not found.")
|
|
77
|
+
|
|
78
|
+
try:
|
|
79
|
+
duration = int(duration_match.group(1))
|
|
80
|
+
except ValueError as e:
|
|
81
|
+
raise Exception(f"hyper-sdk: Invalid duration value: {e}")
|
|
82
|
+
|
|
83
|
+
return duration
|
|
84
|
+
|
|
85
|
+
@staticmethod
|
|
86
|
+
def _parse_challenge_path(src: str) -> str:
|
|
87
|
+
page_match = sec_page_expr.search(src)
|
|
88
|
+
if not page_match:
|
|
89
|
+
raise Exception("hyper-sdk: Challenge path not found.")
|
|
90
|
+
|
|
91
|
+
return page_match.group(1)
|
|
92
|
+
|
|
93
|
+
def generate_sec_cpt_payload(self, sec_cpt_cookie: str) -> str:
|
|
94
|
+
sec, _, _ = sec_cpt_cookie.partition("~")
|
|
95
|
+
if sec == sec_cpt_cookie:
|
|
96
|
+
raise Exception("hyper-sdk: Malformed sec_cpt cookie.")
|
|
97
|
+
|
|
98
|
+
answers = self._generate_sec_cpt_answers(sec)
|
|
99
|
+
|
|
100
|
+
payload = OrderedDict([
|
|
101
|
+
("token", self.challenge_data.token),
|
|
102
|
+
("answers", answers)
|
|
103
|
+
])
|
|
104
|
+
|
|
105
|
+
return json.dumps(payload)
|
|
106
|
+
|
|
107
|
+
def sleep(self):
|
|
108
|
+
time.sleep(self.duration)
|
|
109
|
+
|
|
110
|
+
def _generate_sec_cpt_answers(self, sec: str) -> List[str]:
|
|
111
|
+
answers = []
|
|
112
|
+
if self.challenge_data.count <= 0:
|
|
113
|
+
return answers
|
|
114
|
+
|
|
115
|
+
difficulty = self.challenge_data.difficulty
|
|
116
|
+
|
|
117
|
+
while True:
|
|
118
|
+
answer = f"0.{os.urandom(8).hex()}"
|
|
119
|
+
hash_input = f"{sec}{self.challenge_data.timestamp}{self.challenge_data.nonce}{difficulty}{answer}"
|
|
120
|
+
|
|
121
|
+
output = 0
|
|
122
|
+
for byte in hashlib.sha256(hash_input.encode('ascii')).digest():
|
|
123
|
+
output = (output << 8) | byte
|
|
124
|
+
output %= difficulty
|
|
125
|
+
|
|
126
|
+
if output == 0:
|
|
127
|
+
difficulty += 1
|
|
128
|
+
answers.append(answer)
|
|
129
|
+
|
|
130
|
+
if len(answers) == self.challenge_data.count:
|
|
131
|
+
break
|
|
132
|
+
continue
|
|
133
|
+
|
|
130
134
|
return answers
|
|
@@ -3,15 +3,14 @@ import re
|
|
|
3
3
|
from typing import Optional
|
|
4
4
|
from urllib.parse import urlencode
|
|
5
5
|
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
)
|
|
6
|
+
# A challenge page loads its bundle with the only deferred <script> tag on the
|
|
7
|
+
# page, so the bundle is the src of the first tag carrying a defer attribute.
|
|
8
|
+
# The file name is not checked: DataDome renames the bundle freely, e.g.
|
|
9
|
+
# interstitial.1.36.0.js or captcha.build623.01-c-v1.38.0-2026-11-17-05h07.js.
|
|
10
|
+
# The c.js and i.js loaders are not deferred and never match.
|
|
11
|
+
_SCRIPT_TAG_REGEX = re.compile(r"<script\b([^>]*)>", re.IGNORECASE)
|
|
12
|
+
_DEFER_ATTR_REGEX = re.compile(r"(?:^|\s)defer(?:\s|=|/|$)", re.IGNORECASE)
|
|
13
|
+
_SRC_ATTR_REGEX = re.compile(r"""(?:^|\s)src\s*=\s*["']([^"']+)["']""", re.IGNORECASE)
|
|
15
14
|
|
|
16
15
|
|
|
17
16
|
def parse_slider_device_check_link(src: str, datadome_cookie: str, referer: str) -> str:
|
|
@@ -135,8 +134,12 @@ def parse_challenge_script_url(html: str) -> Optional[str]:
|
|
|
135
134
|
script=script,
|
|
136
135
|
))
|
|
137
136
|
"""
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
137
|
+
for tag in _SCRIPT_TAG_REGEX.finditer(html):
|
|
138
|
+
attrs = tag.group(1)
|
|
139
|
+
if not _DEFER_ATTR_REGEX.search(attrs):
|
|
140
|
+
continue
|
|
141
|
+
src = _SRC_ATTR_REGEX.search(attrs)
|
|
142
|
+
if src is not None:
|
|
143
|
+
return src.group(1)
|
|
144
|
+
|
|
145
|
+
return None
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"""Finds the deferred DataDome challenge bundle on a device check or captcha page."""
|
|
2
|
+
|
|
3
|
+
import unittest
|
|
4
|
+
|
|
5
|
+
from hyper_sdk.datadome import parse_challenge_script_url
|
|
6
|
+
|
|
7
|
+
BUILD_PREFIX_URL = "https://ct.captcha-delivery.com/captcha.build623.01-c-v1.38.0-2026-11-17-05h07.js"
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class TestParseChallengeScriptUrl(unittest.TestCase):
|
|
11
|
+
def test_interstitial_with_build(self):
|
|
12
|
+
html = '<head><script defer src="https://ct.captcha-delivery.com/interstitial.1.33.0.202609141.js"></script></head>'
|
|
13
|
+
self.assertEqual(parse_challenge_script_url(html), "https://ct.captcha-delivery.com/interstitial.1.33.0.202609141.js")
|
|
14
|
+
|
|
15
|
+
def test_captcha_with_build(self):
|
|
16
|
+
html = '<script defer src="https://ct.captcha-delivery.com/captcha.1.34.0.202609141.js"></script>'
|
|
17
|
+
self.assertEqual(parse_challenge_script_url(html), "https://ct.captcha-delivery.com/captcha.1.34.0.202609141.js")
|
|
18
|
+
|
|
19
|
+
def test_interstitial_without_build(self):
|
|
20
|
+
html = '<head><script defer src="https://ct.captcha-delivery.com/interstitial.1.36.0.js"></script></head>'
|
|
21
|
+
self.assertEqual(parse_challenge_script_url(html), "https://ct.captcha-delivery.com/interstitial.1.36.0.js")
|
|
22
|
+
|
|
23
|
+
def test_single_quotes(self):
|
|
24
|
+
html = "<script defer src='https://ct.captcha-delivery.com/captcha.1.37.0.js'></script>"
|
|
25
|
+
self.assertEqual(parse_challenge_script_url(html), "https://ct.captcha-delivery.com/captcha.1.37.0.js")
|
|
26
|
+
|
|
27
|
+
def test_captcha_with_build_prefix(self):
|
|
28
|
+
html = f'<script defer src="{BUILD_PREFIX_URL}"></script>'
|
|
29
|
+
self.assertEqual(parse_challenge_script_url(html), BUILD_PREFIX_URL)
|
|
30
|
+
|
|
31
|
+
def test_build_prefix_after_inline_dd_object(self):
|
|
32
|
+
html = (
|
|
33
|
+
"<script data-cfasync=\"false\">var dd={'rt':'c'}</script>"
|
|
34
|
+
'<script data-cfasync="false" src="https://ct.captcha-delivery.com/c.js"></script>'
|
|
35
|
+
f'<script defer src="{BUILD_PREFIX_URL}"></script>'
|
|
36
|
+
)
|
|
37
|
+
self.assertEqual(parse_challenge_script_url(html), BUILD_PREFIX_URL)
|
|
38
|
+
|
|
39
|
+
def test_any_file_name(self):
|
|
40
|
+
html = '<script defer src="https://ct.captcha-delivery.com/interstitial-next.js"></script>'
|
|
41
|
+
self.assertEqual(parse_challenge_script_url(html), "https://ct.captcha-delivery.com/interstitial-next.js")
|
|
42
|
+
|
|
43
|
+
def test_defer_after_src(self):
|
|
44
|
+
html = f'<script src="{BUILD_PREFIX_URL}" defer></script>'
|
|
45
|
+
self.assertEqual(parse_challenge_script_url(html), BUILD_PREFIX_URL)
|
|
46
|
+
|
|
47
|
+
def test_first_deferred_tag_wins(self):
|
|
48
|
+
html = (
|
|
49
|
+
f'<script defer src="{BUILD_PREFIX_URL}"></script>'
|
|
50
|
+
'<script defer src="https://example.com/other.js"></script>'
|
|
51
|
+
)
|
|
52
|
+
self.assertEqual(parse_challenge_script_url(html), BUILD_PREFIX_URL)
|
|
53
|
+
|
|
54
|
+
def test_defer_in_src_is_not_the_attribute(self):
|
|
55
|
+
html = '<script src="https://example.com/defer.js"></script>'
|
|
56
|
+
self.assertIsNone(parse_challenge_script_url(html))
|
|
57
|
+
|
|
58
|
+
def test_versionless_loader(self):
|
|
59
|
+
html = '<script src="https://ct.captcha-delivery.com/i.js"></script>'
|
|
60
|
+
self.assertIsNone(parse_challenge_script_url(html))
|
|
61
|
+
|
|
62
|
+
def test_inlined_bundle(self):
|
|
63
|
+
html = "<script>var ddm = {};/* DataDome is a cyberfraud solution v1.33.0 */!function(){}()</script>"
|
|
64
|
+
self.assertIsNone(parse_challenge_script_url(html))
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
if __name__ == "__main__":
|
|
68
|
+
unittest.main()
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"""SEC-CPT challenge parsing and answer generation."""
|
|
2
|
+
|
|
3
|
+
import base64
|
|
4
|
+
import json
|
|
5
|
+
import unittest
|
|
6
|
+
|
|
7
|
+
from hyper_sdk.akamai import SecCptChallenge
|
|
8
|
+
|
|
9
|
+
CHALLENGE = {
|
|
10
|
+
"token": "tok",
|
|
11
|
+
"timestamp": 1713283747,
|
|
12
|
+
"nonce": "ebccdb479fcb92636fbc",
|
|
13
|
+
"difficulty": 1500,
|
|
14
|
+
"count": 3,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class ParseFromJsonTest(unittest.TestCase):
|
|
19
|
+
def test_reads_every_challenge_field(self):
|
|
20
|
+
payload = json.dumps({
|
|
21
|
+
**CHALLENGE,
|
|
22
|
+
"sec-cp-challenge": "true",
|
|
23
|
+
"provider": "adaptive",
|
|
24
|
+
"chlg_duration": 5,
|
|
25
|
+
"branding_url_content": "/_sec/cp_challenge/ak-challenge-4-3.htm",
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
challenge = SecCptChallenge.parse_from_json(payload)
|
|
29
|
+
|
|
30
|
+
self.assertEqual(challenge.duration, 5)
|
|
31
|
+
self.assertEqual(challenge.challenge_path, "/_sec/cp_challenge/ak-challenge-4-3.htm")
|
|
32
|
+
data = challenge.challenge_data
|
|
33
|
+
self.assertEqual(
|
|
34
|
+
(data.token, data.timestamp, data.nonce, data.difficulty, data.count),
|
|
35
|
+
("tok", 1713283747, "ebccdb479fcb92636fbc", 1500, 3),
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
def test_payload_has_count_answers(self):
|
|
39
|
+
challenge = SecCptChallenge.parse_from_json(json.dumps(CHALLENGE))
|
|
40
|
+
|
|
41
|
+
payload = json.loads(challenge.generate_sec_cpt_payload("ABCDEF~3~xyz"))
|
|
42
|
+
|
|
43
|
+
self.assertEqual(payload["token"], "tok")
|
|
44
|
+
self.assertEqual(len(payload["answers"]), 3)
|
|
45
|
+
|
|
46
|
+
def test_missing_count_yields_no_answers(self):
|
|
47
|
+
challenge = SecCptChallenge.parse_from_json(json.dumps({k: v for k, v in CHALLENGE.items() if k != "count"}))
|
|
48
|
+
|
|
49
|
+
payload = json.loads(challenge.generate_sec_cpt_payload("ABCDEF~3~xyz"))
|
|
50
|
+
|
|
51
|
+
self.assertEqual(payload["answers"], [])
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class ParseHtmlTest(unittest.TestCase):
|
|
55
|
+
def test_html_and_json_parse_to_the_same_challenge_data(self):
|
|
56
|
+
encoded = base64.b64encode(json.dumps(CHALLENGE).encode()).decode()
|
|
57
|
+
html = (
|
|
58
|
+
f'<iframe id="sec-cpt-if" provider="crypto" challenge="{encoded}" '
|
|
59
|
+
f'data-duration=5 src="/_sec/cp_challenge/ak-challenge-4-3.htm"></iframe>'
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
from_html = SecCptChallenge.parse(html).challenge_data
|
|
63
|
+
from_json = SecCptChallenge.parse_from_json(json.dumps(CHALLENGE)).challenge_data
|
|
64
|
+
|
|
65
|
+
self.assertEqual(vars(from_html), vars(from_json))
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
if __name__ == "__main__":
|
|
69
|
+
unittest.main()
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"""Finds the deferred DataDome challenge bundle on a device check or captcha page."""
|
|
2
|
-
|
|
3
|
-
import unittest
|
|
4
|
-
|
|
5
|
-
from hyper_sdk.datadome import parse_challenge_script_url
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class TestParseChallengeScriptUrl(unittest.TestCase):
|
|
9
|
-
def test_interstitial_with_build(self):
|
|
10
|
-
html = '<head><script defer src="https://ct.captcha-delivery.com/interstitial.1.33.0.202609141.js"></script></head>'
|
|
11
|
-
self.assertEqual(parse_challenge_script_url(html), "https://ct.captcha-delivery.com/interstitial.1.33.0.202609141.js")
|
|
12
|
-
|
|
13
|
-
def test_captcha_with_build(self):
|
|
14
|
-
html = '<script defer src="https://ct.captcha-delivery.com/captcha.1.34.0.202609141.js"></script>'
|
|
15
|
-
self.assertEqual(parse_challenge_script_url(html), "https://ct.captcha-delivery.com/captcha.1.34.0.202609141.js")
|
|
16
|
-
|
|
17
|
-
def test_interstitial_without_build(self):
|
|
18
|
-
html = '<head><script defer src="https://ct.captcha-delivery.com/interstitial.1.36.0.js"></script></head>'
|
|
19
|
-
self.assertEqual(parse_challenge_script_url(html), "https://ct.captcha-delivery.com/interstitial.1.36.0.js")
|
|
20
|
-
|
|
21
|
-
def test_single_quotes(self):
|
|
22
|
-
html = "<script src='https://ct.captcha-delivery.com/captcha.1.37.0.js'></script>"
|
|
23
|
-
self.assertEqual(parse_challenge_script_url(html), "https://ct.captcha-delivery.com/captcha.1.37.0.js")
|
|
24
|
-
|
|
25
|
-
def test_versionless_loader(self):
|
|
26
|
-
html = '<script src="https://ct.captcha-delivery.com/i.js"></script>'
|
|
27
|
-
self.assertIsNone(parse_challenge_script_url(html))
|
|
28
|
-
|
|
29
|
-
def test_inlined_bundle(self):
|
|
30
|
-
html = "<script>var ddm = {};/* DataDome is a cyberfraud solution v1.33.0 */!function(){}()</script>"
|
|
31
|
-
self.assertIsNone(parse_challenge_script_url(html))
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if __name__ == "__main__":
|
|
35
|
-
unittest.main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|