adepierre / SniffCraft

C++ program to capture and display all traffic between a client and a server in minecraft
GNU General Public License v3.0
190 stars 11 forks source link

Connection issue when connecting via 1.19.2 version of library #26

Closed BhavyaSingh2611 closed 1 year ago

BhavyaSingh2611 commented 1 year ago

libc++abi: terminating due to uncaught exception of type std::bad_optional_access: bad_optional_access

^^

when i hit connect in the minecraft and it starts to initiate the connection process

adepierre commented 1 year ago

Hello !

Could you provide more details so I can try to reproduce the error? Like configuration used, which server (vanilla jar/modded ? online true/false ? new one or existing one) etc...

Thanks !

BhavyaSingh2611 commented 1 year ago

@adepierre The configuration is as follows

{
  "LogToConsole": true,
  "LogToReplay": false,
  "LogRawBytes": false,
  "Online": true,
  "MicrosoftAccountCacheKey": "",
  "Handshaking": {
    "ignored_clientbound": [],
    "ignored_serverbound": [],
    "detailed_clientbound": [],
    "detailed_serverbound": []
  },
  "Status": {
    "ignored_clientbound": [],
    "ignored_serverbound": [],
    "detailed_clientbound": [],
    "detailed_serverbound": []
  },
  "Login": {
    "ignored_clientbound": [],
    "ignored_serverbound": [],
    "detailed_clientbound": [],
    "detailed_serverbound": []
  },
  "Play": {
    "ignored_clientbound": [],
    "ignored_serverbound": [],
    "detailed_clientbound": [],
    "detailed_serverbound": []
  }
}

and the server is modded (Fabric). And to reproduce the error compile the SniffCraft with -DGAME_VERSION=1.19.2 and running the sniffcraft instance and connecting to it, the console logs this error and it exits, notably it doesnt even sends a connection request to the server as the console doesnt report anything about that

BhavyaSingh2611 commented 1 year ago

The output of console is

./sniffcraft 25565 xxx.xxx.xxx.xxx:25565 ./conf.json

------------------------------------------------------

Waiting connection on 127.0.0.1:25565
Loading updated conf file...
Conf file loaded!
Trying to authenticate using Microsoft account
[2023-04-28 19:32:35.710] [INFO] [(0x1df3b9b40)] Authentifier.cpp(86): Cached Minecraft token for Microsoft account still valid.
[2023-04-28 19:32:35.711] [INFO] [(0x1df3b9b40)] Authentifier.cpp(89): Getting player certificates...
[2023-04-28 19:32:35.713] [INFO] [(0x1df3b9b40)] Authentifier.cpp(1159): Cached player certificates still valid!
[2023-04-28 19:32:35.713] [INFO] [(0x1df3b9b40)] Authentifier.cpp(96): Player certificates obtained!
Starting new proxy to xxx.xxx.xxx.xxx:25565
Waiting connection on 127.0.0.1:25565
[0:00:00:001] [(SC) --> S] Client Intention
[0:00:00:001] [C --> (SC)] Client Intention
[0:00:00:001] [C --> S] Status Request
[0:00:00:397] [S --> C] Status Response
[0:00:00:406] [C --> S] Ping Request
[0:00:00:598] [S --> C] Pong Response
Loading updated conf file...
Conf file loaded!
Trying to authenticate using Microsoft account
[2023-04-28 19:32:38.605] [INFO] [(0x1df3b9b40)] Authentifier.cpp(86): Cached Minecraft token for Microsoft account still valid.
[2023-04-28 19:32:38.605] [INFO] [(0x1df3b9b40)] Authentifier.cpp(89): Getting player certificates...
[2023-04-28 19:32:38.608] [INFO] [(0x1df3b9b40)] Authentifier.cpp(1159): Cached player certificates still valid!
[2023-04-28 19:32:38.608] [INFO] [(0x1df3b9b40)] Authentifier.cpp(96): Player certificates obtained!
Starting new proxy to xxx.xxx.xxx.xxx:25565
Waiting connection on 127.0.0.1:25565
[0:00:00:000] [(SC) --> S] Client Intention
[0:00:00:000] [C --> (SC)] Client Intention
libc++abi: terminating due to uncaught exception of type std::bad_optional_access: bad_optional_access
zsh: abort      ./sniffcraft 25565 xxx.xxx.xxx.xxx:25565 ./conf.json
adepierre commented 1 year ago

Thanks for the details!

I tried to reproduce the error with a fresh 1.19.2 fabric server but unfortunately I didn't get the error. My best guess is that it's a protocol implementation mistake somewhere in a packet or a bad interaction with a mod.

Based on the logs my best guess would be that it happens in the processing of ServerboundHelloPacket, probably here when trying to read the key but I'm not sure why the server wouldn't send it. I tested it with a 1.19.2 fabric server and no mods, and the key was correctly sent. Do you have any mod installed that could change this behaviour?

As I still can't reproduce the error on my side, you could try to add some logs before and after this if to confirm this is the source of the issue.

Alternatively, you coud also try to test with just the fabric server and no mods to see if you still have the issue. If it works it'll be easy to then add back the mods one by one to find which one causes the problem allowing to reproduce the error on my side.

For my tests I downloaded and launched the server with java -Xmx2G -jar fabric-server-mc.1.19.2-loader.0.14.19-launcher.0.11.2.jar nogui.

BhavyaSingh2611 commented 1 year ago

I think I may have figured it out and its the NoChatReports mod that is adding a mixin named ClientBoundHelloPacket so I am guessing that is modifying the behaviour would try disabling that and trying again

BhavyaSingh2611 commented 1 year ago

Well disabling the NoChatReports mod removed the bad_optional_access, it is now giving segmentation fault 😂

./sniffcraft 25565 xxx.xxx.xxx.xxx:25565 ./conf.json

------------------------------------------------------

Waiting connection on 127.0.0.1:25565
Loading updated conf file...
Conf file loaded!
Trying to authenticate using Microsoft account
[2023-04-28 19:32:35.710] [INFO] [(0x1df3b9b40)] Authentifier.cpp(86): Cached Minecraft token for Microsoft account still valid.
[2023-04-28 19:32:35.711] [INFO] [(0x1df3b9b40)] Authentifier.cpp(89): Getting player certificates...
[2023-04-28 19:32:35.713] [INFO] [(0x1df3b9b40)] Authentifier.cpp(1159): Cached player certificates still valid!
[2023-04-28 19:32:35.713] [INFO] [(0x1df3b9b40)] Authentifier.cpp(96): Player certificates obtained!
Starting new proxy to xxx.xxx.xxx.xxx:25565
Waiting connection on 127.0.0.1:25565
[0:00:00:001] [(SC) --> S] Client Intention
[0:00:00:001] [C --> (SC)] Client Intention
[0:00:00:001] [C --> S] Status Request
[0:00:00:397] [S --> C] Status Response
[0:00:00:406] [C --> S] Ping Request
[0:00:00:598] [S --> C] Pong Response
Loading updated conf file...
Conf file loaded!
Trying to authenticate using Microsoft account
[2023-04-28 19:32:38.605] [INFO] [(0x1df3b9b40)] Authentifier.cpp(86): Cached Minecraft token for Microsoft account still valid.
[2023-04-28 19:32:38.605] [INFO] [(0x1df3b9b40)] Authentifier.cpp(89): Getting player certificates...
[2023-04-28 19:32:38.608] [INFO] [(0x1df3b9b40)] Authentifier.cpp(1159): Cached player certificates still valid!
[2023-04-28 19:32:38.608] [INFO] [(0x1df3b9b40)] Authentifier.cpp(96): Player certificates obtained!
Starting new proxy to xxx.xxx.xxx.xxx:25565
Waiting connection on 127.0.0.1:25565
[0:00:00:000] [(SC) --> S] Client Intention
[0:00:00:000] [C --> (SC)] Client Intention
WARNING, public key mismatch between client and sniffcraft.
You might get kicked out if you send a chat message
[0:00:00:277] [(SC) --> S] Hello
[0:00:00:277] [C --> (SC)] Hello
[0:00:05:872] [(SC) --> S] Key
[0:00:05:872] [S --> (SC)] Hello
[0:00:06:380] [S --> C] Login Compression
[0:00:06:390] [S --> C] Custom Query
[0:00:06:394] [C --> S] Custom Query
[0:00:06:395] [S --> C] Custom Query
[0:00:06:396] [C --> S] Custom Query
[0:00:06:400] [S --> C] Custom Query
[0:00:06:400] [S --> C] Custom Query
[0:00:06:401] [C --> S] Custom Query
[0:00:06:402] [C --> S] Custom Query
[0:00:06:402] [S --> C] Custom Query
[0:00:06:402] [C --> S] Custom Query
[0:00:06:826] [S --> C] Game Profile
[0:00:07:930] [S --> C] Login
[0:00:07:931] [S --> C] Custom Payload
[0:00:07:931] [S --> C] Custom Payload
[0:00:07:932] [S --> C] Custom Payload
[0:00:07:934] [S --> C] Custom Payload
[0:00:07:935] [S --> C] Custom Payload
[0:00:07:935] [S --> C] Custom Payload
[0:00:07:935] [S --> C] Custom Payload
[0:00:07:940] [C --> S] Custom Payload
[0:00:08:027] [C --> S] Custom Payload
[0:00:08:029] [C --> S] Client Information
[0:00:08:029] [C --> S] Custom Payload
[0:00:08:029] [C --> S] Custom Payload
[0:00:08:029] [C --> S] Custom Payload
[0:00:08:030] [C --> S] Custom Payload
[0:00:08:030] [C --> S] Custom Payload
[0:00:08:045] [C --> S] Move Player PosRot
[0:00:08:046] [C --> S] Move Player Pos
[0:00:08:560] [S --> C] Custom Payload
[0:00:08:566] [C --> S] Move Player Pos
[0:00:08:567] [C --> S] Move Player Pos
[0:00:08:567] [C --> S] Move Player Pos
[0:00:08:567] [C --> S] Move Player Pos
[0:00:08:567] [C --> S] Move Player Pos
[0:00:08:567] [C --> S] Move Player Pos
[0:00:08:567] [C --> S] Move Player Pos
[0:00:08:567] [C --> S] Move Player Pos
[0:00:08:567] [C --> S] Move Player Pos
[0:00:08:567] [C --> S] Move Player Pos
[0:00:08:569] [S --> C] Custom Payload
[0:00:08:570] [S --> C] Custom Payload
[0:00:08:570] [S --> C] Custom Payload
[0:00:08:570] [S --> C] Custom Payload
[0:00:08:570] [S --> C] Custom Payload
[0:00:08:570] [S --> C] Custom Payload
[0:00:08:570] [S --> C] Custom Payload
[0:00:08:571] [S --> C] Custom Payload
[0:00:08:571] [S --> C] Custom Payload
[0:00:08:572] [S --> C] Custom Payload
[0:00:08:572] [S --> C] Custom Payload
[0:00:08:572] [S --> C] Custom Payload
[0:00:08:572] [S --> C] Custom Payload
[0:00:08:573] [S --> C] Custom Payload
[0:00:08:573] [S --> C] Custom Payload
[0:00:08:574] [S --> C] Change Difficulty
[0:00:08:575] [S --> C] Player Abilities
[0:00:08:575] [S --> C] Set Carried Item
[0:00:08:575] [S --> C] Custom Payload
[0:00:08:575] [C --> S] Move Player Pos
[0:00:08:713] [S --> C] Custom Payload
[0:00:08:716] [S --> C] Custom Payload
[0:00:08:717] [S --> C] Custom Payload
[0:00:08:717] [S --> C] Custom Payload
[0:00:08:718] [S --> C] Custom Payload
[0:00:08:802] [C --> S] Custom Payload
[0:00:08:842] [C --> S] Set Carried Item
[0:00:08:842] [C --> S] Move Player Pos
[0:00:08:842] [C --> S] Move Player Pos
[0:00:08:842] [C --> S] Move Player Pos
[0:00:08:843] [C --> S] Move Player Pos
[0:00:08:845] [C --> S] Move Player Pos
[0:00:08:872] [C --> S] Move Player Pos
[0:00:08:873] [C --> S] Custom Payload
[0:00:08:873] [C --> S] Custom Payload
[0:00:08:939] [C --> S] Move Player Pos
[0:00:08:965] [C --> S] Move Player Pos
[0:00:09:019] [C --> S] Move Player Pos
[0:00:09:063] [C --> S] Move Player Pos
[0:00:09:116] [C --> S] Move Player Pos
[0:00:09:171] [C --> S] Move Player Pos
[0:00:09:215] [C --> S] Move Player Pos
[0:00:09:269] [C --> S] Move Player Pos
[0:00:09:314] [C --> S] Move Player Pos
[0:00:09:367] [C --> S] Move Player Pos
[0:00:09:421] [C --> S] Move Player Pos
[0:00:09:466] [C --> S] Move Player Pos
Server --> Client: PARSING EXCEPTION: Error reading NBT value, not starting with compound || Update Recipes
[0:00:10:168] [C --> S] Move Player Pos
[0:00:10:168] [C --> S] Move Player Pos
[0:00:10:168] [C --> S] Move Player Pos
[0:00:10:168] [C --> S] Move Player Pos
[0:00:10:168] [C --> S] Move Player Pos
[0:00:10:168] [C --> S] Move Player Pos
[0:00:10:168] [C --> S] Move Player Pos
[0:00:10:168] [C --> S] Move Player Pos
[0:00:10:168] [C --> S] Move Player Pos
[0:00:10:168] [C --> S] Move Player Pos
[0:00:10:204] [S --> C] Update Tags
[0:00:10:207] [C --> S] Move Player Pos
[0:00:10:207] [C --> S] Move Player Pos
[0:00:10:207] [C --> S] Move Player Pos
[0:00:10:208] [S --> C] Entity Event
zsh: segmentation fault  ./sniffcraft 25565 xxx.xxx.xxx.xxx:25565 ./conf.json
adepierre commented 1 year ago

Thanks for the update, will try to investigate again with the new info you gave

adepierre commented 1 year ago

@BhavyaSingh2611 Still no luck reproducing the error on my side, everything is working as expected.

I still think this might be a bad mod interaction as I am currently testing on a mod free fabric server. If you can identify the mod causing the issue I might be able to fix it.

The alternative is that it's due to a specific block or entity that I don't have when creating a new world. In this case a world download of your server would be helpful if it's something you can do.

Thanks

BhavyaSingh2611 commented 1 year ago

Well I was trying to packet sniff during the login cause of the load times and i managed to achieve that purpose.

Thank you for all the help tho really appreciate it 🙏

adepierre commented 1 year ago

Cool, glad you solved your issue eventually 🎉