Skip to content

Commit 037d00a

Browse files
committed
starting to perform deduplication of discovered Organizations
1 parent 97937f7 commit 037d00a

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

engine/plugins/rdap/plugin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func (rd *rdapPlugin) storeEntity(e *et.Event, level int, entity *rdap.Entity, a
243243
_ = rd.createContactEdge(e.Session, cr, a, &general.SimpleRelation{Name: "person"}, src)
244244
}
245245
}
246-
} else if name != "" && m.IsMatch(string(oam.Organization)) {
246+
} else if m.IsMatch(string(oam.Organization)) && name != "" && !support.OrgNameExistsInContactRecord(e.Session, cr, name) {
247247
if a, err := e.Session.Cache().CreateAsset(&org.Organization{
248248
ID: uuid.New().String(),
249249
Name: name,

engine/plugins/support/database.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
oamcert "github.com/owasp-amass/open-asset-model/certificate"
2121
oamdns "github.com/owasp-amass/open-asset-model/dns"
2222
"github.com/owasp-amass/open-asset-model/general"
23+
"github.com/owasp-amass/open-asset-model/org"
2324
"github.com/owasp-amass/open-asset-model/platform"
2425
oamreg "github.com/owasp-amass/open-asset-model/registration"
2526
)
@@ -233,3 +234,20 @@ func CreateServiceAsset(session et.Session, src *dbt.Entity, rel oam.Relation, s
233234
})
234235
return result, err
235236
}
237+
238+
func OrgNameExistsInContactRecord(session et.Session, cr *dbt.Entity, name string) bool {
239+
if cr == nil {
240+
return false
241+
}
242+
243+
if edges, err := session.Cache().OutgoingEdges(cr, time.Time{}, "organization"); err == nil && len(edges) > 0 {
244+
for _, edge := range edges {
245+
if a, err := session.Cache().FindEntityById(edge.ToEntity.ID); err == nil && a != nil {
246+
if org, ok := a.Asset.(*org.Organization); ok && strings.EqualFold(org.Name, name) {
247+
return true
248+
}
249+
}
250+
}
251+
}
252+
return false
253+
}

engine/plugins/whois/domain_record.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ func (r *domrec) storeContact(e *et.Event, c *domrecContact, dr *dbt.Entity, m *
224224
}
225225
}
226226
}
227-
if wc.Organization != "" && m.IsMatch(string(oam.Organization)) {
227+
if m.IsMatch(string(oam.Organization)) && wc.Organization != "" &&
228+
!support.OrgNameExistsInContactRecord(e.Session, cr, wc.Organization) {
228229
if a, err := e.Session.Cache().CreateAsset(&org.Organization{
229230
ID: uuid.New().String(),
230231
Name: wc.Organization,

utils/viz/viz.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ func newNode(db repository.Repository, idx int, a *types.Entity, since time.Time
215215
parts := []string{v.BuildingNumber, v.StreetName, v.City, v.Province, v.PostalCode}
216216
key = strings.Join(parts, " ")
217217
case *org.Organization:
218-
key = fmt.Sprintf("%s, %s", v.Name, v.ID)
218+
key = fmt.Sprintf("%s (%s)", v.Name, v.ID)
219219
case *oamcert.TLSCertificate:
220-
key = fmt.Sprintf("%s, %s", v.SubjectCommonName, v.SerialNumber)
220+
key = fmt.Sprintf("%s (%s)", v.SubjectCommonName, v.SerialNumber)
221221
}
222222
title := fmt.Sprintf("%s: %s", atype, key)
223223

0 commit comments

Comments
 (0)