Skip to content

Commit 2b5c7fc

Browse files
committed
updates related to the Identifier asset type changes
1 parent 24b874d commit 2b5c7fc

File tree

8 files changed

+71
-28
lines changed

8 files changed

+71
-28
lines changed

engine/plugins/enrich/email.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ func (ee *emailexpand) Stop() {
5959
}
6060

6161
func (ee *emailexpand) check(e *et.Event) error {
62-
if id, ok := e.Entity.Asset.(*general.Identifier); !ok || id == nil || id.Type != general.EmailAddress {
62+
if id, ok := e.Entity.Asset.(*general.Identifier); !ok ||
63+
id == nil || id.Type != general.EmailAddress || id.EntityID == "" {
6364
return nil
6465
}
6566

@@ -73,7 +74,7 @@ func (ee *emailexpand) store(e *et.Event, asset *dbt.Entity) []*support.Finding
7374
var findings []*support.Finding
7475
oame := asset.Asset.(*general.Identifier)
7576

76-
parts := strings.Split(oame.ID, "@")
77+
parts := strings.Split(oame.EntityID, "@")
7778
if len(parts) != 2 {
7879
return findings
7980
}

engine/plugins/enrich/tls_cert.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"crypto/x509"
99
"crypto/x509/pkix"
1010
"errors"
11+
"fmt"
1112
"log/slog"
1213
"net/netip"
1314
"strings"
@@ -211,10 +212,14 @@ func (te *tlsexpand) store(e *et.Event, cert *x509.Certificate, asset *dbt.Entit
211212
if m.IsMatch(string(oam.Identifier)) {
212213
for _, emailstr := range cert.EmailAddresses {
213214
email := strings.ToLower(strings.TrimSpace(emailstr))
215+
if email == "" {
216+
continue
217+
}
214218

215219
if a, err := e.Session.Cache().CreateAsset(&general.Identifier{
216-
ID: email,
217-
Type: general.EmailAddress,
220+
UniqueID: fmt.Sprintf("%s:%s", general.EmailAddress, email),
221+
EntityID: email,
222+
Type: general.EmailAddress,
218223
}); err == nil && a != nil {
219224
findings = append(findings, &support.Finding{
220225
From: asset,

engine/plugins/rdap/plugin.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package rdap
77
import (
88
"crypto/tls"
99
"errors"
10+
"fmt"
1011
"log/slog"
1112
"net/http"
1213
"path/filepath"
@@ -258,10 +259,13 @@ func (rd *rdapPlugin) storeEntity(e *et.Event, level int, entity *rdap.Entity, a
258259
}
259260
}
260261
}
261-
if m.IsMatch(string(oam.Identifier)) {
262+
if m.IsMatch(string(oam.Identifier)) && v.Email() != "" {
263+
email := strings.ToLower(v.Email())
264+
262265
if a, err := e.Session.Cache().CreateAsset(&general.Identifier{
263-
ID: v.Email(),
264-
Type: general.EmailAddress,
266+
UniqueID: fmt.Sprintf("%s:%s", general.EmailAddress, email),
267+
EntityID: email,
268+
Type: general.EmailAddress,
265269
}); err == nil && a != nil {
266270
_ = rd.createContactEdge(e.Session, cr, a, &general.SimpleRelation{Name: "id"}, src)
267271
}

engine/plugins/support/database.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ package support
66

77
import (
88
"errors"
9+
"fmt"
910
"log/slog"
1011
"net/netip"
1112
"strconv"
13+
"strings"
1214
"time"
1315

1416
et "github.com/owasp-amass/amass/v4/engine/types"
@@ -35,7 +37,15 @@ func SourceToAssetsWithinTTL(session et.Session, name, atype string, src *et.Sou
3537

3638
entities, _ = utils.FindByFQDNScope(session.Cache(), root, since)
3739
case string(oam.Identifier):
38-
entities, _ = session.Cache().FindEntitiesByContent(&general.Identifier{ID: name}, since)
40+
if parts := strings.Split(name, ":"); len(parts) == 2 {
41+
id := &general.Identifier{
42+
UniqueID: name,
43+
EntityID: parts[1],
44+
Type: parts[0],
45+
}
46+
47+
entities, _ = session.Cache().FindEntitiesByContent(id, since)
48+
}
3949
case string(oam.AutnumRecord):
4050
num, err := strconv.Atoi(name)
4151
if err != nil {
@@ -96,10 +106,13 @@ func StoreEmailsWithSource(session et.Session, emails []string, src *et.Source,
96106
return results
97107
}
98108

99-
for _, email := range emails {
109+
for _, e := range emails {
110+
email := strings.ToLower(e)
111+
100112
if a, err := session.Cache().CreateAsset(&general.Identifier{
101-
ID: email,
102-
Type: general.EmailAddress,
113+
UniqueID: fmt.Sprintf("%s:%s", general.EmailAddress, email),
114+
EntityID: email,
115+
Type: general.EmailAddress,
103116
}); err == nil && a != nil {
104117
results = append(results, a)
105118
_, _ = session.Cache().CreateEntityProperty(a, &general.SourceProperty{

engine/plugins/support/dispatch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func ProcessFQDNsWithSource(e *et.Event, entities []*dbt.Entity, src *et.Source)
7171
func ProcessEmailsWithSource(e *et.Event, entities []*dbt.Entity, src *et.Source) {
7272
for _, entity := range entities {
7373
email, ok := entity.Asset.(*general.Identifier)
74-
if !ok || email == nil || email.Type != general.EmailAddress {
74+
if !ok || email == nil || email.Type != general.EmailAddress || email.EntityID == "" {
7575
continue
7676
}
7777

@@ -93,7 +93,7 @@ func ProcessEmailsWithSource(e *et.Event, entities []*dbt.Entity, src *et.Source
9393
})
9494

9595
_ = e.Dispatcher.DispatchEvent(&et.Event{
96-
Name: email.ID,
96+
Name: email.UniqueID,
9797
Meta: meta,
9898
Entity: entity,
9999
Session: e.Session,

engine/plugins/whois/domain_record.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,11 @@ func (r *domrec) storeContact(e *et.Event, c *domrecContact, dr *dbt.Entity, m *
233233
r.createSimpleEdge(e.Session.Cache(), &general.SimpleRelation{Name: "location"}, cr, a)
234234
}
235235
}
236-
if m.IsMatch(string(oam.Identifier)) {
236+
if email := strings.ToLower(wc.Email); m.IsMatch(string(oam.Identifier)) && email != "" {
237237
if a, err := e.Session.Cache().CreateAsset(&general.Identifier{
238-
ID: wc.Email,
239-
Type: general.EmailAddress,
238+
UniqueID: fmt.Sprintf("%s:%s", general.EmailAddress, email),
239+
EntityID: email,
240+
Type: general.EmailAddress,
240241
}); err == nil && a != nil {
241242
r.createSimpleEdge(e.Session.Cache(), &general.SimpleRelation{Name: "id"}, cr, a)
242243
}

engine/sessions/scope/assoc.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
oam "github.com/owasp-amass/open-asset-model"
1919
oamcert "github.com/owasp-amass/open-asset-model/certificate"
2020
"github.com/owasp-amass/open-asset-model/contact"
21-
"github.com/owasp-amass/open-asset-model/dns"
21+
oamdns "github.com/owasp-amass/open-asset-model/dns"
2222
oamnet "github.com/owasp-amass/open-asset-model/network"
2323
"github.com/owasp-amass/open-asset-model/org"
2424
oamreg "github.com/owasp-amass/open-asset-model/registration"
@@ -378,7 +378,7 @@ func (s *Scope) IsAddressInScope(c *cache.Cache, ip *oamnet.IPAddress) bool {
378378

379379
if edges, err := c.IncomingEdges(addr, c.StartTime(), "dns_record"); err == nil && len(edges) > 0 {
380380
for _, edge := range edges {
381-
if rec, ok := edge.Relation.(*dns.BasicDNSRelation); ok && rec.Header.RRType == rtype {
381+
if rec, ok := edge.Relation.(*oamdns.BasicDNSRelation); ok && rec.Header.RRType == rtype {
382382
from, err := c.FindEntityById(edge.FromEntity.ID)
383383
if err != nil {
384384
continue

engine/sessions/scope/scope.go

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import (
1111
oam "github.com/owasp-amass/open-asset-model"
1212
oamcert "github.com/owasp-amass/open-asset-model/certificate"
1313
"github.com/owasp-amass/open-asset-model/contact"
14-
"github.com/owasp-amass/open-asset-model/dns"
14+
oamdns "github.com/owasp-amass/open-asset-model/dns"
15+
"github.com/owasp-amass/open-asset-model/general"
1516
oamnet "github.com/owasp-amass/open-asset-model/network"
1617
"github.com/owasp-amass/open-asset-model/org"
1718
oamreg "github.com/owasp-amass/open-asset-model/registration"
@@ -22,10 +23,12 @@ func (s *Scope) Add(a oam.Asset) bool {
2223
var newentry bool
2324

2425
switch v := a.(type) {
25-
case *dns.FQDN:
26+
case *oamdns.FQDN:
2627
newentry = s.AddFQDN(v)
27-
/*case *contact.EmailAddress:
28-
newentry = s.AddFQDN(&domain.FQDN{Name: v.Domain})*/
28+
case *general.Identifier:
29+
if domain, found := getEmailDomain(v); found {
30+
newentry = s.AddFQDN(&oamdns.FQDN{Name: domain})
31+
}
2932
case *oamnet.IPAddress:
3033
newentry = s.AddIPAddress(v)
3134
case *oamnet.Netblock:
@@ -62,18 +65,20 @@ func (s *Scope) IsAssetInScope(a oam.Asset, conf int) (oam.Asset, int) {
6265
var match oam.Asset
6366

6467
switch v := a.(type) {
65-
case *dns.FQDN:
68+
case *oamdns.FQDN:
6669
match, accuracy = s.matchesDomain(v)
67-
/*case *contact.EmailAddress:
68-
match, accuracy = s.matchesDomain(&domain.FQDN{Name: v.Domain})*/
70+
case *general.Identifier:
71+
if domain, found := getEmailDomain(v); found {
72+
match, accuracy = s.matchesDomain(&oamdns.FQDN{Name: domain})
73+
}
6974
case *oamnet.IPAddress:
7075
match, accuracy = s.addressInScope(v)
7176
case *oamnet.Netblock:
7277
match, accuracy = s.matchesNetblock(v)
7378
case *oamnet.AutonomousSystem:
7479
match, accuracy = s.matchesAutonomousSystem(v)
7580
case *oamreg.DomainRecord:
76-
match, accuracy = s.matchesDomain(&dns.FQDN{Name: v.Domain})
81+
match, accuracy = s.matchesDomain(&oamdns.FQDN{Name: v.Domain})
7782
if match == nil || accuracy == 0 {
7883
match, accuracy = s.matchesOrg(&org.Organization{Name: v.Name}, conf)
7984
}
@@ -85,9 +90,9 @@ func (s *Scope) IsAssetInScope(a oam.Asset, conf int) (oam.Asset, int) {
8590
match, accuracy = s.matchesOrg(&org.Organization{Name: v.Name}, conf)
8691
}
8792
case *oamcert.TLSCertificate:
88-
match, accuracy = s.matchesDomain(&dns.FQDN{Name: v.SubjectCommonName})
93+
match, accuracy = s.matchesDomain(&oamdns.FQDN{Name: v.SubjectCommonName})
8994
case *oamurl.URL:
90-
match, accuracy = s.matchesDomain(&dns.FQDN{Name: v.Host})
95+
match, accuracy = s.matchesDomain(&oamdns.FQDN{Name: v.Host})
9196
case *org.Organization:
9297
match, accuracy = s.matchesOrg(v, conf)
9398
case *contact.Location:
@@ -107,3 +112,17 @@ func (s *Scope) isBadField(field string) bool {
107112
}
108113
return false
109114
}
115+
116+
func getEmailDomain(email *general.Identifier) (string, bool) {
117+
if email == nil || email.Type != general.EmailAddress {
118+
return "", false
119+
}
120+
121+
parts := strings.Split(email.EntityID, "@")
122+
123+
if len(parts) != 2 {
124+
return "", false
125+
}
126+
127+
return parts[1], true
128+
}

0 commit comments

Comments
 (0)