@@ -10,13 +10,11 @@ import (
1010 "fmt"
1111 "time"
1212
13- "github.com/caffix/stringset"
1413 "github.com/owasp-amass/amass/v5/engine/plugins/support"
1514 et "github.com/owasp-amass/amass/v5/engine/types"
1615 dbt "github.com/owasp-amass/asset-db/types"
1716 oam "github.com/owasp-amass/open-asset-model"
1817 oamcon "github.com/owasp-amass/open-asset-model/contact"
19- oamorg "github.com/owasp-amass/open-asset-model/org"
2018 oamreg "github.com/owasp-amass/open-asset-model/registration"
2119)
2220
@@ -49,7 +47,12 @@ func (h *horRegRec) check(e *et.Event) error {
4947 return fmt .Errorf ("asset type not supported: %s" , t )
5048 }
5149
52- orgs , locs := h .lookupRegistrantOrgsAndLocations (e , rlabel )
50+ cr , err := h .getRegistrantContactRecord (e , rlabel )
51+ if err != nil {
52+ return nil
53+ }
54+
55+ orgs , locs := h .plugin .lookupContactRecordOrgsAndLocations (e .Session , cr )
5356 if len (orgs ) == 0 && len (locs ) == 0 {
5457 return nil
5558 }
@@ -65,58 +68,6 @@ func (h *horRegRec) check(e *et.Event) error {
6568 return nil
6669}
6770
68- func (h * horRegRec ) lookupRegistrantOrgsAndLocations (e * et.Event , rlabel string ) ([]* oamorg.Organization , []* oamcon.Location ) {
69- cr , err := h .getRegistrantContactRecord (e , rlabel )
70- if err != nil {
71- return nil , nil
72- }
73-
74- var orgents []* dbt.Entity
75- var resorgs []* oamorg.Organization
76- if ents , err := h .plugin .getContactRecordOrganizations (e , cr ); err == nil && len (ents ) > 0 {
77- for _ , ent := range ents {
78- if o , valid := ent .Asset .(* oamorg.Organization ); valid {
79- resorgs = append (resorgs , o )
80- orgents = append (orgents , ent )
81- }
82- }
83- }
84-
85- set := stringset .New ()
86- defer set .Close ()
87-
88- var reslocs []* oamcon.Location
89- for _ , o := range orgents {
90- if ents , err := h .plugin .getOrganizationLocations (e , o ); err == nil && len (ents ) > 0 {
91- for _ , ent := range ents {
92- if set .Has (ent .ID ) {
93- continue
94- }
95-
96- if loc , valid := ent .Asset .(* oamcon.Location ); valid {
97- set .Insert (ent .ID )
98- reslocs = append (reslocs , loc )
99- }
100- }
101- }
102- }
103-
104- if ents , err := h .plugin .getContactRecordLocations (e , cr ); err == nil && len (ents ) > 0 {
105- for _ , ent := range ents {
106- if set .Has (ent .ID ) {
107- continue
108- }
109-
110- if loc , valid := ent .Asset .(* oamcon.Location ); valid {
111- set .Insert (ent .ID )
112- reslocs = append (reslocs , loc )
113- }
114- }
115- }
116-
117- return resorgs , reslocs
118- }
119-
12071func (h * horRegRec ) getRegistrantContactRecord (e * et.Event , label string ) (* dbt.Entity , error ) {
12172 since , err := support .TTLStartTime (e .Session .Config (),
12273 string (e .Entity .Asset .AssetType ()), string (oam .ContactRecord ), h .plugin .name )
@@ -143,29 +94,29 @@ func (h *horRegRec) getRegistrantContactRecord(e *et.Event, label string) (*dbt.
14394 return nil , errors .New ("failed to extract the registrant ContactRecord entity" )
14495}
14596
146- func (h * horRegRec ) processAutnumRecord (e * et.Event , orgs []* oamorg. Organization , locs []* oamcon. Location ) {
97+ func (h * horRegRec ) processAutnumRecord (e * et.Event , orgs []* dbt. Entity , locs []* dbt. Entity ) {
14798 // check if the autnum record / registered autonomous system is in scope
14899 if _ , conf := e .Session .Scope ().IsAssetInScope (e .Entity .Asset , 0 ); conf > 0 {
149100 for _ , o := range orgs {
150- e .Session .Scope ().Add (o )
101+ e .Session .Scope ().Add (o . Asset )
151102 }
152103 for _ , loc := range locs {
153- e .Session .Scope ().Add (loc )
104+ e .Session .Scope ().Add (loc . Asset )
154105 }
155106 return
156107 }
157108
158109 var found bool
159110 for _ , o := range orgs {
160- if _ , conf := e .Session .Scope ().IsAssetInScope (o , 0 ); conf > 0 {
111+ if _ , conf := e .Session .Scope ().IsAssetInScope (o . Asset , 0 ); conf > 0 {
161112 found = true
162113 break
163114 }
164115 }
165116
166117 if ! found {
167118 for _ , loc := range locs {
168- if _ , conf := e .Session .Scope ().IsAssetInScope (loc , 0 ); conf > 0 {
119+ if _ , conf := e .Session .Scope ().IsAssetInScope (loc . Asset , 0 ); conf > 0 {
169120 found = true
170121 break
171122 }
@@ -178,50 +129,50 @@ func (h *horRegRec) processAutnumRecord(e *et.Event, orgs []*oamorg.Organization
178129 e .Session .Scope ().AddASN (an .Number )
179130 }
180131 for _ , o := range orgs {
181- e .Session .Scope ().Add (o )
132+ e .Session .Scope ().Add (o . Asset )
182133 }
183134 for _ , loc := range locs {
184- e .Session .Scope ().Add (loc )
135+ e .Session .Scope ().Add (loc . Asset )
185136 }
186137 }
187138}
188139
189- func (h * horRegRec ) processDomainRecord (e * et.Event , orgs []* oamorg. Organization , locs []* oamcon. Location ) {
140+ func (h * horRegRec ) processDomainRecord (e * et.Event , orgs []* dbt. Entity , locs []* dbt. Entity ) {
190141 // check if the domain record / registered domain name is in scope
191142 if _ , conf := e .Session .Scope ().IsAssetInScope (e .Entity .Asset , 0 ); conf > 0 {
192143 for _ , o := range orgs {
193- e .Session .Scope ().Add (o )
144+ e .Session .Scope ().Add (o . Asset )
194145 }
195146 for _ , loc := range locs {
196- e .Session .Scope ().Add (loc )
147+ e .Session .Scope ().Add (loc . Asset )
197148 }
198149 return
199150 }
200151}
201152
202- func (h * horRegRec ) processIPNetRecord (e * et.Event , orgs []* oamorg. Organization , locs []* oamcon. Location ) {
153+ func (h * horRegRec ) processIPNetRecord (e * et.Event , orgs []* dbt. Entity , locs []* dbt. Entity ) {
203154 // check if the ipnet record / registered netblock is in scope
204155 if _ , conf := e .Session .Scope ().IsAssetInScope (e .Entity .Asset , 0 ); conf > 0 {
205156 for _ , o := range orgs {
206- e .Session .Scope ().Add (o )
157+ e .Session .Scope ().Add (o . Asset )
207158 }
208159 for _ , loc := range locs {
209- e .Session .Scope ().Add (loc )
160+ e .Session .Scope ().Add (loc . Asset )
210161 }
211162 return
212163 }
213164
214165 var found bool
215166 for _ , o := range orgs {
216- if _ , conf := e .Session .Scope ().IsAssetInScope (o , 0 ); conf > 0 {
167+ if _ , conf := e .Session .Scope ().IsAssetInScope (o . Asset , 0 ); conf > 0 {
217168 found = true
218169 break
219170 }
220171 }
221172
222173 if ! found {
223174 for _ , loc := range locs {
224- if _ , conf := e .Session .Scope ().IsAssetInScope (loc , 0 ); conf > 0 {
175+ if _ , conf := e .Session .Scope ().IsAssetInScope (loc . Asset , 0 ); conf > 0 {
225176 found = true
226177 break
227178 }
@@ -234,10 +185,10 @@ func (h *horRegRec) processIPNetRecord(e *et.Event, orgs []*oamorg.Organization,
234185 e .Session .Scope ().AddCIDR (iprec .CIDR .String ())
235186 }
236187 for _ , o := range orgs {
237- e .Session .Scope ().Add (o )
188+ e .Session .Scope ().Add (o . Asset )
238189 }
239190 for _ , loc := range locs {
240- e .Session .Scope ().Add (loc )
191+ e .Session .Scope ().Add (loc . Asset )
241192 }
242193 }
243194}
0 commit comments