Skip to content

Commit 2176edd

Browse files
committed
reducing the number of cache requests
1 parent 70d5b50 commit 2176edd

File tree

10 files changed

+74
-18
lines changed

10 files changed

+74
-18
lines changed

engine/plugins/brute/alterations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (d *alts) check(e *et.Event) error {
7575
return nil
7676
}
7777

78-
if !support.NameResolved(e.Session, fqdn) {
78+
if e.Meta == nil {
7979
return nil
8080
}
8181

engine/plugins/dns/apex.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"log/slog"
1010
"strings"
1111

12-
"github.com/owasp-amass/amass/v4/engine/plugins/support"
1312
et "github.com/owasp-amass/amass/v4/engine/types"
1413
dbt "github.com/owasp-amass/asset-db/types"
1514
oamdns "github.com/owasp-amass/open-asset-model/dns"
@@ -27,7 +26,7 @@ func (d *dnsApex) check(e *et.Event) error {
2726
return errors.New("failed to extract the FQDN asset")
2827
}
2928

30-
if !support.NameResolved(e.Session, fqdn) {
29+
if e.Meta == nil {
3130
return nil
3231
}
3332

engine/plugins/dns/cname.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func (d *dnsCNAME) check(e *et.Event) error {
5050

5151
if len(alias) > 0 {
5252
d.process(e, alias)
53+
support.AddDNSRecordType(e, int(dns.TypeCNAME))
5354
}
5455
return nil
5556
}

engine/plugins/dns/ip.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (d *dnsIP) check(e *et.Event) error {
3939
return errors.New("failed to extract the FQDN asset")
4040
}
4141

42-
if _, found := support.IsCNAME(e.Session, fqdn); found {
42+
if support.HasDNSRecordType(e, int(dns.TypeCNAME)) {
4343
return nil
4444
}
4545

@@ -172,6 +172,12 @@ func (d *dnsIP) process(e *et.Event, name string, addrs []*relIP) {
172172
for _, a := range addrs {
173173
ip := a.ip.Asset.(*oamnet.IPAddress)
174174

175+
if ip.Type == "IPv4" {
176+
support.AddDNSRecordType(e, int(dns.TypeA))
177+
} else if ip.Type == "IPv6" {
178+
support.AddDNSRecordType(e, int(dns.TypeAAAA))
179+
}
180+
175181
_ = e.Dispatcher.DispatchEvent(&et.Event{
176182
Name: ip.Address.String(),
177183
Entity: a.ip,

engine/plugins/dns/reverse.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func (d *dnsReverse) check(e *et.Event) error {
7777

7878
if len(rev) > 0 {
7979
d.process(e, rev)
80+
support.AddDNSRecordType(e, int(dns.TypePTR))
8081

8182
var size int
8283
if _, conf := e.Session.Scope().IsAssetInScope(ip, 0); conf > 0 {

engine/plugins/dns/subs.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (d *dnsSubs) check(e *et.Event) error {
6969
return errors.New("failed to extract the FQDN asset")
7070
}
7171

72-
if !support.NameResolved(e.Session, fqdn) {
72+
if e.Meta == nil {
7373
return nil
7474
}
7575

@@ -83,8 +83,7 @@ func (d *dnsSubs) check(e *et.Event) error {
8383
return err
8484
}
8585

86-
src := d.plugin.source
87-
if names := d.traverse(e, dom, e.Entity, src, since); len(names) > 0 {
86+
if names := d.traverse(e, dom, e.Entity, since); len(names) > 0 {
8887
d.process(e, names)
8988
}
9089
return nil
@@ -136,7 +135,7 @@ func (d *dnsSubs) registered(e *et.Event, name string) string {
136135
return ""
137136
}
138137

139-
func (d *dnsSubs) traverse(e *et.Event, dom string, fqdn *dbt.Entity, src *et.Source, since time.Time) []*relSubs {
138+
func (d *dnsSubs) traverse(e *et.Event, dom string, fqdn *dbt.Entity, since time.Time) []*relSubs {
140139
var alias []*relSubs
141140

142141
dlabels := strings.Split(dom, ".")
@@ -153,7 +152,7 @@ func (d *dnsSubs) traverse(e *et.Event, dom string, fqdn *dbt.Entity, src *et.So
153152
if d.fqdnAvailable(e, sub) {
154153
results := d.lookup(e, sub, since)
155154
if len(results) == 0 {
156-
results = d.query(e, sub, src)
155+
results = d.query(e, sub)
157156
}
158157
alias = append(alias, results...)
159158
}
@@ -187,13 +186,13 @@ func (d *dnsSubs) lookup(e *et.Event, subdomain string, since time.Time) []*relS
187186
return alias
188187
}
189188

190-
func (d *dnsSubs) query(e *et.Event, subdomain string, src *et.Source) []*relSubs {
189+
func (d *dnsSubs) query(e *et.Event, subdomain string) []*relSubs {
191190
apex := true
192191
var alias []*relSubs
193192

194193
for i, t := range d.types {
195194
if rr, err := support.PerformQuery(subdomain, t.Qtype); err == nil && len(rr) > 0 {
196-
if records := d.store(e, subdomain, src, rr); len(records) > 0 {
195+
if records := d.store(e, subdomain, rr); len(records) > 0 {
197196
alias = append(alias, records...)
198197
d.plugin.apexList.Insert(subdomain)
199198
}
@@ -217,7 +216,7 @@ func (d *dnsSubs) query(e *et.Event, subdomain string, src *et.Source) []*relSub
217216

218217
var results []*relSubs
219218
if rr, err := support.PerformQuery(n, dns.TypeSRV); err == nil && len(rr) > 0 {
220-
if records := d.store(e, n, src, rr); len(records) > 0 {
219+
if records := d.store(e, n, rr); len(records) > 0 {
221220
results = append(results, records...)
222221
}
223222
}
@@ -233,7 +232,7 @@ func (d *dnsSubs) query(e *et.Event, subdomain string, src *et.Source) []*relSub
233232
return alias
234233
}
235234

236-
func (d *dnsSubs) store(e *et.Event, name string, src *et.Source, rr []*resolve.ExtractedAnswer) []*relSubs {
235+
func (d *dnsSubs) store(e *et.Event, name string, rr []*resolve.ExtractedAnswer) []*relSubs {
237236
var alias []*relSubs
238237

239238
fqdn, err := e.Session.Cache().CreateAsset(&oamdns.FQDN{Name: name})
@@ -260,8 +259,8 @@ func (d *dnsSubs) store(e *et.Event, name string, src *et.Source, rr []*resolve.
260259
}); err == nil && edge != nil {
261260
alias = append(alias, &relSubs{rtype: "dns_record", alias: fqdn, target: a})
262261
_, _ = e.Session.Cache().CreateEdgeProperty(edge, &general.SourceProperty{
263-
Source: src.Name,
264-
Confidence: src.Confidence,
262+
Source: d.plugin.source.Name,
263+
Confidence: d.plugin.source.Confidence,
265264
})
266265
}
267266
} else {

engine/plugins/dns/txt.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func (d *dnsTXT) check(e *et.Event) error {
4545

4646
if len(txtRecords) > 0 {
4747
d.process(e, e.Entity, txtRecords)
48+
support.AddDNSRecordType(e, int(dns.TypeTXT))
4849
}
4950
return nil
5051
}

engine/plugins/horizontals/fqdn.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"errors"
99
"fmt"
1010

11+
"github.com/miekg/dns"
1112
"github.com/owasp-amass/amass/v4/engine/plugins/support"
1213
"github.com/owasp-amass/amass/v4/engine/sessions/scope"
1314
et "github.com/owasp-amass/amass/v4/engine/types"
@@ -42,8 +43,12 @@ func (h *horfqdn) check(e *et.Event) error {
4243
}
4344
}
4445
}
45-
if len(ptrs) == 0 && !support.NameResolved(e.Session, fqdn) {
46-
return nil
46+
if len(ptrs) == 0 {
47+
if !support.HasDNSRecordType(e, int(dns.TypeA)) &&
48+
!support.HasDNSRecordType(e, int(dns.TypeAAAA)) &&
49+
!support.HasDNSRecordType(e, int(dns.TypeCNAME)) {
50+
return nil
51+
}
4752
}
4853
if _, conf := e.Session.Scope().IsAssetInScope(fqdn, 0); conf > 0 {
4954
return nil

engine/plugins/service_discovery/http_probes/fqdn_endpoint.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strconv"
1010
"time"
1111

12+
"github.com/miekg/dns"
1213
"github.com/owasp-amass/amass/v4/engine/plugins/support"
1314
et "github.com/owasp-amass/amass/v4/engine/types"
1415
dbt "github.com/owasp-amass/asset-db/types"
@@ -35,7 +36,9 @@ func (fe *fqdnEndpoint) check(e *et.Event) error {
3536
if !e.Session.Config().Active {
3637
return nil
3738
}
38-
if !support.NameResolved(e.Session, fqdn) {
39+
if !support.HasDNSRecordType(e, int(dns.TypeA)) &&
40+
!support.HasDNSRecordType(e, int(dns.TypeAAAA)) &&
41+
!support.HasDNSRecordType(e, int(dns.TypeCNAME)) {
3942
return nil
4043
}
4144
if _, conf := e.Session.Scope().IsAssetInScope(fqdn, 0); conf == 0 {

engine/plugins/support/support.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,44 @@ func NameResolved(session et.Session, name *oamdns.FQDN) bool {
257257
}
258258
return false
259259
}
260+
261+
type FQDNMeta struct {
262+
RecordTypes map[int]bool
263+
}
264+
265+
func AddDNSRecordType(e *et.Event, rrtype int) {
266+
if e == nil {
267+
return
268+
} else if _, ok := e.Entity.Asset.(*oamdns.FQDN); !ok {
269+
return
270+
}
271+
272+
if e.Meta == nil {
273+
e.Meta = &FQDNMeta{
274+
RecordTypes: make(map[int]bool),
275+
}
276+
}
277+
278+
if fm, ok := e.Meta.(*FQDNMeta); ok {
279+
fm.RecordTypes[rrtype] = true
280+
}
281+
}
282+
283+
func HasDNSRecordType(e *et.Event, rrtype int) bool {
284+
if e == nil {
285+
return false
286+
} else if _, ok := e.Entity.Asset.(*oamdns.FQDN); !ok {
287+
return false
288+
}
289+
290+
if e.Meta == nil {
291+
return false
292+
}
293+
294+
if fm, ok := e.Meta.(*FQDNMeta); ok {
295+
if _, found := fm.RecordTypes[rrtype]; found {
296+
return true
297+
}
298+
}
299+
return false
300+
}

0 commit comments

Comments
 (0)