MooMoo.js

Anti-tamper & the socket hook

:::warning educational, own-server only this page is about how the loader’s socket hook keeps working against my own server’s anti-tamper. it’s here so i (and you, if it’s your server) understand the defense from both sides. don’t use it to get an edge on servers you don’t run. :::

how the server checks the client

the reference server (moomoo-clone) trusts the client to tell on itself. once you’re in, the server sends an integrity probe packet q = [salt, probes] (5s after you spawn, then every 60s; a p>=4 client gets a third field, q = [salt, probes, canaries] — see the beacons section) and the client has to answer with a telemetry packet:

T = [flags, untrustedEvents, probeResult, seal, salt, seq, ledger]

and it’s required: no answer within the window and you’re kicked, so you can’t just block it.

the code seal

this is the one that actually bites. the page ships a moomoo-seal import whose file name is 16 random bytes in hex. the client builds

seal = sealBytes XOR SHA-256(its own bundle)[0..16]

and, in the server’s bind mode, XORs that into the session key. so if the seal is wrong by a single bit, every keyed frame fails its HMAC tag and the connection dies on the first packet — there’s nothing to “report clean”, the transport just doesn’t work.

the loader reproduces the seal the same way the real (unmodified) client does: it reads the moomoo-seal file name off the import map and SHA-256s the exact bundle bytes the page loaded, then folds the result into the key. because the loader only proxies the platform WebSocket and never patches the client’s own functions, the bundle it hashes is untouched, so the seal matches. that’s in loader/src/net/protocol.js, fed by the page lookups in loader.js.

spotting an outdated loader

the same bundle lookup powers an “am i out of date” check. the loader is built for one exact client build; the served file is /assets/index-<stem>.js, where <stem> is a content hash FRVR puts in the name, so it changes whenever the client’s bytes do. loader/build.mjs bakes the stem it was built against into the loader, and at runtime the loader reads the stem the page actually loaded — if they differ it shows a dismissible “this loader may be out of date” card pointing you at the newest build on Discord (or to copy a report). the stem is immune to the IS_SANDBOX byte transform (that rewrites content, never the file name), so it never false-alarms on a dev server. more in docs/updating-the-loader.md.

the frame ledger

the newest thing with teeth, and why T grew two fields. per connection the server keeps the last client→server sequence number it accepted and a rolling FNV-1a hash of every client→server body it has decoded — the “ledger”. every T reports both as they stood just before that frame, and the server compares them to its own copy; one wrong body, one dropped or reordered frame, and they diverge and you’re kicked. the loader keeps the identical pair because it is the thing encoding the stream (it owns the sequence numbers), folding each body into its ledger exactly as the server does, so the two stay in lock-step. it’s in loader/src/net/protocol.js (fnvLedger, the ClientSession ledger). this is also why a mod can’t quietly drop or forge a frame behind the loader’s back — everything goes through the loader’s encoder, which keeps the ledger honest.

why the socket hook doesn’t get caught

the probes include “is WebSocket.prototype.send native” and “was WebSocket wrapped”. the loader is built so the honest answer is “no hook” anyway:

  1. it swaps the constructor, not the prototype, and does it first. window.WebSocket becomes a Proxy of the native constructor, installed at document-start, before the client captures its reference. the interception happens per-socket in the construct trap.
  2. WebSocket.prototype.send is replaced by a Proxy of the native send. a function proxy still reports [native code] from Function.prototype.toString, so the “is it native” probe is satisfied while the apply trap still sees every frame.

the scrub

the loader already owns the client→server stream (it re-encodes every frame to put its own gap-free sequence numbers on, which is what makes injection work), so when the client answers a probe round it reconstructs the outgoing T so that

a companion auditProbeResult raises an alarm if a probe round ever carries an unknown kind the sanitiser has no rule for, a strip that silently failed (a footprint bit still set in what goes out), or a telemetry global that has gone blind to the page — so a brand-new anti-cheat trick shouts instead of leaking quietly. this lives in loader/src/net/binding.js (telemetry.scrub / cleanProbeResult / auditProbeResult) and loader/src/core/antidetect.js, the changeable half, so it moves with the protocol.

self-identification beacons (the index-0e02c00e update)

the sharpest anti-mod measure the server has. the index-0e02c00e client appends &p=2 to its socket url — a probe-protocol version — and a p>=2 client gets two extra integrity probes the server marks expect:

an expect probe inverts the usual logic: a normal probe flags when it matches (a hook or cheat is present); a beacon flags when it is absent — a client that doesn’t match it “isn’t the genuine client”. they ride every round (always) and sit in the answer’s lowest bits, so a vanilla client’s probeResult is never 0.

this is a trap for a lazy bypass. a loader that blanket-zeroes probeResult, or strips too broadly, drops the beacons with the footprint and gets kicked for the absence. the loader passes because cleanProbeResult clears only its own namespaces — mml- / mmj- / mdbg classes and ids, and moomoo.js: events — and never a bare moomoo (the beacons are moomoo-io / moomoo.io:). so it strips the mod menu the same update now probes for directly (kind 8 div.mmj-body / div.mmj-mod) while keeping both beacons: the T it sends is byte-for-byte what a vanilla client sends. the bots sidestep all of it by connecting as p=1 (no beacons sent to an old client), so their plain probeResult: 0 is still correct.

more beacons + per-round canaries (the index-3a141db7 update)

index-3a141db7 appends &p=4 and sharpens the trap in two ways.

beacons crafted to look like ours. a p>=4 client gets three more expect beacons, and they deliberately sit inside the loader’s namespace so a naive matcher strips them:

the genuine page ships all three (<span class="ui-mml-gap">, <div id="hmmjoin">, and a moomoo.js:ping listener). the fix is to match only at a token / id start, never as a substring: ownClassOrId tests /(?:^|\s)(?:mml-|mmj-|mdbg|moomoojs)/ on the class and /^(?:mml-|mmj-|mdbg|moomoojs)/ on the id, and kind 9 strips the handshake by exact name (=== "moomoo.js:api"), not by prefix. so ui-mml-gap / hmmjoin / moomoo.js:ping are left alone while mml-gui / mmj-body / moomoo.js:api are still cleared. (the class enumerator still uses a loose [class*='mml-'] selector to find candidates, so loaderOwnedElement re-checks every hit with ownClassOrId and walks ancestors before deciding a bit is ours.)

create-and-check canaries. a p>=4 q carries a third field, q[2] — a list of throwaway DOM/event canaries (div.mmc-<rand> / mmc:<rand>, a fresh tag each round) the client creates and then matches, with a paired expect rule confirming it could. they catch a hooked DOM / event layer. the loader keeps them for free: mmc- isn’t in its namespace and it hooks neither createElement nor addEventListener, so the bits ride through untouched.

the live proof is tests/live/ac-log.live.mjs — it logs every probe of every round, classified (beacon / canary / footprint / env), and shows the client’s match vs what the loader sends: every beacon + canary kept, every footprint bit stripped, real flags 0 and a valid checksum, no kick, no incident. the unit side is tests/footprint.test.mjs (the keep/strip matrix) and tests/antidetect.test.mjs (the checksum-bearing T).

the shame window

not a hook check, but it bites auto heal. the server counts an eat as shame when it lands within 120ms of your last hit, and 8 of those put the shame hat on you: no eating for 30 seconds. on a real server your ping alone usually pushes an eat past that window. on your own server (localhost, ~1ms) an instant heal lands inside it every single time.

so the loader exposes ctx.combat.shameWait(): how long to wait until an eat is safe, worked out from when you saw the hit and your quickest recent round trip. it’s 0 on a laggy connection and about 125ms locally. MooMoo Lite’s auto heal waits for it when its “shame-safe” setting is on.

the takeaway for your own anti-cheat

client-reported telemetry is only ever as trustworthy as the client. the one check here with teeth is the seal bound into the key, because it fails the transport instead of asking the client a question — but even that only proves the bundle is unmodified, not that nothing is reading or re-sending its frames from outside. if you’re hardening your own server, the lesson is the same: the checks that actually matter are server-side — movement validation, rate limits, sequence integrity — all of which the reference server does and the loader respects.