Giter Site home page Giter Site logo

sean0x42 / mineshark Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 572 KB

A (work in progress) packet sniffing proxy that sits between a Minecraft client and server. Essentially a MITM attack with custom middleware

JavaScript 0.30% TypeScript 22.81% Go 76.89%

mineshark's Introduction

๐ŸŒ

mineshark's People

Contributors

sean0x42 avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

mineshark's Issues

Race condition when establishing new connections

There appears to be a race condition that occurs at the start of every new connection. About 60% of the time, the client will send its first packet before we have opened a connection with the server (I think), causing the connection to go silent.

I did attempt to resolve this issue by collecting all packets into a queue until the server explicitly fires the connect event, and then releasing the queue. But this has not resolved the issue.

More investigation is needed.

Change to a payload spec model in the packet registry

Currently writing a packet's registry entry is a pretty exhausting task. Writing a reader and writer involves a LOT of duplication. See example:

Click to see a large example registry entry
Registry.register({
  id: 0x26,
  kind: PacketKind.JoinGame,
  source: PacketSource.Server,
  state: State.Play,

  read: (reader) => ({
    kind: PacketKind.JoinGame,
    payload: {
      entityId: reader.readInt(),
      isHardcore: reader.readBoolean(),
      gamemode: reader.readUnsignedByte(),
      previousGamemode: reader.readByte(),
      worlds: reader.readIdentifierArray(),
      dimensionCodec: reader.readNbt(),
      dimension: reader.readNbt(),
      worldName: reader.readString(),
      hashedSeed: reader.readLong(),
      maxPlayers: reader.readVarInt(),
      viewDistance: reader.readVarInt(),
      reducedDebugInfo: reader.readBoolean(),
      enableRespawnScreen: reader.readBoolean(),
      isDebug: reader.readBoolean(),
      isFlat: reader.readBoolean(),
    },
  }),

  write: (writer, packet) => {
    const payload = (packet as JoinGamePacket).payload;
    writer
      .writeInt(payload.entityId)
      .writeBoolean(payload.isHardcore)
      .writeUnsignedByte(payload.gamemode)
      .writeByte(payload.previousGamemode)
      .writeIdentifierArray(payload.worlds)
      .writeNbt(payload.dimensionCodec)
      .writeNbt(payload.dimension)
      .writeString(payload.worldName)
      .writeLong(payload.hashedSeed)
      .writeVarInt(payload.maxPlayers)
      .writeVarInt(payload.viewDistance)
      .writeBoolean(payload.reducedDebugInfo)
      .writeBoolean(payload.enableRespawnScreen)
      .writeBoolean(payload.isDebug)
      .writeBoolean(payload.isFlat);
  },
});

It would be fantastic if we moved towards a different model, where you define a specification for the packet's payload instead. Something like:

Registry.register({
  id: 0x26,
  kind: PacketKind.JoinGame,
  source: PacketSource.Server,
  state: State.Play,

  payload: {
    entityId: DataType.Int,
    isHardcore: DataType.Boolean,
    gamemode: DataType.UnsignedByte,
    // ...

    // Custom data types could provide a callback reader and writer like the old way
    worlds: {
      read(reader) { /* ... */ },
      write(writer, packet) { /* ... */ }
    },
    // ...

    // Optional trailing data could be denoted with an extra flag
    isFlat: {
      type: DataType.Boolean,
      optional: true
    }
  }
});

Catch exceptions from middleware

If a middleware throws an error, it would be good to catch that error and pass the packet to the next middleware in the chain. This would prevent middleware from bringing down the entire proxy when they encounter unexpected territory.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.