CyberStrikeAI/internal/surfaceingest/precipitation_test.go

57 lines
1.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package surfaceingest
import "testing"
func TestExtractPrecipitatedTargetsFiltersNoiseAndKeepsProjectAssets(t *testing.T) {
structured := []string{
"主域名 cargosmart.com,发现子域 portal.cargosmart.com、https://api.cargosmart.com:8443/v1/auth 和后台 203.0.113.25:8080",
"脚本 exploit.py 读取 config.json、web.xml、login.jsp、spac.do,本地 127.0.0.1:4444,参考 https://github.com/projectdiscovery/httpx 与 xxx.dnslog.cn",
}
prose := []string{
"subfinder 结果:edi.cargosmart.com\nhttps://owasp.org/www-project-top-ten/\nhttp://169.254.169.254/latest/meta-data/\nhttps://admin.hxt.com.cn/console\n无关裸词 other-company.org",
}
excluded := []ScopeSeed{{Domain: "skip.cargosmart.com"}}
hits := ExtractPrecipitatedTargets(structured, prose, nil, excluded)
got := map[string]bool{}
for _, hit := range hits {
if hit.Domain != "" {
got[hit.Domain] = true
}
if hit.IP != "" {
got[hit.IP] = true
}
}
for _, want := range []string{
"cargosmart.com",
"portal.cargosmart.com",
"api.cargosmart.com",
"edi.cargosmart.com",
"admin.hxt.com.cn",
"203.0.113.25",
} {
if !got[want] {
t.Fatalf("missing expected precipitated target %s in %+v", want, hits)
}
}
for _, unwanted := range []string{
"exploit.py",
"config.json",
"web.xml",
"login.jsp",
"spac.do",
"127.0.0.1",
"169.254.169.254",
"github.com",
"xxx.dnslog.cn",
"owasp.org",
"other-company.org",
} {
if got[unwanted] {
t.Fatalf("noise token %s leaked into precipitated targets: %+v", unwanted, hits)
}
}
}