Tenacity 6.0 AntiExploit module 1 files, 136 lines

Tenacity 6.0 AntiExploit: Full Source Analysis

Tenacity 6.0's AntiExploit is a receive-side packet filter that defends the client against malicious servers.

dev/tenacity/module/impl/misc/AntiExploit.java · GitHub source ↗

Published 2026-08-13 · Updated 2026-08-13

Analysis

Overview

Tenacity 6.0's AntiExploit is a receive-side packet filter that defends the client against malicious servers. One PacketReceiveEvent handler branches on instanceof over seven packet classes and cancels the ones that look like exploits: S48 resource-pack sends with a non-whitelisted URI scheme or a level: URL that escapes the pack directory, S43 camera takes when the player is not a spectator, S2A particle bursts, S27 explosions that are too strong or arrive faster than one per millisecond, S18 entity teleports past the 30000000 coordinate bound, and S11 experience-orbs spammed more than twice in a millisecond. Every blocked packet prints a Tenacity chat line, and the resource-pack branches answer the server with a C19 FAILED_DOWNLOAD status carrying the original pack hash, which is the vanilla protocol's own refusal message. The module is a pure filter: it only ever emits C19 replies, never movement or combat traffic.

Architecture

All interception funnels through the onReceivePacket IEventListener, which the EventSubscriberPool binds by scanning the module's declared fields for IEventListener types when the module is enabled. The handler calls handlePacketCount() on every packet and then walks an if-else chain over the packet's runtime type. Each branch validates the payload against a hardcoded constant and cancels the event on failure, which stops the vanilla handler from processing the packet; the filter is per-instance with no per-server state, so the thresholds apply identically on every server.

Key techniques

The S48 branch parses the pack URL with java.net.URI and whitelists the http, https and level schemes; a level: URL is additionally rejected when it contains '..' or does not end with '/resources.zip', which blocks traversal-style file access, and a URISyntaxException also cancels. Every rejected pack gets a C19PacketResourcePackStatus with Action.FAILED_DOWNLOAD and the pack's original hash pushed through addToSendQueue, the normal send path. The S43 branch cancels camera takes unless mc.thePlayer.isSpectator(), the S18 branch cancels entity teleports whose absolute x, y or z exceeds 30000000 (the vanilla world border), and the S27 branch cancels explosions with an absolute strength above 1 or arriving within 1ms of the previous one. The S2A branch cancels particles with an absolute speed of 1 or more and bursts of more than one particle, and the S11 branch counts orbs arriving within a 1ms window, cancelling from the second one on.

Dead and broken branches

Two branches are inert. The packet counter in handlePacketCount() declares long lastPacketCheckTime = 0 as a local variable on every call, so currentTime - 0 > CHECK_INTERVAL is always true and packetCount resets to zero before it can ever exceed the 100-packet threshold; the triggerKick() path prints a message and is never reached. The S27 branch also contains a nested else-if testing packet instanceof S2APacketParticles, which can never match because the outer chain already confirmed the packet is an S27PacketExplosion. These are snapshot artifacts worth noting because they mean the module's advertised packet-rate kick does not exist and the duplicated particle checks at the top level are the only live ones.

source AntiExploit.java

AntiExploit.java136 lines · JavaOriginal ↗
1
package dev.tenacity.module.impl.misc;
2
3
import dev.tenacity.event.IEventListener;
4
import dev.tenacity.event.impl.packet.PacketReceiveEvent;
5
import dev.tenacity.module.Module;
6
import dev.tenacity.module.ModuleCategory;
7
import dev.tenacity.util.misc.ChatUtil;
8
import net.minecraft.network.Packet;
9
import net.minecraft.network.play.client.C19PacketResourcePackStatus;
10
import net.minecraft.network.play.server.*;
11
12
import java.net.URI;
13
import java.net.URISyntaxException;
14
15
public class AntiExploit extends Module {
16
17
18
19
    private long lastExplosion = 0, lastExperience = 0;
20
    private int invalidExperience = 0;
21
   final int PACKET_THRESHOLD = 100;
22
    final long CHECK_INTERVAL = 1000;
23
    int packetCount = 0;
24
25
    public AntiExploit() {
26
        super("AntiExploit", "Prevents server exploits", ModuleCategory.MISC);
27
    }
28
29
    private final IEventListener<PacketReceiveEvent> onReceivePacket = event -> {
30
        Packet<?> packet = event.getPacket();
31
        handlePacketCount();
32
        if(packet instanceof S48PacketResourcePackSend) {
33
            S48PacketResourcePackSend resourcePack = (S48PacketResourcePackSend) packet;
34
35
            try {
36
                URI uri = new URI(resourcePack.getURL());
37
                String scheme = uri.getScheme();
38
39
                boolean isLevelProtocol = scheme.equalsIgnoreCase("level");
40
                boolean isHttpProtocol = scheme.equalsIgnoreCase("http");
41
                boolean isHttpsProtocol = scheme.equalsIgnoreCase("https");
42
43
                if(!isHttpProtocol && !isHttpsProtocol && !isLevelProtocol) {
44
                    ChatUtil.print("§cBlocked Exploit: Resource Pack");
45
                    event.cancel();
46
                } else if(isLevelProtocol && (resourcePack.getURL().contains("..") || !((S48PacketResourcePackSend) packet).getURL().endsWith("/resources.zip"))) {
47
                    ChatUtil.print("§cBlocked Exploit: File Access");
48
                    event.cancel();
49
                    mc.getNetHandler().addToSendQueue(new C19PacketResourcePackStatus(((S48PacketResourcePackSend) packet).getHash(), C19PacketResourcePackStatus.Action.FAILED_DOWNLOAD));
50
                }
51
            } catch (URISyntaxException exception) {
52
                ChatUtil.print("§cBlocked Exploit: Resource Pack");
53
                event.cancel();
54
                mc.getNetHandler().addToSendQueue(new C19PacketResourcePackStatus(((S48PacketResourcePackSend) packet).getHash(), C19PacketResourcePackStatus.Action.FAILED_DOWNLOAD));
55
            }
56
        } else if(packet instanceof S43PacketCamera && !mc.thePlayer.isSpectator()) {
57
            ChatUtil.print("§cBlocked Exploit: Crash");
58
            event.cancel();
59
        } else if(packet instanceof S2APacketParticles) {
60
            S2APacketParticles particles = (S2APacketParticles) packet;
61
            if(Math.abs(particles.getParticleSpeed()) >= 1) {
62
                ChatUtil.print("§cBlocked Exploit: Particles");
63
                event.cancel();
64
            } else if(((S2APacketParticles) packet).getParticleCount() > 1) {
65
                ChatUtil.print("§cBlocked Exploit: Crash");
66
                event.cancel();
67
            }
68
        } else if(packet instanceof S27PacketExplosion) {
69
            S27PacketExplosion explosion = (S27PacketExplosion) packet;
70
71
            if(Math.abs(explosion.getStrength()) > 1) {
72
                ChatUtil.print("§cBlocked Exploit: Crash");
73
                event.cancel();
74
            } else if(System.currentTimeMillis() - lastExplosion <= 1) {
75
                ChatUtil.print("§cBlocked Exploit: Crash");
76
                event.cancel();
77
            } else if(packet instanceof S2APacketParticles) {
78
            S2APacketParticles particles = (S2APacketParticles) packet;
79
80
            if(Math.abs(particles.getParticleSpeed()) > 1) {
81
                ChatUtil.print("§cBlocked Exploit: Particles");
82
                event.cancel();
83
            } else if(particles.getParticleCount() >= 1) {
84
                ChatUtil.print("§cBlocked Exploit: Crash");
85
                event.cancel();
86
            }
87
        }
88
89
            lastExplosion = System.currentTimeMillis();
90
        } else if(packet instanceof S18PacketEntityTeleport) {
91
            S18PacketEntityTeleport teleport = (S18PacketEntityTeleport) packet;
92
93
            double packetX = Math.abs(teleport.getX());
94
            double packetY = Math.abs(teleport.getY());
95
            double packetZ = Math.abs(teleport.getZ());
96
97
            if(packetX > 30000000 || packetY > 30000000 || packetZ > 30000000) {
98
                ChatUtil.print("§cBlocked Exploit: Teleport");
99
                event.cancel();
100
            }
101
        } else if(packet instanceof S11PacketSpawnExperienceOrb) {
102
            if(System.currentTimeMillis() - lastExperience <= 1) {
103
                invalidExperience++;
104
105
                if(invalidExperience >= 2) {
106
                    ChatUtil.print("§cBlocked Exploit: Crash");
107
                    event.cancel();
108
                }
109
            } else {
110
                invalidExperience = 0;
111
            }
112
            lastExperience = System.currentTimeMillis();
113
        }
114
115
    };
116
117
    private void triggerKick() {
118
        ChatUtil.print("§cAbnormal packet activity detected. Kicking player...");
119
    }
120
        private void handlePacketCount() {
121
            long currentTime = System.currentTimeMillis();
122
123
            long lastPacketCheckTime = 0;
124
            if (currentTime - lastPacketCheckTime > CHECK_INTERVAL) {
125
                packetCount = 0;
126
                lastPacketCheckTime = currentTime;
127
            }
128
            packetCount++;
129
            if (packetCount > PACKET_THRESHOLD) {
130
                triggerKick();
131
                packetCount = 0;
132
        }
133
134
    }
135
136
}

What this file does

The module file is the entire filter. onReceivePacket is the single instanceof chain over S48, S43, S2A, S27, S18 and S11, with the C19 FAILED_DOWNLOAD replies built inline via mc.getNetHandler().addToSendQueue and the pack hash read from the incoming S48. handlePacketCount() and triggerKick() sit below the handler; the counter is broken as described in the sections, since lastPacketCheckTime is re-declared to 0 inside the method on every invocation, so the 100-packet kick can never fire. The class imports C19PacketResourcePackStatus and the server packet package, and all other branches cancel the event without sending anything.

anticheat Countering Checks

The anticheat code that detects or counters the techniques this module uses. Full source, with the detection mechanism explained below each box.

anticheat ExplosionHandler (S27 knockback prediction)

ExplosionHandler.java267 lines · Java
1
package ac.grim.grimac.checks.impl.velocity;
2
3
import ac.grim.grimac.api.config.ConfigManager;
4
import ac.grim.grimac.api.storage.verbose.Verbose;
5
import ac.grim.grimac.checks.Check;
6
import ac.grim.grimac.checks.CheckData;
7
import ac.grim.grimac.checks.type.PacketSendListener;
8
import ac.grim.grimac.checks.type.PostPredictionListener;
9
import ac.grim.grimac.player.GrimPlayer;
10
import ac.grim.grimac.utils.anticheat.update.PredictionComplete;
11
import ac.grim.grimac.utils.data.VectorData;
12
import ac.grim.grimac.utils.data.VelocityData;
13
import ac.grim.grimac.utils.math.Vector3dm;
14
import com.github.retrooper.packetevents.PacketEvents;
15
import com.github.retrooper.packetevents.event.PacketSendEvent;
16
import com.github.retrooper.packetevents.manager.server.ServerVersion;
17
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
18
import com.github.retrooper.packetevents.protocol.world.states.WrappedBlockState;
19
import com.github.retrooper.packetevents.protocol.world.states.defaulttags.BlockTags;
20
import com.github.retrooper.packetevents.protocol.world.states.type.StateType;
21
import com.github.retrooper.packetevents.protocol.world.states.type.StateTypes;
22
import com.github.retrooper.packetevents.protocol.world.states.type.StateValue;
23
import com.github.retrooper.packetevents.util.Vector3d;
24
import com.github.retrooper.packetevents.util.Vector3i;
25
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerExplosion;
26
import lombok.Getter;
27
import org.jetbrains.annotations.NotNull;
28
import org.jetbrains.annotations.Nullable;
29
30
import java.util.Deque;
31
import java.util.LinkedList;
32
33
@CheckData(name = "AntiExplosion", stableKey = "grim.velocity.anti_explosion", configName = "Explosion", description = "Did not take the expected explosion knockback", setback = 10)
34
public class ExplosionHandler extends Check implements PacketSendListener, PostPredictionListener {
35
    private static final Verbose V = Verbose.of("[ignored explosion|o: {offset}]");
36
37
    private final Deque<VelocityData> firstBreadMap = new LinkedList<>();
38
39
    private VelocityData lastExplosionsKnownTaken = null;
40
    private VelocityData firstBreadAddedExplosion = null;
41
42
    @Getter
43
    private boolean explosionPointThree = false;
44
45
    private double offsetToFlag;
46
47
    public ExplosionHandler(GrimPlayer player) {
48
        super(player);
49
    }
50
51
    @Override
52
    public void onPacketSend(final PacketSendEvent event) {
53
        if (event.getPacketType() == PacketType.Play.Server.EXPLOSION) {
54
            WrapperPlayServerExplosion explosion = new WrapperPlayServerExplosion(event);
55
56
            // Since 1.21.2, the server will instead send these changes via block change packets
57
            final boolean hasBlocks = PacketEvents.getAPI().getServerManager().getVersion().isOlderThan(ServerVersion.V_1_21_2);
58
            if (hasBlocks) {
59
                this.handleBlockExplosions(explosion);
60
            }
61
62
            Vector3d velocity = explosion.getKnockback();
63
            if (velocity != null && (velocity.x != 0 || velocity.y != 0 || velocity.z != 0)) {
64
                // No need to spam transactions
65
                if (!hasBlocks || explosion.getRecords().isEmpty()) player.sendTransaction();
66
                addPlayerExplosion(player.lastTransactionSent.get(), velocity);
67
                event.getTasksAfterSend().add(player::sendTransaction);
68
            }
69
        }
70
    }
71
72
    private void handleBlockExplosions(WrapperPlayServerExplosion explosion) {
73
        final @Nullable WrapperPlayServerExplosion.BlockInteraction blockInteraction = explosion.getBlockInteraction();
74
        final boolean shouldDestroy = blockInteraction != WrapperPlayServerExplosion.BlockInteraction.KEEP_BLOCKS;
75
        if (explosion.getRecords().isEmpty() || !shouldDestroy) {
76
            return;
77
        }
78
79
        player.sendTransaction();
80
81
        player.latencyUtils.addRealTimeTask(player.lastTransactionSent.get(), () -> {
82
            for (Vector3i record : explosion.getRecords()) {
83
                // Null OR not flip redstone blocks, then set to air
84
                if (blockInteraction != WrapperPlayServerExplosion.BlockInteraction.TRIGGER_BLOCKS) {
85
                    player.compensatedWorld.updateBlock(record.x, record.y, record.z, 0);
86
                } else {
87
                    // We need to flip redstone blocks, or do special things with other blocks
88
                    final WrappedBlockState state = player.compensatedWorld.getBlock(record);
89
                    final StateType type = state.getType();
90
                    if (BlockTags.CANDLES.contains(type) || BlockTags.CANDLE_CAKES.contains(type)) {
91
                        state.setLit(false);
92
                        continue;
93
                    } else if (type == StateTypes.BELL) {
94
                        // Does this affect anything? I don't know, I don't see anything that relies on whether a bell is ringing.
95
                        continue;
96
                    }
97
98
                    // Otherwise try and flip/open it.
99
                    final boolean canFlip = state.hasProperty(StateValue.POWERED) && !state.isPowered() || type == StateTypes.LEVER;
100
                    if (canFlip) {
101
                        player.compensatedWorld.tickOpenable(record.x, record.y, record.z);
102
                    }
103
                }
104
            }
105
        });
106
    }
107
108
    public VelocityData getFutureExplosion() {
109
        // Chronologically in the future
110
        if (!firstBreadMap.isEmpty()) {
111
            return firstBreadMap.peek();
112
        }
113
114
        // Less in the future
115
        if (lastExplosionsKnownTaken != null) {
116
            return lastExplosionsKnownTaken;
117
        }
118
119
        // Uncertain, might be in the future
120
        if (player.firstBreadExplosion != null && player.likelyExplosions == null) {
121
            return player.firstBreadExplosion;
122
        } else if (player.likelyExplosions != null) { // Known to be in the present
123
            return player.likelyExplosions;
124
        }
125
        return null;
126
    }
127
128
    public boolean shouldIgnoreForPrediction(VectorData data) {
129
        if (data.isExplosion() && data.isFirstBreadExplosion()) {
130
            return player.firstBreadExplosion.offset > offsetToFlag;
131
        }
132
        return false;
133
    }
134
135
    public boolean wouldFlag() {
136
        return (player.likelyExplosions != null && player.likelyExplosions.offset > offsetToFlag) || (player.firstBreadExplosion != null && player.firstBreadExplosion.offset > offsetToFlag);
137
    }
138
139
    public void addPlayerExplosion(int breadOne, Vector3d explosion) {
140
        firstBreadMap.add(new VelocityData(-1, breadOne, player.getSetbackTeleportUtil().isSendingSetback, new Vector3dm(explosion.getX(), explosion.getY(), explosion.getZ())));
141
    }
142
143
    public void setPointThree(boolean isPointThree) {
144
        explosionPointThree = explosionPointThree || isPointThree;
145
    }
146
147
    public void handlePredictionAnalysis(double offset) {
148
        if (player.firstBreadExplosion != null) {
149
            player.firstBreadExplosion.offset = Math.min(player.firstBreadExplosion.offset, offset);
150
        }
151
152
        if (player.likelyExplosions != null) {
153
            player.likelyExplosions.offset = Math.min(player.likelyExplosions.offset, offset);
154
        }
155
    }
156
157
    public void forceExempt() {
158
        // Unsure explosion was taken
159
        if (player.firstBreadExplosion != null) {
160
            player.firstBreadExplosion.offset = 0;
161
        }
162
163
        if (player.likelyExplosions != null) {
164
            player.likelyExplosions.offset = 0;
165
        }
166
    }
167
168
    @Override
169
    public void onPredictionComplete(final PredictionComplete predictionComplete) {
170
        double offset = predictionComplete.getOffset();
171
172
        boolean wasZero = explosionPointThree;
173
        explosionPointThree = false;
174
175
        if (player.likelyExplosions == null && player.firstBreadExplosion == null) {
176
            firstBreadAddedExplosion = null;
177
            return;
178
        }
179
180
        // We must check to see if knockback has overridden this explosion
181
        // (Yes, I could make this very simple and exempt on kb, but that allows people to ignore most explosions)
182
        //
183
        // We do this by finding the minimum explosion transaction that could have been overridden
184
        // We then compare this against the maximum velocity transaction that could override
185
        //
186
        // If velocity is over transaction, exempt
187
        int minTrans = Math.min(player.likelyExplosions != null ? player.likelyExplosions.transaction : Integer.MAX_VALUE,
188
                player.firstBreadExplosion != null ? player.firstBreadExplosion.transaction : Integer.MAX_VALUE);
189
        int kbTrans = Math.max(player.likelyKB != null ? player.likelyKB.transaction : Integer.MIN_VALUE,
190
                player.firstBreadKB != null ? player.firstBreadKB.transaction : Integer.MIN_VALUE);
191
192
        if (player.predictedVelocity.isFirstBreadExplosion()) {
193
            firstBreadAddedExplosion = null;
194
            firstBreadMap.poll(); // Remove from map so we don't pull it again
195
        }
196
197
        if (wasZero || player.predictedVelocity.isExplosion() ||
198
                (minTrans < kbTrans)) {
199
            // Unsure knockback was taken
200
            if (player.firstBreadExplosion != null) {
201
                player.firstBreadExplosion.offset = Math.min(player.firstBreadExplosion.offset, offset);
202
            }
203
204
            if (player.likelyExplosions != null) {
205
                player.likelyExplosions.offset = Math.min(player.likelyExplosions.offset, offset);
206
            }
207
        }
208
209
        // 100% known kb was taken
210
        if (player.likelyExplosions != null && !player.compensatedEntities.self.isDead) {
211
            if (player.likelyExplosions.offset > offsetToFlag) {
212
                boolean ignored = player.likelyExplosions.offset == Integer.MAX_VALUE;
213
                flagWithSetback(V.write(verbose()).bool(ignored).f64(offset));
214
            } else {
215
                reward();
216
            }
217
        }
218
    }
219
220
    public VelocityData getPossibleExplosions(int lastTransaction, boolean isJustTesting) {
221
        handleTransactionPacket(lastTransaction);
222
        if (lastExplosionsKnownTaken == null)
223
            return null;
224
225
        VelocityData returnLastExplosion = lastExplosionsKnownTaken;
226
        if (!isJustTesting) {
227
            lastExplosionsKnownTaken = null;
228
        }
229
        return returnLastExplosion;
230
    }
231
232
    private void handleTransactionPacket(int transactionID) {
233
        VelocityData data = firstBreadMap.peek();
234
        while (data != null) {
235
            if (data.transaction == transactionID) { // First bread explosion
236
                if (lastExplosionsKnownTaken != null)
237
                    firstBreadAddedExplosion = new VelocityData(-1, data.transaction, data.isSetback, lastExplosionsKnownTaken.vector.clone().add(data.vector));
238
                else
239
                    firstBreadAddedExplosion = new VelocityData(-1, data.transaction, data.isSetback, data.vector);
240
                break; // All knockback after this will have not been applied
241
            } else if (data.transaction < transactionID) {
242
                if (lastExplosionsKnownTaken != null) {
243
                    lastExplosionsKnownTaken.vector.add(data.vector);
244
                } else {
245
                    lastExplosionsKnownTaken = new VelocityData(-1, data.transaction, data.isSetback, data.vector);
246
                }
247
248
                // Explosion has been applied and is now required, remove it from first bread
249
                firstBreadAddedExplosion = null;
250
                firstBreadMap.poll();
251
                data = firstBreadMap.peek();
252
            } else { // We are too far ahead in the future
253
                break;
254
            }
255
        }
256
    }
257
258
    public VelocityData getFirstBreadAddedExplosion(int lastTransaction) {
259
        handleTransactionPacket(lastTransaction);
260
        return firstBreadAddedExplosion;
261
    }
262
263
    @Override
264
    public void onReload(@NotNull ConfigManager config) {
265
        offsetToFlag = config.getDoubleElse("Explosion.threshold", 0.00001);
266
    }
267
}

How it counteracts this module

S27 is server-originated: the anticheat already applied the explosion knockback to its own copy of the player before the packet left. Grim consumes the S27 it sent to seed a knockback prediction and flags the player's subsequent movement when the expected post-explosion motion is missing. The module's S27 branch cancels explosions with an absolute strength above 1, which removes the client-side velocity while the server keeps its own; the player's next C03 then shows no knockback displacement and the prediction mismatches. The honest framing is a trade: the crash filter against S27 floods trades away explosion knockback, and that missing motion is exactly the surface the velocity-prediction checks score. Strength-1 and slower explosions still pass the filter and move normally.

anticheat AntiVelocityBasic (knockback motion ledger)

AntiVelocityBasic.java46 lines · Java
1
/*
2
 * This file is part of Hawk Anticheat.
3
 * Copyright (C) 2018 Hawk Development Team
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17
 */
18
19
package me.islandscout.hawk.check.movement.position;
20
21
import me.islandscout.hawk.HawkPlayer;
22
import me.islandscout.hawk.check.MovementCheck;
23
import me.islandscout.hawk.check.Cancelless;
24
import me.islandscout.hawk.event.MoveEvent;
25
26
/**
27
 * The AntiVelocityBasic check verifies that players accept knockback.
28
 * It relies on MoveEvent's knockback acceptance detection.
29
 * The AntiVelocityBasic check has been tested to detect as low as a
30
 * 10% difference in horizontal and/or vertical knockback.
31
 */
32
public class AntiVelocityBasic extends MovementCheck implements Cancelless {
33
34
    public AntiVelocityBasic() {
35
        super("antivelocitybasic", true, -1, 5, 0.999, 5000, "%player% may be using anti-velocity (basic), VL: %vl%", null);
36
    }
37
38
    @Override
39
    protected void check(MoveEvent event) {
40
        HawkPlayer pp = event.getHawkPlayer();
41
        if(event.hasFailedKnockback())
42
            punish(pp, false, event);
43
        else
44
            reward(pp);
45
    }
46
}

How it counteracts this module

Hawk's basic anti-velocity check punishes a player whenever the movement event carries a failed knockback flag, which Hawk sets when the player's post-knockback motion does not match the velocity the server applied from its own S27. The module's strength-above-1 cancel produces precisely that condition: the server entity carries the knockback, the client does not, and the next move reports no displacement. For explosions the filter lets through (strength at or below 1, or spaced more than 1ms apart) the client keeps the vanilla knockback and the check stays clean, so the counter bites only on the cancelled branch. This is the same velocity-mismatch surface as Grim's ExplosionHandler, on the Hawk side of the tree.

anticheat PingSpoofProtocol (C19 status ledger)

PingSpoofProtocol.java181 lines · Java
1
package ac.artemis.checks.enterprise.spoof;
2
3
import ac.artemis.core.v4.check.ArtemisCheck;
4
import ac.artemis.core.v4.check.FastProcessHandler;
5
import ac.artemis.core.v4.check.PacketHandler;
6
import ac.artemis.core.v4.check.annotations.Check;
7
import ac.artemis.anticheat.api.check.type.Type;
8
import ac.artemis.core.v4.check.exempt.type.ExemptType;
9
import ac.artemis.core.v4.check.settings.CheckInformation;
10
import ac.artemis.core.v4.data.PlayerData;
11
import ac.artemis.core.v4.utils.chat.StringUtil;
12
import ac.artemis.packet.PacketManager;
13
import cc.ghast.packet.PacketAPI;
14
import ac.artemis.packet.protocol.ProtocolVersion;
15
import cc.ghast.packet.wrapper.mc.PlayerEnums;
16
import ac.artemis.packet.spigot.wrappers.GPacket;
17
import cc.ghast.packet.wrapper.packet.play.client.GPacketPlayClientCustomPayload;
18
import cc.ghast.packet.wrapper.packet.play.client.GPacketPlayClientKeepAlive;
19
import cc.ghast.packet.wrapper.packet.play.client.GPacketPlayClientResourcePackStatus;
20
import cc.ghast.packet.wrapper.packet.play.server.GPacketPlayServerKeepAlive;
21
import cc.ghast.packet.wrapper.packet.play.server.GPacketPlayServerResourcePackSend;
22
import java.util.Deque;
23
import java.util.LinkedList;
24
25
/**
26
 * @author Ghast
27
 * @since 25/03/2021
28
 * Artemis © 2021
29
 *
30
 * This is most effectively the best antibot protection I've got on Artemis. By combining the
31
 * concept of checking a random resource pack link and the usage of keep alives, we can pretty
32
 * much capture whether or not a player is a bot or has a broken client misplacing keep-alives/
33
 * resource packs.
34
 */
35
@Check(type = Type.PINGSPOOF, var = "Protocol")
36
public class PingSpoofProtocol extends ArtemisCheck implements PacketHandler, FastProcessHandler {
37
    public PingSpoofProtocol(PlayerData data, CheckInformation info) {
38
        super(data, info);
39
    }
40
41
    private final Deque<Long> ids = new LinkedList<>();
42
    private Long next;
43
44
    @Override
45
    public void handle(GPacket packet) {
46
        final boolean exempt = this.isExempt(ExemptType.JOIN);
47
48
        /*
49
         * They removed the hash :(. We can't use it to identify packet order. How unlucky. This would mean
50
         * this would false on laggy and latter clients; We can instead from 1.9+ use fake teleports.
51
         */
52
        if (data.getVersion().isOrAbove(ProtocolVersion.V1_10))
53
            return;
54
55
        /*
56
         * Lets handle resource pack status. Since we flush the channel before, theoretically this should be processed
57
         * beforehand?
58
         */
59
        if (packet instanceof GPacketPlayClientResourcePackStatus) {
60
            final GPacketPlayClientResourcePackStatus sts = (GPacketPlayClientResourcePackStatus) packet;
61
            /*
62
             * Lets not interfere with real resource pack requests alright?
63
             */
64
            if (!StringUtil.isNumeric(sts.getUrl().get())) {
65
                this.debug("Invalid id");
66
                return;
67
            }
68
69
            /*
70
             * Theoretically speaking, the client can ONLY respond with FAILED_DOWNLOAD. Anything other
71
             * than that is completely invalid. Hence we can just skip over it.
72
             */
73
            if (!sts.getStatus().equals(PlayerEnums.ResourcePackStatus.FAILED_DOWNLOAD) && !exempt) {
74
                this.log("Successfully downloaded - Invalid");
75
                this.debug("[FLAG] Successfully downloaded - Invalid");
76
                return;
77
            }
78
79
            /*
80
             * Both resource pack and keep alive packets are async to the threading. Meaning they aren't ticked.
81
             * This means these are synchronous but not correlated to other packets. Perfect for a pingspoof check.
82
             * If no response is received, it's invalid
83
             */
84
            if (ids.isEmpty() && !exempt) {
85
                this.log("Packet coming from idk where");
86
                this.debug("[FLAG] Packet coming from idk where");
87
                return;
88
            }
89
90
            /*
91
             * Alrighty lets get decoding.
92
             */
93
            final long var = Long.decode(sts.getUrl().get());
94
95
            /*
96
             * No clue where tf this keep alive coming from hommie, but it defo ain't ours, so it's a bad
97
             * packet.
98
             */
99
            if (!ids.contains(var) && !exempt) {
100
                this.log("Keep alive does not exist bruh");
101
                this.debug("[FLAG] Keep alive does not exist bruh");
102
                return;
103
            }
104
105
            long id = ids.poll();
106
107
            /*
108
             * Well this is awkward. We're receiving the wrong... packet id?
109
             * Hence, this is deemed as a bad packet.
110
             */
111
            if (id != var && ids.contains(var)) {
112
113
                while (id != var && !ids.isEmpty()) {
114
                    id = ids.poll();
115
116
                    if (exempt)
117
                        continue;
118
119
                    this.log("Invalid identifier, polling queue...");
120
                }
121
            }
122
123
            /*
124
             * Nice alright, valid keep alive, lets mark the next id to receive.
125
             */
126
            else {
127
                next = var;
128
                ids.remove(var);
129
130
                this.debug("resource=" + var);
131
            }
132
        }
133
134
        /*
135
         * Since the keep alive flushed out a resource pack status packet, the next packet received should be the
136
         * resource pack denial then only the keep alive.
137
         */
138
        else if (packet instanceof GPacketPlayClientKeepAlive) {
139
            final GPacketPlayClientKeepAlive ka = (GPacketPlayClientKeepAlive) packet;
140
141
            if (next == null) {
142
                if (!exempt)
143
                    this.log("No confirmation");
144
                return;
145
            }
146
147
            if (next == ka.getId()) {
148
                this.debug("ka=" + ka.getId());
149
            } else if (!exempt) {
150
                this.log("Packet order 0x1");
151
                this.debug("[FLAG] Packet order 0x1");
152
            }
153
        }
154
    }
155
156
    @Override
157
    public void fastHandle(GPacket packet) {
158
        /*
159
         * They removed the hash :(. We can't use it to identify packet order. How unlucky. This would mean
160
         * this would false on laggy and latter clients; We can instead from 1.9+ use fake teleports.
161
         */
162
        if (data.getVersion().isOrAbove(ProtocolVersion.V1_10))
163
            return;
164
165
        /*
166
         * Only handle server keep alives because uhhh
167
         */
168
        if (packet instanceof GPacketPlayServerKeepAlive) {
169
            final GPacketPlayServerKeepAlive ka = (GPacketPlayServerKeepAlive) packet;
170
171
            this.ids.add(ka.getId());
172
            final String encoded = Long.toString(ka.getId());
173
            PacketManager.getApi().sendPacket(
174
                    data.getPlayer().getUniqueId(),
175
                    new GPacketPlayServerResourcePackSend(
176
                            "level://" + Math.random() + "/resources.zip", encoded
177
                    )
178
            );
179
        }
180
    }
181
}

How it counteracts this module

This is the only check in the C19 corpus that consumes resource-pack status packets. Artemis treats FAILED_DOWNLOAD as the only valid client response, flags any other status as 'Successfully downloaded - Invalid', and additionally matches the response's id against a deque of packs it sent, flagging responses whose id is unknown. The module answers every blocked pack with Action.FAILED_DOWNLOAD carrying the S48's original hash, so both branches pass by construction: the status is the whitelisted class and the hash is one artemis itself issued. The check is version-gated and returns early on 1.10 and above, so on modern servers it does not run at all. Net effect: the module's only wire output sails under the only check that watches it.

anticheat PacketFrequency (all-Play.Client rate ledger)

PacketFrequency.java79 lines · Java
1
/*
2
 * This program is free software: you can redistribute it and/or modify
3
 *   it under the terms of the GNU General Public License as published by
4
 *   the Free Software Foundation, either version 3 of the License, or
5
 *   (at your option) any later version.
6
 *
7
 *   This program is distributed in the hope that it will be useful,
8
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 *   GNU General Public License for more details.
11
 *
12
 *   You should have received a copy of the GNU General Public License
13
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
14
 */
15
package fr.neatmonster.nocheatplus.checks.net;
16
17
import org.bukkit.entity.Player;
18
19
import fr.neatmonster.nocheatplus.checks.Check;
20
import fr.neatmonster.nocheatplus.checks.CheckType;
21
import fr.neatmonster.nocheatplus.utilities.TickTask;
22
23
/**
24
 * Fall-back check for pre 1.9: Limit the overall packet frequency, aiming at
25
 * crash exploits only. Thus the default actions should be kicking, as this
26
 * won't distinguish type of packets with the global packet count.
27
 * 
28
 * @author asofold
29
 *
30
 */
31
public class PacketFrequency extends Check {
32
33
    public PacketFrequency() {
34
        super(CheckType.NET_PACKETFREQUENCY);
35
    }
36
37
    /**
38
     * Actual state.
39
     * 
40
     * @param player
41
     * @param data
42
     *           
43
     * @param cc
44
     *            
45
     * @return If to cancel a packet event.
46
     */
47
    public boolean check(final Player player, final NetData data, final NetConfig cc) {
48
        data.packetFrequency.add(System.currentTimeMillis(), 1f);
49
        final long fDur = data.packetFrequency.bucketDuration() * data.packetFrequency.numberOfBuckets();
50
        double amount = data.packetFrequency.score(1f) * 1000f / (float) fDur;
51
        //        if (data.debug) {
52
        //            debug(player, "Basic amount: " + amount);
53
        //        }
54
        if (amount > cc.packetFrequencyPacketsPerSecond) {
55
            amount /= TickTask.getLag(fDur);
56
            if (amount > cc.packetFrequencyPacketsPerSecond) {
57
                if (executeActions(player, amount - cc.packetFrequencyPacketsPerSecond, 1.0, cc.packetFrequencyActions).willCancel()) {
58
                    return true;
59
                }
60
            }
61
        }
62
        return false; // Cancel state.
63
    }
64
65
    /**
66
     * Allow to relax the count by 1, e.g. with outgoing teleport.
67
     * 
68
     * @param player
69
     * @param data
70
     * 
71
     * @param cc
72
     * 
73
     * @return
74
     */
75
    public void relax(final Player player, final NetData data, final NetConfig cc) {
76
        // TODO: Concept (not more locking, instead a counter (optimistic)).
77
    }
78
79
}

How it counteracts this module

NCP's pre-1.9 fallback rate check counts every Play.Client packet through the ProtocolLib CatchAllAdapter, which iterates the full PacketType.Play.Client set, and scores them into an ActionFrequency window with a config-driven packets-per-second ceiling. The module's C19 replies are the only serverbound traffic it generates, at most one per blocked resource pack, so the ledger sees a handful of packets per session and never approaches the ceiling. This entry is the honest boundary for the module's wire presence: the generic flood counter exists and covers C19, but a filter that emits one refusal per pack is structurally invisible to it. Only a server streaming S48s continuously would make the reply rate worth counting.

← Back to Analysis Hub