Todos os posts
45 min de leituraglizzykingdreko

DataDome plv3: reverse engineering the VM behind the token

DataDome's plv3 runs a VM whose opcode table does not exist until the bytecode is already running. Here is the disassembler, and what it measures about you.

DataDome plv3: reverse engineering the VM behind the token

Let's walk through the virtual machine behind DataDome's plv3 token, the one running on both the interstitial and the captcha, and build a disassembler for it. The interesting part is not that they wrote a VM, everybody writes a VM. It is that their opcode table does not exist until the bytecode has already started running.

Everything here is reproducible with the tool in this repo, verified against 6 different bundles across both challenge types.

What a VM is, and why they use one

First, what a VM actually is

You can skip this if you already know VMs. If you have only ever seen "the code is obfuscated" and not "the code is a VM", this part makes everything below make sense.

Normal JavaScript is executed by your browser's engine. You write a + b, V8 compiles it, the CPU runs it. If I want to know what your script does, I read the script.

A virtual machine inserts a layer. Instead of shipping the logic as JavaScript, you ship:

  1. An interpreter, a small piece of real JavaScript that knows how to execute a made-up instruction set
  2. Bytecode, a blob of bytes that means nothing on its own, encoding the actual logic in that made-up instruction set

The interpreter loops: read a byte, decide what it means, do it, move to the next byte. That loop is the dispatch loop, and the byte it reads is an opcode.

bytecode 578600 542fc1 pc fetch opcode look up handler run it advance pc, repeat stack + registers reads / writes
One opcode byte per turn. The handler does the work, the loop advances, and nothing about the guest program is visible in the interpreter itself.

Here is a toy version in 20 lines:

function run(bytecode) {
  const stack = [];
  let pc = 0;                                     // program counter
  while (pc < bytecode.length) {
    const op = bytecode[pc++];                    // fetch
    switch (op) {                                 // decode
      case 1: stack.push(bytecode[pc++]); break;  // PUSH <imm>
      case 2: stack.push(stack.pop() + stack.pop()); break;  // ADD
      case 3: console.log(stack.pop()); break;    // PRINT
      case 4: return;                             // HALT
    }
  }
}

run([1, 2, 1, 3, 2, 3, 4]);   // push 2, push 3, add, print -> 5

[1, 2, 1, 3, 2, 3, 4] is the whole program. You cannot read it. There is no + anywhere, no console.log call you can breakpoint, no function names, no control flow you can follow in a debugger. The logic is data now, and data does not show up in a stack trace.

That is the entire point. The interpreter is visible and boring, the interesting part is in a byte array, and to understand the byte array you first have to understand the interpreter well enough to decode it. That work is called writing a disassembler: recovering, for each opcode byte, what it does and how many operand bytes follow it, so a blob of numbers turns back into a listing you can read.

The vocabulary that comes up below, in one place:

term meaning
bytecode the byte array holding the program
opcode one byte that selects an operation
operand bytes following an opcode that parametrise it, like the 2 in PUSH 2
program counter (PC) index of the next byte to read
stack where values live between operations
accumulator a single scratch register, often where results land
dispatch loop the fetch, decode, execute cycle
handler the code implementing one opcode
disassembler tool that turns bytecode back into readable instructions

Every one of those exists in DataDome's VM. The twist is where the handlers come from.

Why anti-bot vendors like them

Three reasons, and they are good ones.

Reading is expensive. Deobfuscating a bundle doesn't get you the logic, just the interpreter. You have done maybe 10% of the work at the point where normally you would be done.

Debuggers stop helping. Every operation runs through the same lines. A breakpoint in the dispatch loop hits millions of times and tells you nothing about which guest operation you are in.

The instruction set is a knob they own. They can shuffle opcode numbers, change operand widths, add instructions, and it costs them a rebuild while it costs you a rewrite of your tooling.

The counterweight is that a VM has to be able to build itself before it can run. Follow that construction path and it hands you the pieces in order, which is exactly what the rest of this article does.

How this VM is put together

The file that got smaller

The vm-obf.js module inside a DataDome challenge used to be a standard obfuscated VM. Around 614 lines after running it through my deobfuscator, with a big dispatch switch and an opcode table you could read straight out of the JavaScript. Annoying, but a known quantity.

Then it shrank. Same job, 163 lines. Sorting my bundle collection by date makes the switch obvious:

bundles lines new Function dispatch
older 613, 614, 734 no static opcode table in the JS
current 162, 163, 206 yes thread-of-code, table built at runtime

A file getting four times smaller while doing the same work is usually good news for whoever has to read it. Not this time. The old bundle was bigger because it contained its instruction set. The new one is small because it moved that instruction set into the payload, and it is a different instruction set in every build.

So the opcode table you carefully document on Monday is worth nothing on Tuesday. That is the actual upgrade, and it is a smart one.

Anatomy of the loader

Deobfuscated, the whole thing is six pieces:

piece lines job
const block 1 to 9 register offsets and buffer geometry
o() 10 to 16 xorshift LCG byte generator
s(A) 17 to 57 tagged-value reader, 9 tags plus a small-int fast path
c(A,g,C) 58 to 87 string cipher
M(A,B) 88 to 139 initializer, fills the primitive table, installs MAKE_FUNC
entry 140 to 163 base64 blob to flat buffer, then the dispatch loop

The entry is where a disassembler gets its footing:

const Q = function (A) {
  const g = o();
  return Array.from({ length: 209725 }, (Q, D) =>
    D >= C && D < C + B ? A.charCodeAt(D - C) : g());
}(atob(A));

Three important things there: the flat buffer is 209725 bytes, the bytecode sits at offset C, and it is B bytes long. Everything outside that window is LCG filler.

Every concrete number in this walkthrough comes from one bundle, interstitial-e813eb1. They all rotate per build, so the sample bundle in the repo prints its own set. The rotation surface at the end has the table.

LCG filler LCG filler bytecode, B bytes 0 C = 4624 C+B = 203734 209725 registers live here handlers read entropy here entry 11405 Zero the filler instead of generating it and the VM still runs, with the wrong answer.
The bytecode is a window inside a much larger buffer. Both sides of it are load-bearing, which is why the LCG has to be reproduced rather than padded.

That filler is not padding. The registers live below the bytecode and handlers read entropy from above it, so if you rebuild the buffer with zeros instead you get a VM that runs and produces the wrong answer, which is the worst possible failure mode. The generator is 6 lines:

function o() {
  let A = 2078235825, g = 0;
  return function () {
    return 3 & g++ || (A ^= A << 13, A ^= A >> 17, A ^= A << 5),
      (A >> ((3 & g) << 3)) % 256;
  };
}

Seed, xorshift 13/17/5, and a rotation through the four bytes of the state so one state advance yields four output bytes. Port it exactly, including the counter increment happening before the shift, or your buffer diverges a few thousand bytes in.

Because that charCodeAt is the only one in the file, it makes a perfect anchor. My loader finds it, reads the window guard next to it, resolves the identifiers through the const block, and never once looks up a name it was told to expect.

The const block deserves a note. The interstitial declares one block of plain integers. The captcha declares three, and computes half of them off each other:

var c = 790629505, D = 3492, w = 10600, B = D + 114, Q = B + 348,
    I = D - 1, J = 194136, Y = Q + J, M = D + 16, ...;
var s = 116, a = 111, P = 67, z = 53, y = 62, ...;          // value tags
var l = 31, H = 11, X = 34, k = 24, j = 0, ..., AA = 182;   // primitive slots

So the evaluator has to be a tiny expression system with multiple passes, not a regex for integer literals. Fun detail: the captcha names its tag bytes and primitive slot IDs as constants while the interstitial inlines them. Two different compiler settings for the same VM.

There is no switch

Here is the entire dispatch loop:

const s = Q[C + Q[D]++], c = g + s;
for (Q[I] = Q[c], Q[4222] = s; !Q[w] && P++ < 1e8;) Q[I]();

Compare that to the toy loop earlier. Same fetch, decode, execute, except decode is not a switch, it is an array index. Read a byte, index a table of closures with it, keep calling whatever is in Q[I]. Every handler ends by calling NEXT, which reads the following byte and swaps in the next closure. That structure has a name, thread-of-code, and it means there is no jump table you can point at.

Registers are just offsets in the same flat buffer:

offset role
4221 program counter
4158 stack pointer
4182 accumulator
4190 current handler
4196 halt flag
4322 base of the 256-entry function slot table
4624 first byte of bytecode
-1 reported separately, see the tripwires

Yes, -1. In JavaScript that is just a property named "-1" on the array. Keep this in mind.

Note P++ < 1e8 in the loop condition. P counts iterations, and it does not stay inside the VM. That matters later.

MAKE_FUNC, or how the opcodes arrive

Walking the bytecode from byte 0 with the naive assumption that instructions start there gives you this:

57 86 00 00 54 "const n=arguments[0];n[34](86);const s=n[43](),t=n[32][n[36]];n[32][t-1]^=s,n[17]();"

That is not an instruction. That is a record:

[ 1B opcode 57 ][ 1B slot 86 ][ 3B length 0x000054 = 84 ][ 84 bytes of JavaScript ]
op 57slot 86 len 8484 bytes of JavaScript one MAKE_FUNC record new Function(body) handler table slot 0... slot 86slot 165 = HALT 103 records, back to back chain ends at 11405, the real program starts
The opcode semantics ship inside the payload. Every bundle installs its own 103 handlers before executing a single instruction, so no hardcoded opcode table survives a rotation.

And the handler installed at slot 57 does exactly what you would expect:

A[4379] = function () {
  const B = M(),                                    // u8, target slot
    Q = o(),                                        // u24, source length
    P = String.fromCharCode.apply(null, /* slice Q bytes */),
    E = new Function(P);
  A[g + B] = E.bind(null, d), n();                  // install, bound to primitives
};

There are 103 of these records back to back, occupying the first ~11 KB of every bundle I have looked at. Interstitial or captcha, every rotation, always 103. Then the chain stops and the real program begins.

The .bind(null, d) is the piece that makes the rest tractable. Every compiled handler receives the primitive table as arguments[0], which is why they all open the same way:

const n = arguments[0];

A handler cannot touch the DOM, cannot call a global, cannot do anything except index into n. That is a hard sandbox, and it means the vocabulary of the entire VM is about two dozen entries wide. Recover them and every one of the 103 bodies becomes readable.

Which, to be clear, they already are. This is the trade DataDome made: the opcode semantics are now plaintext JavaScript sitting in the payload, in exchange for the table being different every build. Anyone reading one bundle has an easier time than before. Anyone trying to write a static tool that survives the next push has a much harder time. Given how these things are usually attacked, that is the right call.

Writing the disassembler

Recovering the primitive table

The initializer is the only function containing new Function, so it is easy to locate, and the table it fills is named by the .bind(null, X) call. Then it is a matter of classifying two dozen or so assignments by shape:

d[32] = A;                                            // the flat buffer
d[41] = B;                                            // the OUTPUT object, remember this one
d[14] = M;                                            // read u8 at PC
d[45] = function () { ... return A[D] = g + 2, B << 8 | Q; };    // read u16
d[49] = o;                                            // read u24
d[43] = function () { return s(() => A[C + A[D]++]); };          // tagged value
d[17] = n;                                            // NEXT
d[15] = function () { A[E] = A[--A[P]]; };            // pop to accumulator
d[44] = function (g) { A[A[P]++] = A[Q + g]; };       // push register
d[7]  = function (g) { A[Q + g] = A[A[P] - 1]; };     // store register
d[3]  = function () { ... A[A[P] - 1] = C[g]; };      // property get
d[50] = function () { ... A[--A[P]][g] = A[A[P] - 1]; };         // property set
d[23] = c;                                            // string cipher
d[34] = function (A) {};                              // telemetry no-op

Two traps in here, both of which cost me a debugging cycle.

One: several entries are references to named inner functions (d[49] = o), so you have to resolve the name to its body before classifying, otherwise you classify the string "o".

Two: the string cipher reads a 4-byte header key, which means its body contains << 16 and << 8, which means a naive "widest shift wins" classifier labels the cipher as the u24 reader. Check for the cipher first. Everything downstream depends on those five reader slots being right, since they are where operand widths come from.

The reward for getting it right is that the numbers below are all recovered, never assumed:

bundle u8 u16 u24 typed NEXT mem cipher
interstitial-e813eb1 14 45 49 43 17 32 23
interstitial-fa96b7a 32 18 7 36 0 11 35
captcha-3f9a12d 22 49 35 38 12 31 36
captcha-d7aa843 24 0 15 7 5 33 12

The value tags

Plenty of opcodes take an immediate that is not fixed width. One tag byte, then 0 to 8 payload bytes:

function s(A) {
  let g = A();
  if (128 & g) return 127 & g;              // 7-bit small int, 1 byte total
  let C = 0, B = 24;
  switch (g) {
    case 55:  return !0;
    case 72:  return !1;
    case 34:  return null;
    case 64:  return;
    case 114: return <f64 decoder>(A);      // 8 payload bytes
    case 103: C |= A() << 24, B -= 8;       // i32, falls through
    case 94:  C |= A() << 16, B -= 8;       // i24, falls through
    case 62:  C |= A() << 8,  B -= 8;       // i16, falls through
    case 108: return C |= A(), C << B >> B; // i8, terminal
  }
}

The tag bytes rotate per bundle, so hardcoding 114 = float is pointless. What does not rotate is the fall-through chain: the terminal integer arm reads one payload byte, the arm above it reads two, and so on up. Count the chain arms in source order and the widths fall out without knowing a single tag value. The boolean and null arms are 1 byte, the arm building an 8-element array is the float.

Nine tags in every bundle, plus the small-int fast path. By getting one width wrong the walker desyncs on the first immediate it meets, which is a nice property: you notice immediately.

Building an opcode table that does not exist yet

Now the useful part. For each of the 103 handlers, two things are needed.

The operand signature. A handler consumes bytecode only by calling a reader primitive, so the ordered list of reader calls in the body is the operand list. This one is exact, no heuristics:

const n = arguments[0];
n[34](140);
const s = n[43](),                 // one tagged value
  t = n[32][n[36]];
n[32][t - 1] >>= s, n[17]();

Signature: one tagged value. Semantics: shift the top of the stack right by an immediate. In listing terms, SHR_IMM.

A mnemonic. This one is pattern matching, and the trick that made it work is stripping every bind[N] reference out of the body first. What is left is the guest-level expression:

n[32][n[32][n[36]]++] = s     ->     @[@[@]++] = s      // a push
t[s] = c                      ->     t[s] = c           // property store
t(s)                          ->     t(s)               // a call

Suddenly the shapes are obvious and 85 of 103 opcodes get real names: JMP, JMP_IF_FALSE, PUSH_STR, GET_PROP, SET_PROP, CALL, CALL_APPLY, MAKE_CLOSURE, HALT, XOR, MUL, CMP_GT, KEYS, NEW_ARRAY, and so on. The remaining 18 keep an OP_<slot> name and print their source, which is honest and still perfectly usable, since their operand signatures are exact regardless.

Walking the program

Handlers jump by adding to the PC slot at runtime:

const n = arguments[0], s = n[49]();
n[32][n[21]] += s, n[17]();                                   // JMP
const n = arguments[0], s = n[49]();
n[32][--n[32][n[36]]] || (n[32][n[21]] += s), n[17]();        // JMP_IF_FALSE

Which means a linear sweep is wrong. Sooner or later it walks into a jump's padding, decodes an operand as an opcode, and everything after that is fiction that still looks plausible.

So the walker is a worklist: start at the entry, decode until the block ends, queue branch targets, decode every address at most once. Unconditional jumps end a block. Regions nothing reaches are printed as gaps instead of being swept over, because a wrong instruction is worse than a missing one.

This also hands us a free correctness check. If any operand width is off by even one byte, jump targets stop landing on instruction boundaries. Across all 6 bundles:

captcha-3f9a12d       jmp=1119/1119      interstitial-161af37  jmp=1020/1020
captcha-d18541a       jmp=1014/1014      interstitial-e813eb1  jmp=1135/1135
captcha-d7aa843       jmp=1010/1010      interstitial-fa96b7a  jmp=976/976

Every branch, every bundle, dead on a boundary. That is about as much confidence as you get without running the thing.

Coverage lands around 90%. The missing tenth sits behind computed dispatch that only a live VM resolves, and I would rather report it as a gap than invent instructions for it.

The instruction that hides 4 KB

First instruction of the program, and the first thing that broke my walker:

const r = arguments[0];
for (var n = r[49](), a = new Uint8Array(n), t = 0; t < n; t++)
  a[t] = r[14]();
r[32][r[32][r[36]]++] = a, r[17]();

Read a u24, then read that many bytes one at a time. Counting reader calls naively gives "u24 plus one u8", four bytes of operands. The real answer is 3 + 4262, because the u8 read is inside a loop.

By failing here you land 4258 bytes early, in the middle of a data blob, where the bytes decode into perfectly reasonable looking instructions that mean nothing at all.

So the analyzer tracks for-loop spans and marks reads inside them as repeating, with the count taken from the operand read just before. Same shape shows up with tagged values:

const t = arguments[0], e = t[14]();
for (let n = 0; n < e; n++) t[32][t[32][t[36]]++] = t[43]();

That one is "read a count, then read that many tagged values", each of which is 1 to 9 bytes depending on its own tag. Two nested variable lengths in a single instruction.

And a third variant that looks identical from the operand side but is not a data blob at all:

const o = arguments[0], t = o[14](), n = [], s = o[14]();
for (let t = 0; t < s; t++) { const t = o[14](), s = o[32][o[32][o[35]] + t]; n.push(s) }
const c = o[32][o[21]] + o[19], e = function (s) { /* new frame */ };
o[32][o[32][o[36]]++] = e, o[17]();

Arity, capture count, then that many capture slots, and it pushes a closure. That is the VM's function constructor, so it gets MAKE_CLOSURE rather than being lumped in with the byte pushers.

Strings, and the byte that was not missing

The cipher is short and has no S-box:

header    bytes 0..3, little-endian u32, the base key
table     starts at byte 4, six bytes per entry:
          [ u24 LE offset ][ u16 LE length ][ u8 flags ]
keystream k[i] = (baseKey ^ ctx ^ (i + 1)) & 0xff
plaintext text[i] = image[offset + i] ^ k[i]

Two problems. The ctx byte is not stored anywhere, and the table is not where you would expect it.

The usual answer to a missing key byte is to sweep all 256 values and keep whatever looks readable. I did that first, and it is really useless: XOR against a wrong key lands in printable ASCII most of the time, so you get thousands of candidates like "tsohr}qy" and "MIYNEoYPY_HSN" sitting right next to "pathname" with the same score. You can eyeball the real ones. You cannot automate it.

sweep all 256 keys ctx = 0..255 "tsohr}qy" "pathname" "MIYNEoYPY_HSN" all printable, all same score thousands of candidates, not automatable read ctx as an operand DECODEindex ctx the call site carries it "pathname" exact, every time 217 to 231 strings per bundle
The key byte was never missing. It is an operand of the instruction that calls the decoder, so the disassembly hands it over and the guessing disappears.

Then look at the handler that actually decodes strings:

const a = arguments[0];
var n = a[45](), r = a[45](), s = a[14](), t = a[32][a[11] + n];
a[32][a[32][a[36]]++] = a[23](t, r, s), a[17]();

ctx is not missing. It is an operand. Every string decode site reads a register index, a table id and a ctx byte right out of the instruction stream, then hands all three to the cipher. Once the program is disassembled, every PUSH_STR instruction carries the exact table id and the exact ctx for that call site.

So the sweep goes in the bin and string recovery becomes exact. My resolver maps the cipher call's argument names back to the order the operands were read in, so it keeps working when a rotation reshuffles them, then decodes each site directly.

The second problem sorts itself out along the way. The string image is not at bytecode offset 4, because the cipher is handed a buffer read out of a register. That buffer is the 4262-byte blob the prologue pushes as its very first instruction. So the strings cannot be found until the program has been disassembled, and the disassembly is far more readable once the strings are attached. Chicken, egg, and the egg wins if you do the passes in the right order.

Result on a current interstitial: 224 unique strings from 1198 call sites, all exact.

What comes out, and what it reports

How the token gets out

accumulator HALT, slot 165 the only handler that does not chain out.r plv3= loader attaches afterwards i, t, u, e signals
One value on the wire, and a step count riding beside it. The token is what you reproduce, the telemetry is what catches you reproducing it wrong.

Look again at the primitive table:

d[41] = B;      // B is the initializer's second parameter

And at the loader:

const E = {};                      // the output object
try {
  M(Q, E);                         // handed to the initializer -> lands in d[41]
  ...
  for (Q[I] = Q[c], ...) Q[I]();   // run
  E.u = Q[-1];
} catch (A) {
  E.e = A;
} finally {
  return E.i = P, E.t = performance.now() - Q | 0, E;
}

So the guest program has a handle on the output object. It can write properties on it directly, and exactly one handler in the entire VM does. My classifier now flags it as HALT:

// interstitial e813eb1, slot 165
const n = arguments[0];
n[41].r = n[32][n[10]],    // out.r = MEM[accumulator]
n[32][n[22]] = 1;          // halt = 1
// captcha 3f9a12d, slot 140
const n = arguments[0];
n[11].r = n[31][n[19]],
n[31][n[45]] = 1;

That value is the plv3 token, the thing that ends up in the plv3 field of the POST body. It is not Q[-1], and it is not returned by anything. The guest computes it, leaves it in the accumulator, and the last instruction it ever executes copies it onto the output object and raises the halt flag. Notice there is no n[17]() call at the end: HALT is the only handler that does not dispatch to the next one, because there is no next one.

One HALT per bundle, every time:

bundle HALT slot guest writes loader writes
interstitial-e813eb1 165 r i, t, u, e
interstitial-fa96b7a 32 r i, t, u, e
interstitial-161af37 70 r i, t, u, e
captcha-3f9a12d 140 r i, t, u, e
captcha-d18541a 144 r i, t, u, e
captcha-d7aa843 255 r i, t, u, e

So the VM's return value is a five-field object. Note the internal field is called r, but nothing outside the bundle ever sees that name: main.js reads it straight into the plv3 field of the request, which is what everyone actually calls it.

field written by meaning
r guest HALT instruction the plv3 token, copied verbatim into the plv3 wire field
i loader how many dispatch iterations the loop ran
t loader wall-clock milliseconds the run took
u loader whatever sits at Q[-1]
e loader the exception, if it threw

Four of those five have nothing to do with the token. They are telemetry about how the VM ran, and that is where this gets interesting.

The orchestrator, and where every signal comes from

main.js in the same bundle is 60 lines and it is the Rosetta stone. It schedules the challenge across five steps paced by window.ddm.durationMs, and step 2 is the VM:

case 2:
  D("W285lp", s(window.ddm.seed));
  var N = Date.now();
  try {
    var J = C(872)();                                    // run the VM
    D("CUu1rJ", J.i),                                    // iterations   -> signal
    D("V3s4H9", J.u),                                    // Q[-1]        -> signal
    J.e && D("Uznj9t", "i:" + String(J.e).slice(0, 150)); // error       -> signal
    E = J.r;                                             // token, kept for the wire
  } catch (A) {
    D("Uznj9t", "e:" + String(A).slice(0, 150));
  }
  var i = Date.now();
  D("RfE0EQ", i - N);                                    // elapsed      -> signal
  break;

and step 4 assembles the request:

case 4:
  D("k63MOw", K), D("5E2YI5", K), (0, B[1])(), Q = {
    plv2: P(window.ddm.cid),
    plv3: E
  };

D(key, value) is the signal setter. So every field the VM returns goes somewhere, and only one of them is the token.

Cross-referencing those obfuscated keys against the signal mapping in the same bundle turns it into plain English.

Signal by signal

signal obf key (e813eb1) fed from what it is really measuring
vm_challenge_interactions CUu1rJ J.i how many times the dispatch loop iterated, around 467k on a real run
vm_challenge_elapsed RfE0EQ Date.now() around the call wall-clock cost of the VM run
vm_challenge_undef V3s4H9 J.u, that is Q[-1] the negative-index slot, see below
vm_challenge_errors Uznj9t J.e, truncated to 150 chars the exception message if the VM threw
plv3 (wire field, not a signal) n/a J.r the token itself
tts / tts2 k63MOw / 5E2YI5 cumulative Date.now() across all 5 steps total challenge time
response W285lp s(window.ddm.seed) ties this payload to this challenge's seed
v w1uNfL literal "1.30.0" bundle version
ctype hKujgT window.ddm.displayEnabled invisible vs display mode
chksm tCsQW2 M(s.toString() + B.toString() + D.toString() + P.toString()) see below
ddets1 / ddets2 DYDW4M / tFB9Op n() helper environment detection pair

Two rows in that table are not fingerprints at all. They are traps.

The two tripwires

vm_challenge_interactions is a step counter. The VM reports precisely how many dispatch iterations it took to produce the token. For a given bundle and a given input, that number is essentially deterministic. If you reimplement the VM, or hook the dispatch loop to trace it, or short-circuit a loop to make it faster, the count moves and the server can see it.

I know how sensitive this is because I have watched it: browser 467499 against 463596 from an offline run, a 0.8% gap, on a value that is meant to be reproducible. It is a cheap and very effective way to ask "did you actually execute my program, all of it, the way I wrote it".

chksm hashes the interpreter's own source. Look at what it feeds the hash:

var l = s.toString() + B.toString() + D.toString() + P.toString(),
  z = M(l);

Function.prototype.toString on its own functions. Monkey-patch any of them to instrument the VM and the source text changes, so the checksum changes. Classic self-integrity check, and it pairs neatly with the step counter: one catches you rewriting the code, the other catches you rewriting the execution.

And vm_challenge_undef is the third. E.u = Q[-1] reads a slot that is below the buffer, which in JavaScript means a property that simply does not exist unless something explicitly wrote to it. The signal name DataDome's own code generates for it is literally vm_challenge_undef, which reads a lot like "this is expected to be undefined". Nothing in the disassembly writes there in a clean run. As I understood it, it is a canary for a tampered or instrumented buffer rather than a payload field, though unlike the other two I cannot prove intent from static analysis alone.

Note: none of these three cost DataDome anything. They are free by-products of running a VM you control, and they punish exactly the shortcuts people take.

Captcha versus interstitial

The two challenge types feel like different products. One is the silent "verifying your browser" page, the other is the puzzle. I assumed the VMs would differ in interesting ways, and went looking for it. Same tool, three interstitial rotations against three captcha rotations.

They do not differ. At all, structurally:

property interstitial captcha
handlers installed 103 / 103 / 103 103 / 103 / 103
primitive slots 23 / 23 / 23 23 / 23 / 23
value tags 9 9
named opcodes present in one family only none none
program size 37k to 43k instructions 37k to 42k instructions
entry point ~11.3 KB in ~11.2 KB in
exit one HALT, writes out.r one HALT, writes out.r

Not "similar". Identical counts, and every mnemonic my classifier produces for one family shows up in the other.

The instruction mix says the same thing. Sharing of named instructions across the two families, aggregated over three bundles each:

opcode interstitial captcha delta
GET_PROP_IMM 13.63% 13.24% -0.39
PUSH_CONST 12.26% 12.10% -0.17
PUSH_IMM 3.63% 3.77% +0.14
GET_PROP 6.35% 6.48% +0.13
PUSH_STR 3.31% 3.43% +0.12
ADD 2.10% 2.00% -0.10

Those are the six largest differences in the entire instruction set. The biggest gap anywhere is under half a percentage point, which is noise between two builds of the same source.

Strings tell the same story, as long as you are strict about what "only" means. Take the strings present in all three rotations of one family and absent from every bundle of the other. On that test 130 strings are common to all six, and the captcha-only set is two entries:

crypto
getRandomValues

That is the whole difference. The captcha pulls entropy from crypto.getRandomValues on top of Math.random, and everything else, the WebGL shader, the canvas compositing, the SVG probe, the CSS calc() measurement, the timing reads, is the same program. The interstitial-only set is empty.

That criterion is doing real work, so it is worth spelling out. Relax it to "in all of one family, not in all of the other" and the same six bundles report 26 captcha-only and 13 interstitial-only strings. Every one of the extras is a chain like performance.memory.usedJSHeapSize sitting at 3/3 in one family and 1/3 in the other, which is a build that happened to drop a probe, not a design decision. Pick the loose test and you will write up rotation noise as strategy.

The part where I was wrong

My first pass compared one interstitial against one captcha and produced a much more exciting list: maxTouchPoints, hardwareConcurrency, XMLDocument, a pile of differing CSS custom property names. I nearly wrote it up as "same machine, different questionnaire".

It was rotation noise. Those CSS variable names (--b4, --oj, --za) are regenerated per build, so a single-bundle comparison shows dozens of "differences" that are really just two different Tuesdays. Intersecting three rotations per family before diffing collapses the list from dozens to two. If you take one thing from this section, take that: against a target that rebuilds daily, never diff two files, diff two sets.

The same discipline caught a bug in my own tool. The comparison initially reported 23 primitive slots for the interstitial and 22 for the captcha, which looked like a real structural difference and was in fact my const-block parser dropping $ = 18. The regex used \b before the identifier, and \b does not match before $ because $ is not a word character. After a double check, both families report 23. A "difference" that only shows up on one side of a comparison is worth suspecting before you publish it.

So why two challenge types

Because the difference is not in the VM, it is around it. Same interpreter, same program, same collection surface, wrapped in a different orchestrator, submitted to a different endpoint, inside a completely different envelope:

interstitial captcha
submit POST /interstitial/ GET /captcha/check
carries the token as plv3 plv3
signal blob field payload ddCaptchaEncodedPayload
other fields cid hash referer url s e env userEnv seed b dm ps cid icid ccid userEnv dm ddCaptchaChallenge ddCaptchaEnv ddCaptchaAudioChallenge hash ua referer parent_url s ir

Only plv3, cid, hash, userEnv and dm appear on both sides.

Which is good news if you have already done the work for one of them. The plv3 half carries over completely.

What the VM computes, proven from the listing

A string dump tells you a bundle contains the word webdriver. It does not tell you the program reads it. That gap matters, because a 4 KB blob of strings includes plenty the program never touches on a given path.

Thanks to the disassembly we can settle it. Property access in this VM is always the same two-instruction shape:

PUSH_STR "document"     ; push a decoded string
GET_PROP                ; pop key, pop object, push object[key]
PUSH_STR "timeline"
GET_PROP
PUSH_STR "currentTime"
GET_PROP

So a run of those pairs is a property chain, and joining the strings back together reconstructs document.timeline.currentTime with a byte offset attached. That is the difference between "this string exists somewhere" and "the program evaluates this expression, at pc 35310".

The tool does this with --chains. Two details make it correct rather than approximate:

  • Any non-string push closes the chain. The fn.apply(thisArg, ...) idiom pushes the receiver and then re-resolves it to reach the method, so without this you reconstruct Math.Math.random instead of two separate reads.
  • A SCREAMING_CASE key closes the chain. gl.ARRAY_BUFFER is a constant read off an object, never a container you walk into, so sibling reads stop gluing together.

The stable core

Twenty-five chains appear in all six bundles, three interstitial rotations and three captcha rotations:

what chains
entropy Math.random, Math.round
clock Date.now, performance.now, performance.timing, document.lastModified
DOM construction document.createElement, document.createElementNS, document.body, document.body.appendChild, document.body.removeChild
layout readback lastChild.offsetWidth, window.devicePixelRatio
page context window.ddm, window.ddm.userEnv, location.pathname, document.hidden, window.isSecureContext
encoding window.atob, String.fromCharCode
automation checks navigator.webdriver, window._virtualConsole, window.Buffer, window._userAgent, window.atob.toString

Call frequency from a current interstitial, and the counts are worth a look on their own:

 32x () Math.random                          @pc 34130
 21x () Date.now                             @pc 34099
 10x () document.createElement               @pc 148413
  6x () document.createElementNS             @pc 142720
  5x () performance.now                      @pc 52322
  5x () document.body.appendChild            @pc 154486
  3x    document.timeline.currentTime        @pc 35310
  3x    window._virtualConsole               @pc 170307
  2x    performance.memory.usedJSHeapSize    @pc 52080
  2x () window.atob.toString                 @pc 173254

Math.random 32 times and Date.now 21 times is a way to salt and time itself through the run. The DOM constructors are the probe being built. Everything else is the measurement.

The five checks that are looking for you specifically

This is the group that needs special attention, because four of these five are not fingerprinting, they are automation detection, and every one is confirmed present in all six bundles:

chain what it catches
navigator.webdriver the standard WebDriver flag
window._virtualConsole a jsdom internal, only exists if the page is running in jsdom
window._userAgent also jsdom, which stores the UA on the window object
window.Buffer a Node global, present if the DOM is faked inside Node
window.atob.toString see below

That last one is the sharpest. The VM stringifies the atob. And [native code] sits right there in the recovered string table. Function.prototype.toString on a real builtin returns function atob() { [native code] }, and on a hooked one returns your replacement source. So the VM is checking whether the primitives it depends on have been monkey-patched, which is exactly what an instrumentation harness does to observe it.

Put that next to the two tripwires from earlier, the step counter and the chksm self-hash, and the anti-tamper story is coherent: chksm catches you rewriting the interpreter's own functions, the step counter catches you changing how it executes, and atob.toString catches you rewriting the browser underneath it.

Where the effort actually goes

Bucketing the resolved call sites by area, averaged per bundle:

area strings call sites (interstitial) call sites (captcha)
encoding 17 348 360
DOM 16 169 192
layout probe 53 135 111
entropy 2 108 104
timing 9 105 84
WebGL 25 57 52
canvas 13 36 43
SVG 3 15 22
navigator 7 13 17

Two things stand out.

The layout probe has the largest vocabulary by far. 53 distinct strings, more than double WebGL's 25, because every rotation ships its own generated CSS custom property names (--b4, --oj, --za) plus the selectors and declarations to go with them. The VM writes a <style> block, nests divs, parks them at position:absolute;left:-9999px, and reads offsetWidth back out. The answer comes from the browser's own layout arithmetic over calc() expressions, which is precisely why it is hard to fake: you cannot patch a getter to return a plausible number, you would have to reimplement CSS length resolution and agree with the real engine.

navigator is nearly the smallest. Seven strings, thirteen call sites. The classic fingerprinting surface everyone patches first is the part this VM cares least about. It spends its time on rendered output and layout instead, which is a rational choice given how easy navigator is to spoof.

WebGL, end to end

The full pipeline is recoverable, including the shader source, which is sitting in the string table as a literal:

attribute vec2 p;void main(){gl_Position=vec4(p,0,1);}

and the chains show it being built and executed in order: createShader, shaderSource, compileShader, attachShader, createProgram, linkProgram, useProgram, getAttribLocation, enableVertexAttribArray, bindBuffer with ARRAY_BUFFER, bufferData with STATIC_DRAW, vertexAttribPointer with FLOAT, drawArrays with TRIANGLES, then readPixels with RGBA and UNSIGNED_BYTE.

That last call is the point of the whole exercise: it renders a triangle and reads the pixels back. The value that comes out depends on the GPU, the driver and the rasteriser, so it is a hardware fingerprint that no amount of JavaScript spoofing reproduces. The canvas path does the same trick with globalCompositeOperation set to difference and getImageData.

The captcha delta, at chain level

Earlier I compared the two challenge types by their string tables and found two captcha-only strings. Repeating it at chain level, with the same discipline of requiring presence in all three rotations of a family:

count chains
in 3/3 of both families 25 the stable core above
strictly captcha-only 1 crypto.getRandomValues
strictly interstitial-only 0 none

One chain. The captcha pulls extra entropy from crypto.getRandomValues on top of Math.random, and that is the entire difference in what the two programs ask the browser.

Everything else that looks like a difference is per-rotation drift, and the counts make it obvious:

document.timeline.currentTime        int=3/3  cap=1/3
performance.memory.usedJSHeapSize    int=3/3  cap=1/3
window.outerWidth                    int=2/3  cap=3/3
performance.timeOrigin               int=3/3  cap=2/3
window.screen.height                 int=3/3  cap=1/3
location.href                        int=3/3  cap=1/3

Those are not challenge-type differences, they are build-to-build differences that happen to fall unevenly. Compare one interstitial against one captcha and you would write up half of that list as meaningful. Compare three against three and only crypto.getRandomValues survives.

What this means if you are reproducing it

The chain list is a to-do list, in priority order. The reads are cheap to satisfy and the renders are not:

  • navigator.*, location.*, document.hidden, window.isSecureContext: plain values, spoof freely
  • the clock and entropy chains: plain values, but they feed the timing signals, so stay self-consistent
  • lastChild.offsetWidth after a calc() style block: needs a real layout engine or an exact reimplementation
  • readPixels and getImageData: need a real rasteriser, or a captured value from the machine you are claiming to be
  • navigator.webdriver, window._virtualConsole, window.Buffer, window._userAgent, atob.toString: must be absent or native, and jsdom fails four of the five by existing

That last line is why headless-DOM approaches to this particular VM tend to die early, and it took a disassembler rather than a string dump to say so with a byte offset attached.

The rotation surface

Every number in this table changes per build:

bundle buffer code base LCG seed MAKE_FUNC entry instructions strings
interstitial-e813eb1 209725 4624 2078235825 57 11405 43215 224
interstitial-fa96b7a 183813 4878 1203021935 57 11295 37135 218
interstitial-161af37 188088 5485 1084808355 80 11276 38392 212
captcha-3f9a12d 204736 3954 790629505 182 11396 42003 227
captcha-d18541a 184300 4176 849279761 77 11015 36877 231
captcha-d7aa843 185755 4988 204181867 89 11157 37076 231

So do all identifier names, all register offsets, all value tag bytes, all primitive slot IDs, the HALT slot, and the opcode byte of every instruction in the program.

What does not change is the shape: a const block, an LCG closure, a tagged-value reader with a fall-through chain, a 6-byte string table entry, a MAKE_FUNC record layout, 23 primitives, exactly one HALT, and exactly 103 handlers in every bundle in my collection. By anchoring on shape you get a tool that survives rotations. By anchoring on values you get a tool that survives until the next deploy.

The 103 is the detail I keep coming back to. Identical across interstitial and captcha, identical across every rotation. That is not randomness, that is a compiler emitting a fixed instruction set with shuffled encodings.

Conclusion

This was a case study, and a good one. Moving the opcode semantics into the payload is a real improvement over the old static switch: it kills every hardcoded opcode table in existence and makes each bundle its own dialect. That is a much better idea than renaming variables one more time. The step counter and the source checksum riding along for free are the kind of details that separate a VM someone built because it sounded cool from a VM someone built to catch people.

It also has a structural weakness, which is that a VM has to be able to build itself. The loader must tell you where the bytecode lives, the initializer must hand every handler the same primitive table, and the handlers must arrive as readable source before they can be compiled. Follow that construction path in the same order the VM does and it hands you the instruction set on the way past.

The ctx byte is still my favourite bit. Everyone treats it as a missing key and brute forces it into a pile of nonsense. It was sitting in the instruction stream the whole time, one operand over, waiting for someone to disassemble the program first.

Tool is here, MIT, zero dependencies. Point it at a bundle and it will tell you what changed since yesterday.

Need DataDome bypass solutions?

TakionAPI, we handle the wall. You ship the rest.

If you would rather skip all of this and just get a working cookie, TakionAPI handles DataDome interstitials, captchas and tags in production, plv3 included. One call returns the datadome cookie against a consistent fingerprint, no browser. We know what we are doing. Start with a trial.

Connect with me

If you enjoyed this, follow me on GitHub and Medium to get a ping whenever I post or open-source something.

Sources

datadomeplv3virtual-machinedisassemblerreverse-engineeringbytecodeanti-bot

Pule a engenharia reversa.

O Takion retorna cookies, headers e tokens novos para cada grande muro antibot. Um POST, sem navegador, primeira chamada em menos de uma hora.