aijavascript2211
AI Face Swap Generator & Scraper (aifaceswap.io)
Reverse-engineered scraper & generator untuk https://aifaceswap.io/ (AI Face Swap online tanpa registrasi). Dilengkapi dynamic session handshake, pertukaran kunci RSA PKCS#1 v1.5, enkripsi data payload AES-256-GCM dengan kunci dinamis SHA256 dari data-kt-theme-version, serta integrasi direct upload ke Aliyun OSS. Zero external dependencies.
Vamz Spectre24 Okt 2026361 baris kode
Jalankan via Terminal / CLI:
# 1. Download file script
curl -sL "https://code.vamxapi.my.id/snippet/raw/aifaceswap-scraper" -o aifaceswap-scraper.js
# 2. Jalankan script
node aifaceswap-scraper.js
Dependencies npm yang Dibutuhkan:
npm install None (Pure Node.js built-in)Panduan Penggunaan:
Cara Download: curl -sL "https://code.vamxapi.my.id/snippet/raw/aifaceswap-scraper" -o aifaceswap-scraper.js Cara Eksekusi: node aifaceswap-scraper.js "<target_image_or_url>" "<face_image_or_url>"
aifaceswap-scraper.js(361 lines)
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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
/**
* AI Face Swap Scraper & Generator (aifaceswap.io)
* Reverse-engineered by Vamz Spectre / VamxAPI
*
* Capabilities:
* - High-speed AI Face Swap without registration / free quota bypass
* - Automatic dynamic session handshake & RSA PKCS#1 v1.5 key exchange
* - Payload encryption using AES-256-GCM + dynamic theme-version SHA256 key
* - Aliyun OSS direct pre-signed upload integration
* - Supports Local File Paths, Remote Image URLs, and Base64 Data URIs
*
* Usage:
* node aifaceswap-scraper.js "<target_image_or_url>" "<face_image_or_url>"
*
* Example:
* node aifaceswap-scraper.js "https://temp.aifaceswap.io/aifaceswap/static_img/204de792a133b31edd255f7bb0d2e76f.webp" "https://temp.aifaceswap.io/aifaceswap/static_img/8a1bce5ea303791589165a5f607e7399.webp"
*/
const fs = require("fs");
const crypto = require("crypto");
const BASE_URL = "https://aifaceswap.io";
const CDN_PREFIX = "https://art-global.ezmaker.ai/";
const APP_ID_V1 = "aifaceswap_v1";
const SECRET = "1H5tRtzsBkqXcaJ";
const RSA_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCwlO+boC6cwRo3UfXVBadaYwcX
0zKS2fuVNY2qZ0dgwb1NJ+/Q9FeAosL4ONiosD71on3PVYqRUlL5045mvH2K9i8b
AFVMEip7E6RMK6tKAAif7xzZrXnP1GZ5Rijtqdgwh+YmzTo39cuBCsZqK9oEoeQ3
r/myG9S+9cR5huTuFQIDAQAB
-----END PUBLIC KEY-----`;
function makeid(length = 16) {
let result = "";
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (let i = 0; i < length; i++) {
result += chars.charAt(Math.floor(Math.random() * chars.length));
}
return result;
}
function encryptAesCbc(text, key, iv) {
const cipher = crypto.createCipheriv("aes-128-cbc", Buffer.from(key, "utf8"), Buffer.from(iv, "utf8"));
let encrypted = cipher.update(text, "utf8", "base64");
encrypted += cipher.final("base64");
return encrypted;
}
function encryptRsa(text, publicKey) {
return crypto.publicEncrypt(
{
key: publicKey,
padding: crypto.constants.RSA_PKCS1_PADDING
},
Buffer.from(text, "utf8")
).toString("base64");
}
function signux() {
const aesSecret = makeid(16);
const nonce = crypto.randomUUID();
const secret_key = encryptRsa(aesSecret, RSA_PUBLIC_KEY);
const sign = encryptAesCbc(`${APP_ID_V1}:${nonce}:${secret_key}`, aesSecret, aesSecret);
return { nonce, secret_key, sign, aesSecret };
}
function signx() {
const t = Math.floor(Date.now() / 1000);
const nonce = crypto.randomUUID();
const aesSecret = makeid(16);
const secret_key = encryptRsa(aesSecret, RSA_PUBLIC_KEY);
const sign = encryptAesCbc(`${APP_ID_V1}:${SECRET}:${t}:${nonce}:${secret_key}`, aesSecret, aesSecret);
return { t, nonce, secret_key, sign, aesSecret };
}
function getFpEncrypt(fp, aesSecret) {
return encryptAesCbc(`${APP_ID_V1}:${fp}`, aesSecret, aesSecret);
}
function encryptGcm(dataObj, themeVersion) {
const jsonStr = JSON.stringify(dataObj);
const keyHash = crypto.createHash("sha256").update(themeVersion).digest();
const iv = crypto.randomBytes(12);
const cipher = crypto.createCipheriv("aes-256-gcm", keyHash, iv);
const encrypted = Buffer.concat([cipher.update(jsonStr, "utf8"), cipher.final()]);
const tag = cipher.getAuthTag();
const combined = Buffer.concat([iv, encrypted, tag]);
return combined.toString("base64");
}
async function resolveImageBuffer(input) {
if (Buffer.isBuffer(input)) {
return { buffer: input, ext: "jpg" };
}
if (typeof input !== "string") {
throw new Error("Input gambar tidak valid (harus URL, Path File, atau Base64).");
}
// Remote URL
if (input.startsWith("http://") || input.startsWith("https://")) {
const res = await fetch(input, {
headers: {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36"
}
});
if (!res.ok) throw new Error(`Gagal mengunduh gambar dari URL: ${input} (${res.status})`);
const arrayBuffer = await res.arrayBuffer();
const contentType = res.headers.get("content-type") || "";
let ext = "jpg";
if (contentType.includes("png") || input.endsWith(".png")) ext = "png";
else if (contentType.includes("webp") || input.endsWith(".webp")) ext = "webp";
return { buffer: Buffer.from(arrayBuffer), ext };
}
// Base64 Data URI
if (input.startsWith("data:image/")) {
const match = input.match(/^data:image\/([a-zA-Z0-9_\-]+);base64,(.+)$/);
if (match) {
return { buffer: Buffer.from(match[2], "base64"), ext: match[1] === "jpeg" ? "jpg" : match[1] };
}
}
// Local file path
if (fs.existsSync(input)) {
const buffer = fs.readFileSync(input);
const extMatch = input.match(/\.([a-zA-Z0-9]+)$/);
const ext = extMatch ? extMatch[1].toLowerCase() : "jpg";
return { buffer, ext: ext === "jpeg" ? "jpg" : ext };
}
throw new Error(`File atau URL gambar tidak ditemukan: ${input}`);
}
async function aiFaceSwap(targetImageInput, faceImageInput, options = {}) {
const timeoutMs = options.timeoutMs || 90000;
const pollIntervalMs = options.pollIntervalMs || 2500;
// 1. Dapatkan Session & Dynamic Theme Version
const initRes = await fetch(`${BASE_URL}/id/`, {
headers: {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36"
}
});
if (!initRes.ok) throw new Error(`Gagal menghubungi server aifaceswap.io: ${initRes.status}`);
const cookies = initRes.headers.getSetCookie ? initRes.headers.getSetCookie() : [initRes.headers.get("set-cookie") || ""];
const cookieHeader = cookies.filter(Boolean).map(c => c.split(";")[0]).join("; ");
const html = await initRes.text();
const themeVersionMatch = html.match(/data-kt-theme-version=["\x27]([^"\x27]+)["\x27]/i);
if (!themeVersionMatch) throw new Error("Gagal mengekstrak data-kt-theme-version dari aifaceswap.io");
const themeVersion = themeVersionMatch[1];
// Helper OSS Upload
async function uploadToOss(resolvedImg) {
const { buffer, ext } = resolvedImg;
const md5 = crypto.createHash("md5").update(buffer).digest("hex");
const fileName = `${md5}.${ext}`;
const s = signux();
const upReq = await fetch(`${BASE_URL}/api/upload_file?batch=1`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36",
"Origin": BASE_URL,
"Referer": `${BASE_URL}/id/`,
"Cookie": cookieHeader,
"x-guide": s.secret_key,
"x-sign": s.sign,
"nonce": s.nonce,
"x-code": String(Date.now()),
"theme-version": themeVersion
},
body: JSON.stringify({ file_name: fileName, type: "image" })
});
const upData = await upReq.json();
if (upData.code !== 200 || !upData.data?.url) {
throw new Error(`Inisialisasi upload OSS gagal: ${JSON.stringify(upData)}`);
}
const ossUrl = upData.data.url;
const mime = ext === "png" ? "image/png" : ext === "webp" ? "image/webp" : "image/jpeg";
const putReq = await fetch(ossUrl, {
method: "PUT",
headers: {
"Content-Type": mime,
"x-oss-storage-class": "Standard"
},
body: buffer
});
if (!putReq.ok) {
throw new Error(`Upload binary ke OSS gagal dengan status: ${putReq.status}`);
}
const cdnUrl = ossUrl.split("?")[0].split("https://yimeta-ai-face-swap.oss-us-west-1.aliyuncs.com/")[1];
return { cdnUrl, extra_data: upData.extra_data || {} };
}
// 2. Upload kedua gambar
const [targetImg, faceImg] = await Promise.all([
resolveImageBuffer(targetImageInput).then(uploadToOss),
resolveImageBuffer(faceImageInput).then(uploadToOss)
]);
// 3. Buat handshake signature & payload
const targetBase = targetImg.cdnUrl.split("/").pop().split(".")[0];
const faceBase = faceImg.cdnUrl.split("/").pop().split(".")[0];
const nonceN = crypto.createHash("md5").update(`${targetBase}:${faceBase}`).digest("hex");
const sx = signx();
const fp = crypto.randomBytes(16).toString("hex");
const fp1 = getFpEncrypt(fp, sx.aesSecret);
const encData = encryptGcm(
{
source_image: targetImg.cdnUrl,
face_image: faceImg.cdnUrl,
type_1: targetImg.extra_data.type_1 || 0,
type_2: faceImg.extra_data.type_2 || 0
},
themeVersion
);
// 4. Submit Face Swap Task
const genReq = await fetch(`${BASE_URL}/api/generate_face_v1`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36",
"Origin": BASE_URL,
"Referer": `${BASE_URL}/id/`,
"Cookie": cookieHeader,
"theme-version": themeVersion,
"X-code": String(Date.now()),
"x-guide": sx.secret_key,
"x-sign": sx.sign,
"nonce": nonceN,
"fp": fp,
"fp1": fp1
},
body: JSON.stringify({
request_type: 2,
data: encData
})
});
const genData = await genReq.json();
if (genData.code !== 200 || !genData.data) {
throw new Error(`Generate Face gagal: ${JSON.stringify(genData)}`);
}
// Jika hasil langsung keluar tanpa queue
if (genData.data.result_image) {
const finalUrl = genData.data.result_image.startsWith("http")
? genData.data.result_image
: `${CDN_PREFIX}${genData.data.result_image}`;
return {
status: true,
creator: "Vamz Spectre",
data: {
task_id: genData.data.task_id || null,
result_url: finalUrl,
source_image: `${CDN_PREFIX}${targetImg.cdnUrl}`,
face_image: `${CDN_PREFIX}${faceImg.cdnUrl}`
}
};
}
const taskId = genData.data.task_id;
if (!taskId) {
throw new Error("Task ID tidak ditemukan dalam response server.");
}
// 5. Polling Task Status
const startTime = Date.now();
while (Date.now() - startTime < timeoutMs) {
await new Promise(r => setTimeout(r, pollIntervalMs));
const chkReq = await fetch(`${BASE_URL}/api/check_status`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36",
"Origin": BASE_URL,
"Referer": `${BASE_URL}/id/`,
"Cookie": cookieHeader,
"theme-version": themeVersion,
"X-code": String(Date.now())
},
body: JSON.stringify({ task_id: taskId, nonce: nonceN })
});
const chk = await chkReq.json();
if (chk.code === 200 && chk.data) {
if (chk.data.status === 2 && chk.data.result_image) {
const finalUrl = chk.data.result_image.startsWith("http")
? chk.data.result_image
: `${CDN_PREFIX}${chk.data.result_image}`;
return {
status: true,
creator: "Vamz Spectre",
data: {
task_id: taskId,
result_url: finalUrl,
source_image: `${CDN_PREFIX}${targetImg.cdnUrl}`,
face_image: `${CDN_PREFIX}${faceImg.cdnUrl}`
}
};
}
if (chk.data.status === -1) {
throw new Error(`Proses swap gagal dari sisi server: ${chk.data.error || "Task Failed"}`);
}
}
}
throw new Error("Waktu tunggu swap melebihi batas (Timeout).");
}
module.exports = { aiFaceSwap };
// CLI Execution Support
if (require.main === module) {
const targetArg = process.argv[2];
const faceArg = process.argv[3];
if (!targetArg || !faceArg) {
console.log(
JSON.stringify(
{
status: false,
creator: "Vamz Spectre",
message: "Harap masukkan target_image dan face_image.",
usage: 'node aifaceswap-scraper.js "<target_image_or_url>" "<face_image_or_url>"'
},
null,
2
)
);
process.exit(1);
}
aiFaceSwap(targetArg, faceArg)
.then(res => {
console.log(JSON.stringify(res, null, 2));
})
.catch(err => {
console.error(
JSON.stringify(
{
status: false,
creator: "Vamz Spectre",
error: err.message || String(err)
},
null,
2
)
);
process.exit(1);
});
}