Files
magpie/internal/redact/symbol_test.go
T
yetone d6df72a2ba redact: a disassembly's symbols (system@plt, foo@@GLIBC_2.2.5, system@got) are no email
ch35tnut_ on X: reversing, symbols like system@plt were masked as
emails, so masking had to be turned off for reverse engineering.

The rule's regexp already needs a dot and a mail TLD (mailTLD), so
system@plt, puts@got.plt and memcpy@GLIBC_2.14 went as written by it at
origin/main. The local model's EMAIL spans pass realEmail too, which
never asked for a dot: .got is an ICANN top-level domain, so a model
span on system@got (IDA's "; system@got") was masked. And a
foo@plt.got ends in .got with a dot, so the rule masked that too.

realEmail now asks mailHost first, for the rule and the model alike: the
host has a dot, every label is letters, digits and hyphens (or non-ASCII,
an IDN's), no label empty, the local part does not end in @ (foo@@VER),
and the host is not made of linker table words alone (plt, got, sec,
iplt, igot: free@plt.got, memcpy@plt.sec). A version with an underscore
(@GLIBC_2_2_5) or no dot (@Base, @GLIBC_PRIVATE) is no host.

TestSymbolIsNoEmail has objdump, readelf, nm, gdb and IDA lines as they
print them, for the rule and for a fake model flagging each symbol as
private_email, and checks that rina.k@fastmail.com in code and
ops@build01.acme.io beside a symbol are still masked by both.

Run at this head (origin/main aca0f0d8a), through mote-run:
- go test ./internal/redact ./internal/pii ./internal/masking
  -count=1 -timeout 45m: ok, ok, ok.
- gofmt -l clean; go vet of the three on darwin, GOOS=linux -tags nogui
  and GOOS=windows: clean.

Broken by hand:
- mailHost's call made `false &&`: TestSymbolIsNoEmail red, the model
  masked "; system@got" as {{EMAIL_…}}.
- linker check made `return true || !linker`: red, rule and model both
  masked <free@plt.got>.

Not tried: the real local model (AstrLink / Privacy Filter) on a
disassembly; the fake model stands in for its spans. Full go test ./...
not run; this touches internal/redact and its doc only.
2026-10-28 17:23:59 +08:00

70 lines
3.1 KiB
Go

package redact
import (
"strings"
"testing"
)
// A disassembly's symbols read as addresses: a function reached through
// the PLT or the GOT (system@plt, puts@got.plt) and a symbol's version
// (memcpy@GLIBC_2.14, foo@@GLIBC_2.2.5). .got is a top-level domain, and
// the local model took system@got for an email, so a reverse engineer
// had to turn masking off (ch35tnut_ on X, 10-28). These are objdump's,
// readelf's, nm's, gdb's and IDA's lines as they print them.
var symbolLines = []string{
" 401126:\te8 05 ff ff ff \tcall 401030 <system@plt>",
"0000000000401030 <system@plt>:",
" 401030:\tff 25 e2 2f 00 00 \tjmp *0x2fe2(%rip) # 404018 <system@GLIBC_2.2.5>",
" 4011a2:\tff 15 48 2e 00 00 \tcall *0x2e48(%rip) # 403ff0 <puts@got.plt>",
" 401156:\te8 e5 fe ff ff \tcall 401040 <_ZNSt8ios_base4InitC1Ev@plt>",
" 7: 0000000000000000 0 FUNC GLOBAL DEFAULT UND printf@GLIBC_2.2.5 (2)",
"0000000000000000 F *UND*\t0000000000000000 memcpy@GLIBC_2.14",
"0000000000001139 g F .text\t000000000000001e foo@@GLIBC_2.2.5",
" U __libc_start_main@GLIBC_2.34",
" foo@Base 1.0",
" 0x0000555555555171 <+8>:\tcall 0x555555555030 <printf@plt>",
"\tcall\tprintf@PLT",
"call _system",
".plt.sec:0000000000001060 jmp cs:off_3FD0 ; system@got",
"extrn system@@GLIBC_2_2_5:near",
" 401040:\tff 25 d2 2f 00 00 \tjmp *0x2fd2(%rip) # 404018 <memcpy@plt.sec>",
" 401050:\tff 25 ca 2f 00 00 \tjmp *0x2fca(%rip) # 403fe0 <free@plt.got>",
}
func TestSymbolIsNoEmail(t *testing.T) {
o := Options{Secrets: true, Personal: true}
for _, s := range symbolLines {
if out, n := Mask(s, o); n != 0 || out != s {
t.Errorf("rule: %q masked: %q", s, out)
}
}
// nor does the local model's EMAIL take one
f := &fakeModel{values: map[string]string{}}
for _, v := range []string{"system@plt", "system@GLIBC_2.2.5", "puts@got.plt", "_ZNSt8ios_base4InitC1Ev@plt",
"printf@GLIBC_2.2.5", "memcpy@GLIBC_2.14", "foo@@GLIBC_2.2.5", "__libc_start_main@GLIBC_2.34", "foo@Base",
"printf@plt", "printf@PLT", "system@got", "free@plt.got", "system@@GLIBC_2_2_5", "memcpy@plt.sec"} {
f.values[v] = "private_email"
}
for _, s := range symbolLines {
if out, n := Mask(s, Options{Personal: true, Model: f.find}); n != 0 {
t.Errorf("model: %q masked: %q", s, out)
}
}
// an address is still one: in prose, in code, at a host, by the model
f = &fakeModel{values: map[string]string{"rina.k@fastmail.com": "private_email", "ops@build01.acme.io": "private_email"}}
for _, s := range []string{
"call 401030 <system@plt> then mail rina.k@fastmail.com",
` const owner = "rina.k@fastmail.com" // see <puts@got.plt>`,
"objdump -d ./a.out | grep system@plt, and send it to ops@build01.acme.io",
} {
for _, m := range []Model{nil, f.find} {
out, n := Mask(s, Options{Personal: true, Model: m})
if n != 1 || strings.Contains(out, "rina.k@") || strings.Contains(out, "ops@build01") || !strings.Contains(out, "puts@got.plt") && !strings.Contains(out, "system@plt") {
t.Errorf("%q: %d masked: %q", s, n, out)
}
}
}
}