Skip to content

Commit ab618ad

Browse files
committed
changes related to scope expansion
1 parent fa2e576 commit ab618ad

File tree

4 files changed

+41
-92
lines changed

4 files changed

+41
-92
lines changed

engine/plugins/horizontals/contact.go

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
package horizontals
66

77
import (
8-
"context"
98
"errors"
10-
"time"
119

1210
"github.com/owasp-amass/amass/v5/engine/plugins/support"
1311
et "github.com/owasp-amass/amass/v5/engine/types"
@@ -41,14 +39,17 @@ func (h *horContact) check(e *et.Event) error {
4139
if conf == -1 {
4240
conf = matches.Confidence(string(oam.ContactRecord))
4341
}
42+
if conf == -1 {
43+
return nil
44+
}
4445

4546
since, err := support.TTLStartTime(e.Session.Config(),
4647
string(oam.ContactRecord), string(oam.ContactRecord), h.plugin.name)
4748
if err != nil {
4849
return nil
4950
}
5051

51-
if assocs := h.lookup(e, e.Entity, since, conf); len(assocs) > 0 {
52+
if assocs := h.lookup(e, e.Entity, conf); len(assocs) > 0 {
5253
var impacted []*dbt.Entity
5354

5455
for _, assoc := range assocs {
@@ -65,28 +66,14 @@ func (h *horContact) check(e *et.Event) error {
6566
return nil
6667
}
6768

68-
func (h *horContact) lookup(e *et.Event, entity *dbt.Entity, since time.Time, conf int) []*et.Association {
69-
labels := []string{"organization", "location", "id"}
70-
71-
ctx, cancel := context.WithTimeout(e.Session.Ctx(), 5*time.Second)
72-
defer cancel()
73-
74-
var results []*et.Association
75-
if edges, err := e.Session.DB().OutgoingEdges(ctx, entity, since, labels...); err == nil && len(edges) > 0 {
76-
for _, edge := range edges {
77-
to, err := e.Session.DB().FindEntityById(ctx, edge.ToEntity.ID)
78-
if err != nil {
79-
continue
80-
}
81-
// check if these asset discoveries could change the scope
82-
if assocs, err := e.Session.Scope().IsAssociated(&et.Association{
83-
Submission: to,
84-
Confidence: conf,
85-
ScopeChange: true,
86-
}); err == nil && len(assocs) > 0 {
87-
results = append(results, assocs...)
88-
}
89-
}
69+
func (h *horContact) lookup(e *et.Event, asset *dbt.Entity, conf int) []*et.Association {
70+
assocs, err := e.Session.Scope().IsAssociated(&et.Association{
71+
Submission: asset,
72+
Confidence: conf,
73+
ScopeChange: true,
74+
})
75+
if err != nil {
76+
return nil
9077
}
91-
return results
78+
return assocs
9279
}

engine/plugins/horizontals/plugin.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,13 @@ func (h *horizPlugin) Start(r et.Registry) error {
9494
Name: h.horContact.name,
9595
Position: 10,
9696
MaxInstances: support.MaxHandlerInstances,
97-
Transforms: []string{string(oam.ContactRecord)},
98-
EventType: oam.ContactRecord,
99-
Callback: h.horContact.check,
97+
Transforms: []string{
98+
string(oam.Organization),
99+
string(oam.Location),
100+
string(oam.Identifier),
101+
},
102+
EventType: oam.ContactRecord,
103+
Callback: h.horContact.check,
100104
}); err != nil {
101105
return err
102106
}
@@ -166,16 +170,16 @@ func (h *horizPlugin) process(e *et.Event, since time.Time, assets []*dbt.Entity
166170
}
167171
}
168172

173+
_, _ = e.Session.DB().CreateEntityProperty(ctx, asset, &oamgen.SourceProperty{
174+
Source: h.source.Name,
175+
Confidence: h.source.Confidence,
176+
})
177+
169178
_ = e.Dispatcher.DispatchEvent(&et.Event{
170179
Name: asset.Asset.Key(),
171180
Entity: asset,
172181
Session: e.Session,
173182
})
174-
175-
_, _ = e.Session.DB().CreateEntityProperty(ctx, asset, &oamgen.SourceProperty{
176-
Source: h.source.Name,
177-
Confidence: h.source.Confidence,
178-
})
179183
}
180184
}
181185

engine/sessions/scope/assoc.go

Lines changed: 16 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
oam "github.com/owasp-amass/open-asset-model"
2020
oamcert "github.com/owasp-amass/open-asset-model/certificate"
2121
oamcon "github.com/owasp-amass/open-asset-model/contact"
22+
oamdns "github.com/owasp-amass/open-asset-model/dns"
2223
oamorg "github.com/owasp-amass/open-asset-model/org"
2324
oamreg "github.com/owasp-amass/open-asset-model/registration"
2425
"golang.org/x/net/publicsuffix"
@@ -48,13 +49,6 @@ func (s *Scope) IsAssociated(req *et.Association) ([]*et.Association, error) {
4849
impacted = append(impacted, im)
4950
}
5051
}
51-
// review all previously seen assets that provide association for scope changes
52-
for size := len(impacted); size > 0; {
53-
added := s.reviewAndUpdate(req)
54-
55-
size = len(added)
56-
impacted = append(impacted, added...)
57-
}
5852

5953
result.ImpactedAssets = impacted
6054
if len(result.ImpactedAssets) > 0 {
@@ -80,43 +74,6 @@ func (s *Scope) addScopeChangesToRationale(result *et.Association) {
8074
result.Rationale += ". The following assets were added to the session scope: " + strings.Join(changes, ", ")
8175
}
8276

83-
func (s *Scope) reviewAndUpdate(req *et.Association) []*dbt.Entity {
84-
var assocs []*dbt.Entity
85-
86-
ctx, cancel := context.WithTimeout(s.Session.Ctx(), 10*time.Second)
87-
defer cancel()
88-
89-
since := s.ttlStartTime(oam.DomainRecord, oam.DomainRecord)
90-
if drs, err := s.Session.DB().FindEntitiesByType(ctx, oam.DomainRecord, since, 0); err == nil && len(drs) > 0 {
91-
assocs = append(assocs, drs...)
92-
}
93-
94-
since = s.ttlStartTime(oam.IPNetRecord, oam.IPNetRecord)
95-
if iprecs, err := s.Session.DB().FindEntitiesByType(ctx, oam.IPNetRecord, since, 0); err == nil && len(iprecs) > 0 {
96-
assocs = append(assocs, iprecs...)
97-
}
98-
99-
since = s.ttlStartTime(oam.AutnumRecord, oam.AutnumRecord)
100-
if autnums, err := s.Session.DB().FindEntitiesByType(ctx, oam.AutnumRecord, since, 0); err == nil && len(autnums) > 0 {
101-
assocs = append(assocs, autnums...)
102-
}
103-
104-
since = s.ttlStartTime(oam.TLSCertificate, oam.TLSCertificate)
105-
if certs, err := s.Session.DB().FindEntitiesByType(ctx, oam.TLSCertificate, since, 0); err == nil && len(certs) > 0 {
106-
assocs = append(assocs, certs...)
107-
}
108-
109-
var impacted []*dbt.Entity
110-
for _, assoc := range s.checkRelatedAssetsforAssoc(req, assocs) {
111-
for _, a := range append(assoc.ImpactedAssets, assoc.Match) {
112-
if s.Add(a.Asset) {
113-
impacted = append(impacted, a)
114-
}
115-
}
116-
}
117-
return impacted
118-
}
119-
12077
func (s *Scope) checkRelatedAssetsforAssoc(req *et.Association, assocs []*dbt.Entity) []*et.Association {
12178
var results []*et.Association
12279

@@ -129,14 +86,17 @@ func (s *Scope) checkRelatedAssetsforAssoc(req *et.Association, assocs []*dbt.En
12986
if req.ScopeChange {
13087
impacted = append(impacted, asset)
13188
}
132-
if match, conf := s.IsAssetInScope(asset.Asset, req.Confidence); conf > 0 {
89+
90+
atype := asset.Asset.AssetType()
91+
rconf := s.confidence(atype, atype)
92+
if match, conf := s.IsAssetInScope(asset.Asset, rconf); conf > 0 {
13393
if conf > best {
13494
best = conf
13595

13696
aa := assoc.Asset
13797
sa := req.Submission.Asset
13898
msg = fmt.Sprintf("[%s: %s] is related to an asset with associative value [%s: %s], ", sa.AssetType(), sa.Key(), aa.AssetType(), aa.Key())
139-
msg += fmt.Sprintf("which has a related asset [%s: %s] that was determined associated with [%s: %s] at a confidence of %d out of 100",
99+
msg += fmt.Sprintf("which has a related asset [%s: %s] that is in scope: matches [%s: %s] at a confidence of %d out of 100",
140100
asset.Asset.AssetType(), asset.Asset.Key(), match.AssetType(), match.Key(), conf)
141101
}
142102
}
@@ -168,15 +128,9 @@ func (s *Scope) assetsRelatedToAssetWithAssoc(assoc *dbt.Entity) []*dbt.Entity {
168128
var found bool
169129

170130
switch v := a.Asset.(type) {
171-
/*case *oamdns.FQDN:
172-
ctx, cancel := context.WithTimeout(s.Session.Ctx(), 3*time.Second)
173-
defer cancel()
174-
175-
since := s.ttlStartTime(oam.FQDN, oam.FQDN)
176-
if ents, err := s.Session.DB().IncomingEdges(ctx, a, since, "node"); err != nil || len(ents) == 0 {
131+
case *oamdns.FQDN:
177132
found = true
178133
results = append(results, a)
179-
}*/
180134
case *oamorg.Organization:
181135
found = true
182136
if cert, ok := assoc.Asset.(*oamcert.TLSCertificate); !ok || s.orgNameSimilarToCommon(v, cert) {
@@ -258,10 +212,6 @@ func (s *Scope) awayFromAssetsWithAssociation(assoc *dbt.Entity) ([]*dbt.Entity,
258212
var outRels, inRels []string
259213
var outSince, inSince time.Time
260214
switch assoc.Asset.AssetType() {
261-
/*case oam.FQDN:
262-
in = true
263-
inRels = append(inRels, "node")
264-
inSince = s.ttlStartTime(oam.FQDN, oam.FQDN)*/
265215
case oam.DomainRecord:
266216
out = true
267217
outRels = append(outRels, "registrant_contact")
@@ -412,6 +362,15 @@ func (s *Scope) ttlStartTime(from, to oam.AssetType) time.Time {
412362
return time.Time{}
413363
}
414364

365+
func (s *Scope) confidence(from, to oam.AssetType) int {
366+
if matches, err := s.Session.Config().CheckTransformations(string(from), string(to)); err == nil && matches != nil {
367+
if conf := matches.Confidence(string(to)); conf >= 0 {
368+
return conf
369+
}
370+
}
371+
return -1
372+
}
373+
415374
func (s *Scope) orgNameSimilarToCommon(o *oamorg.Organization, cert *oamcert.TLSCertificate) bool {
416375
swg := metrics.NewSmithWatermanGotoh()
417376
swg.CaseSensitive = false

internal/enum/cli.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,6 @@ func CLIWorkflow(cmdName string, clArgs []string) {
293293
case <-done:
294294
case <-interrupt:
295295
close(done)
296-
return
297296
}
298297

299298
if !args.Options.Silent {

0 commit comments

Comments
 (0)