chore: more plugin api work
also added bedrock fuzzing
This commit is contained in:
1 parent
7bf248d16a
commit
c15ebf181d
15 files changed
+625
-137
No files matched your search
@@ -0,0 +1,97 @@
|
||||
#![no_main]
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
use pumpkin_protocol::bedrock::packet_decoder::UDPNetworkDecoder;
|
||||
use pumpkin_protocol::bedrock::server::{
|
||||
client_cache_status::SClientCacheStatus,
|
||||
command_request::SCommandRequest,
|
||||
container_close::SContainerClose,
|
||||
interaction::SInteraction,
|
||||
loading_screen::SLoadingScreen,
|
||||
login::SLogin,
|
||||
player_auth_input::SPlayerAuthInput,
|
||||
raknet::{
|
||||
connection::SConnectionRequest,
|
||||
open_connection::{SOpenConnectionRequest1, SOpenConnectionRequest2},
|
||||
unconnected_ping::SUnconnectedPing,
|
||||
},
|
||||
request_chunk_radius::SRequestChunkRadius,
|
||||
request_network_settings::SRequestNetworkSettings,
|
||||
text::SText,
|
||||
};
|
||||
use pumpkin_protocol::serial::PacketRead;
|
||||
use std::io::Cursor;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Helper: Run every Serverbound packet's read method.
|
||||
// ---------------------------------------------------------------------------
|
||||
fn fuzz_serverbound_packets(payload: &[u8]) {
|
||||
let mut cursor = Cursor::new(payload);
|
||||
|
||||
macro_rules! run_read {
|
||||
($($packet:ty),* $(,)?) => {
|
||||
$(
|
||||
cursor.set_position(0);
|
||||
// Attempt to read as a standard Game Packet (with version)
|
||||
let _ = <$packet>::read(&mut cursor);
|
||||
)*
|
||||
};
|
||||
}
|
||||
|
||||
// Standard Bedrock Serverbound Packets
|
||||
run_read!(
|
||||
SClientCacheStatus,
|
||||
SCommandRequest,
|
||||
SContainerClose,
|
||||
SInteraction,
|
||||
SLoadingScreen,
|
||||
SLogin,
|
||||
SPlayerAuthInput,
|
||||
SRequestChunkRadius,
|
||||
SRequestNetworkSettings,
|
||||
SText,
|
||||
);
|
||||
|
||||
// RakNet Handshake Packets (Usually read without version)
|
||||
cursor.set_position(0);
|
||||
let _ = SConnectionRequest::read(&mut cursor);
|
||||
cursor.set_position(0);
|
||||
let _ = SOpenConnectionRequest1::read(&mut cursor);
|
||||
cursor.set_position(0);
|
||||
let _ = SOpenConnectionRequest2::read(&mut cursor);
|
||||
cursor.set_position(0);
|
||||
let _ = SUnconnectedPing::read(&mut cursor);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Fuzz Target
|
||||
// ---------------------------------------------------------------------------
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
if data.len() < 20 {
|
||||
return;
|
||||
}
|
||||
|
||||
// Split data for decoder configuration vs raw payload
|
||||
let threshold_raw = data[0];
|
||||
let key: [u8; 16] = data[1..17].try_into().unwrap();
|
||||
let stream_data = &data[17..];
|
||||
|
||||
let mut decoder = UDPNetworkDecoder::new();
|
||||
|
||||
// Setup Decoder
|
||||
if threshold_raw > 0 {
|
||||
// Assuming your CompressionThreshold is a wrapper around u32
|
||||
decoder.set_compression((threshold_raw as u32).try_into().unwrap());
|
||||
}
|
||||
decoder.set_encryption(&key);
|
||||
|
||||
// 1. Fuzz the Decoder (Framing/VarInts/Bitmasks)
|
||||
let decoder_cursor = Cursor::new(stream_data.to_vec());
|
||||
if let Ok(raw_packet) = decoder.get_game_packet(decoder_cursor) {
|
||||
// If framed correctly, fuzz the internal payload
|
||||
fuzz_serverbound_packets(&raw_packet.payload);
|
||||
}
|
||||
|
||||
// 2. Shotgun Fuzz
|
||||
// Pass raw data directly to all readers to catch panics in the parsers
|
||||
fuzz_serverbound_packets(stream_data);
|
||||
});
|
||||
@@ -1,96 +1,102 @@
|
||||
#![no_main]
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
use pumpkin_protocol::{
|
||||
ServerPacket,
|
||||
java::{
|
||||
packet_decoder::TCPNetworkDecoder,
|
||||
server::{
|
||||
config::{
|
||||
SClientInformationConfig, SConfigCookieResponse, SConfigResourcePack, SKnownPacks,
|
||||
SPluginMessage,
|
||||
},
|
||||
handshake::SHandShake,
|
||||
login::{SEncryptionResponse, SLoginCookieResponse, SLoginPluginResponse, SLoginStart},
|
||||
play::{
|
||||
SChangeGameMode, SChatCommand, SChatMessage, SChunkBatch, SClickSlot,
|
||||
SClientCommand, SClientInformationPlay, SCloseContainer, SCommandSuggestion,
|
||||
SConfirmTeleport, SCookieResponse, SCustomPayload, SInteract, SKeepAlive,
|
||||
SMoveVehicle, SPaddleBoat, SPickItemFromBlock, SPlayPingRequest, SPlayerAbilities,
|
||||
SPlayerAction, SPlayerCommand, SPlayerInput, SPlayerLoaded, SPlayerPosition,
|
||||
SPlayerPositionRotation, SPlayerRotation, SPlayerSession, SSetCommandBlock,
|
||||
SSetCreativeSlot, SSetHeldItem, SSetPlayerGround, SSwingArm, SUpdateSign, SUseItem,
|
||||
SUseItemOn,
|
||||
},
|
||||
status::SStatusPingRequest,
|
||||
use pumpkin_protocol::ServerPacket;
|
||||
use pumpkin_protocol::java::{
|
||||
packet_decoder::TCPNetworkDecoder,
|
||||
server::{
|
||||
config::{
|
||||
SClientInformationConfig, SConfigCookieResponse, SConfigResourcePack, SKnownPacks,
|
||||
SPluginMessage,
|
||||
},
|
||||
handshake::SHandShake,
|
||||
login::{SEncryptionResponse, SLoginCookieResponse, SLoginPluginResponse, SLoginStart},
|
||||
play::{
|
||||
SChangeGameMode, SChatCommand, SChatMessage, SChunkBatch, SClickSlot, SClientCommand,
|
||||
SClientInformationPlay, SCloseContainer, SCommandSuggestion, SConfirmTeleport,
|
||||
SCookieResponse, SCustomPayload, SInteract, SKeepAlive, SMoveVehicle, SPaddleBoat,
|
||||
SPickItemFromBlock, SPlayPingRequest, SPlayerAbilities, SPlayerAction, SPlayerCommand,
|
||||
SPlayerInput, SPlayerLoaded, SPlayerPosition, SPlayerPositionRotation, SPlayerRotation,
|
||||
SPlayerSession, SSetCommandBlock, SSetCreativeSlot, SSetHeldItem, SSetPlayerGround,
|
||||
SSwingArm, SUpdateSign, SUseItem, SUseItemOn,
|
||||
},
|
||||
status::SStatusPingRequest,
|
||||
},
|
||||
};
|
||||
use pumpkin_util::version::MinecraftVersion;
|
||||
use std::io::Cursor;
|
||||
use tokio::runtime::Runtime;
|
||||
|
||||
const TARGET_VERSION: MinecraftVersion = MinecraftVersion::V_26_1;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Helper: run every known ServerPacket::read against the same payload.
|
||||
// We don't care about the result — only that nothing panics.
|
||||
// Uses a Cursor and the Version enum as required by the new signature.
|
||||
// ---------------------------------------------------------------------------
|
||||
fn fuzz_all_deserializers(payload: &[u8]) {
|
||||
// Handshake
|
||||
let _ = SHandShake::read(payload);
|
||||
let mut cursor = Cursor::new(payload);
|
||||
|
||||
// Status
|
||||
//let _ = SStatusRequest::read(payload);
|
||||
let _ = SStatusPingRequest::read(payload);
|
||||
macro_rules! run_read {
|
||||
($($packet:ty),* $(,)?) => {
|
||||
$(
|
||||
cursor.set_position(0);
|
||||
let _ = <$packet>::read(&mut cursor, &TARGET_VERSION);
|
||||
)*
|
||||
};
|
||||
}
|
||||
|
||||
// Login
|
||||
let _ = SLoginStart::read(payload);
|
||||
let _ = SEncryptionResponse::read(payload);
|
||||
let _ = SLoginPluginResponse::read(payload);
|
||||
//let _ = SLoginAcknowledged::read(payload);
|
||||
let _ = SLoginCookieResponse::read(payload);
|
||||
|
||||
// Config
|
||||
let _ = SClientInformationConfig::read(payload);
|
||||
let _ = SPluginMessage::read(payload);
|
||||
//let _ = SAcknowledgeFinishConfig::read(payload);
|
||||
let _ = SKnownPacks::read(payload);
|
||||
let _ = SConfigCookieResponse::read(payload);
|
||||
let _ = SConfigResourcePack::read(payload);
|
||||
|
||||
// Play
|
||||
let _ = SConfirmTeleport::read(payload);
|
||||
let _ = SChangeGameMode::read(payload);
|
||||
let _ = SChatCommand::read(payload);
|
||||
let _ = SChatMessage::read(payload);
|
||||
let _ = SClientInformationPlay::read(payload);
|
||||
let _ = SClientCommand::read(payload);
|
||||
let _ = SPlayerInput::read(payload);
|
||||
let _ = SMoveVehicle::read(payload);
|
||||
let _ = SPaddleBoat::read(payload);
|
||||
let _ = SInteract::read(payload);
|
||||
let _ = SKeepAlive::read(payload);
|
||||
let _ = SPlayerPosition::read(payload);
|
||||
let _ = SPlayerPositionRotation::read(payload);
|
||||
let _ = SPlayerRotation::read(payload);
|
||||
let _ = SSetPlayerGround::read(payload);
|
||||
let _ = SPickItemFromBlock::read(payload);
|
||||
let _ = SPlayerAbilities::read(payload);
|
||||
let _ = SPlayerAction::read(payload);
|
||||
let _ = SSetCommandBlock::read(payload);
|
||||
let _ = SPlayerCommand::read(payload);
|
||||
let _ = SPlayerLoaded::read(payload);
|
||||
let _ = SPlayPingRequest::read(payload);
|
||||
let _ = SClickSlot::read(payload);
|
||||
let _ = SSetHeldItem::read(payload);
|
||||
let _ = SSetCreativeSlot::read(payload);
|
||||
let _ = SSwingArm::read(payload);
|
||||
let _ = SUpdateSign::read(payload);
|
||||
let _ = SUseItemOn::read(payload);
|
||||
let _ = SUseItem::read(payload);
|
||||
let _ = SCommandSuggestion::read(payload);
|
||||
let _ = SCookieResponse::read(payload);
|
||||
let _ = SCloseContainer::read(payload);
|
||||
let _ = SChunkBatch::read(payload);
|
||||
let _ = SPlayerSession::read(payload);
|
||||
let _ = SCustomPayload::read(payload);
|
||||
run_read!(
|
||||
// Handshake
|
||||
SHandShake,
|
||||
// Status
|
||||
SStatusPingRequest,
|
||||
// Login
|
||||
SLoginStart,
|
||||
SEncryptionResponse,
|
||||
SLoginPluginResponse,
|
||||
SLoginCookieResponse,
|
||||
// Config
|
||||
SClientInformationConfig,
|
||||
SPluginMessage,
|
||||
SKnownPacks,
|
||||
SConfigCookieResponse,
|
||||
SConfigResourcePack,
|
||||
// Play
|
||||
SConfirmTeleport,
|
||||
SChangeGameMode,
|
||||
SChatCommand,
|
||||
SChatMessage,
|
||||
SClientInformationPlay,
|
||||
SClientCommand,
|
||||
SPlayerInput,
|
||||
SMoveVehicle,
|
||||
SPaddleBoat,
|
||||
SInteract,
|
||||
SKeepAlive,
|
||||
SPlayerPosition,
|
||||
SPlayerPositionRotation,
|
||||
SPlayerRotation,
|
||||
SSetPlayerGround,
|
||||
SPickItemFromBlock,
|
||||
SPlayerAbilities,
|
||||
SPlayerAction,
|
||||
SSetCommandBlock,
|
||||
SPlayerCommand,
|
||||
SPlayerLoaded,
|
||||
SPlayPingRequest,
|
||||
SClickSlot,
|
||||
SSetHeldItem,
|
||||
SSetCreativeSlot,
|
||||
SSwingArm,
|
||||
SUpdateSign,
|
||||
SUseItemOn,
|
||||
SUseItem,
|
||||
SCommandSuggestion,
|
||||
SCookieResponse,
|
||||
SCloseContainer,
|
||||
SChunkBatch,
|
||||
SPlayerSession,
|
||||
SCustomPayload,
|
||||
);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -101,13 +107,6 @@ fuzz_target!(|data: &[u8]| {
|
||||
return;
|
||||
}
|
||||
|
||||
// Byte layout:
|
||||
// [0] = decoder mode (0=plain, 1=compressed, 2=encrypted, 3=both)
|
||||
// [1] = split point % rest.len() — how much goes to the decoder vs
|
||||
// the deserializers, letting the fuzzer explore both paths
|
||||
// independently with different byte patterns
|
||||
// [2..18] = 16-byte AES key candidate
|
||||
// [18..] = raw bytes fed to both fuzzing paths
|
||||
let mode = data[0] % 4;
|
||||
let key = &data[2..18];
|
||||
let rest = &data[18..];
|
||||
@@ -143,5 +142,6 @@ fuzz_target!(|data: &[u8]| {
|
||||
let _ = decoder.get_raw_packet().await;
|
||||
});
|
||||
|
||||
// --- Path 2: Individual Packet Deserializers ---------------------------
|
||||
fuzz_all_deserializers(deser_bytes);
|
||||
});
|
||||
Reference in new issue
Block a user