-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdecrypt.html
317 lines (268 loc) · 9.75 KB
/
decrypt.html
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
<html lang="en">
<head>
<title>Arkose BDA Decoder</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="UTF-8">
<link rel="icon" type="image/png" href="https://external-content.duckduckgo.com/ip3/arkoselabs.com.ico"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/picocss/2.0.6/pico.min.css" integrity="sha512-UXfikgakSZBii5lkvmDCRO+IYWQhTtwMOJ+3EmGEA+oA82kvbSskgw3OI16Jx1kINgF8aqOkYE+c9h4m6muONg==" crossorigin="anonymous" referrerpolicy="no-referrer"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/nord.min.css" integrity="sha512-U/cZqAAOThvb4J9UCt/DWkkjoJWHXvutFDS/nZmZlirci2ZMuH6qFokOQDuuKgE7pXD+FmhDNH2jT43x0GreCQ==" crossorigin="anonymous" referrerpolicy="no-referrer"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js" integrity="sha512-D9gUyxqja7hBtkWpPWGt9wfbfaMGVt9gnyCvYa+jojwwPHLCzUm5i8rpk7vD7wNee9bA35eYIjobYPaQuKS1MQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/json.min.js" integrity="sha512-Tj35Q81ghoSFK84ee0H7qn2IjAyKwZQ9oYJDjtBmKOmlSz3MUqHrXxoMxIR9GrXzFakEiSV/VMrWwyAp45Bqjw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<style>
html {
scroll-behavior: smooth;
}
code {
white-space: pre-wrap;
overflow-y: scroll;
min-height: 90%;
max-height: 90%;
/*min-height: 90vh;*/
/*max-height: 90vh;*/
}
.grid > div {
min-height: 100vh;
max-height: 100vh;
overflow: hidden;
}
</style>
</head>
<body>
<div class="container">
<header>
<h1>BDA Decoder</h1>
</header>
<details open>
<summary role="button" class="secondary">BDA Encryption</summary>
<div class="grid">
<div>
<label>
x-ark-esync-value:
<input id="timestampInput" type="number" placeholder="1700000000" aria-label="max events">
</label>
<label>
User Agent:
<input id="userAgentInput" placeholder="Mozilla/5.0..." aria-label="user agent">
</label>
<label>
Encrypted Payload:
<textarea id="inputContent" rows="8" placeholder="eyJjdCI6I..." style="width: 100%"></textarea>
</label>
</div>
<div>
<label>
Decrypted Payload:
<code style="width: 100%" id="outputContent"></code>
</label>
</div>
</div>
</details>
<details open>
<summary role="button" class="secondary">Other Encryption</summary>
<label for="sessionGroup">
Session Token:
</label>
<fieldset role="group" id="sessionGroup">
<input id="sessionTokenInput" type="text" name="text" placeholder="00000000000000000.0000000000" aria-label="Session token">
<select id="encryptionTypeInput" aria-label="Default" required>
<option selected value="default_method">Default</option>
<option value="default_method">Guess</option>
<option value="default_method">TGuess</option>
<option value="requested_id_method">x-requested-id</option>
</select>
</fieldset>
<div class="grid">
<div>
<label>
Encrypted Payload:
<textarea id="miscInput" rows="8" placeholder="{"ct": "...", "s": "...", "iv": "..."}" style="width: 100%"></textarea>
</label>
</div>
<div>
<label>
Decrypted Payload:
<code style="width: 100%" id="miscOutputContent"></code>
</label>
</div>
</div>
</details>
</div>
<script src="https://cdn.jsdelivr.net/npm/js-md5@0.8.3/build/md5.min.js" integrity="sha512-Vspwtv6dGEzathjxMiV7hNvO1ZSKSAho+dtQieeqCgsmepPEukPl6WBsLCho0OMu2UieR5OC4AsPT7bD+E3InA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script>
const timestampInputElement = document.getElementById("timestampInput");
const userAgentInputElement = document.getElementById("userAgentInput");
const inputContentElement = document.getElementById("inputContent");
const outputContentElement = document.getElementById("outputContent");
const sessionTokenElement = document.getElementById("sessionTokenInput");
const encryptionTypeElement = document.getElementById("encryptionTypeInput");
const miscInputElement = document.getElementById("miscInput");
const miscOutputContentElement = document.getElementById("miscOutputContent");
timestampInputElement.value = Date.now().toString();
userAgentInputElement.value = navigator.userAgent;
async function changeEventHandler() {
try {
const cipherObject = JSON.parse(atob(inputContentElement.value));
const userAgent = userAgentInputElement.value;
let timestamp = parseInt(timestampInputElement.value, 10);
timestamp = timestampInputElement.value.length > 10 ? timestamp : timestamp * 1000;
console.log("Attempting to decrypt with:", {
cipherObject,
userAgent,
timestamp,
});
const decryptedBda = await decryptSensor({
cipherObject,
userAgent,
timestamp,
});
outputContentElement.innerHTML = hljs.highlight(
JSON.stringify(decryptedBda, null, 4),
{language: "json"},
).value;
}
catch(err) {
console.error("Failed to decrypt with these values.");
}
}
timestampInputElement.addEventListener("input", changeEventHandler);
userAgentInputElement.addEventListener("input", changeEventHandler);
inputContentElement.addEventListener("input", changeEventHandler);
async function changeEventHandlerDecryptMisc() {
try {
const encryptionMethod = encryptionTypeElement.value;
const sessionToken = sessionTokenElement.value;
let key;
switch(encryptionMethod) {
case "default_method":
key = sessionToken;
break;
case "requested_id_method":
key = `REQUESTED${sessionToken}ID`;
break;
default:
console.error("Unsupported encryption method");
return;
}
const cipherObject = JSON.parse(miscInputElement.value);
const decryptedPayload = await decrypt({
cipherObject,
key,
});
miscOutputContentElement.innerHTML = hljs.highlight(
JSON.stringify(decryptedPayload, null, 4),
{language: "json"},
).value;
}
catch(err) {
console.error("Failed to decrypt with these values.");
}
}
sessionTokenElement.addEventListener("input", changeEventHandlerDecryptMisc);
encryptionTypeElement.addEventListener("input", changeEventHandlerDecryptMisc);
miscInputElement.addEventListener("input", changeEventHandlerDecryptMisc);
const TIME_CONSTANT_VALUE = 21600;
/**
* @param {CipherObject} cipherObject
* @param {string} userAgent
* @param {number} timestamp
* @returns {Promise<object>}
*/
async function decryptSensor({cipherObject, userAgent, timestamp = Date.now()}) {
const timeFrame = timestamp / 1000;
const timeFrameKey = Math.floor(timeFrame - (timeFrame % TIME_CONSTANT_VALUE));
return decrypt({
cipherObject,
key: userAgent + timeFrameKey,
});
}
/**
* @typedef {object} CipherObject
* @property {string} ct Encrypted content in base64.
* @property {string} s Salt in hex.
* @property {string} iv IV in hex.
*/
/**
* @param {CipherObject} cipherObject
* @param {string} key
* @param {boolean} [isObject]
* @returns {Promise<string|object>}
*/
async function decrypt({cipherObject, key, isObject = true}) {
if(cipherObject === undefined || cipherObject.ct === undefined || cipherObject.s === undefined || cipherObject.iv === undefined) {
throw new TypeError("Malformed encryption data");
}
if(!key) {
throw new TypeError("Invalid encryption key");
}
const ciphertextBytes = fromBase64(cipherObject.ct);
const saltBytes = fromHex(cipherObject.s);
const iv = fromHex(cipherObject.iv);
const derivedKey = EVP_BytesToKey(key, saltBytes, 32, 16);
const importedKey = await crypto.subtle.importKey(
"raw",
derivedKey.key,
{
name: "AES-CBC",
},
false,
["decrypt"],
);
const decrypted = await crypto.subtle.decrypt(
{
name: "AES-CBC",
iv: iv,
},
importedKey,
ciphertextBytes,
);
const plainText = new TextDecoder().decode(decrypted);
if(isObject) {
return JSON.parse(plainText);
}
return plainText;
}
/**
* @param {string} password
* @param {Uint8Array} saltBuffer
* @param {number} keyLen
* @param {number} ivLen
* @returns {{iv: Uint8Array, key: Uint8Array}}
*/
function EVP_BytesToKey(password, saltBuffer, keyLen, ivLen) {
const passwordBuffer = new TextEncoder().encode(password);
if(saltBuffer.length !== 8) {
throw new RangeError("salt should be Buffer with 8 byte length");
}
let keyIv = new Uint8Array(0);
while(keyIv.length < (keyLen + ivLen)) {
const data = new Uint8Array([...keyIv, ...passwordBuffer, ...saltBuffer]);
// const hash = crypto.createHash("md5").update(data).digest();
const hash = md5.arrayBuffer(data);
keyIv = new Uint8Array([...keyIv, ...new Uint8Array(hash)]);
}
const key = keyIv.slice(0, keyLen);
const iv = keyIv.slice(keyLen, keyLen + ivLen);
return {key, iv};
}
/**
* @param {string} base64String
* @returns {Uint8Array}
*/
function fromBase64(base64String) {
const binaryString = atob(base64String);
const bytes = new Uint8Array(binaryString.length);
for(let i = 0; i < binaryString.length; i++) {
bytes[i] = binaryString.charCodeAt(i);
}
return bytes;
}
/**
* @param {string} hexString
* @returns {Uint8Array}
*/
function fromHex(hexString) {
return Uint8Array.from(hexString.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
}
</script>
</body>
</html>