Code Monkey home page Code Monkey logo

Comments (8)

barneygale avatar barneygale commented on July 27, 2024 1

Yes, you can absolutely do this! If you have a chunk_data packet saved to disk, you can do something like:

from quarry.types.buffer import Buffer
with open("packet.bin", "rb") as fd:
    buff = Buffer(fd.read())
x, z, contiguous = buff.unpack('ii?')
# etc

There's an example of unpacking a chunk data packet using quarry here: https://github.com/barneygale/minebnc/blob/master/plugins/world.py#L73-L107

from quarry.

Retsim avatar Retsim commented on July 27, 2024

Thanks Barney, I'm using scapy to debug it while packet sniffing:

def sniffPackets(packet):
    if packet.haslayer(IP):
        pckt_src=packet[IP].src
        if '192' not in pckt_src: # Only incoming packets !
            pckt_dst=packet[IP].dst
            pckt_ttl=packet[IP].ttl
            payload=packet[IP].payload
            hex_dump = hexdump(packet)
            bytesd = bytes(packet)
            
            from quarry.types.buffer import Buffer
            # Do something with quarry...
            buff = Buffer(bytesd)
            x, y, z = buff.unpack_position()

def main():
    print('custom packet sniffer')
    sniff(prn=sniffPackets, filter="port 25565")

How can I use quarry unpack to get packet ID and such directly from packet bytes ?
Also, will quarry detect gzip compression and help to deal with that ?

Thanks for your work !

from quarry.

barneygale avatar barneygale commented on July 27, 2024

So a couple of things to note:

  1. Minecraft packets will fragment across multiple TCP/IP packets. You can't receive a TCP packet and expect that a minecraft packet is right at the beginning
  2. If you're connecting to an online-mode server, your connection will be encrypted pretty soon, making sniffing impossible.

You can work around issue 1 by keeping a single global Buffer object and adding data to it every time you receive a TCP packet. You can then attempt to decode a packet by calling buff.unpack_packet() - this method handles gzip compression and will give you another Buffer object back that contains the packet's payload, starting with its ID. Note that you might not have enough data in your buffer, or conversely you might have enough data for multiple packets! You can see how quarry handles that here.

You can work around 2 by running the server in offline mode. If that's not possible, you won't be able to passively sniff connections (for the same reasons you can't sniff HTTPS connections), but you can write a proxy that does online-mode authentication with the remote server (the proxy will need to know a genuine minecraft.net account). The logic here is a little complex so I'd suggest using quarry's proxy infrastructure if you go this route.

from quarry.

Retsim avatar Retsim commented on July 27, 2024

I was planning to treat packets using a Bufffer.
But yes, random aspect of incoming packets is not an easiest part.
Also , i'm not concerned by encryption as I want to sniff non online-mode servers.

I will give a look to how quarry handles it, thanks for the link.
If I plan to use quarry proxy (or rex directly maybe ?), how will it handle unknow packets ?
For example for a server that added few customs packets (not using the dedicated custom packet or plugins channels !) :
Will we need to implement them to allow proper gameplay / don't crash the client (or quarry "client") or will they pass through, be ignored, and still redirected client-->proxy-->server / server-->proxy-->client without problem ?

from quarry.

barneygale avatar barneygale commented on July 27, 2024

If you're using a quarry proxy (such as rex) at the moment you'll get a protocol exception for unknown packets - I'll look into making this hookable.

from quarry.

Retsim avatar Retsim commented on July 27, 2024

Using your indications I got my 'real' sniffer to work:
Listening to chat messages: http://puu.sh/Almac/83c47b69a9.png
(Russian server,I took it from a server list around the web, whatever...)

Here is the current code (using global and ugly vars):
https://pastebin.com/s9h1s3Cb

Really simple, and no need to use a proxy, thanks for your advices !

Can you show me an example to decode more packets like the "Entity Look And Relative Move", using your Buffer and unpacks ?
For ex, format is Entity ID (varint), X (short), Y (short), Z (short), Yaw (angle), Pitch (angle), On Ground (bool)
I don't know how to unpack those types, but I suppose quarry can help me on that too.

Also, how should I know which compression treshold I'm currently in ?
I'm getting random errors while decompressing the buffer.
(Listening for set compression packet and unpack it to get a value ?)

from quarry.

barneygale avatar barneygale commented on July 27, 2024

Great to hear that you've got something working!

There's an example of unpacking "Entity Look And Relative Move" here: https://github.com/barneygale/minebnc/blob/master/plugins/entities.py#L294-L301. You may find the rest of the code in that repository quite useful.

For compression, you'll need to hook the login_set_compression packet and store the new value.

from quarry.

Retsim avatar Retsim commented on July 27, 2024

Those examples are quite complete, I got everything I needed, thanks for taking the time to give some directions, this is actually very useful.
No need to keep this issue opened anymore.

from quarry.

Related Issues (20)

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.