Skip to content

Commit 7e60f0f

Browse files
committed
starting to remove refs to old asset types
1 parent eeeb79a commit 7e60f0f

File tree

3 files changed

+62
-103
lines changed

3 files changed

+62
-103
lines changed

engine/plugins/service_discovery/http_probes/http_interrogation.go

Lines changed: 43 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
oamcert "github.com/owasp-amass/open-asset-model/certificate"
2222
"github.com/owasp-amass/open-asset-model/domain"
2323
"github.com/owasp-amass/open-asset-model/network"
24+
"github.com/owasp-amass/open-asset-model/relation"
2425
"github.com/owasp-amass/open-asset-model/service"
2526
)
2627

@@ -46,11 +47,6 @@ func (r *interrogation) check(e *et.Event) error {
4647
return nil
4748
}
4849

49-
src := support.GetSource(e.Session, r.plugin.source)
50-
if src == nil {
51-
return errors.New("failed to obtain the plugin source information")
52-
}
53-
5450
matches, err := e.Session.Config().CheckTransformations(string(atype), append(r.transforms, r.plugin.name)...)
5551
if err != nil || matches.Len() == 0 {
5652
return nil
@@ -67,12 +63,13 @@ func (r *interrogation) check(e *et.Event) error {
6763
return err
6864
}
6965

66+
src := r.plugin.source
7067
var findings []*support.Finding
71-
if support.AssetMonitoredWithinTTL(e.Session, e.Asset, src, since) {
72-
findings = append(findings, r.lookup(e, e.Asset, src, since)...)
68+
if support.AssetMonitoredWithinTTL(e.Session, e.Entity, src, since) {
69+
findings = append(findings, r.lookup(e, e.Entity, src, since)...)
7370
} else {
74-
findings = append(findings, r.query(e, e.Asset, src)...)
75-
support.MarkAssetMonitored(e.Session, e.Asset, src)
71+
findings = append(findings, r.query(e, e.Entity, src)...)
72+
support.MarkAssetMonitored(e.Session, e.Entity, src)
7673
}
7774

7875
if len(findings) > 0 {
@@ -81,7 +78,7 @@ func (r *interrogation) check(e *et.Event) error {
8178
return nil
8279
}
8380

84-
func (r *interrogation) lookup(e *et.Event, asset, src *dbt.Asset, since time.Time) []*support.Finding {
81+
func (r *interrogation) lookup(e *et.Event, asset *dbt.Entity, src *et.Source, since time.Time) []*support.Finding {
8582
fqdn := asset.Asset.Key()
8683
var findings []*support.Finding
8784
atype := string(oam.NetworkEndpoint)
@@ -103,11 +100,11 @@ func (r *interrogation) lookup(e *et.Event, asset, src *dbt.Asset, since time.Ti
103100
return findings
104101
}
105102

106-
func (r *interrogation) query(e *et.Event, asset, src *dbt.Asset) []*support.Finding {
103+
func (r *interrogation) query(e *et.Event, entity *dbt.Entity, src *et.Source) []*support.Finding {
107104
var findings []*support.Finding
108105

109106
var addr, host string
110-
if sa, ok := asset.Asset.(*network.SocketAddress); ok {
107+
if sa, ok := entity.Asset.(*network.SocketAddress); ok {
111108
addr = sa.Protocol + "://"
112109
host = sa.IPAddress.String()
113110

@@ -116,7 +113,7 @@ func (r *interrogation) query(e *et.Event, asset, src *dbt.Asset) []*support.Fin
116113
} else {
117114
addr += sa.Address.String()
118115
}
119-
} else if ne, ok := asset.Asset.(*domain.NetworkEndpoint); ok {
116+
} else if ne, ok := entity.Asset.(*domain.NetworkEndpoint); ok {
120117
host = ne.Name
121118
addr = ne.Protocol + "://"
122119

@@ -138,55 +135,42 @@ func (r *interrogation) query(e *et.Event, asset, src *dbt.Asset) []*support.Fin
138135
return findings
139136
}
140137

141-
func (r *interrogation) store(e *et.Event, resp *http.Response, asset, src *dbt.Asset) []*support.Finding {
142-
addr := asset.Asset.Key()
138+
func (r *interrogation) store(e *et.Event, resp *http.Response, entity *dbt.Entity, src *et.Source) []*support.Finding {
139+
addr := entity.Asset.Key()
143140
var findings []*support.Finding
144141

145-
var firstAsset *dbt.Asset
142+
var firstAsset *dbt.Entity
146143
var firstCert *x509.Certificate
147144
if resp.TLS != nil && resp.TLS.HandshakeComplete && len(resp.TLS.PeerCertificates) > 0 {
148-
done := make(chan struct{}, 1)
149-
150-
support.AppendToDBQueue(func() {
151-
defer func() { done <- struct{}{} }()
145+
var prev *dbt.Entity
146+
// traverse the certificate chain
147+
for _, cert := range resp.TLS.PeerCertificates {
148+
c := support.X509ToOAMTLSCertificate(cert)
149+
if c == nil {
150+
break
151+
}
152152

153-
if e.Session.Done() {
154-
return
153+
a, err := e.Session.Cache().CreateAsset(c)
154+
if err != nil {
155+
break
155156
}
156157

157-
var prev *dbt.Asset
158-
// traverse the certificate chain
159-
for _, cert := range resp.TLS.PeerCertificates {
160-
c := support.X509ToOAMTLSCertificate(cert)
161-
if c == nil {
162-
break
163-
}
164-
165-
a, err := e.Session.DB().Create(prev, "issuing_certificate", c)
166-
if err != nil {
167-
break
168-
}
169-
_, _ = e.Session.DB().Link(a, "source", src)
170-
171-
if prev == nil {
172-
firstAsset = a
173-
firstCert = cert
174-
} else {
175-
tls := prev.Asset.(*oamcert.TLSCertificate)
176-
findings = append(findings, &support.Finding{
177-
From: prev,
178-
FromName: tls.SerialNumber,
179-
To: a,
180-
ToName: c.SerialNumber,
181-
ToMeta: cert,
182-
Rel: "issuing_certificate",
183-
})
184-
}
185-
prev = a
158+
if prev == nil {
159+
firstAsset = a
160+
firstCert = cert
161+
} else {
162+
tls := prev.Asset.(*oamcert.TLSCertificate)
163+
findings = append(findings, &support.Finding{
164+
From: prev,
165+
FromName: tls.SerialNumber,
166+
To: a,
167+
ToName: c.SerialNumber,
168+
ToMeta: cert,
169+
Rel: &relation.SimpleRelation{Name: "issuing_certificate"},
170+
})
186171
}
187-
})
188-
<-done
189-
close(done)
172+
prev = a
173+
}
190174
}
191175

192176
serv := support.ServiceWithIdentifier(&r.plugin.hash, e.Session.ID().String(), addr)
@@ -202,18 +186,18 @@ func (r *interrogation) store(e *et.Event, resp *http.Response, asset, src *dbt.
202186
c = firstAsset.Asset.(*oamcert.TLSCertificate)
203187
}
204188

205-
s, err := support.CreateServiceAsset(e.Session, asset, "service", serv, c)
189+
s, err := support.CreateServiceAsset(e.Session, entity, "service", serv, c)
206190
if err != nil {
207191
return findings
208192
}
209193

210194
serv = s.Asset.(*service.Service)
211195
findings = append(findings, &support.Finding{
212-
From: asset,
196+
From: entity,
213197
FromName: addr,
214198
To: s,
215199
ToName: "Service: " + serv.Identifier,
216-
Rel: "service",
200+
Rel: &relation.SimpleRelation{Name: "port"},
217201
})
218202

219203
if firstAsset != nil && firstCert != nil {
@@ -223,24 +207,14 @@ func (r *interrogation) store(e *et.Event, resp *http.Response, asset, src *dbt.
223207
To: firstAsset,
224208
ToName: c.SerialNumber,
225209
ToMeta: firstCert,
226-
Rel: "certificate",
210+
Rel: &relation.SimpleRelation{Name: "certificate"},
227211
})
228212
}
229213

230-
done := make(chan struct{}, 1)
231-
support.AppendToDBQueue(func() {
232-
defer func() { done <- struct{}{} }()
233-
_, _ = e.Session.DB().Link(s, "source", src)
234-
if firstAsset != nil {
235-
_, _ = e.Session.DB().Link(s, "certificate", firstAsset)
236-
}
237-
})
238-
<-done
239-
close(done)
240214
return findings
241215
}
242216

243-
func (r *interrogation) process(e *et.Event, findings []*support.Finding, src *dbt.Asset) {
217+
func (r *interrogation) process(e *et.Event, findings []*support.Finding, src *et.Source) {
244218
support.ProcessAssetsWithSource(e, findings, src, r.plugin.name, r.name)
245219
}
246220

engine/plugins/service_discovery/http_probes/ipaddr_endpoint.go

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
dbt "github.com/owasp-amass/asset-db/types"
1717
oam "github.com/owasp-amass/open-asset-model"
1818
"github.com/owasp-amass/open-asset-model/network"
19+
"github.com/owasp-amass/open-asset-model/property"
1920
)
2021

2122
type ipaddrEndpoint struct {
@@ -28,7 +29,7 @@ func (r *ipaddrEndpoint) Name() string {
2829
}
2930

3031
func (r *ipaddrEndpoint) check(e *et.Event) error {
31-
ip, ok := e.Asset.Asset.(*network.IPAddress)
32+
ip, ok := e.Entity.Asset.(*network.IPAddress)
3233
if !ok {
3334
return errors.New("failed to extract the IPAddress asset")
3435
}
@@ -45,22 +46,18 @@ func (r *ipaddrEndpoint) check(e *et.Event) error {
4546
return nil
4647
}
4748

48-
src := support.GetSource(e.Session, r.plugin.source)
49-
if src == nil {
50-
return errors.New("failed to obtain the plugin source information")
51-
}
52-
5349
since, err := support.TTLStartTime(e.Session.Config(), string(oam.IPAddress), string(oam.SocketAddress), r.name)
5450
if err != nil {
5551
return err
5652
}
5753

54+
src := r.plugin.source
5855
var findings []*support.Finding
59-
if support.AssetMonitoredWithinTTL(e.Session, e.Asset, src, since) {
60-
findings = append(findings, r.lookup(e, e.Asset, src, since)...)
56+
if support.AssetMonitoredWithinTTL(e.Session, e.Entity, src, since) {
57+
findings = append(findings, r.lookup(e, e.Entity, src, since)...)
6158
} else {
62-
findings = append(findings, r.store(e, e.Asset, src)...)
63-
support.MarkAssetMonitored(e.Session, e.Asset, src)
59+
findings = append(findings, r.store(e, e.Entity, src)...)
60+
support.MarkAssetMonitored(e.Session, e.Entity, src)
6461
}
6562

6663
if len(findings) > 0 {
@@ -71,7 +68,7 @@ func (r *ipaddrEndpoint) check(e *et.Event) error {
7168
return nil
7269
}
7370

74-
func (r *ipaddrEndpoint) lookup(e *et.Event, asset, src *dbt.Asset, since time.Time) []*support.Finding {
71+
func (r *ipaddrEndpoint) lookup(e *et.Event, asset *dbt.Entity, src *et.Source, since time.Time) []*support.Finding {
7572
addr := asset.Asset.Key()
7673
var findings []*support.Finding
7774
atype := string(oam.SocketAddress)
@@ -93,7 +90,7 @@ func (r *ipaddrEndpoint) lookup(e *et.Event, asset, src *dbt.Asset, since time.T
9390
return findings
9491
}
9592

96-
func (r *ipaddrEndpoint) store(e *et.Event, asset, src *dbt.Asset) []*support.Finding {
93+
func (r *ipaddrEndpoint) store(e *et.Event, asset *dbt.Entity, src *et.Source) []*support.Finding {
9794
var findings []*support.Finding
9895
ip := asset.Asset.(*network.IPAddress)
9996

@@ -139,31 +136,20 @@ func (r *ipaddrEndpoint) store(e *et.Event, asset, src *dbt.Asset) []*support.Fi
139136
return findings
140137
}
141138

142-
func (r *ipaddrEndpoint) process(e *et.Event, findings []*support.Finding, src *dbt.Asset) {
139+
func (r *ipaddrEndpoint) process(e *et.Event, findings []*support.Finding, src *et.Source) {
143140
support.ProcessAssetsWithSource(e, findings, src, r.plugin.name, r.name)
144141
}
145142

146-
func sweepCallback(e *et.Event, ip *network.IPAddress, src *dbt.Asset) {
147-
done := make(chan *dbt.Asset, 1)
148-
support.AppendToDBQueue(func() {
149-
if e.Session.Done() {
150-
done <- nil
151-
return
152-
}
153-
154-
addr, err := e.Session.DB().Create(nil, "", ip)
155-
if err == nil && addr != nil {
156-
_, _ = e.Session.DB().Link(addr, "source", src)
157-
}
158-
done <- addr
159-
})
160-
161-
if addr := <-done; addr != nil {
143+
func sweepCallback(e *et.Event, ip *network.IPAddress, src *et.Source) {
144+
if entity, err := e.Session.Cache().CreateAsset(ip); err == nil && entity != nil {
145+
_, _ = e.Session.Cache().CreateEntityProperty(entity, &property.SourceProperty{
146+
Source: src.Name,
147+
Confidence: src.Confidence,
148+
})
162149
_ = e.Dispatcher.DispatchEvent(&et.Event{
163150
Name: ip.Address.String(),
164-
Asset: addr,
151+
Entity: entity,
165152
Session: e.Session,
166153
})
167154
}
168-
close(done)
169155
}

engine/plugins/service_discovery/http_probes/plugin.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/owasp-amass/amass/v4/engine/plugins/support"
1212
et "github.com/owasp-amass/amass/v4/engine/types"
1313
oam "github.com/owasp-amass/open-asset-model"
14-
"github.com/owasp-amass/open-asset-model/source"
1514
)
1615

1716
type httpProbing struct {
@@ -20,14 +19,14 @@ type httpProbing struct {
2019
fqdnend *fqdnEndpoint
2120
ipaddr *ipaddrEndpoint
2221
interr *interrogation
23-
source *source.Source
22+
source *et.Source
2423
hash maphash.Hash
2524
}
2625

2726
func NewHTTPProbing() et.Plugin {
2827
return &httpProbing{
2928
name: "HTTP-Probes",
30-
source: &source.Source{
29+
source: &et.Source{
3130
Name: "HTTP-Probes",
3231
Confidence: 100,
3332
},

0 commit comments

Comments
 (0)