chore: move to crates folder
This commit is contained in:
1 parent
5d10c0d8a8
commit
cb3660bcd2
3393 files changed
+1270
-741
No files matched your search
@@ -0,0 +1,99 @@
|
||||
#![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, SUnconnectedPingOpenConnections},
|
||||
},
|
||||
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);
|
||||
cursor.set_position(0);
|
||||
let _ = SUnconnectedPingOpenConnections::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);
|
||||
});
|
||||
@@ -0,0 +1,149 @@
|
||||
#![no_main]
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
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,
|
||||
SContainerButtonClick, 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::JavaMinecraftVersion;
|
||||
use std::io::Cursor;
|
||||
use tokio::runtime::Runtime;
|
||||
|
||||
const TARGET_VERSION: JavaMinecraftVersion = JavaMinecraftVersion::V_26_1;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Helper: run every known ServerPacket::read against the same payload.
|
||||
// Uses a Cursor and the Version enum as required by the new signature.
|
||||
// ---------------------------------------------------------------------------
|
||||
fn fuzz_all_deserializers(payload: &[u8]) {
|
||||
let mut cursor = Cursor::new(payload);
|
||||
|
||||
macro_rules! run_read {
|
||||
($($packet:ty),* $(,)?) => {
|
||||
$(
|
||||
cursor.set_position(0);
|
||||
let _ = <$packet>::read(&mut cursor, &TARGET_VERSION);
|
||||
)*
|
||||
};
|
||||
}
|
||||
|
||||
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,
|
||||
SContainerButtonClick,
|
||||
SSetHeldItem,
|
||||
SSetCreativeSlot,
|
||||
SSwingArm,
|
||||
SUpdateSign,
|
||||
SUseItemOn,
|
||||
SUseItem,
|
||||
SCommandSuggestion,
|
||||
SCookieResponse,
|
||||
SCloseContainer,
|
||||
SChunkBatch,
|
||||
SPlayerSession,
|
||||
SCustomPayload,
|
||||
);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Fuzz target
|
||||
// ---------------------------------------------------------------------------
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
if data.len() < 18 {
|
||||
return;
|
||||
}
|
||||
|
||||
let mode = data[0] % 4;
|
||||
let key = &data[2..18];
|
||||
let rest = &data[18..];
|
||||
|
||||
let split = if rest.is_empty() {
|
||||
0
|
||||
} else {
|
||||
(data[1] as usize) % rest.len()
|
||||
};
|
||||
let (decoder_bytes, deser_bytes) = rest.split_at(split);
|
||||
|
||||
// --- Path 1: decoder (framing / encryption / compression) --------------
|
||||
let rt = Runtime::new().unwrap();
|
||||
rt.block_on(async {
|
||||
let mut decoder = TCPNetworkDecoder::new(Cursor::new(decoder_bytes));
|
||||
match mode {
|
||||
1 => {
|
||||
decoder.set_compression(256);
|
||||
}
|
||||
2 => {
|
||||
let mut aes_key = [0u8; 16];
|
||||
aes_key.copy_from_slice(key);
|
||||
decoder.set_encryption(&aes_key);
|
||||
}
|
||||
3 => {
|
||||
decoder.set_compression(256);
|
||||
let mut aes_key = [0u8; 16];
|
||||
aes_key.copy_from_slice(key);
|
||||
decoder.set_encryption(&aes_key);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
let _ = decoder.get_raw_packet().await;
|
||||
});
|
||||
|
||||
// --- Path 2: Individual Packet Deserializers ---------------------------
|
||||
fuzz_all_deserializers(deser_bytes);
|
||||
});
|
||||
@@ -0,0 +1,43 @@
|
||||
#![no_main]
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
use pumpkin_protocol::bedrock::packet_encoder::UDPNetworkEncoder;
|
||||
use pumpkin_protocol::bedrock::SubClient;
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
if data.len() < 10 {
|
||||
return;
|
||||
}
|
||||
|
||||
let compression_threshold = data[0] as usize;
|
||||
let compression_level = (data[1] % 10) as u32;
|
||||
let packet_id = u16::from_be_bytes([data[2], data[3]]);
|
||||
let sender = match data[4] % 4 {
|
||||
0 => SubClient::Main,
|
||||
1 => SubClient::SubClient0,
|
||||
2 => SubClient::SubClient1,
|
||||
_ => SubClient::SubClietn2,
|
||||
};
|
||||
let target = match data[5] % 4 {
|
||||
0 => SubClient::Main,
|
||||
1 => SubClient::SubClient0,
|
||||
2 => SubClient::SubClient1,
|
||||
_ => SubClient::SubClietn2,
|
||||
};
|
||||
let use_compression = data[6] % 2 == 0;
|
||||
let packet_payload = &data[7..];
|
||||
|
||||
let mut encoder = UDPNetworkEncoder::new();
|
||||
|
||||
if use_compression {
|
||||
encoder.set_compression((compression_threshold, compression_level));
|
||||
}
|
||||
|
||||
let mut out = Vec::new();
|
||||
let _ = encoder.write_game_packet(
|
||||
packet_id,
|
||||
sender,
|
||||
target,
|
||||
packet_payload,
|
||||
&mut out
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,59 @@
|
||||
#![no_main]
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
use pumpkin_protocol::java::packet_encoder::TCPNetworkEncoder;
|
||||
use pumpkin_protocol::codec::var_int::VarInt;
|
||||
use pumpkin_protocol::ser::NetworkWriteExt;
|
||||
use pumpkin_protocol::ServerPacket;
|
||||
use pumpkin_protocol::java::client::play::CPlayerPosition;
|
||||
use pumpkin_protocol::packet::MultiVersionJavaPacket;
|
||||
use pumpkin_protocol::ClientPacket;
|
||||
use pumpkin_util::version::JavaMinecraftVersion;
|
||||
use std::io::Cursor;
|
||||
use tokio::runtime::Runtime;
|
||||
|
||||
const TARGET_VERSION: JavaMinecraftVersion = JavaMinecraftVersion::V_1_21_4;
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
if data.len() < 20 {
|
||||
return;
|
||||
}
|
||||
|
||||
let compression_threshold = data[0] as usize;
|
||||
let compression_level = (data[1] % 10) as u32;
|
||||
let encryption_key: [u8; 16] = data[2..18].try_into().unwrap();
|
||||
let use_compression = data[18] % 2 == 0;
|
||||
let use_encryption = data[19] % 2 == 0;
|
||||
let packet_data = &data[20..];
|
||||
|
||||
let rt = Runtime::new().unwrap();
|
||||
rt.block_on(async {
|
||||
let mut out = Vec::new();
|
||||
let mut encoder = TCPNetworkEncoder::new(&mut out);
|
||||
|
||||
if use_compression {
|
||||
encoder.set_compression((compression_threshold, compression_level));
|
||||
}
|
||||
if use_encryption {
|
||||
encoder.set_encryption(&encryption_key);
|
||||
}
|
||||
|
||||
// 1. Fuzz with raw bytes (simulating various packet payloads)
|
||||
let mut buf = Vec::new();
|
||||
let packet_id = if packet_data.is_empty() { 0 } else { packet_data[0] as i32 };
|
||||
let _ = buf.write_var_int(&VarInt(packet_id));
|
||||
buf.extend_from_slice(packet_data);
|
||||
let _ = encoder.write_packet(buf.into()).await;
|
||||
|
||||
// 2. Fuzz with actual packets if they can be partially read
|
||||
let mut cursor = Cursor::new(packet_data);
|
||||
if let Ok(packet) = CPlayerPosition::read(&mut cursor, &TARGET_VERSION) {
|
||||
let mut packet_buf = Vec::new();
|
||||
let id = CPlayerPosition::to_id(TARGET_VERSION);
|
||||
let _ = packet_buf.write_var_int(&VarInt(id));
|
||||
let _ = packet.write_packet_data(&mut packet_buf, &TARGET_VERSION);
|
||||
let _ = encoder.write_packet(packet_buf.into()).await;
|
||||
}
|
||||
|
||||
let _ = encoder.flush().await;
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
#![no_main]
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
use pumpkin_protocol::query::{RawQueryPacket, SHandshake, SStatusRequest};
|
||||
use tokio::runtime::Runtime;
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
let rt = Runtime::new().unwrap();
|
||||
|
||||
rt.block_on(async {
|
||||
if let Ok(mut raw) = RawQueryPacket::decode(data.to_vec()).await {
|
||||
match raw.packet_type {
|
||||
pumpkin_protocol::query::PacketType::Handshake => {
|
||||
let _ = SHandshake::decode(&mut raw).await;
|
||||
}
|
||||
pumpkin_protocol::query::PacketType::Status => {
|
||||
let _ = SStatusRequest::decode(&mut raw).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,8 @@
|
||||
#![no_main]
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
use pumpkin::net::rcon::packet::Packet;
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
let mut incoming = data.to_vec();
|
||||
let _ = Packet::deserialize(&mut incoming);
|
||||
});
|
||||
Reference in new issue
Block a user