Files
Operation-Lovecraft-Fallen-…/frida_hooks/run_sniffer.py
T
2026-04-15 22:24:44 -07:00

178 lines
5.0 KiB
Python

#!/usr/bin/env python3
"""
run_sniffer.py - Frida game server traffic sniffer for Fallen Doll / Paralogue
Captures encrypted traffic on port 11001 and EOS P2P packets.
Usage:
python run_sniffer.py # attach to running game
python run_sniffer.py --spawn # launch game and attach
python run_sniffer.py --dump FILE # also write raw packets to file
"""
import frida
import sys
import os
import time
import struct
import argparse
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
JS_PATH = os.path.join(SCRIPT_DIR, 'sniff_gameserver.js')
PROCESS_NAME = 'Paralogue-Win64-Shipping.exe'
MSG_TYPES = {
1001: 'KEY_A',
1002: 'KEY_B',
}
packet_log = []
def hexdump(data, width=16, limit=128):
lines = []
for i in range(0, min(len(data), limit), width):
chunk = data[i:i+width]
hx = ' '.join(f'{b:02x}' for b in chunk)
asc = ''.join(chr(b) if 32 <= b < 127 else '.' for b in chunk)
lines.append(f' {i:04x} {hx:<{width*3}} {asc}')
if len(data) > limit:
lines.append(f' ... +{len(data)-limit} bytes')
return '\n'.join(lines)
def decode_envelope(data):
"""Decode the [2-byte BE hdr_len][protobuf header] envelope."""
if len(data) < 4 or data[0] != 0x00:
return None
hdr_len = (data[0] << 8) | data[1]
if hdr_len < 2 or 2 + hdr_len > len(data):
return None
hdr = data[2:2+hdr_len]
fields = {}
pos = 0
try:
while pos < len(hdr):
byte = hdr[pos]
fn = byte >> 3
wt = byte & 0x07
pos += 1
if wt == 0:
val = 0; shift = 0
while pos < len(hdr):
b = hdr[pos]; val |= (b & 0x7f) << shift; shift += 7; pos += 1
if (b & 0x80) == 0: break
fields[fn] = val
else:
break
except (IndexError, ValueError):
return None
if not fields:
return None
return {'hdr_len': hdr_len, 'fields': fields, 'payload_off': 2 + hdr_len}
def on_message(message, data):
if message['type'] == 'error':
print(f'[!] JS Error: {message["description"]}')
return
p = message.get('payload', {})
if not isinstance(p, dict):
return
t = p.get('t', '')
if t == 'ready':
print(f'[*] {p["msg"]}')
return
if t == 'found':
print(f'[+] Game socket fd={p["fd"]} -> {p["ip"]}:{p["port"]}')
return
if t in ('s', 'r') and data:
raw = bytes(data)
direction = 'C->S' if t == 's' else 'S->C'
n = p.get('n', 0)
packet_log.append((time.time(), direction, raw))
env = decode_envelope(raw)
if env:
f = env['fields']
msg_id = f.get(2, 0)
name = MSG_TYPES.get(msg_id, f'type_{msg_id}')
payload_sz = len(raw) - env['payload_off']
print(f'[#{n:04d}] {direction} {len(raw):5d}B ENVELOPE route={f.get(1,"?")} {name}({msg_id}) f4={f.get(4,"?")} payload={payload_sz}B')
else:
print(f'[#{n:04d}] {direction} {len(raw):5d}B encrypted first8={raw[:8].hex()}')
if len(raw) <= 64 or env:
print(hexdump(raw))
print()
return
if t == 'eos_send':
print(f'[#{p.get("n",0):04d}] EOS_P2P_SendPacket called')
return
if t == 'eos_recv' and data:
raw = bytes(data)
n = p.get('n', 0)
print(f'[#{n:04d}] EOS_P2P_ReceivePacket {len(raw)}B first8={raw[:8].hex()}')
if len(raw) <= 128:
print(hexdump(raw))
print()
return
def main():
parser = argparse.ArgumentParser(description='Fallen Doll game server traffic sniffer')
parser.add_argument('--dump', help='Write raw packets to file')
args = parser.parse_args()
print('=' * 60)
print(' Fallen Doll / Paralogue - Game Server Sniffer')
print(' Hooks: ws2_32 recv/send + EOS P2P')
print('=' * 60)
with open(JS_PATH, 'r') as f:
js_code = f.read()
try:
session = frida.attach(PROCESS_NAME)
print(f'[*] Attached to {PROCESS_NAME}')
except frida.ProcessNotFoundError:
print(f'[!] {PROCESS_NAME} not running.')
print('[!] Start the game, then run this script.')
sys.exit(1)
script = session.create_script(js_code)
script.on('message', on_message)
script.load()
print('[*] Press Ctrl+C to stop.\n')
try:
while True:
time.sleep(0.5)
except KeyboardInterrupt:
pass
print(f'\n[*] Captured {len(packet_log)} packets.')
if args.dump and packet_log:
with open(args.dump, 'wb') as f:
for ts, direction, raw in packet_log:
# Simple format: [8-byte timestamp][1-byte dir (0=C->S, 1=S->C)][4-byte len][data]
d = 0 if direction == 'C->S' else 1
f.write(struct.pack('<dBI', ts, d, len(raw)))
f.write(raw)
print(f'[*] Dumped to {args.dump}')
session.detach()
print('[*] Detached.')
if __name__ == '__main__':
main()