Skip to content

Commit

Permalink
feat: update heuristics for v1.66+ (#39)
Browse files Browse the repository at this point in the history
* feat: update heuristics for v1.66+
  • Loading branch information
TheMythologist authored Aug 2, 2023
1 parent 6da0cd5 commit 5c79cee
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
run: poetry run build
- uses: actions/upload-artifact@v3
with:
name: Guardian.exe
name: Guardian
path: dist/Guardian-*.exe
- uses: softprops/action-gh-release@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Guardian

Custom firewall for the game GTA Online (version 1.54 and onwards).
Custom firewall for the game GTA Online (version 1.66 and onwards).

[![Latest release](https://img.shields.io/github/v/release/TheMythologist/guardian)](https://github.com/TheMythologist/guardian/releases/latest)
[![CI status](https://github.com/TheMythologist/guardian/workflows/build/badge.svg)](https://github.com/TheMythologist/guardian/actions?query=branch%3Amain)
Expand Down
40 changes: 34 additions & 6 deletions guardian/network/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,17 @@

# Interesting note: All the matchmaker requests have payload sizes that may be 16 bytes apart.

HEARTBEAT_SIZES = {12, 18}
HEARTBEAT_SIZES = {12, 18, 63}
MATCHMAKING_SIZES = {
245,
261,
277,
293,
191,
207,
223,
239,
} # probably a player looking to join the session.
DTLs = {0xFEFF, 0xFEFD}
KNOWNS = {0x39, 0x31, 0x29}
# RECORDS = {20, 21, 22, 23}


KNOWN_SIZES = HEARTBEAT_SIZES.union(MATCHMAKING_SIZES)

Expand Down Expand Up @@ -196,7 +200,31 @@ def is_packet_allowed(self, packet: pydivert.Packet) -> bool:

# The "special sauce" for the new filtering logic. We're using payload sizes to guess if the packet
# has a behaviour we want to allow through.
return ip in self.ips or size in KNOWN_SIZES
if ip in self.ips or size in HEARTBEAT_SIZES:
return True

wrapper = 0 if size < 5 else int.from_bytes(packet.raw[28:30], "big")
magic_byte = packet.payload[4]

if size == wrapper:
offset = packet.payload[2] ^ magic_byte
code = 0
alt = 0
if offset == 17 and size >= 27:
code = int.from_bytes(packet.payload[25:27], "big")
alt = packet.payload[24]
elif offset == 49 and size >= 91:
code = int.from_bytes(packet.payload[89:91], "big")

magic = 0 if size < 5 else int.from_bytes([magic_byte, magic_byte], "big")
if (
code ^ magic in DTLs
or alt ^ magic_byte in KNOWNS
or code ^ magic < 0x10
):
return True

return False


class BlacklistSession(AbstractPacketFilter):
Expand Down

0 comments on commit 5c79cee

Please sign in to comment.