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.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -130,7 +130,8 @@ func modelTakes(kind, v string) bool {
|
||||
return !madeID(v)
|
||||
case "EMAIL":
|
||||
// as the rule's: a file's name (icon@2x.png) or an example's is no
|
||||
// address, nor a host's name with no @ (eu.stg.acme.io)
|
||||
// address, nor a host's name with no @ (eu.stg.acme.io), nor a
|
||||
// symbol (system@got, foo@@GLIBC_2.2.5): realEmail's mailHost
|
||||
return strings.Contains(v, "@") && realEmail(v)
|
||||
}
|
||||
return true
|
||||
|
||||
@@ -441,6 +441,9 @@ func realEmail(v string) bool {
|
||||
return false
|
||||
}
|
||||
host := strings.ToLower(v[at+1:])
|
||||
if !mailHost(v[:at], host) {
|
||||
return false
|
||||
}
|
||||
if fileHost(host) || docFiles[host] || !mailTLD(host[strings.LastIndexByte(host, '.')+1:]) {
|
||||
return false
|
||||
}
|
||||
@@ -452,6 +455,34 @@ func realEmail(v string) bool {
|
||||
return !strings.HasPrefix(host, "noreply") && !strings.Contains(v, "noreply@")
|
||||
}
|
||||
|
||||
// mailHost is whether host, after local and an @, can be a mail domain:
|
||||
// it has a dot, labels of letters, digits and hyphens (or a name's own
|
||||
// script's: 例子.中国), and is not a
|
||||
// linker's table; and local has no @ of its own. A disassembly's symbols
|
||||
// read as addresses: system@plt, puts@got.plt, a version after one @ or
|
||||
// two (memcpy@GLIBC_2.14, foo@@GLIBC_2.2.5, foo@Base). .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).
|
||||
func mailHost(local, host string) bool {
|
||||
if strings.HasSuffix(local, "@") || !strings.Contains(host, ".") || strings.Trim(host, ".") != host {
|
||||
return false
|
||||
}
|
||||
linker := true
|
||||
for _, l := range strings.Split(host, ".") {
|
||||
if l == "" || strings.ContainsFunc(l, func(r rune) bool { return r < 0x80 && r != '-' && !(r >= 'a' && r <= 'z') && !(r >= '0' && r <= '9') }) {
|
||||
return false
|
||||
}
|
||||
if !linkerWords[l] {
|
||||
linker = false
|
||||
}
|
||||
}
|
||||
return !linker
|
||||
}
|
||||
|
||||
// linkerWords are the names of a binary's tables a symbol is reached
|
||||
// through (system@plt, puts@got.plt, foo@plt.sec), no domain's labels.
|
||||
var linkerWords = map[string]bool{"plt": true, "got": true, "sec": true, "iplt": true, "igot": true}
|
||||
|
||||
// docFiles are the files agents read by name, on a domain's ending
|
||||
// (.md): "@AGENTS.md" after a word, as a prompt names one, is no address
|
||||
// (ydzh on Discord: xxx@Agents.md was masked).
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user