EAC Linux v2 on Gentoo with OpenRC: ebuilds, host config, tools, docs
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
# Debugging tools
|
||||
|
||||
Used to find out what EAC's setup asks of systemd. Nothing here is installed by
|
||||
the packages; run them from this directory.
|
||||
|
||||
| File | Does |
|
||||
| --- | --- |
|
||||
| `exec-snoop [seconds]` | as root: prints every `execve`/`execveat` attempt with path and `argv[0..5]`, failed ones included (tracefs event probes; works under `lockdown=integrity`) |
|
||||
| `exec-trace [seconds]` | as root: JSON lines for every exec on the system (pid, parent, uid, command) and the exit status of each exec'd process (kernel proc connector) |
|
||||
| `eac-catch [seconds] [prefix] [dir]` | as the game's user: hardlinks every file created below `/tmp/EasyAntiCheat_EOS_Setup.*` into `/tmp/.eac-catch/` before EAC deletes it |
|
||||
| `efi-sig-list.py FILE...` | lists the certificates in efivarfs dumps or `.esl` files (sha256 prefix, subject, issuer) and counts duplicates |
|
||||
| `systemctl-trace` | logs argv, uid and parent to `$SYSTEMD_TRACE_DIR/systemd-trace.<uid>.log` (default `/tmp`) and exits with `$SYSTEMD_TRACE_RC` (default 0) |
|
||||
| `systemd1-trace [--session]` | owns `org.freedesktop.systemd1` on the system (or session) bus, prints every method call as a JSON line with the caller, replies `NotSupported` |
|
||||
| `systemd1-trace.conf` | D-Bus policy that lets root own `org.freedesktop.systemd1` on the system bus |
|
||||
|
||||
## Capturing a first launch
|
||||
|
||||
With `sys-apps/eac-openrc-compat` installed, its `systemctl` and
|
||||
`systemd-run-agent` already log every call to syslog. For a new EAC setup
|
||||
version, run as root and as the user, then launch the game:
|
||||
|
||||
```sh
|
||||
doas ./exec-snoop 1800 > /tmp/eac-snoop.log &
|
||||
./eac-catch 1800 &
|
||||
```
|
||||
|
||||
Afterwards: `grep -v pactl /tmp/eac-snoop.log`, the setup's
|
||||
`~/.cache/com.epicgames.easyanticheat/service.log`, and
|
||||
`strings /tmp/.eac-catch/*/EasyAntiCheat_EOS_Setup` for its commands, unit
|
||||
files and `--help` text.
|
||||
|
||||
## Without the compatibility layer
|
||||
|
||||
`systemctl-trace` and `systemd1-trace` were for the first captures, before the
|
||||
layer existed. Link `systemctl-trace` as `/usr/bin/systemctl` only when
|
||||
`eac-openrc-compat` is not installed (it owns that path):
|
||||
|
||||
```sh
|
||||
doas install -m644 systemd1-trace.conf /etc/dbus-1/system.d/
|
||||
doas ln -s "$PWD/systemctl-trace" /usr/bin/systemctl
|
||||
doas ./systemd1-trace > /tmp/systemd1-system.jsonl
|
||||
```
|
||||
|
||||
Remove both files afterwards. Never create `/run/systemd/system` for longer than
|
||||
a capture: other programs then assume systemd runs.
|
||||
Executable
+75
@@ -0,0 +1,75 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Hardlink every file created below <watch-dir>/<prefix>*, so it survives its creator deleting it.
|
||||
|
||||
Usage: eac-catch [seconds] [prefix] [watch-dir]
|
||||
Defaults: 1800, EasyAntiCheat_EOS_Setup., /tmp. Copies land in <watch-dir>/.eac-catch/ (a hardlink
|
||||
must stay on the same filesystem). Run it as the user who starts the game.
|
||||
"""
|
||||
import ctypes
|
||||
import os
|
||||
import select
|
||||
import struct
|
||||
import sys
|
||||
import time
|
||||
|
||||
secs = float(sys.argv[1]) if len(sys.argv) > 1 else 1800
|
||||
prefix = sys.argv[2] if len(sys.argv) > 2 else "EasyAntiCheat_EOS_Setup."
|
||||
top = sys.argv[3] if len(sys.argv) > 3 else "/tmp"
|
||||
stash = os.path.join(top, ".eac-catch")
|
||||
IN_CLOSE_WRITE, IN_MOVED_TO, IN_CREATE, IN_ISDIR = 0x8, 0x80, 0x100, 0x40000000
|
||||
|
||||
libc = ctypes.CDLL(None, use_errno=True)
|
||||
fd = libc.inotify_init1(os.O_CLOEXEC)
|
||||
dirs = {}
|
||||
|
||||
|
||||
def log(*args):
|
||||
print(time.strftime("%T"), *args, flush=True)
|
||||
|
||||
|
||||
def grab(path):
|
||||
dst = os.path.join(stash, os.path.relpath(path, top))
|
||||
os.makedirs(os.path.dirname(dst), exist_ok=True)
|
||||
try:
|
||||
os.link(path, dst)
|
||||
log("caught", path)
|
||||
except FileExistsError:
|
||||
pass
|
||||
except OSError as e:
|
||||
log("missed", path, e.strerror)
|
||||
|
||||
|
||||
def watch(path):
|
||||
wd = libc.inotify_add_watch(fd, path.encode(), IN_CREATE | IN_MOVED_TO | IN_CLOSE_WRITE)
|
||||
if wd < 0:
|
||||
log("cannot watch", path, os.strerror(ctypes.get_errno()))
|
||||
return
|
||||
dirs[wd] = path
|
||||
if path == top:
|
||||
return
|
||||
log("watching", path)
|
||||
# Entries created before the watch existed.
|
||||
for entry in os.scandir(path):
|
||||
watch(entry.path) if entry.is_dir(follow_symlinks=False) else grab(entry.path)
|
||||
|
||||
|
||||
watch(top)
|
||||
deadline = time.monotonic() + secs
|
||||
while (left := deadline - time.monotonic()) > 0:
|
||||
if not select.select([fd], [], [], left)[0]:
|
||||
break
|
||||
buf, i = os.read(fd, 65536), 0
|
||||
while i < len(buf):
|
||||
wd, mask, _, n = struct.unpack_from("iIII", buf, i)
|
||||
name = buf[i + 16:i + 16 + n].rstrip(b"\0").decode(errors="replace")
|
||||
i += 16 + n
|
||||
parent = dirs.get(wd)
|
||||
if parent is None or not name:
|
||||
continue
|
||||
path = os.path.join(parent, name)
|
||||
if parent == top and not name.startswith(prefix):
|
||||
continue
|
||||
try:
|
||||
watch(path) if mask & IN_ISDIR else grab(path)
|
||||
except FileNotFoundError:
|
||||
log("gone before it was caught", path)
|
||||
Executable
+62
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env python3
|
||||
"""List the entries of UEFI signature lists and count duplicates.
|
||||
|
||||
Usage: efi-sig-list.py FILE...
|
||||
FILE = an efivarfs dump (/sys/firmware/efi/efivars/{PK,KEK,db,dbx}-<guid> or a
|
||||
`cat` copy; the 4-byte attribute prefix is skipped) or a plain `.esl` file
|
||||
(e.g. from `sbctl enroll-keys --export esl`).
|
||||
Prints per entry: sha256 prefix, subject CN, issuer CN; then entries vs unique.
|
||||
No arguments runs a self-check.
|
||||
"""
|
||||
import hashlib
|
||||
import struct
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
X509 = bytes.fromhex("a159c0a5e494a74a87b5ab155c2bf072")
|
||||
SHA256 = bytes.fromhex("2616c4c14c509240aca941f936934328")
|
||||
|
||||
|
||||
def cn(der, field):
|
||||
out = subprocess.run(["openssl", "x509", "-inform", "DER", "-noout", f"-{field}", "-nameopt", "multiline"],
|
||||
input=der, capture_output=True).stdout.decode()
|
||||
return next((l.split("=", 1)[1].strip() for l in out.splitlines() if "commonName" in l), "?")
|
||||
|
||||
|
||||
def entries(b):
|
||||
i = 0
|
||||
while i + 28 <= len(b):
|
||||
stype = b[i:i + 16]
|
||||
lsize, hsize, ssize = struct.unpack_from("<III", b, i + 16)
|
||||
if lsize < 28:
|
||||
break
|
||||
j = i + 28 + hsize
|
||||
while j + ssize <= i + lsize:
|
||||
data = b[j + 16:j + ssize] # skip the owner GUID
|
||||
fp = hashlib.sha256(data).hexdigest()[:12]
|
||||
yield (fp, cn(data, "subject"), cn(data, "issuer")) if stype == X509 else (fp, "hash", "")
|
||||
j += ssize
|
||||
i += lsize
|
||||
|
||||
|
||||
def load(path):
|
||||
blob = open(path, "rb").read()
|
||||
return blob if path.endswith(".esl") else blob[4:]
|
||||
|
||||
|
||||
def selftest():
|
||||
sig = b"\0" * 16 + b"\x11" * 32
|
||||
lst = SHA256 + struct.pack("<III", 28 + 2 * len(sig), 0, len(sig)) + 2 * sig
|
||||
found = list(entries(lst))
|
||||
assert len(found) == 2 and len({f[0] for f in found}) == 1
|
||||
print("selftest ok")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) == 1:
|
||||
selftest()
|
||||
for path in sys.argv[1:]:
|
||||
found = list(entries(load(path)))
|
||||
print(f"{path}: {len(found)} entries, {len({f[0] for f in found})} unique")
|
||||
for fp, subject, issuer in found:
|
||||
print(f" {fp} {subject:<40} issued by {issuer}")
|
||||
Executable
+23
@@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
# Log every execve/execveat attempt, failed ones included, with the path and argv[0..5].
|
||||
# Uses tracefs event probes, so nothing is attached to the traced processes.
|
||||
# Usage (root): exec-snoop [seconds] > log
|
||||
set -eu
|
||||
secs=${1:-600}
|
||||
T=/sys/kernel/tracing
|
||||
I=$T/instances/exec-snoop
|
||||
A='a0=+0(+u0($argv)):ustring a1=+0(+u8($argv)):ustring a2=+0(+u16($argv)):ustring'
|
||||
A+=' a3=+0(+u24($argv)):ustring a4=+0(+u32($argv)):ustring a5=+0(+u40($argv)):ustring'
|
||||
|
||||
cleanup() {
|
||||
[[ -d $I ]] && { echo 0 > "$I/events/exec_snoop/enable"; rmdir "$I"; }
|
||||
for e in execve execveat; do echo "-:exec_snoop/$e" >> $T/dynamic_events 2>/dev/null || true; done
|
||||
}
|
||||
cleanup
|
||||
trap cleanup EXIT
|
||||
|
||||
echo "e:exec_snoop/execve syscalls.sys_enter_execve file=+0(\$filename):ustring $A" >> $T/dynamic_events
|
||||
echo "e:exec_snoop/execveat syscalls.sys_enter_execveat file=+0(\$filename):ustring $A" >> $T/dynamic_events
|
||||
mkdir "$I"
|
||||
echo 1 > "$I/events/exec_snoop/enable"
|
||||
timeout "$secs" cat "$I/trace_pipe" || true
|
||||
Executable
+60
@@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Log every exec, and the exit of every exec'd process, as JSON lines (kernel proc connector).
|
||||
|
||||
Needs root. Nothing is attached to the traced processes. Usage: exec-trace [seconds]
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import socket
|
||||
import struct
|
||||
import sys
|
||||
import time
|
||||
|
||||
NETLINK_CONNECTOR, CN_IDX_PROC, CN_VAL_PROC = 11, 1, 1
|
||||
PROC_CN_MCAST_LISTEN, PROC_EVENT_EXEC, PROC_EVENT_EXIT = 1, 0x2, 0x80000000
|
||||
|
||||
|
||||
def read(pid, name):
|
||||
try:
|
||||
with open(f"/proc/{pid}/{name}", "rb") as f:
|
||||
return f.read()
|
||||
except OSError:
|
||||
return b""
|
||||
|
||||
|
||||
def cmdline(pid):
|
||||
return read(pid, "cmdline").replace(b"\0", b" ").decode(errors="replace").strip()
|
||||
|
||||
|
||||
def emit(**fields):
|
||||
print(json.dumps({"time": time.strftime("%T"), **fields}), flush=True)
|
||||
|
||||
|
||||
sock = socket.socket(socket.AF_NETLINK, socket.SOCK_DGRAM, NETLINK_CONNECTOR)
|
||||
sock.bind((os.getpid(), CN_IDX_PROC))
|
||||
op = struct.pack("=I", PROC_CN_MCAST_LISTEN)
|
||||
cn = struct.pack("=4I2H", CN_IDX_PROC, CN_VAL_PROC, 0, 0, len(op), 0) + op
|
||||
sock.send(struct.pack("=IHHII", 16 + len(cn), 3, 0, 0, os.getpid()) + cn)
|
||||
|
||||
deadline = time.monotonic() + float(sys.argv[1]) if len(sys.argv) > 1 else None
|
||||
seen = {}
|
||||
while deadline is None or time.monotonic() < deadline:
|
||||
sock.settimeout(None if deadline is None else max(0.1, deadline - time.monotonic()))
|
||||
try:
|
||||
data = sock.recv(65536)
|
||||
except socket.timeout:
|
||||
break
|
||||
what = struct.unpack_from("=I", data, 36)[0]
|
||||
if what == PROC_EVENT_EXEC:
|
||||
tgid = struct.unpack_from("=ii", data, 52)[1]
|
||||
status = dict(l.split(":\t", 1) for l in read(tgid, "status").decode(errors="replace").splitlines() if ":\t" in l)
|
||||
ppid = status.get("PPid", "").strip()
|
||||
seen[tgid] = cmdline(tgid)
|
||||
emit(event="exec", pid=tgid, ppid=ppid, uid=status.get("Uid", "").split()[:2],
|
||||
exe=os.path.realpath(f"/proc/{tgid}/exe") if os.path.exists(f"/proc/{tgid}/exe") else "",
|
||||
cmd=seen[tgid], parent=cmdline(ppid)[:200] if ppid.isdigit() else "")
|
||||
elif what == PROC_EVENT_EXIT:
|
||||
pid, tgid, code, sig = struct.unpack_from("=iiII", data, 52)
|
||||
if pid == tgid and tgid in seen:
|
||||
emit(event="exit", pid=tgid, cmd=seen.pop(tgid)[:120],
|
||||
status=(code >> 8) if code & 0x7f == 0 else f"signal {code & 0x7f}")
|
||||
Executable
+11
@@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
# Logs every call and succeeds, so the caller moves on to its next step.
|
||||
log=${SYSTEMD_TRACE_DIR:-/tmp}/systemd-trace.$(id -u).log
|
||||
{
|
||||
printf '%s systemctl pid=%s uid=%s parent=%s\n' "$(date +%T.%N)" "$$" "$(id -u)" \
|
||||
"$(tr '\0' ' ' </proc/$PPID/cmdline)"
|
||||
printf ' argv:'
|
||||
printf ' %q' "$@"
|
||||
echo
|
||||
} >>"$log"
|
||||
exit "${SYSTEMD_TRACE_RC:-0}"
|
||||
Executable
+58
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Own org.freedesktop.systemd1 and log every method call as a JSON line.
|
||||
|
||||
Each call gets an org.freedesktop.DBus.Error.NotSupported reply, so the log shows
|
||||
the first call of every attempt. Reply with real values here once the calls are known.
|
||||
"""
|
||||
import json
|
||||
import sys
|
||||
import time
|
||||
|
||||
import dbus
|
||||
import dbus.lowlevel
|
||||
from dbus.mainloop.glib import DBusGMainLoop
|
||||
from gi.repository import GLib
|
||||
|
||||
NAME = "org.freedesktop.systemd1"
|
||||
|
||||
DBusGMainLoop(set_as_default=True)
|
||||
bus = dbus.SessionBus() if "--session" in sys.argv[1:] else dbus.SystemBus()
|
||||
commands = {}
|
||||
|
||||
|
||||
def command(sender):
|
||||
if sender not in commands:
|
||||
try:
|
||||
pid = bus.call_blocking("org.freedesktop.DBus", "/org/freedesktop/DBus",
|
||||
"org.freedesktop.DBus", "GetConnectionUnixProcessID",
|
||||
"s", (sender,))
|
||||
with open(f"/proc/{pid}/cmdline", "rb") as f:
|
||||
commands[sender] = f"{pid} " + f.read().replace(b"\0", b" ").decode().strip()
|
||||
except (dbus.DBusException, OSError) as e:
|
||||
commands[sender] = f"? ({e})"
|
||||
return commands[sender]
|
||||
|
||||
|
||||
def on_message(conn, msg):
|
||||
if msg.get_type() != dbus.lowlevel.MESSAGE_TYPE_METHOD_CALL or msg.get_destination() != NAME:
|
||||
return dbus.lowlevel.HANDLER_RESULT_NOT_YET_HANDLED
|
||||
print(json.dumps({
|
||||
"time": time.strftime("%T"),
|
||||
"sender": msg.get_sender(),
|
||||
"command": command(msg.get_sender()),
|
||||
"path": msg.get_path(),
|
||||
"method": f"{msg.get_interface()}.{msg.get_member()}",
|
||||
"signature": msg.get_signature(),
|
||||
"args": msg.get_args_list(),
|
||||
}, default=str), flush=True)
|
||||
if not msg.get_no_reply():
|
||||
conn.send_message(dbus.lowlevel.ErrorMessage(
|
||||
msg, "org.freedesktop.DBus.Error.NotSupported", "systemd1-trace: logged only"))
|
||||
return dbus.lowlevel.HANDLER_RESULT_HANDLED
|
||||
|
||||
|
||||
bus.add_message_filter(on_message)
|
||||
if bus.request_name(NAME, dbus.bus.NAME_FLAG_DO_NOT_QUEUE) != dbus.bus.REQUEST_NAME_REPLY_PRIMARY_OWNER:
|
||||
sys.exit(f"{NAME} is already owned")
|
||||
print(f"owning {NAME}", file=sys.stderr, flush=True)
|
||||
GLib.MainLoop().run()
|
||||
@@ -0,0 +1,10 @@
|
||||
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
|
||||
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
|
||||
<busconfig>
|
||||
<policy user="root">
|
||||
<allow own="org.freedesktop.systemd1"/>
|
||||
</policy>
|
||||
<policy context="default">
|
||||
<allow send_destination="org.freedesktop.systemd1"/>
|
||||
</policy>
|
||||
</busconfig>
|
||||
Reference in New Issue
Block a user